1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?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);
}
}