@@ -40,17 +40,26 @@ class ThemeProviderTest extends \PHPUnit_Framework_TestCase
40
40
/** @var \Magento\Theme\Model\Theme\ThemeProvider|\PHPUnit_Framework_MockObject_MockObject */
41
41
private $ themeProvider ;
42
42
43
+ /** @var \Magento\Theme\Model\Theme|\PHPUnit_Framework_MockObject_MockObject */
44
+ private $ theme ;
45
+
43
46
protected function setUp ()
44
47
{
45
48
$ this ->objectManager = new ObjectManagerHelper ($ this );
46
49
$ this ->collectionFactory = $ this ->getMock (
47
50
\Magento \Theme \Model \ResourceModel \Theme \CollectionFactory::class,
51
+ ['create ' ],
48
52
[],
53
+ '' ,
54
+ false
55
+ );
56
+ $ this ->themeFactory = $ this ->getMock (
57
+ \Magento \Theme \Model \ThemeFactory::class,
58
+ ['create ' ],
49
59
[],
50
60
'' ,
51
61
false
52
62
);
53
- $ this ->themeFactory = $ this ->getMock (\Magento \Theme \Model \ThemeFactory::class, [], [], '' , false );
54
63
$ this ->cache = $ this ->getMockBuilder (\Magento \Framework \App \CacheInterface::class)
55
64
->disableOriginalConstructor ()
56
65
->getMock ();
@@ -64,24 +73,24 @@ protected function setUp()
64
73
'serializer ' => $ this ->serializer
65
74
]
66
75
);
76
+ $ this ->theme = $ this ->getMock (\Magento \Theme \Model \Theme::class, [], [], '' , false );
67
77
}
68
78
69
79
public function testGetByFullPath ()
70
80
{
71
81
$ themeArray = ['theme_data ' => 'theme_data ' ];
72
- $ theme = $ this ->getMock (\Magento \Theme \Model \Theme::class, [], [], '' , false );
73
- $ theme ->expects ($ this ->exactly (2 ))
82
+ $ this ->theme ->expects ($ this ->exactly (2 ))
74
83
->method ('getId ' )
75
84
->willReturn (self ::THEME_ID );
76
- $ theme ->expects ($ this ->exactly (2 ))
85
+ $ this -> theme ->expects ($ this ->exactly (2 ))
77
86
->method ('toArray ' )
78
87
->willReturn ($ themeArray );
79
88
80
89
$ collectionMock = $ this ->getMock (\Magento \Theme \Model \ResourceModel \Theme \Collection::class, [], [], '' , false );
81
90
$ collectionMock ->expects ($ this ->once ())
82
91
->method ('getThemeByFullPath ' )
83
92
->with (self ::THEME_PATH )
84
- ->willReturn ($ theme );
93
+ ->willReturn ($ this -> theme );
85
94
$ this ->collectionFactory ->expects ($ this ->once ())
86
95
->method ('create ' )
87
96
->willReturn ($ collectionMock );
@@ -106,9 +115,9 @@ public function testGetByFullPath()
106
115
\Magento \Framework \App \ObjectManager::setInstance ($ objectManagerMock );
107
116
108
117
// Assertion for first time load
109
- $ this ->assertSame ($ theme , $ this ->themeProvider ->getThemeByFullPath (self ::THEME_PATH ));
118
+ $ this ->assertSame ($ this -> theme , $ this ->themeProvider ->getThemeByFullPath (self ::THEME_PATH ));
110
119
// Assertion for loading from local cache
111
- $ this ->assertSame ($ theme , $ this ->themeProvider ->getThemeByFullPath (self ::THEME_PATH ));
120
+ $ this ->assertSame ($ this -> theme , $ this ->themeProvider ->getThemeByFullPath (self ::THEME_PATH ));
112
121
}
113
122
114
123
public function testGetByFullPathWithCache ()
@@ -129,41 +138,46 @@ public function testGetByFullPathWithCache()
129
138
\Magento \Framework \App \ObjectManager::setInstance ($ objectManagerMock );
130
139
131
140
$ serializedTheme = '{"theme_data":"theme_data"} ' ;
132
- $ theme = $ this -> getMock (\ Magento \ Theme \ Model \Theme::class, [], [], '' , false ) ;
133
- $ theme ->expects ($ this ->once ())
141
+ $ themeArray = [ ' theme_data ' => ' theme_data ' ] ;
142
+ $ this -> theme ->expects ($ this ->once ())
134
143
->method ('populateFromArray ' )
144
+ ->with ($ themeArray )
135
145
->willReturnSelf ();
136
146
$ this ->themeFactory ->expects ($ this ->once ())
137
147
->method ('create ' )
138
- ->willReturn ($ theme );
148
+ ->willReturn ($ this -> theme );
139
149
140
150
$ this ->serializer ->expects ($ this ->once ())
141
151
->method ('unserialize ' )
142
152
->with ($ serializedTheme )
143
- ->willReturn ([ ' theme_data ' => ' theme_data ' ] );
153
+ ->willReturn ($ themeArray );
144
154
145
155
$ this ->cache ->expects ($ this ->once ())
146
156
->method ('load ' )
147
157
->with ('theme ' . self ::THEME_PATH )
148
158
->willReturn ($ serializedTheme );
149
159
150
160
// Assertion for load from cache
151
- $ this ->assertSame ($ theme , $ this ->themeProvider ->getThemeByFullPath (self ::THEME_PATH ));
161
+ $ this ->assertSame ($ this -> theme , $ this ->themeProvider ->getThemeByFullPath (self ::THEME_PATH ));
152
162
// Assertion for load from object cache
153
- $ this ->assertSame ($ theme , $ this ->themeProvider ->getThemeByFullPath (self ::THEME_PATH ));
163
+ $ this ->assertSame ($ this -> theme , $ this ->themeProvider ->getThemeByFullPath (self ::THEME_PATH ));
154
164
}
155
165
156
166
public function testGetById ()
157
167
{
158
168
$ themeArray = ['theme_data ' => 'theme_data ' ];
159
- $ theme = $ this ->getMock (\Magento \Theme \Model \Theme::class, [], [], '' , false );
160
- $ theme ->expects ($ this ->once ())->method ('load ' )->with (self ::THEME_ID )->will ($ this ->returnSelf ());
161
- $ theme ->expects ($ this ->once ())->method ('getId ' )->will ($ this ->returnValue (self ::THEME_ID ));
162
- $ theme ->expects ($ this ->once ())
169
+ $ this ->theme ->expects ($ this ->once ())
170
+ ->method ('load ' )
171
+ ->with (self ::THEME_ID )
172
+ ->willReturnSelf ();
173
+ $ this ->theme ->expects ($ this ->once ())
174
+ ->method ('getId ' )
175
+ ->willReturn (self ::THEME_ID );
176
+ $ this ->theme ->expects ($ this ->once ())
163
177
->method ('toArray ' )
164
178
->willReturn ($ themeArray );
165
179
166
- $ this ->themeFactory ->expects ($ this ->once ())->method ('create ' )->will ($ this ->returnValue ($ theme ));
180
+ $ this ->themeFactory ->expects ($ this ->once ())->method ('create ' )->will ($ this ->returnValue ($ this -> theme ));
167
181
$ this ->cache ->expects ($ this ->once ())
168
182
->method ('load ' )
169
183
->with ('theme-by-id- ' . self ::THEME_ID )
@@ -174,18 +188,18 @@ public function testGetById()
174
188
->willReturn ('{"theme_data":"theme_data"} ' );
175
189
176
190
// Assertion for initial load
177
- $ this ->assertSame ($ theme , $ this ->themeProvider ->getThemeById (self ::THEME_ID ));
191
+ $ this ->assertSame ($ this -> theme , $ this ->themeProvider ->getThemeById (self ::THEME_ID ));
178
192
// Assertion for load from object cache
179
- $ this ->assertSame ($ theme , $ this ->themeProvider ->getThemeById (self ::THEME_ID ));
193
+ $ this ->assertSame ($ this -> theme , $ this ->themeProvider ->getThemeById (self ::THEME_ID ));
180
194
}
181
195
182
196
public function testGetByIdWithCache ()
183
197
{
184
198
$ serializedTheme = '{"theme_data":"theme_data"} ' ;
185
- $ theme = $ this -> getMock (\ Magento \ Theme \ Model \Theme::class, [], [], '' , false ) ;
186
- $ theme ->expects ($ this ->once ())
199
+ $ themeArray = [ ' theme_data ' => ' theme_data ' ] ;
200
+ $ this -> theme ->expects ($ this ->once ())
187
201
->method ('populateFromArray ' )
188
- ->with ([ ' theme_data ' => ' theme_data ' ] )
202
+ ->with ($ themeArray )
189
203
->willReturnSelf ();
190
204
$ this ->cache ->expects ($ this ->once ())
191
205
->method ('load ' )
@@ -194,15 +208,15 @@ public function testGetByIdWithCache()
194
208
$ this ->serializer ->expects ($ this ->once ())
195
209
->method ('unserialize ' )
196
210
->with ($ serializedTheme )
197
- ->willReturn ([ ' theme_data ' => ' theme_data ' ] );
211
+ ->willReturn ($ themeArray );
198
212
$ this ->themeFactory ->expects ($ this ->once ())
199
213
->method ('create ' )
200
- ->willReturn ($ theme );
214
+ ->willReturn ($ this -> theme );
201
215
202
216
// Assertion for initial load from cache
203
- $ this ->assertSame ($ theme , $ this ->themeProvider ->getThemeById (self ::THEME_ID ));
217
+ $ this ->assertSame ($ this -> theme , $ this ->themeProvider ->getThemeById (self ::THEME_ID ));
204
218
// Assertion for load from object cache
205
- $ this ->assertSame ($ theme , $ this ->themeProvider ->getThemeById (self ::THEME_ID ));
219
+ $ this ->assertSame ($ this -> theme , $ this ->themeProvider ->getThemeById (self ::THEME_ID ));
206
220
}
207
221
208
222
public function testGetThemeCustomizations ()
0 commit comments