|
5 | 5 | */
|
6 | 6 | namespace Magento\Framework\App\Test\Unit\Config;
|
7 | 7 |
|
| 8 | +use Magento\Config\App\Config\Source\EnvironmentConfigSource; |
| 9 | +use Magento\Framework\App\Config\ConfigPathResolver; |
| 10 | +use Magento\Framework\App\Config\Data\ProcessorFactory; |
| 11 | +use Magento\Framework\App\Config\Data\ProcessorInterface; |
| 12 | +use Magento\Framework\App\Config\Initial; |
| 13 | +use Magento\Framework\App\Config\MetadataConfigTypeProcessor; |
| 14 | +use PHPUnit_Framework_MockObject_MockObject as MockObject; |
| 15 | + |
8 | 16 | class MetadataConfigTypeProcessorTest extends \PHPUnit_Framework_TestCase
|
9 | 17 | {
|
10 | 18 | /**
|
11 |
| - * @var \Magento\Framework\App\Config\MetadataProcessor |
| 19 | + * @var MetadataConfigTypeProcessor |
12 | 20 | */
|
13 | 21 | protected $_model;
|
14 | 22 |
|
15 | 23 | /**
|
16 |
| - * @var \PHPUnit_Framework_MockObject_MockObject |
| 24 | + * @var Initial|MockObject |
17 | 25 | */
|
18 | 26 | protected $_initialConfigMock;
|
19 | 27 |
|
20 | 28 | /**
|
21 |
| - * @var \PHPUnit_Framework_MockObject_MockObject |
| 29 | + * @var ProcessorFactory|MockObject |
22 | 30 | */
|
23 | 31 | protected $_modelPoolMock;
|
24 | 32 |
|
25 | 33 | /**
|
26 |
| - * @var \PHPUnit_Framework_MockObject_MockObject |
| 34 | + * @var ProcessorInterface|MockObject |
27 | 35 | */
|
28 | 36 | protected $_backendModelMock;
|
29 | 37 |
|
| 38 | + /** |
| 39 | + * @var EnvironmentConfigSource|MockObject |
| 40 | + */ |
| 41 | + private $environmentConfigSourceMock; |
| 42 | + |
| 43 | + /** |
| 44 | + * @var ConfigPathResolver|MockObject |
| 45 | + */ |
| 46 | + private $configPathResolverMock; |
| 47 | + |
30 | 48 | protected function setUp()
|
31 | 49 | {
|
32 |
| - $this->_modelPoolMock = $this->getMock( |
33 |
| - \Magento\Framework\App\Config\Data\ProcessorFactory::class, |
34 |
| - [], |
35 |
| - [], |
36 |
| - '', |
37 |
| - false |
38 |
| - ); |
39 |
| - $this->_initialConfigMock = $this->getMock(\Magento\Framework\App\Config\Initial::class, [], [], '', false); |
40 |
| - $this->_backendModelMock = $this->getMock(\Magento\Framework\App\Config\Data\ProcessorInterface::class); |
41 |
| - $this->_initialConfigMock->expects( |
42 |
| - $this->any() |
43 |
| - )->method( |
44 |
| - 'getMetadata' |
45 |
| - )->will( |
46 |
| - $this->returnValue(['some/config/path' => ['backendModel' => 'Custom_Backend_Model']]) |
47 |
| - ); |
48 |
| - $this->_model = new \Magento\Framework\App\Config\MetadataConfigTypeProcessor( |
| 50 | + $this->_modelPoolMock = $this->getMockBuilder(ProcessorFactory::class) |
| 51 | + ->disableOriginalConstructor() |
| 52 | + ->getMock(); |
| 53 | + $this->_initialConfigMock = $this->getMockBuilder(Initial::class) |
| 54 | + ->disableOriginalConstructor() |
| 55 | + ->getMock(); |
| 56 | + $this->_backendModelMock= $this->getMockBuilder(ProcessorInterface::class) |
| 57 | + ->getMockForAbstractClass(); |
| 58 | + $this->environmentConfigSourceMock = $this->getMockBuilder(EnvironmentConfigSource::class) |
| 59 | + ->disableOriginalConstructor() |
| 60 | + ->getMock(); |
| 61 | + $this->configPathResolverMock = $this->getMockBuilder(ConfigPathResolver::class) |
| 62 | + ->disableOriginalConstructor() |
| 63 | + ->getMock(); |
| 64 | + $this->_initialConfigMock->expects($this->once()) |
| 65 | + ->method('getMetadata') |
| 66 | + ->willReturn([ |
| 67 | + 'some/config/path1' => ['backendModel' => 'Custom_Backend_Model'], |
| 68 | + 'some/config/path2' => ['backendModel' => 'Custom_Backend_Model'], |
| 69 | + 'some/config/path3' => ['backendModel' => 'Custom_Backend_Model'] |
| 70 | + ]); |
| 71 | + |
| 72 | + $this->_model = new MetadataConfigTypeProcessor( |
49 | 73 | $this->_modelPoolMock,
|
50 |
| - $this->_initialConfigMock |
| 74 | + $this->_initialConfigMock, |
| 75 | + $this->environmentConfigSourceMock, |
| 76 | + $this->configPathResolverMock |
51 | 77 | );
|
52 | 78 | }
|
53 | 79 |
|
54 | 80 | public function testProcess()
|
55 | 81 | {
|
56 |
| - $this->_modelPoolMock->expects( |
57 |
| - $this->once() |
58 |
| - )->method( |
59 |
| - 'get' |
60 |
| - )->with( |
61 |
| - 'Custom_Backend_Model' |
62 |
| - )->will( |
63 |
| - $this->returnValue($this->_backendModelMock) |
64 |
| - ); |
65 |
| - $this->_backendModelMock->expects( |
66 |
| - $this->once() |
67 |
| - )->method( |
68 |
| - 'processValue' |
69 |
| - )->with( |
70 |
| - 'value' |
71 |
| - )->will( |
72 |
| - $this->returnValue('processed_value') |
73 |
| - ); |
74 |
| - $data = ['default' => [ 'some' => ['config' => ['path' => 'value']], 'active' => 1]]; |
| 82 | + $this->configPathResolverMock->expects($this->exactly(6)) |
| 83 | + ->method('resolve') |
| 84 | + ->withConsecutive( |
| 85 | + ['some/config/path1', 'default'], |
| 86 | + ['some/config/path2', 'default'], |
| 87 | + ['some/config/path3', 'default'], |
| 88 | + ['some/config/path1', 'websites', 'website_one'], |
| 89 | + ['some/config/path2', 'websites', 'website_one'], |
| 90 | + ['some/config/path3', 'websites', 'website_one'] |
| 91 | + ) |
| 92 | + ->willReturnOnConsecutiveCalls( |
| 93 | + 'default/some/config/path1', |
| 94 | + 'default/some/config/path2', |
| 95 | + 'default/some/config/path3', |
| 96 | + 'websites/website_one/some/config/path1', |
| 97 | + 'websites/website_one/some/config/path2', |
| 98 | + 'websites/website_one/some/config/path3' |
| 99 | + ); |
| 100 | + $this->environmentConfigSourceMock->expects($this->exactly(6)) |
| 101 | + ->method('get') |
| 102 | + ->withConsecutive( |
| 103 | + ['default/some/config/path1'], |
| 104 | + ['default/some/config/path2'], |
| 105 | + ['default/some/config/path3'], |
| 106 | + ['websites/website_one/some/config/path1'], |
| 107 | + ['websites/website_one/some/config/path2'], |
| 108 | + ['websites/website_one/some/config/path3'] |
| 109 | + ) |
| 110 | + ->willReturnOnConsecutiveCalls( |
| 111 | + 'someValue', |
| 112 | + [], |
| 113 | + 'someValue', |
| 114 | + [], |
| 115 | + 'someValue', |
| 116 | + [] |
| 117 | + ); |
| 118 | + $this->_modelPoolMock->expects($this->exactly(3)) |
| 119 | + ->method('get') |
| 120 | + ->with('Custom_Backend_Model') |
| 121 | + ->willReturn($this->_backendModelMock); |
| 122 | + $this->_backendModelMock->expects($this->exactly(3)) |
| 123 | + ->method('processValue') |
| 124 | + ->withConsecutive( |
| 125 | + ['value2'], |
| 126 | + ['value1'], |
| 127 | + ['value3'] |
| 128 | + ) |
| 129 | + ->willReturnOnConsecutiveCalls( |
| 130 | + 'default_processed_value_path2', |
| 131 | + 'website_one_processed_value_path1', |
| 132 | + 'website_one_processed_value_path3' |
| 133 | + ); |
| 134 | + |
| 135 | + $data = [ |
| 136 | + 'default' => [ |
| 137 | + 'some' => [ |
| 138 | + 'config' => [ |
| 139 | + 'path1' => 'value1', |
| 140 | + 'path2' => 'value2', |
| 141 | + 'path3' => 'value3' |
| 142 | + ] |
| 143 | + ] |
| 144 | + ], |
| 145 | + 'websites' => [ |
| 146 | + 'website_one' => [ |
| 147 | + 'some' => [ |
| 148 | + 'config' => [ |
| 149 | + 'path1' => 'value1', |
| 150 | + 'path2' => 'value2', |
| 151 | + 'path3' => 'value3', |
| 152 | + ] |
| 153 | + ] |
| 154 | + ] |
| 155 | + ] |
| 156 | + ]; |
| 157 | + |
75 | 158 | $expectedResult = $data;
|
76 |
| - $expectedResult['default']['some']['config']['path'] = 'processed_value'; |
| 159 | + $expectedResult['default']['some']['config']['path2'] = 'default_processed_value_path2'; |
| 160 | + $expectedResult['websites']['website_one']['some']['config']['path1'] = 'website_one_processed_value_path1'; |
| 161 | + $expectedResult['websites']['website_one']['some']['config']['path3'] = 'website_one_processed_value_path3'; |
| 162 | + |
77 | 163 | $this->assertEquals($expectedResult, $this->_model->process($data));
|
78 | 164 | }
|
79 | 165 | }
|
0 commit comments