5
5
*/
6
6
namespace Magento \Framework \View \Test \Unit \File \Collector ;
7
7
8
- use \Magento \Framework \View \File \Collector \Theme ;
9
-
8
+ use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
10
9
use Magento \Framework \View \File \Factory ;
11
10
12
- /**
13
- * Tests Theme
14
- */
15
11
class ThemeTest extends \PHPUnit_Framework_TestCase
16
12
{
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
+
17
23
/**
18
24
* @var \Magento\Framework\Filesystem|\PHPUnit_Framework_MockObject_MockObject
19
25
*/
@@ -27,7 +33,7 @@ class ThemeTest extends \PHPUnit_Framework_TestCase
27
33
/**
28
34
* @var \Magento\Framework\Filesystem\Directory\ReadInterface|\PHPUnit_Framework_MockObject_MockObject
29
35
*/
30
- protected $ themesDirectoryMock ;
36
+ protected $ directoryMock ;
31
37
32
38
/**
33
39
* @var \Magento\Framework\View\Design\ThemeInterface|\PHPUnit_Framework_MockObject_MockObject
@@ -37,99 +43,101 @@ class ThemeTest extends \PHPUnit_Framework_TestCase
37
43
public function setup ()
38
44
{
39
45
$ 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 ' )
43
49
->getMock ();
44
- $ this ->filesystemMock ->expects ($ this ->any ())->method ('getDirectoryRead ' )
45
- ->will ($ this ->returnValue ($ this ->themesDirectoryMock ));
46
-
47
50
$ 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 ();
49
55
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
+ );
51
68
}
52
69
53
70
public function testGetFilesEmpty ()
54
71
{
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 ([]);
60
75
61
76
// Verify no files were returned
62
- $ this ->assertEquals ([], $ theme ->getFiles ($ this ->themeMock , '' ));
77
+ $ this ->assertEquals ([], $ this -> themeFileCollector ->getFiles ($ this ->themeMock , '' ));
63
78
}
64
79
65
80
public function testGetFilesSingle ()
66
81
{
67
82
$ 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 ));
75
83
76
84
$ fileMock = $ this ->getMockBuilder ('Magento\Framework\View\File ' )
77
- ->disableOriginalConstructor ()->getMock ();
85
+ ->disableOriginalConstructor ()
86
+ ->getMock ();
78
87
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 );
79
95
$ this ->fileFactoryMock ->expects ($ this ->once ())
80
96
->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 );
88
99
89
100
// 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 ' ));
91
102
}
92
103
93
104
public function testGetFilesMultiple ()
94
105
{
95
106
$ dirPath = '/Magento_Customer/css/ ' ;
96
107
$ themePath = '/opt/magento2/app/design/frontend/Magento/blank ' ;
97
108
$ 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
- );
112
109
113
110
$ fileMock = $ this ->getMockBuilder ('Magento\Framework\View\File ' )
114
- ->disableOriginalConstructor ()->getMock ();
111
+ ->disableOriginalConstructor ()
112
+ ->getMock ();
115
113
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
+ );
116
126
// Verifies correct files are searched for
117
- $ this ->themesDirectoryMock ->expects ($ this ->once ())
127
+ $ this ->directoryMock ->expects ($ this ->once ())
118
128
->method ('search ' )
119
129
->with ($ themePath . '/ ' . $ searchPath )
120
- ->will ($ this ->returnValue (['fileA.test ' , 'fileC.test ' ]));
121
-
130
+ ->willReturn (['fileA.test ' , 'fileC.test ' ]);
122
131
// Verifies Magento_Customer was correctly produced from directory path
123
132
$ this ->fileFactoryMock ->expects ($ this ->any ())
124
133
->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 );
127
136
128
- $ theme = new Theme (
129
- $ this ->filesystemMock ,
130
- $ this ->fileFactoryMock
131
- );
132
137
// 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
+ );
134
142
}
135
143
}
0 commit comments