10
10
namespace ZendTest \View \Helper ;
11
11
12
12
use PHPUnit_Framework_TestCase as TestCase ;
13
- use Zend \Mvc \Controller \Plugin \FlashMessenger as PluginFlashMessenger ;
13
+ use Zend \Mvc \Controller \Plugin \FlashMessenger as V2PluginFlashMessenger ;
14
14
use Zend \Mvc \Controller \PluginManager ;
15
+ use Zend \Mvc \Plugin \FlashMessenger \FlashMessenger as V3PluginFlashMessenger ;
15
16
use Zend \ServiceManager \Config ;
16
17
use Zend \ServiceManager \ServiceManager ;
17
18
use Zend \View \Helper \FlashMessenger ;
@@ -27,14 +28,9 @@ class FlashMessengerTest extends TestCase
27
28
{
28
29
public function setUp ()
29
30
{
30
- if (! class_exists (PluginFlashMessenger::class)) {
31
- $ this ->markTestSkipped (
32
- 'Skipping zend-mvc-related tests until that component is updated '
33
- . 'to be forwards-compatible with zend-eventmanager, zend-stdlib, '
34
- . 'and zend-servicemanager v3. '
35
- );
36
- }
37
-
31
+ $ this ->mvcPluginClass = class_exists (V2PluginFlashMessenger::class)
32
+ ? V2PluginFlashMessenger::class
33
+ : V3PluginFlashMessenger::class;
38
34
$ this ->helper = new FlashMessenger ();
39
35
$ this ->plugin = $ this ->helper ->getPluginFlashMessenger ();
40
36
}
@@ -63,34 +59,32 @@ public function seedCurrentMessages()
63
59
64
60
public function createServiceManager (array $ config = [])
65
61
{
66
- $ config = new Config (
67
- [
68
- 'services ' => [
69
- 'config ' => $ config ,
70
- ],
71
- 'factories ' => [
72
- 'ControllerPluginManager ' => function ($ services , $ name , $ options ) {
73
- return new PluginManager ($ services , [
74
- 'invokables ' => [
75
- 'flashmessenger ' => PluginFlashMessenger::class,
76
- ],
77
- ]);
78
- },
79
- 'ViewHelperManager ' => function ($ services , $ name , $ options ) {
80
- return new HelperPluginManager ($ services );
81
- },
82
- ],
83
- ]
84
- );
62
+ $ config = new Config ([
63
+ 'services ' => [
64
+ 'config ' => $ config ,
65
+ ],
66
+ 'factories ' => [
67
+ 'ControllerPluginManager ' => function ($ services , $ name , $ options ) {
68
+ return new PluginManager ($ services , [
69
+ 'invokables ' => [
70
+ 'flashmessenger ' => $ this ->mvcPluginClass ,
71
+ ],
72
+ ]);
73
+ },
74
+ 'ViewHelperManager ' => function ($ services , $ name , $ options ) {
75
+ return new HelperPluginManager ($ services );
76
+ },
77
+ ],
78
+ ]);
85
79
$ sm = new ServiceManager ();
86
80
$ config ->configureServiceManager ($ sm );
87
81
return $ sm ;
88
82
}
89
83
90
84
public function testCanAssertPluginClass ()
91
85
{
92
- $ this ->assertEquals (PluginFlashMessenger::class , get_class ($ this ->plugin ));
93
- $ this ->assertEquals (PluginFlashMessenger::class , get_class ($ this ->helper ->getPluginFlashMessenger ()));
86
+ $ this ->assertEquals ($ this -> mvcPluginClass , get_class ($ this ->plugin ));
87
+ $ this ->assertEquals ($ this -> mvcPluginClass , get_class ($ this ->helper ->getPluginFlashMessenger ()));
94
88
$ this ->assertSame ($ this ->plugin , $ this ->helper ->getPluginFlashMessenger ());
95
89
}
96
90
@@ -176,26 +170,26 @@ public function testCanProxyAndRetrieveCurrentMessagesFromPluginController()
176
170
public function testCanDisplayListOfMessages ()
177
171
{
178
172
$ displayInfoAssertion = '' ;
179
- $ displayInfo = $ this ->helper ->render (PluginFlashMessenger:: NAMESPACE_INFO );
173
+ $ displayInfo = $ this ->helper ->render (' info ' );
180
174
$ this ->assertEquals ($ displayInfoAssertion , $ displayInfo );
181
175
182
176
$ this ->seedMessages ();
183
177
184
178
$ displayInfoAssertion = '<ul class="info"><li>bar-info</li></ul> ' ;
185
- $ displayInfo = $ this ->helper ->render (PluginFlashMessenger:: NAMESPACE_INFO );
179
+ $ displayInfo = $ this ->helper ->render (' info ' );
186
180
$ this ->assertEquals ($ displayInfoAssertion , $ displayInfo );
187
181
}
188
182
189
183
public function testCanDisplayListOfCurrentMessages ()
190
184
{
191
185
$ displayInfoAssertion = '' ;
192
- $ displayInfo = $ this ->helper ->renderCurrent (PluginFlashMessenger:: NAMESPACE_INFO );
186
+ $ displayInfo = $ this ->helper ->renderCurrent (' info ' );
193
187
$ this ->assertEquals ($ displayInfoAssertion , $ displayInfo );
194
188
195
189
$ this ->seedCurrentMessages ();
196
190
197
191
$ displayInfoAssertion = '<ul class="info"><li>bar-info</li></ul> ' ;
198
- $ displayInfo = $ this ->helper ->renderCurrent (PluginFlashMessenger:: NAMESPACE_INFO );
192
+ $ displayInfo = $ this ->helper ->renderCurrent (' info ' );
199
193
$ this ->assertEquals ($ displayInfoAssertion , $ displayInfo );
200
194
}
201
195
@@ -225,7 +219,7 @@ public function testCanDisplayListOfMessagesByInvoke()
225
219
$ this ->seedMessages ();
226
220
227
221
$ displayInfoAssertion = '<ul class="info"><li>bar-info</li></ul> ' ;
228
- $ displayInfo = $ helper ()->render (PluginFlashMessenger:: NAMESPACE_INFO );
222
+ $ displayInfo = $ helper ()->render (' info ' );
229
223
$ this ->assertEquals ($ displayInfoAssertion , $ displayInfo );
230
224
}
231
225
@@ -235,7 +229,7 @@ public function testCanDisplayListOfCurrentMessagesByInvoke()
235
229
$ this ->seedCurrentMessages ();
236
230
237
231
$ displayInfoAssertion = '<ul class="info"><li>bar-info</li></ul> ' ;
238
- $ displayInfo = $ helper ()->renderCurrent (PluginFlashMessenger:: NAMESPACE_INFO );
232
+ $ displayInfo = $ helper ()->renderCurrent (' info ' );
239
233
$ this ->assertEquals ($ displayInfoAssertion , $ displayInfo );
240
234
}
241
235
@@ -248,7 +242,7 @@ public function testCanDisplayListOfMessagesCustomised()
248
242
->setMessageOpenFormat ('<div%s><p> ' )
249
243
->setMessageSeparatorString ('</p><p> ' )
250
244
->setMessageCloseString ('</p></div> ' )
251
- ->render (PluginFlashMessenger:: NAMESPACE_INFO , ['foo-baz ' , 'foo-bar ' ]);
245
+ ->render (' info ' , ['foo-baz ' , 'foo-bar ' ]);
252
246
$ this ->assertEquals ($ displayInfoAssertion , $ displayInfo );
253
247
}
254
248
@@ -261,7 +255,7 @@ public function testCanDisplayListOfCurrentMessagesCustomised()
261
255
->setMessageOpenFormat ('<div%s><p> ' )
262
256
->setMessageSeparatorString ('</p><p> ' )
263
257
->setMessageCloseString ('</p></div> ' )
264
- ->renderCurrent (PluginFlashMessenger:: NAMESPACE_INFO , ['foo-baz ' , 'foo-bar ' ]);
258
+ ->renderCurrent (' info ' , ['foo-baz ' , 'foo-bar ' ]);
265
259
$ this ->assertEquals ($ displayInfoAssertion , $ displayInfo );
266
260
}
267
261
@@ -274,7 +268,7 @@ public function testCanDisplayListOfMessagesCustomisedSeparator()
274
268
->setMessageOpenFormat ('<div><p%s> ' )
275
269
->setMessageSeparatorString ('</p><p%s> ' )
276
270
->setMessageCloseString ('</p></div> ' )
277
- ->render (PluginFlashMessenger:: NAMESPACE_DEFAULT , ['foo-baz ' , 'foo-bar ' ]);
271
+ ->render (' default ' , ['foo-baz ' , 'foo-bar ' ]);
278
272
$ this ->assertEquals ($ displayInfoAssertion , $ displayInfo );
279
273
}
280
274
@@ -287,7 +281,7 @@ public function testCanDisplayListOfCurrentMessagesCustomisedSeparator()
287
281
->setMessageOpenFormat ('<div><p%s> ' )
288
282
->setMessageSeparatorString ('</p><p%s> ' )
289
283
->setMessageCloseString ('</p></div> ' )
290
- ->renderCurrent (PluginFlashMessenger:: NAMESPACE_DEFAULT , ['foo-baz ' , 'foo-bar ' ]);
284
+ ->renderCurrent (' default ' , ['foo-baz ' , 'foo-bar ' ]);
291
285
$ this ->assertEquals ($ displayInfoAssertion , $ displayInfo );
292
286
}
293
287
@@ -310,7 +304,7 @@ public function testCanDisplayListOfMessagesCustomisedByConfig()
310
304
$ helper = $ helperPluginManager ->get ('flashmessenger ' );
311
305
312
306
$ displayInfoAssertion = '<div class="info"><ul><li>bar-info</li></ul></div> ' ;
313
- $ displayInfo = $ helper ->render (PluginFlashMessenger:: NAMESPACE_INFO );
307
+ $ displayInfo = $ helper ->render (' info ' );
314
308
$ this ->assertEquals ($ displayInfoAssertion , $ displayInfo );
315
309
}
316
310
@@ -331,7 +325,7 @@ public function testCanDisplayListOfCurrentMessagesCustomisedByConfig()
331
325
$ helper = $ helperPluginManager ->get ('flashmessenger ' );
332
326
333
327
$ displayInfoAssertion = '<div class="info"><ul><li>bar-info</li></ul></div> ' ;
334
- $ displayInfo = $ helper ->renderCurrent (PluginFlashMessenger:: NAMESPACE_INFO );
328
+ $ displayInfo = $ helper ->renderCurrent (' info ' );
335
329
$ this ->assertEquals ($ displayInfoAssertion , $ displayInfo );
336
330
}
337
331
@@ -353,7 +347,7 @@ public function testCanDisplayListOfMessagesCustomisedByConfigSeparator()
353
347
$ helper = $ helperPluginManager ->get ('flashmessenger ' );
354
348
355
349
$ displayInfoAssertion = '<div><ul><li class="foo-baz foo-bar">foo</li><li class="foo-baz foo-bar">bar</li></ul></div> ' ;
356
- $ displayInfo = $ helper ->render (PluginFlashMessenger:: NAMESPACE_DEFAULT , ['foo-baz ' , 'foo-bar ' ]);
350
+ $ displayInfo = $ helper ->render (' default ' , ['foo-baz ' , 'foo-bar ' ]);
357
351
$ this ->assertEquals ($ displayInfoAssertion , $ displayInfo );
358
352
}
359
353
@@ -375,7 +369,7 @@ public function testCanDisplayListOfCurrentMessagesCustomisedByConfigSeparator()
375
369
$ helper = $ helperPluginManager ->get ('flashmessenger ' );
376
370
377
371
$ displayInfoAssertion = '<div><ul><li class="foo-baz foo-bar">foo</li><li class="foo-baz foo-bar">bar</li></ul></div> ' ;
378
- $ displayInfo = $ helper ->renderCurrent (PluginFlashMessenger:: NAMESPACE_DEFAULT , ['foo-baz ' , 'foo-bar ' ]);
372
+ $ displayInfo = $ helper ->renderCurrent (' default ' , ['foo-baz ' , 'foo-bar ' ]);
379
373
$ this ->assertEquals ($ displayInfoAssertion , $ displayInfo );
380
374
}
381
375
@@ -392,7 +386,7 @@ public function testCanTranslateMessages()
392
386
$ this ->seedMessages ();
393
387
394
388
$ displayAssertion = '<ul class="info"><li>translated message</li></ul> ' ;
395
- $ display = $ this ->helper ->render (PluginFlashMessenger:: NAMESPACE_INFO );
389
+ $ display = $ this ->helper ->render (' info ' );
396
390
$ this ->assertEquals ($ displayAssertion , $ display );
397
391
}
398
392
@@ -409,7 +403,7 @@ public function testCanTranslateCurrentMessages()
409
403
$ this ->seedCurrentMessages ();
410
404
411
405
$ displayAssertion = '<ul class="info"><li>translated message</li></ul> ' ;
412
- $ display = $ this ->helper ->renderCurrent (PluginFlashMessenger:: NAMESPACE_INFO );
406
+ $ display = $ this ->helper ->renderCurrent (' info ' );
413
407
$ this ->assertEquals ($ displayAssertion , $ display );
414
408
}
415
409
@@ -437,7 +431,7 @@ public function testMessageIsEscapedByDefault()
437
431
unset($ helper );
438
432
439
433
$ displayAssertion = '<ul class="default"><li>Foo<br />bar</li></ul> ' ;
440
- $ display = $ this ->helper ->render (PluginFlashMessenger:: NAMESPACE_DEFAULT );
434
+ $ display = $ this ->helper ->render (' default ' );
441
435
$ this ->assertSame ($ displayAssertion , $ display );
442
436
}
443
437
@@ -452,7 +446,7 @@ public function testMessageIsNotEscapedWhenAutoEscapeIsFalse()
452
446
453
447
$ displayAssertion = '<ul class="default"><li>Foo<br />bar</li></ul> ' ;
454
448
$ display = $ this ->helper ->setAutoEscape (false )
455
- ->render (PluginFlashMessenger:: NAMESPACE_DEFAULT );
449
+ ->render (' default ' );
456
450
$ this ->assertSame ($ displayAssertion , $ display );
457
451
}
458
452
@@ -466,7 +460,7 @@ public function testCanSetAutoEscapeOnRender()
466
460
unset($ helper );
467
461
468
462
$ displayAssertion = '<ul class="default"><li>Foo<br />bar</li></ul> ' ;
469
- $ display = $ this ->helper ->render (PluginFlashMessenger:: NAMESPACE_DEFAULT , [], false );
463
+ $ display = $ this ->helper ->render (' default ' , [], false );
470
464
$ this ->assertSame ($ displayAssertion , $ display );
471
465
}
472
466
@@ -481,7 +475,7 @@ public function testRenderUsesCurrentAutoEscapeByDefault()
481
475
482
476
$ this ->helper ->setAutoEscape (false );
483
477
$ displayAssertion = '<ul class="default"><li>Foo<br />bar</li></ul> ' ;
484
- $ display = $ this ->helper ->render (PluginFlashMessenger:: NAMESPACE_DEFAULT );
478
+ $ display = $ this ->helper ->render (' default ' );
485
479
$ this ->assertSame ($ displayAssertion , $ display );
486
480
487
481
$ helper = new FlashMessenger ;
@@ -490,7 +484,7 @@ public function testRenderUsesCurrentAutoEscapeByDefault()
490
484
491
485
$ this ->helper ->setAutoEscape (true );
492
486
$ displayAssertion = '<ul class="default"><li>Foo<br />bar</li></ul> ' ;
493
- $ display = $ this ->helper ->render (PluginFlashMessenger:: NAMESPACE_DEFAULT );
487
+ $ display = $ this ->helper ->render (' default ' );
494
488
$ this ->assertSame ($ displayAssertion , $ display );
495
489
}
496
490
@@ -502,7 +496,7 @@ public function testCurrentMessageIsEscapedByDefault()
502
496
$ this ->helper ->addMessage ('Foo<br />bar ' );
503
497
504
498
$ displayAssertion = '<ul class="default"><li>Foo<br />bar</li></ul> ' ;
505
- $ display = $ this ->helper ->renderCurrent (PluginFlashMessenger:: NAMESPACE_DEFAULT );
499
+ $ display = $ this ->helper ->renderCurrent (' default ' );
506
500
$ this ->assertSame ($ displayAssertion , $ display );
507
501
}
508
502
@@ -515,7 +509,7 @@ public function testCurrentMessageIsNotEscapedWhenAutoEscapeIsFalse()
515
509
516
510
$ displayAssertion = '<ul class="default"><li>Foo<br />bar</li></ul> ' ;
517
511
$ display = $ this ->helper ->setAutoEscape (false )
518
- ->renderCurrent (PluginFlashMessenger:: NAMESPACE_DEFAULT );
512
+ ->renderCurrent (' default ' );
519
513
$ this ->assertSame ($ displayAssertion , $ display );
520
514
}
521
515
@@ -527,7 +521,7 @@ public function testCanSetAutoEscapeOnRenderCurrent()
527
521
$ this ->helper ->addMessage ('Foo<br />bar ' );
528
522
529
523
$ displayAssertion = '<ul class="default"><li>Foo<br />bar</li></ul> ' ;
530
- $ display = $ this ->helper ->renderCurrent (PluginFlashMessenger:: NAMESPACE_DEFAULT , [], false );
524
+ $ display = $ this ->helper ->renderCurrent (' default ' , [], false );
531
525
$ this ->assertSame ($ displayAssertion , $ display );
532
526
}
533
527
@@ -540,12 +534,12 @@ public function testRenderCurrentUsesCurrentAutoEscapeByDefault()
540
534
541
535
$ this ->helper ->setAutoEscape (false );
542
536
$ displayAssertion = '<ul class="default"><li>Foo<br />bar</li></ul> ' ;
543
- $ display = $ this ->helper ->renderCurrent (PluginFlashMessenger:: NAMESPACE_DEFAULT );
537
+ $ display = $ this ->helper ->renderCurrent (' default ' );
544
538
$ this ->assertSame ($ displayAssertion , $ display );
545
539
546
540
$ this ->helper ->setAutoEscape (true );
547
541
$ displayAssertion = '<ul class="default"><li>Foo<br />bar</li></ul> ' ;
548
- $ display = $ this ->helper ->renderCurrent (PluginFlashMessenger:: NAMESPACE_DEFAULT );
542
+ $ display = $ this ->helper ->renderCurrent (' default ' );
549
543
$ this ->assertSame ($ displayAssertion , $ display );
550
544
}
551
545
}
0 commit comments