@@ -124,21 +124,13 @@ public function testBeforeGenerateXmlPageCacheEnabled()
124
124
->method ('isEnabled ' )
125
125
->with ('Magento_PageCache ' )
126
126
->will ($ this ->returnValue (true ));
127
- $ this ->cacheConfigMock
128
- ->expects ($ this ->once ())
129
- ->method ('isEnabled ' )
130
- ->will ($ this ->returnValue (true ));
131
- $ this ->requestMock
132
- ->expects ($ this ->once ())
133
- ->method ('isAjax ' )
134
- ->will ($ this ->returnValue (false ));
135
- $ this ->layoutMock
127
+ $ this ->cacheConfigMock ->expects ($ this ->once ())->method ('isEnabled ' )->will ($ this ->returnValue (true ));
128
+ $ this ->requestMock ->expects ($ this ->once ())->method ('isAjax ' )->will ($ this ->returnValue (false ));
129
+ $ this ->requestMock ->expects ($ this ->once ())->method ('isGet ' )->will ($ this ->returnValue (true ));
130
+ $ this ->layoutMock ->expects ($ this ->once ())->method ('isCacheable ' )->will ($ this ->returnValue (true ));
131
+ $ this ->customerSessionMock ->expects ($ this ->once ())->method ('getCustomerGroupId ' );
132
+ $ this ->sessionMock
136
133
->expects ($ this ->once ())
137
- ->method ('isCacheable ' )
138
- ->will ($ this ->returnValue (true ));
139
- $ this ->customerSessionMock ->expects ($ this ->once ())
140
- ->method ('getCustomerGroupId ' );
141
- $ this ->sessionMock ->expects ($ this ->once ())
142
134
->method ('getData ' )
143
135
->with ($ this ->equalTo (\Magento \Framework \Data \Form \FormKey::FORM_KEY ));
144
136
$ output = $ this ->plugin ->beforeGenerateXml ($ this ->layoutMock );
@@ -155,9 +147,7 @@ public function testBeforeGenerateXmlPageCacheDisabled()
155
147
->method ('isEnabled ' )
156
148
->with ('Magento_PageCache ' )
157
149
->will ($ this ->returnValue (false ));
158
- $ this ->requestMock
159
- ->expects ($ this ->never ())
160
- ->method ('isAjax ' );
150
+ $ this ->requestMock ->expects ($ this ->never ())->method ('isAjax ' );
161
151
$ output = $ this ->plugin ->beforeGenerateXml ($ this ->layoutMock );
162
152
$ this ->assertEquals ([], $ output );
163
153
}
@@ -172,16 +162,9 @@ public function testBeforeGenerateXmlRequestIsAjax()
172
162
->method ('isEnabled ' )
173
163
->with ('Magento_PageCache ' )
174
164
->will ($ this ->returnValue (true ));
175
- $ this ->cacheConfigMock
176
- ->expects ($ this ->once ())
177
- ->method ('isEnabled ' )
178
- ->will ($ this ->returnValue (true ));
179
- $ this ->requestMock
180
- ->expects ($ this ->once ())
181
- ->method ('isAjax ' )
182
- ->will ($ this ->returnValue (true ));
183
- $ this ->layoutMock ->expects ($ this ->never ())
184
- ->method ('isCacheable ' );
165
+ $ this ->cacheConfigMock ->expects ($ this ->once ())->method ('isEnabled ' )->will ($ this ->returnValue (true ));
166
+ $ this ->requestMock ->expects ($ this ->once ())->method ('isAjax ' )->will ($ this ->returnValue (true ));
167
+ $ this ->layoutMock ->expects ($ this ->never ())->method ('isCacheable ' );
185
168
$ output = $ this ->plugin ->beforeGenerateXml ($ this ->layoutMock );
186
169
$ this ->assertEquals ([], $ output );
187
170
}
@@ -196,19 +179,11 @@ public function testBeforeGenerateXmlLayoutIsNotCacheable()
196
179
->method ('isEnabled ' )
197
180
->with ('Magento_PageCache ' )
198
181
->will ($ this ->returnValue (true ));
199
- $ this ->cacheConfigMock
200
- ->expects ($ this ->once ())
201
- ->method ('isEnabled ' )
202
- ->will ($ this ->returnValue (true ));
203
- $ this ->requestMock
204
- ->expects ($ this ->once ())
205
- ->method ('isAjax ' )
206
- ->will ($ this ->returnValue (false ));
207
- $ this ->layoutMock ->expects ($ this ->once ())
208
- ->method ('isCacheable ' )
209
- ->will ($ this ->returnValue (false ));
210
- $ this ->customerSessionMock ->expects ($ this ->never ())
211
- ->method ('getCustomerGroupId ' );
182
+ $ this ->cacheConfigMock ->expects ($ this ->once ())->method ('isEnabled ' )->will ($ this ->returnValue (true ));
183
+ $ this ->requestMock ->expects ($ this ->once ())->method ('isAjax ' )->will ($ this ->returnValue (false ));
184
+ $ this ->requestMock ->expects ($ this ->once ())->method ('isGet ' )->will ($ this ->returnValue (true ));
185
+ $ this ->layoutMock ->expects ($ this ->once ())->method ('isCacheable ' )->will ($ this ->returnValue (false ));
186
+ $ this ->customerSessionMock ->expects ($ this ->never ())->method ('getCustomerGroupId ' );
212
187
$ output = $ this ->plugin ->beforeGenerateXml ($ this ->layoutMock );
213
188
$ this ->assertEquals ([], $ output );
214
189
}
@@ -224,40 +199,16 @@ public function testAfterGenerateXmlPageCacheEnabled()
224
199
->method ('isEnabled ' )
225
200
->with ('Magento_PageCache ' )
226
201
->will ($ this ->returnValue (true ));
227
- $ this ->cacheConfigMock
228
- ->expects ($ this ->once ())
229
- ->method ('isEnabled ' )
230
- ->will ($ this ->returnValue (true ));
231
- $ this ->requestMock
232
- ->expects ($ this ->once ())
233
- ->method ('isAjax ' )
234
- ->will ($ this ->returnValue (false ));
235
- $ this ->layoutMock
236
- ->expects ($ this ->once ())
237
- ->method ('isCacheable ' )
238
- ->will ($ this ->returnValue (true ));
239
- $ this ->visitorMock
240
- ->expects ($ this ->once ())
241
- ->method ('setSkipRequestLogging ' )
242
- ->with ($ this ->equalTo (true ));
243
- $ this ->visitorMock
244
- ->expects ($ this ->once ())
245
- ->method ('unsetData ' );
246
- $ this ->sessionMock
247
- ->expects ($ this ->once ())
248
- ->method ('clearStorage ' );
249
- $ this ->customerSessionMock
250
- ->expects ($ this ->once ())
251
- ->method ('clearStorage ' );
252
- $ this ->customerSessionMock
253
- ->expects ($ this ->once ())
254
- ->method ('setCustomerGroupId ' )
255
- ->with ($ this ->equalTo (null ));
256
- $ this ->customerMock
257
- ->expects ($ this ->once ())
258
- ->method ('setGroupId ' )
259
- ->with ($ this ->equalTo (null ))
260
- ->willReturnSelf ();
202
+ $ this ->cacheConfigMock ->expects ($ this ->once ())->method ('isEnabled ' )->will ($ this ->returnValue (true ));
203
+ $ this ->requestMock ->expects ($ this ->once ())->method ('isAjax ' )->will ($ this ->returnValue (false ));
204
+ $ this ->requestMock ->expects ($ this ->once ())->method ('isGet ' )->will ($ this ->returnValue (true ));
205
+ $ this ->layoutMock ->expects ($ this ->once ())->method ('isCacheable ' )->will ($ this ->returnValue (true ));
206
+ $ this ->visitorMock ->expects ($ this ->once ())->method ('setSkipRequestLogging ' )->with ($ this ->equalTo (true ));
207
+ $ this ->visitorMock ->expects ($ this ->once ())->method ('unsetData ' );
208
+ $ this ->sessionMock ->expects ($ this ->once ())->method ('clearStorage ' );
209
+ $ this ->customerSessionMock ->expects ($ this ->once ())->method ('clearStorage ' );
210
+ $ this ->customerSessionMock ->expects ($ this ->once ())->method ('setCustomerGroupId ' )->with ($ this ->equalTo (null ));
211
+ $ this ->customerMock ->expects ($ this ->once ())->method ('setGroupId ' )->with ($ this ->equalTo (null ))->willReturnSelf ();
261
212
$ this ->sessionMock
262
213
->expects ($ this ->once ())
263
214
->method ('setData ' )
@@ -284,9 +235,7 @@ public function testAfterGenerateXmlPageCacheDisabled()
284
235
->method ('isEnabled ' )
285
236
->with ('Magento_PageCache ' )
286
237
->will ($ this ->returnValue (false ));
287
- $ this ->requestMock
288
- ->expects ($ this ->never ())
289
- ->method ('isAjax ' );
238
+ $ this ->requestMock ->expects ($ this ->never ())->method ('isAjax ' );
290
239
$ actualResult = $ this ->plugin ->afterGenerateXml ($ this ->layoutMock , $ expectedResult );
291
240
$ this ->assertSame ($ expectedResult , $ actualResult );
292
241
}
@@ -302,16 +251,29 @@ public function testAfterGenerateXmlRequestIsAjax()
302
251
->method ('isEnabled ' )
303
252
->with ($ this ->equalTo ('Magento_PageCache ' ))
304
253
->will ($ this ->returnValue (true ));
305
- $ this ->cacheConfigMock
254
+ $ this ->cacheConfigMock ->expects ($ this ->once ())->method ('isEnabled ' )->will ($ this ->returnValue (true ));
255
+ $ this ->requestMock ->expects ($ this ->once ())->method ('isAjax ' )->will ($ this ->returnValue (true ));
256
+ $ this ->layoutMock ->expects ($ this ->never ())->method ('isCacheable ' );
257
+ $ actualResult = $ this ->plugin ->afterGenerateXml ($ this ->layoutMock , $ expectedResult );
258
+ $ this ->assertSame ($ expectedResult , $ actualResult );
259
+ }
260
+
261
+ /**
262
+ * Test afterGenerateXml method with enabled module PageCache and request is Post
263
+ */
264
+ public function testAfterGenerateXmlRequestIsPost ()
265
+ {
266
+ $ expectedResult = $ this ->getMock ('Magento\Framework\View\Layout ' , [], [], '' , false );
267
+ $ this ->moduleManagerMock
306
268
->expects ($ this ->once ())
307
269
->method ('isEnabled ' )
270
+ ->with ($ this ->equalTo ('Magento_PageCache ' ))
308
271
->will ($ this ->returnValue (true ));
309
- $ this ->requestMock
310
- ->expects ($ this ->once ())
311
- ->method ('isAjax ' )
312
- ->will ($ this ->returnValue (true ));
313
- $ this ->layoutMock ->expects ($ this ->never ())
314
- ->method ('isCacheable ' );
272
+ $ this ->cacheConfigMock ->expects ($ this ->once ())->method ('isEnabled ' )->will ($ this ->returnValue (true ));
273
+ $ this ->requestMock ->expects ($ this ->once ())->method ('isAjax ' )->will ($ this ->returnValue (false ));
274
+ $ this ->requestMock ->expects ($ this ->once ())->method ('isGet ' )->will ($ this ->returnValue (false ));
275
+ $ this ->requestMock ->expects ($ this ->once ())->method ('isHead ' )->will ($ this ->returnValue (false ));
276
+ $ this ->layoutMock ->expects ($ this ->never ())->method ('isCacheable ' );
315
277
$ actualResult = $ this ->plugin ->afterGenerateXml ($ this ->layoutMock , $ expectedResult );
316
278
$ this ->assertSame ($ expectedResult , $ actualResult );
317
279
}
@@ -327,20 +289,11 @@ public function testAfterGenerateXmlLayoutIsNotCacheable()
327
289
->method ('isEnabled ' )
328
290
->with ($ this ->equalTo ('Magento_PageCache ' ))
329
291
->will ($ this ->returnValue (true ));
330
- $ this ->cacheConfigMock
331
- ->expects ($ this ->once ())
332
- ->method ('isEnabled ' )
333
- ->will ($ this ->returnValue (true ));
334
- $ this ->requestMock
335
- ->expects ($ this ->once ())
336
- ->method ('isAjax ' )
337
- ->will ($ this ->returnValue (false ));
338
- $ this ->layoutMock ->expects ($ this ->once ())
339
- ->method ('isCacheable ' )
340
- ->will ($ this ->returnValue (false ));
341
- $ this ->visitorMock
342
- ->expects ($ this ->never ())
343
- ->method ('setSkipRequestLogging ' );
292
+ $ this ->cacheConfigMock ->expects ($ this ->once ())->method ('isEnabled ' )->will ($ this ->returnValue (true ));
293
+ $ this ->requestMock ->expects ($ this ->once ())->method ('isAjax ' )->will ($ this ->returnValue (false ));
294
+ $ this ->requestMock ->expects ($ this ->once ())->method ('isGet ' )->will ($ this ->returnValue (true ));
295
+ $ this ->layoutMock ->expects ($ this ->once ())->method ('isCacheable ' )->will ($ this ->returnValue (false ));
296
+ $ this ->visitorMock ->expects ($ this ->never ())->method ('setSkipRequestLogging ' );
344
297
$ actualResult = $ this ->plugin ->afterGenerateXml ($ this ->layoutMock , $ expectedResult );
345
298
$ this ->assertSame ($ expectedResult , $ actualResult );
346
299
}
0 commit comments