1010namespace ZendTest \View \Helper ;
1111
1212use PHPUnit_Framework_TestCase as TestCase ;
13- use Zend \Mvc \Controller \Plugin \FlashMessenger as PluginFlashMessenger ;
13+ use Zend \Mvc \Controller \Plugin \FlashMessenger as V2PluginFlashMessenger ;
1414use Zend \Mvc \Controller \PluginManager ;
15+ use Zend \Mvc \Plugin \FlashMessenger \FlashMessenger as V3PluginFlashMessenger ;
1516use Zend \ServiceManager \Config ;
1617use Zend \ServiceManager \ServiceManager ;
1718use Zend \View \Helper \FlashMessenger ;
@@ -27,14 +28,9 @@ class FlashMessengerTest extends TestCase
2728{
2829 public function setUp ()
2930 {
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;
3834 $ this ->helper = new FlashMessenger ();
3935 $ this ->plugin = $ this ->helper ->getPluginFlashMessenger ();
4036 }
@@ -63,34 +59,32 @@ public function seedCurrentMessages()
6359
6460 public function createServiceManager (array $ config = [])
6561 {
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+ ]);
8579 $ sm = new ServiceManager ();
8680 $ config ->configureServiceManager ($ sm );
8781 return $ sm ;
8882 }
8983
9084 public function testCanAssertPluginClass ()
9185 {
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 ()));
9488 $ this ->assertSame ($ this ->plugin , $ this ->helper ->getPluginFlashMessenger ());
9589 }
9690
@@ -176,26 +170,26 @@ public function testCanProxyAndRetrieveCurrentMessagesFromPluginController()
176170 public function testCanDisplayListOfMessages ()
177171 {
178172 $ displayInfoAssertion = '' ;
179- $ displayInfo = $ this ->helper ->render (PluginFlashMessenger:: NAMESPACE_INFO );
173+ $ displayInfo = $ this ->helper ->render (' info ' );
180174 $ this ->assertEquals ($ displayInfoAssertion , $ displayInfo );
181175
182176 $ this ->seedMessages ();
183177
184178 $ displayInfoAssertion = '<ul class="info"><li>bar-info</li></ul> ' ;
185- $ displayInfo = $ this ->helper ->render (PluginFlashMessenger:: NAMESPACE_INFO );
179+ $ displayInfo = $ this ->helper ->render (' info ' );
186180 $ this ->assertEquals ($ displayInfoAssertion , $ displayInfo );
187181 }
188182
189183 public function testCanDisplayListOfCurrentMessages ()
190184 {
191185 $ displayInfoAssertion = '' ;
192- $ displayInfo = $ this ->helper ->renderCurrent (PluginFlashMessenger:: NAMESPACE_INFO );
186+ $ displayInfo = $ this ->helper ->renderCurrent (' info ' );
193187 $ this ->assertEquals ($ displayInfoAssertion , $ displayInfo );
194188
195189 $ this ->seedCurrentMessages ();
196190
197191 $ displayInfoAssertion = '<ul class="info"><li>bar-info</li></ul> ' ;
198- $ displayInfo = $ this ->helper ->renderCurrent (PluginFlashMessenger:: NAMESPACE_INFO );
192+ $ displayInfo = $ this ->helper ->renderCurrent (' info ' );
199193 $ this ->assertEquals ($ displayInfoAssertion , $ displayInfo );
200194 }
201195
@@ -225,7 +219,7 @@ public function testCanDisplayListOfMessagesByInvoke()
225219 $ this ->seedMessages ();
226220
227221 $ displayInfoAssertion = '<ul class="info"><li>bar-info</li></ul> ' ;
228- $ displayInfo = $ helper ()->render (PluginFlashMessenger:: NAMESPACE_INFO );
222+ $ displayInfo = $ helper ()->render (' info ' );
229223 $ this ->assertEquals ($ displayInfoAssertion , $ displayInfo );
230224 }
231225
@@ -235,7 +229,7 @@ public function testCanDisplayListOfCurrentMessagesByInvoke()
235229 $ this ->seedCurrentMessages ();
236230
237231 $ displayInfoAssertion = '<ul class="info"><li>bar-info</li></ul> ' ;
238- $ displayInfo = $ helper ()->renderCurrent (PluginFlashMessenger:: NAMESPACE_INFO );
232+ $ displayInfo = $ helper ()->renderCurrent (' info ' );
239233 $ this ->assertEquals ($ displayInfoAssertion , $ displayInfo );
240234 }
241235
@@ -248,7 +242,7 @@ public function testCanDisplayListOfMessagesCustomised()
248242 ->setMessageOpenFormat ('<div%s><p> ' )
249243 ->setMessageSeparatorString ('</p><p> ' )
250244 ->setMessageCloseString ('</p></div> ' )
251- ->render (PluginFlashMessenger:: NAMESPACE_INFO , ['foo-baz ' , 'foo-bar ' ]);
245+ ->render (' info ' , ['foo-baz ' , 'foo-bar ' ]);
252246 $ this ->assertEquals ($ displayInfoAssertion , $ displayInfo );
253247 }
254248
@@ -261,7 +255,7 @@ public function testCanDisplayListOfCurrentMessagesCustomised()
261255 ->setMessageOpenFormat ('<div%s><p> ' )
262256 ->setMessageSeparatorString ('</p><p> ' )
263257 ->setMessageCloseString ('</p></div> ' )
264- ->renderCurrent (PluginFlashMessenger:: NAMESPACE_INFO , ['foo-baz ' , 'foo-bar ' ]);
258+ ->renderCurrent (' info ' , ['foo-baz ' , 'foo-bar ' ]);
265259 $ this ->assertEquals ($ displayInfoAssertion , $ displayInfo );
266260 }
267261
@@ -274,7 +268,7 @@ public function testCanDisplayListOfMessagesCustomisedSeparator()
274268 ->setMessageOpenFormat ('<div><p%s> ' )
275269 ->setMessageSeparatorString ('</p><p%s> ' )
276270 ->setMessageCloseString ('</p></div> ' )
277- ->render (PluginFlashMessenger:: NAMESPACE_DEFAULT , ['foo-baz ' , 'foo-bar ' ]);
271+ ->render (' default ' , ['foo-baz ' , 'foo-bar ' ]);
278272 $ this ->assertEquals ($ displayInfoAssertion , $ displayInfo );
279273 }
280274
@@ -287,7 +281,7 @@ public function testCanDisplayListOfCurrentMessagesCustomisedSeparator()
287281 ->setMessageOpenFormat ('<div><p%s> ' )
288282 ->setMessageSeparatorString ('</p><p%s> ' )
289283 ->setMessageCloseString ('</p></div> ' )
290- ->renderCurrent (PluginFlashMessenger:: NAMESPACE_DEFAULT , ['foo-baz ' , 'foo-bar ' ]);
284+ ->renderCurrent (' default ' , ['foo-baz ' , 'foo-bar ' ]);
291285 $ this ->assertEquals ($ displayInfoAssertion , $ displayInfo );
292286 }
293287
@@ -310,7 +304,7 @@ public function testCanDisplayListOfMessagesCustomisedByConfig()
310304 $ helper = $ helperPluginManager ->get ('flashmessenger ' );
311305
312306 $ displayInfoAssertion = '<div class="info"><ul><li>bar-info</li></ul></div> ' ;
313- $ displayInfo = $ helper ->render (PluginFlashMessenger:: NAMESPACE_INFO );
307+ $ displayInfo = $ helper ->render (' info ' );
314308 $ this ->assertEquals ($ displayInfoAssertion , $ displayInfo );
315309 }
316310
@@ -331,7 +325,7 @@ public function testCanDisplayListOfCurrentMessagesCustomisedByConfig()
331325 $ helper = $ helperPluginManager ->get ('flashmessenger ' );
332326
333327 $ displayInfoAssertion = '<div class="info"><ul><li>bar-info</li></ul></div> ' ;
334- $ displayInfo = $ helper ->renderCurrent (PluginFlashMessenger:: NAMESPACE_INFO );
328+ $ displayInfo = $ helper ->renderCurrent (' info ' );
335329 $ this ->assertEquals ($ displayInfoAssertion , $ displayInfo );
336330 }
337331
@@ -353,7 +347,7 @@ public function testCanDisplayListOfMessagesCustomisedByConfigSeparator()
353347 $ helper = $ helperPluginManager ->get ('flashmessenger ' );
354348
355349 $ 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 ' ]);
357351 $ this ->assertEquals ($ displayInfoAssertion , $ displayInfo );
358352 }
359353
@@ -375,7 +369,7 @@ public function testCanDisplayListOfCurrentMessagesCustomisedByConfigSeparator()
375369 $ helper = $ helperPluginManager ->get ('flashmessenger ' );
376370
377371 $ 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 ' ]);
379373 $ this ->assertEquals ($ displayInfoAssertion , $ displayInfo );
380374 }
381375
@@ -392,7 +386,7 @@ public function testCanTranslateMessages()
392386 $ this ->seedMessages ();
393387
394388 $ displayAssertion = '<ul class="info"><li>translated message</li></ul> ' ;
395- $ display = $ this ->helper ->render (PluginFlashMessenger:: NAMESPACE_INFO );
389+ $ display = $ this ->helper ->render (' info ' );
396390 $ this ->assertEquals ($ displayAssertion , $ display );
397391 }
398392
@@ -409,7 +403,7 @@ public function testCanTranslateCurrentMessages()
409403 $ this ->seedCurrentMessages ();
410404
411405 $ displayAssertion = '<ul class="info"><li>translated message</li></ul> ' ;
412- $ display = $ this ->helper ->renderCurrent (PluginFlashMessenger:: NAMESPACE_INFO );
406+ $ display = $ this ->helper ->renderCurrent (' info ' );
413407 $ this ->assertEquals ($ displayAssertion , $ display );
414408 }
415409
@@ -437,7 +431,7 @@ public function testMessageIsEscapedByDefault()
437431 unset($ helper );
438432
439433 $ displayAssertion = '<ul class="default"><li>Foo<br />bar</li></ul> ' ;
440- $ display = $ this ->helper ->render (PluginFlashMessenger:: NAMESPACE_DEFAULT );
434+ $ display = $ this ->helper ->render (' default ' );
441435 $ this ->assertSame ($ displayAssertion , $ display );
442436 }
443437
@@ -452,7 +446,7 @@ public function testMessageIsNotEscapedWhenAutoEscapeIsFalse()
452446
453447 $ displayAssertion = '<ul class="default"><li>Foo<br />bar</li></ul> ' ;
454448 $ display = $ this ->helper ->setAutoEscape (false )
455- ->render (PluginFlashMessenger:: NAMESPACE_DEFAULT );
449+ ->render (' default ' );
456450 $ this ->assertSame ($ displayAssertion , $ display );
457451 }
458452
@@ -466,7 +460,7 @@ public function testCanSetAutoEscapeOnRender()
466460 unset($ helper );
467461
468462 $ 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 );
470464 $ this ->assertSame ($ displayAssertion , $ display );
471465 }
472466
@@ -481,7 +475,7 @@ public function testRenderUsesCurrentAutoEscapeByDefault()
481475
482476 $ this ->helper ->setAutoEscape (false );
483477 $ displayAssertion = '<ul class="default"><li>Foo<br />bar</li></ul> ' ;
484- $ display = $ this ->helper ->render (PluginFlashMessenger:: NAMESPACE_DEFAULT );
478+ $ display = $ this ->helper ->render (' default ' );
485479 $ this ->assertSame ($ displayAssertion , $ display );
486480
487481 $ helper = new FlashMessenger ;
@@ -490,7 +484,7 @@ public function testRenderUsesCurrentAutoEscapeByDefault()
490484
491485 $ this ->helper ->setAutoEscape (true );
492486 $ displayAssertion = '<ul class="default"><li>Foo<br />bar</li></ul> ' ;
493- $ display = $ this ->helper ->render (PluginFlashMessenger:: NAMESPACE_DEFAULT );
487+ $ display = $ this ->helper ->render (' default ' );
494488 $ this ->assertSame ($ displayAssertion , $ display );
495489 }
496490
@@ -502,7 +496,7 @@ public function testCurrentMessageIsEscapedByDefault()
502496 $ this ->helper ->addMessage ('Foo<br />bar ' );
503497
504498 $ displayAssertion = '<ul class="default"><li>Foo<br />bar</li></ul> ' ;
505- $ display = $ this ->helper ->renderCurrent (PluginFlashMessenger:: NAMESPACE_DEFAULT );
499+ $ display = $ this ->helper ->renderCurrent (' default ' );
506500 $ this ->assertSame ($ displayAssertion , $ display );
507501 }
508502
@@ -515,7 +509,7 @@ public function testCurrentMessageIsNotEscapedWhenAutoEscapeIsFalse()
515509
516510 $ displayAssertion = '<ul class="default"><li>Foo<br />bar</li></ul> ' ;
517511 $ display = $ this ->helper ->setAutoEscape (false )
518- ->renderCurrent (PluginFlashMessenger:: NAMESPACE_DEFAULT );
512+ ->renderCurrent (' default ' );
519513 $ this ->assertSame ($ displayAssertion , $ display );
520514 }
521515
@@ -527,7 +521,7 @@ public function testCanSetAutoEscapeOnRenderCurrent()
527521 $ this ->helper ->addMessage ('Foo<br />bar ' );
528522
529523 $ 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 );
531525 $ this ->assertSame ($ displayAssertion , $ display );
532526 }
533527
@@ -540,12 +534,12 @@ public function testRenderCurrentUsesCurrentAutoEscapeByDefault()
540534
541535 $ this ->helper ->setAutoEscape (false );
542536 $ displayAssertion = '<ul class="default"><li>Foo<br />bar</li></ul> ' ;
543- $ display = $ this ->helper ->renderCurrent (PluginFlashMessenger:: NAMESPACE_DEFAULT );
537+ $ display = $ this ->helper ->renderCurrent (' default ' );
544538 $ this ->assertSame ($ displayAssertion , $ display );
545539
546540 $ this ->helper ->setAutoEscape (true );
547541 $ displayAssertion = '<ul class="default"><li>Foo<br />bar</li></ul> ' ;
548- $ display = $ this ->helper ->renderCurrent (PluginFlashMessenger:: NAMESPACE_DEFAULT );
542+ $ display = $ this ->helper ->renderCurrent (' default ' );
549543 $ this ->assertSame ($ displayAssertion , $ display );
550544 }
551545}
0 commit comments