CountryTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Directory\Test\Unit\Model;
  7. use Magento\Directory\Model\Country;
  8. class CountryTest extends \PHPUnit\Framework\TestCase
  9. {
  10. protected $country;
  11. /**
  12. * @var \Magento\Framework\Locale\ListsInterface|\PHPUnit_Framework_MockObject_MockObject
  13. */
  14. protected $localeListsMock;
  15. protected function setUp()
  16. {
  17. $this->localeListsMock = $this->createMock(\Magento\Framework\Locale\ListsInterface::class);
  18. $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  19. $this->country = $objectManager->getObject(
  20. \Magento\Directory\Model\Country::class,
  21. ['localeLists' => $this->localeListsMock]
  22. );
  23. }
  24. public function testGetName()
  25. {
  26. $this->localeListsMock->expects($this->once())
  27. ->method('getCountryTranslation')
  28. ->with(1, null)
  29. ->willReturn('United States');
  30. $this->country->setId(1);
  31. $this->assertEquals('United States', $this->country->getName());
  32. }
  33. public function testGetNameWithLocale()
  34. {
  35. $this->localeListsMock->expects($this->once())
  36. ->method('getCountryTranslation')
  37. ->with(1, 'de_DE')
  38. ->willReturn('Vereinigte Staaten');
  39. $this->country->setId(1);
  40. $this->assertEquals('Vereinigte Staaten', $this->country->getName('de_DE'));
  41. }
  42. }