InformationTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Store\Test\Unit\Model;
  7. use Magento\Store\Model\Information;
  8. class InformationTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var Information
  12. */
  13. protected $model;
  14. /**
  15. * @var \Magento\Store\Model\Store|\PHPUnit_Framework_MockObject_MockObject
  16. */
  17. protected $store;
  18. /**
  19. * @var \Magento\Store\Model\Address\Renderer|\PHPUnit_Framework_MockObject_MockObject
  20. */
  21. protected $renderer;
  22. /**
  23. * @var \Magento\Directory\Model\RegionFactory|\PHPUnit_Framework_MockObject_MockObject
  24. */
  25. protected $regionFactory;
  26. /**
  27. * @var \Magento\Directory\Model\CountryFactory|\PHPUnit_Framework_MockObject_MockObject
  28. */
  29. protected $countryFactory;
  30. /**
  31. * @var array
  32. */
  33. protected $mockConfigData;
  34. /**
  35. * Init mocks for tests
  36. */
  37. protected function setUp()
  38. {
  39. $mockData = $this->mockConfigData = [
  40. Information::XML_PATH_STORE_INFO_NAME => 'Country Furnishings',
  41. Information::XML_PATH_STORE_INFO_PHONE => '000-000-0000',
  42. Information::XML_PATH_STORE_INFO_HOURS => '9 AM to 5 PM',
  43. Information::XML_PATH_STORE_INFO_STREET_LINE1 => '1234 Example Ct',
  44. Information::XML_PATH_STORE_INFO_STREET_LINE2 => 'Suite A',
  45. Information::XML_PATH_STORE_INFO_CITY => 'Aldburg',
  46. Information::XML_PATH_STORE_INFO_POSTCODE => '65804',
  47. Information::XML_PATH_STORE_INFO_REGION_CODE => 1989,
  48. Information::XML_PATH_STORE_INFO_COUNTRY_CODE => 'ED',
  49. Information::XML_PATH_STORE_INFO_VAT_NUMBER => '123456789',
  50. ];
  51. $this->store = $this->createMock(\Magento\Store\Model\Store::class);
  52. $this->store->expects($this->any())
  53. ->method('getConfig')
  54. ->willReturnCallback(function ($path) use ($mockData) {
  55. return isset($mockData[$path]) ? $mockData[$path] : null;
  56. });
  57. $this->renderer = $this->getMockBuilder(\Magento\Store\Model\Address\Renderer::class)
  58. ->disableOriginalConstructor()
  59. ->setMethods(['format'])
  60. ->getMock();
  61. $this->renderer->expects($this->once())
  62. ->method('format')
  63. ->willReturnCallback(function ($storeInfo) {
  64. return implode("\n", $storeInfo->getData());
  65. });
  66. $region = $this->createPartialMock(\Magento\Framework\DataObject::class, ['load', 'getName']);
  67. $region->expects($this->once())->method('load')->willReturnSelf();
  68. $region->expects($this->once())->method('getName')->willReturn('Rohan');
  69. $this->regionFactory = $this->createMock(\Magento\Directory\Model\RegionFactory::class);
  70. $this->regionFactory->expects($this->once())->method('create')->willReturn($region);
  71. $country = $this->createPartialMock(\Magento\Framework\DataObject::class, ['loadByCode', 'getName']);
  72. $country->expects($this->once())->method('loadByCode')->with('ED')->willReturnSelf();
  73. $country->expects($this->once())->method('getName')->willReturn('Edoras');
  74. $this->countryFactory = $this->createMock(\Magento\Directory\Model\CountryFactory::class);
  75. $this->countryFactory->expects($this->once())->method('create')->willReturn($country);
  76. $this->model = new Information(
  77. $this->renderer,
  78. $this->regionFactory,
  79. $this->countryFactory
  80. );
  81. }
  82. /**
  83. * @covers \Magento\Store\Model\Information::getFormattedAddress
  84. * @covers \Magento\Store\Model\Information::getStoreInformationObject
  85. */
  86. public function testGetFormattedAddress()
  87. {
  88. $expected = implode("\n", $this->mockConfigData + ['country' => 'Rohan', 'region' => 'Edoras']);
  89. $result = $this->model->getFormattedAddress($this->store);
  90. $this->assertEquals($expected, $result);
  91. }
  92. }