123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Store\Test\Unit\Model;
- use Magento\Store\Model\Information;
- class InformationTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var Information
- */
- protected $model;
- /**
- * @var \Magento\Store\Model\Store|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $store;
- /**
- * @var \Magento\Store\Model\Address\Renderer|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $renderer;
- /**
- * @var \Magento\Directory\Model\RegionFactory|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $regionFactory;
- /**
- * @var \Magento\Directory\Model\CountryFactory|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $countryFactory;
- /**
- * @var array
- */
- protected $mockConfigData;
- /**
- * Init mocks for tests
- */
- protected function setUp()
- {
- $mockData = $this->mockConfigData = [
- Information::XML_PATH_STORE_INFO_NAME => 'Country Furnishings',
- Information::XML_PATH_STORE_INFO_PHONE => '000-000-0000',
- Information::XML_PATH_STORE_INFO_HOURS => '9 AM to 5 PM',
- Information::XML_PATH_STORE_INFO_STREET_LINE1 => '1234 Example Ct',
- Information::XML_PATH_STORE_INFO_STREET_LINE2 => 'Suite A',
- Information::XML_PATH_STORE_INFO_CITY => 'Aldburg',
- Information::XML_PATH_STORE_INFO_POSTCODE => '65804',
- Information::XML_PATH_STORE_INFO_REGION_CODE => 1989,
- Information::XML_PATH_STORE_INFO_COUNTRY_CODE => 'ED',
- Information::XML_PATH_STORE_INFO_VAT_NUMBER => '123456789',
- ];
- $this->store = $this->createMock(\Magento\Store\Model\Store::class);
- $this->store->expects($this->any())
- ->method('getConfig')
- ->willReturnCallback(function ($path) use ($mockData) {
- return isset($mockData[$path]) ? $mockData[$path] : null;
- });
- $this->renderer = $this->getMockBuilder(\Magento\Store\Model\Address\Renderer::class)
- ->disableOriginalConstructor()
- ->setMethods(['format'])
- ->getMock();
- $this->renderer->expects($this->once())
- ->method('format')
- ->willReturnCallback(function ($storeInfo) {
- return implode("\n", $storeInfo->getData());
- });
- $region = $this->createPartialMock(\Magento\Framework\DataObject::class, ['load', 'getName']);
- $region->expects($this->once())->method('load')->willReturnSelf();
- $region->expects($this->once())->method('getName')->willReturn('Rohan');
- $this->regionFactory = $this->createMock(\Magento\Directory\Model\RegionFactory::class);
- $this->regionFactory->expects($this->once())->method('create')->willReturn($region);
- $country = $this->createPartialMock(\Magento\Framework\DataObject::class, ['loadByCode', 'getName']);
- $country->expects($this->once())->method('loadByCode')->with('ED')->willReturnSelf();
- $country->expects($this->once())->method('getName')->willReturn('Edoras');
- $this->countryFactory = $this->createMock(\Magento\Directory\Model\CountryFactory::class);
- $this->countryFactory->expects($this->once())->method('create')->willReturn($country);
- $this->model = new Information(
- $this->renderer,
- $this->regionFactory,
- $this->countryFactory
- );
- }
- /**
- * @covers \Magento\Store\Model\Information::getFormattedAddress
- * @covers \Magento\Store\Model\Information::getStoreInformationObject
- */
- public function testGetFormattedAddress()
- {
- $expected = implode("\n", $this->mockConfigData + ['country' => 'Rohan', 'region' => 'Edoras']);
- $result = $this->model->getFormattedAddress($this->store);
- $this->assertEquals($expected, $result);
- }
- }
|