1313use PHPUnit_Framework_TestCase as TestCase ;
1414use ReflectionProperty ;
1515use Zend \Expressive \Container \Template \ZendViewFactory ;
16+ use Zend \Expressive \Router \RouterInterface ;
1617use Zend \Expressive \Template \ZendView ;
18+ use Zend \View \HelperPluginManager ;
1719use Zend \View \Model \ModelInterface ;
1820use Zend \View \Resolver \AggregateResolver ;
1921use Zend \View \Resolver \TemplateMapResolver ;
@@ -37,6 +39,7 @@ public function fetchPhpRenderer(ZendView $view)
3739 public function testCallingFactoryWithNoConfigReturnsZendViewInstance ()
3840 {
3941 $ this ->container ->has ('config ' )->willReturn (false );
42+ $ this ->container ->has (HelperPluginManager::class)->willReturn (false );
4043 $ factory = new ZendViewFactory ();
4144 $ view = $ factory ($ this ->container ->reveal ());
4245 $ this ->assertInstanceOf (ZendView::class, $ view );
@@ -62,6 +65,7 @@ public function testConfiguresLayout()
6265 ];
6366 $ this ->container ->has ('config ' )->willReturn (true );
6467 $ this ->container ->get ('config ' )->willReturn ($ config );
68+ $ this ->container ->has (HelperPluginManager::class)->willReturn (false );
6569 $ factory = new ZendViewFactory ();
6670 $ view = $ factory ($ this ->container ->reveal ());
6771
@@ -81,6 +85,7 @@ public function testConfiguresPaths()
8185 ];
8286 $ this ->container ->has ('config ' )->willReturn (true );
8387 $ this ->container ->get ('config ' )->willReturn ($ config );
88+ $ this ->container ->has (HelperPluginManager::class)->willReturn (false );
8489 $ factory = new ZendViewFactory ();
8590 $ view = $ factory ($ this ->container ->reveal ());
8691
@@ -113,6 +118,7 @@ public function testConfiguresTemplateMap()
113118 ];
114119 $ this ->container ->has ('config ' )->willReturn (true );
115120 $ this ->container ->get ('config ' )->willReturn ($ config );
121+ $ this ->container ->has (HelperPluginManager::class)->willReturn (false );
116122 $ factory = new ZendViewFactory ();
117123 $ view = $ factory ($ this ->container ->reveal ());
118124
@@ -133,4 +139,54 @@ public function testConfiguresTemplateMap()
133139 $ this ->assertTrue ($ resolver ->has ('bar ' ));
134140 $ this ->assertEquals ('baz ' , $ resolver ->get ('bar ' ));
135141 }
142+
143+ public function testInjectsCustomHelpersIntoHelperManager ()
144+ {
145+ $ router = $ this ->prophesize (RouterInterface::class)->reveal ();
146+ $ this ->container ->has ('config ' )->willReturn (false );
147+ $ this ->container ->has (HelperPluginManager::class)->willReturn (false );
148+ $ this ->container ->has (RouterInterface::class)->willReturn (true );
149+ $ this ->container ->get (RouterInterface::class)->willReturn ($ router );
150+ $ factory = new ZendViewFactory ();
151+ $ view = $ factory ($ this ->container ->reveal ());
152+ $ this ->assertInstanceOf (ZendView::class, $ view );
153+
154+ $ renderer = $ this ->fetchPhpRenderer ($ view );
155+ $ helpers = $ renderer ->getHelperPluginManager ();
156+ $ this ->assertInstanceOf (HelperPluginManager::class, $ helpers );
157+ $ this ->assertTrue ($ helpers ->has ('url ' ));
158+ $ this ->assertTrue ($ helpers ->has ('serverurl ' ));
159+ $ this ->assertInstanceOf (ZendView \UrlHelper::class, $ helpers ->get ('url ' ));
160+ $ this ->assertInstanceOf (ZendView \ServerUrlHelper::class, $ helpers ->get ('serverurl ' ));
161+ }
162+
163+ public function testWillUseHelperManagerFromContainer ()
164+ {
165+ $ router = $ this ->prophesize (RouterInterface::class)->reveal ();
166+ $ this ->container ->has ('config ' )->willReturn (false );
167+ $ this ->container ->has (RouterInterface::class)->willReturn (true );
168+ $ this ->container ->get (RouterInterface::class)->willReturn ($ router );
169+
170+ $ helpers = new HelperPluginManager ();
171+ $ this ->container ->has (HelperPluginManager::class)->willReturn (true );
172+ $ this ->container ->get (HelperPluginManager::class)->willReturn ($ helpers );
173+ $ factory = new ZendViewFactory ();
174+ $ view = $ factory ($ this ->container ->reveal ());
175+ $ this ->assertInstanceOf (ZendView::class, $ view );
176+
177+ $ renderer = $ this ->fetchPhpRenderer ($ view );
178+ $ this ->assertSame ($ helpers , $ renderer ->getHelperPluginManager ());
179+ return $ helpers ;
180+ }
181+
182+ /**
183+ * @depends testWillUseHelperManagerFromContainer
184+ */
185+ public function testInjectsCustomHelpersIntoHelperManagerFromContainer (HelperPluginManager $ helpers )
186+ {
187+ $ this ->assertTrue ($ helpers ->has ('url ' ));
188+ $ this ->assertTrue ($ helpers ->has ('serverurl ' ));
189+ $ this ->assertInstanceOf (ZendView \UrlHelper::class, $ helpers ->get ('url ' ));
190+ $ this ->assertInstanceOf (ZendView \ServerUrlHelper::class, $ helpers ->get ('serverurl ' ));
191+ }
136192}
0 commit comments