forked from tomispepe/magento2-1
/
ConfigTest.php
executable file
·117 lines (104 loc) · 5.07 KB
/
ConfigTest.php
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
112
113
114
115
116
117
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\View\Test\Unit;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
class ConfigTest extends \PHPUnit_Framework_TestCase
{
/** @var \Magento\Framework\View\Config */
protected $config;
/** @var ObjectManagerHelper */
protected $objectManagerHelper;
/** @var \Magento\Framework\Module\Dir\Reader|\PHPUnit_Framework_MockObject_MockObject */
protected $readerMock;
/** @var \Magento\Framework\Filesystem|\PHPUnit_Framework_MockObject_MockObject */
protected $filesystemMock;
/** @var \Magento\Framework\View\Asset\Repository|\PHPUnit_Framework_MockObject_MockObject */
protected $repositoryMock;
/** @var \Magento\Framework\View\FileSystem|\PHPUnit_Framework_MockObject_MockObject */
protected $fileSystemMock;
/** @var \Magento\Framework\Config\FileIteratorFactory|\PHPUnit_Framework_MockObject_MockObject */
protected $fileIteratorFactoryMock;
/** @var \Magento\Framework\Filesystem\Directory\ReadInterface|\PHPUnit_Framework_MockObject_MockObject */
protected $directoryReadMock;
protected function setUp()
{
$this->readerMock = $this->getMock('Magento\Framework\Module\Dir\Reader', [], [], '', false);
$this->filesystemMock = $this->getMock('Magento\Framework\Filesystem', [], [], '', false);
$this->directoryReadMock = $this->getMock('Magento\Framework\Filesystem\Directory\ReadInterface');
$this->filesystemMock->expects($this->once())
->method('getDirectoryRead')
->with($this->equalTo(DirectoryList::ROOT))
->will($this->returnValue($this->directoryReadMock));
$this->repositoryMock = $this->getMock('Magento\Framework\View\Asset\Repository', [], [], '', false);
$this->fileSystemMock = $this->getMock('Magento\Framework\View\FileSystem', [], [], '', false);
$this->fileIteratorFactoryMock = $this->getMock('Magento\Framework\Config\FileIteratorFactory');
$this->objectManagerHelper = new ObjectManagerHelper($this);
$this->config = $this->objectManagerHelper->getObject(
'Magento\Framework\View\Config',
[
'moduleReader' => $this->readerMock,
'filesystem' => $this->filesystemMock,
'assetRepo' => $this->repositoryMock,
'viewFileSystem' => $this->fileSystemMock,
'fileIteratorFactory' => $this->fileIteratorFactoryMock
]
);
}
public function testGetViewConfig()
{
$themeMock = $this->getMock(
'Magento\Theme\Model\Theme',
['getCode', 'getCustomization', 'getCustomViewConfigPath'],
[],
'',
false
);
$themeMock->expects($this->atLeastOnce())
->method('getCode')
->will($this->returnValue(2));
$themeMock->expects($this->once())
->method('getCustomization')
->will($this->returnSelf());
$themeMock->expects($this->once())
->method('getCustomViewConfigPath')
->will($this->returnValue(''));
$params = ['themeModel' => $themeMock];
$configFile = 'config.xml';
$this->repositoryMock->expects($this->atLeastOnce())
->method('updateDesignParams')
->with($this->equalTo($params))
->will($this->returnSelf());
$iterator = $this->getMock('Magento\Framework\Config\FileIterator', [], [], '', false);
$iterator->expects($this->once())
->method('toArray')
->will($this->returnValue([]));
$this->readerMock->expects($this->once())
->method('getConfigurationFiles')
->with($this->equalTo(basename(\Magento\Framework\View\ConfigInterface::CONFIG_FILE_NAME)))
->will($this->returnValue($iterator));
$this->directoryReadMock->expects($this->once())
->method('isExist')
->with($this->anything())
->will($this->returnValue(true));
$this->fileSystemMock->expects($this->once())
->method('getFilename')
->with($this->equalTo(\Magento\Framework\View\ConfigInterface::CONFIG_FILE_NAME), $params)
->will($this->returnValue($configFile));
$this->directoryReadMock->expects($this->any())
->method('getRelativePath')
->with($this->equalTo($configFile))
->will($this->returnArgument(0));
$xmlData = '<view><vars module="Magento_Catalog"><var name="test">1</var></vars></view>';
$this->directoryReadMock->expects($this->once())
->method('readFile')
->with($this->equalTo($configFile))
->will($this->returnValue($xmlData));
$this->assertInstanceOf('Magento\Framework\Config\View', $this->config->getViewConfig($params));
// lazy load test
$this->assertInstanceOf('Magento\Framework\Config\View', $this->config->getViewConfig($params));
}
}