Skip to content

Commit 070c6ce

Browse files
author
Yuri Kovsher
committed
MAGETWO-22618: View File Collectors Don't Support All glob() Patterns
1 parent 83cc2cf commit 070c6ce

File tree

1 file changed

+69
-61
lines changed
  • lib/internal/Magento/Framework/View/Test/Unit/File/Collector

1 file changed

+69
-61
lines changed

lib/internal/Magento/Framework/View/Test/Unit/File/Collector/ThemeTest.php

Lines changed: 69 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,21 @@
55
*/
66
namespace Magento\Framework\View\Test\Unit\File\Collector;
77

8-
use \Magento\Framework\View\File\Collector\Theme;
9-
8+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
109
use Magento\Framework\View\File\Factory;
1110

12-
/**
13-
* Tests Theme
14-
*/
1511
class ThemeTest extends \PHPUnit_Framework_TestCase
1612
{
13+
/**
14+
* @var \Magento\Framework\View\File\Collector\Theme
15+
*/
16+
protected $themeFileCollector;
17+
18+
/**
19+
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
20+
*/
21+
protected $objectManagerHelper;
22+
1723
/**
1824
* @var \Magento\Framework\Filesystem|\PHPUnit_Framework_MockObject_MockObject
1925
*/
@@ -27,7 +33,7 @@ class ThemeTest extends \PHPUnit_Framework_TestCase
2733
/**
2834
* @var \Magento\Framework\Filesystem\Directory\ReadInterface|\PHPUnit_Framework_MockObject_MockObject
2935
*/
30-
protected $themesDirectoryMock;
36+
protected $directoryMock;
3137

3238
/**
3339
* @var \Magento\Framework\View\Design\ThemeInterface|\PHPUnit_Framework_MockObject_MockObject
@@ -37,99 +43,101 @@ class ThemeTest extends \PHPUnit_Framework_TestCase
3743
public function setup()
3844
{
3945
$this->filesystemMock = $this->getMockBuilder('Magento\Framework\Filesystem')
40-
->disableOriginalConstructor()->getMock();
41-
42-
$this->themesDirectoryMock = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\ReadInterface')
46+
->disableOriginalConstructor()
47+
->getMock();
48+
$this->directoryMock = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\ReadInterface')
4349
->getMock();
44-
$this->filesystemMock->expects($this->any())->method('getDirectoryRead')
45-
->will($this->returnValue($this->themesDirectoryMock));
46-
4750
$this->fileFactoryMock = $this->getMockBuilder('Magento\Framework\View\File\Factory')
48-
->disableOriginalConstructor()->getMock();
51+
->disableOriginalConstructor()
52+
->getMock();
53+
$this->themeMock = $this->getMockBuilder('Magento\Framework\View\Design\ThemeInterface')
54+
->getMock();
4955

50-
$this->themeMock = $this->getMockBuilder('Magento\Framework\View\Design\ThemeInterface')->getMock();
56+
$this->filesystemMock->expects($this->any())
57+
->method('getDirectoryRead')
58+
->willReturn($this->directoryMock);
59+
60+
$this->objectManagerHelper = new ObjectManagerHelper($this);
61+
$this->themeFileCollector = $this->objectManagerHelper->getObject(
62+
'Magento\Framework\View\File\Collector\Theme',
63+
[
64+
'filesystem' => $this->filesystemMock,
65+
'fileFactory' => $this->fileFactoryMock
66+
]
67+
);
5168
}
5269

5370
public function testGetFilesEmpty()
5471
{
55-
$this->themesDirectoryMock->expects($this->any())->method('search')->will($this->returnValue([]));
56-
$theme = new Theme(
57-
$this->filesystemMock,
58-
$this->fileFactoryMock
59-
);
72+
$this->directoryMock->expects($this->any())
73+
->method('search')
74+
->willReturn([]);
6075

6176
// Verify no files were returned
62-
$this->assertEquals([], $theme->getFiles($this->themeMock, ''));
77+
$this->assertEquals([], $this->themeFileCollector->getFiles($this->themeMock, ''));
6378
}
6479

6580
public function testGetFilesSingle()
6681
{
6782
$filePath = '/opt/magento2/app/design/frontend/Magento/blank/Magento_Customer/css/something.less';
68-
$this->themesDirectoryMock->expects($this->once())
69-
->method('search')
70-
->will($this->returnValue(['file']));
71-
$this->themesDirectoryMock->expects($this->once())
72-
->method('getAbsolutePath')
73-
->with('file')
74-
->will($this->returnValue($filePath));
7583

7684
$fileMock = $this->getMockBuilder('Magento\Framework\View\File')
77-
->disableOriginalConstructor()->getMock();
85+
->disableOriginalConstructor()
86+
->getMock();
7887

88+
$this->directoryMock->expects($this->once())
89+
->method('search')
90+
->willReturn(['file']);
91+
$this->directoryMock->expects($this->once())
92+
->method('getAbsolutePath')
93+
->with('file')
94+
->willReturn($filePath);
7995
$this->fileFactoryMock->expects($this->once())
8096
->method('create')
81-
->with($this->equalTo($filePath), null, $this->themeMock)
82-
->will($this->returnValue($fileMock));
83-
84-
$theme = new Theme(
85-
$this->filesystemMock,
86-
$this->fileFactoryMock
87-
);
97+
->with($filePath, null, $this->themeMock)
98+
->willReturn($fileMock);
8899

89100
// One file was returned from search
90-
$this->assertEquals([$fileMock], $theme->getFiles($this->themeMock, 'css/*.less'));
101+
$this->assertEquals([$fileMock], $this->themeFileCollector->getFiles($this->themeMock, 'css/*.less'));
91102
}
92103

93104
public function testGetFilesMultiple()
94105
{
95106
$dirPath = '/Magento_Customer/css/';
96107
$themePath = '/opt/magento2/app/design/frontend/Magento/blank';
97108
$searchPath = 'css/*.test';
98-
$this->themeMock->expects($this->any())->method('getFullPath')
99-
->will($this->returnValue($themePath));
100-
101-
$this->themesDirectoryMock->expects($this->any())
102-
->method('getAbsolutePath')
103-
->will(
104-
$this->returnValueMap(
105-
[
106-
['fileA.test', $dirPath . 'fileA.test'],
107-
['fileB.tst', $dirPath . 'fileB.tst'],
108-
['fileC.test', $dirPath . 'fileC.test'],
109-
]
110-
)
111-
);
112109

113110
$fileMock = $this->getMockBuilder('Magento\Framework\View\File')
114-
->disableOriginalConstructor()->getMock();
111+
->disableOriginalConstructor()
112+
->getMock();
115113

114+
$this->themeMock->expects($this->any())
115+
->method('getFullPath')
116+
->willReturn($themePath);
117+
$this->directoryMock->expects($this->any())
118+
->method('getAbsolutePath')
119+
->willReturnMap(
120+
[
121+
['fileA.test', $dirPath . 'fileA.test'],
122+
['fileB.tst', $dirPath . 'fileB.tst'],
123+
['fileC.test', $dirPath . 'fileC.test'],
124+
]
125+
);
116126
// Verifies correct files are searched for
117-
$this->themesDirectoryMock->expects($this->once())
127+
$this->directoryMock->expects($this->once())
118128
->method('search')
119129
->with($themePath . '/' . $searchPath)
120-
->will($this->returnValue(['fileA.test', 'fileC.test']));
121-
130+
->willReturn(['fileA.test', 'fileC.test']);
122131
// Verifies Magento_Customer was correctly produced from directory path
123132
$this->fileFactoryMock->expects($this->any())
124133
->method('create')
125-
->with($this->isType('string'), null, $this->equalTo($this->themeMock))
126-
->will($this->returnValue($fileMock));
134+
->with($this->isType('string'), null, $this->themeMock)
135+
->willReturn($fileMock);
127136

128-
$theme = new Theme(
129-
$this->filesystemMock,
130-
$this->fileFactoryMock
131-
);
132137
// Only two files should be in array, which were returned from search
133-
$this->assertEquals([$fileMock, $fileMock], $theme->getFiles($this->themeMock, 'css/*.test'));
138+
$this->assertEquals(
139+
[$fileMock, $fileMock],
140+
$this->themeFileCollector->getFiles($this->themeMock, 'css/*.test')
141+
);
134142
}
135143
}

0 commit comments

Comments
 (0)