|
Hello all
In the setUp() method of the unit tests for View Helpers, which have a dependency on another View Helper, I could use HelperLoader::addStaticMap to inject the dependency into the component under test, in zf2 prior to beta5, like this: protected function setUp() { HelperLoader::addStaticMap(array( 'mailto' => 'My\View\Helper\Mailto', )); $this->view = new PhpRenderer(); $this->helper = new Imprint(); $this->helper->setView($this->view); } The View Helper "Imprint" returns HTML, which includes the HTML of (an obfuscated) e-mail address. The View Helper "mailto" offers the functionality to return the formatted e-mail address. What is the best approach to do this in ZF2 beta5? TIA Jonathan |
|
Hi again,
this one should solve your problem: http://zend-framework-community.634137.n4.nabble.com/Alias-for-translate-Helper-td4655640.html#a4655647 Hasan H. Gürsoy (HHGAG) Jonathan Maron <[hidden email]> schrieb: >Hello all > >In the setUp() method of the unit tests for View Helpers, which have a >dependency on another View Helper, I could use >HelperLoader::addStaticMap to inject the dependency into the component >under test, in zf2 prior to beta5, like this: > >protected function setUp() >{ > HelperLoader::addStaticMap(array( > 'mailto' => 'My\View\Helper\Mailto', > )); > > $this->view = new PhpRenderer(); > > $this->helper = new Imprint(); > $this->helper->setView($this->view); >} > >The View Helper "Imprint" returns HTML, which includes the HTML of (an >obfuscated) e-mail address. The View Helper "mailto" offers the >functionality to return the formatted e-mail address. > >What is the best approach to do this in ZF2 beta5? > >TIA > >Jonathan
Hasan H. Gürsoy (HHGAG)
|
|
In reply to this post by Jonathan Maron
Hi Jonathan,
2012/7/10 Jonathan Maron <[hidden email]> Hello all I have a Google Analytics module, depending on the InlineScript helper to inject the javascript. The module (SlmGoogleAnalytics) is completely tested and runs also on Travis. Check out my repository: https://github.com/juriansluiman/SlmGoogleAnalytics Especially the test for the view helper might be interesting for you: https://github.com/juriansluiman/SlmGoogleAnalytics/blob/master/tests/SlmGoogleAnalyticsTest/View/Helper/GoogleAnalyticsTest.php
Like you, I also instantiate a view helper, then inject the PhpRenderer with $helper->setView($view); You can also register another view helper by the PhpRenderer's plugin manager: use Foo\View\Helper as FooHelper; use Zend\View\Renderer\PhpRenderer; $helper = new FooHelper(); $view = new PhpRenderer(); $manager = $view->getHelperPluginManager();
$manager->setService('myCustomHelper', $helper); -- Jurian Sluiman |
|
Hello Jurian
Thank you very much for your suggestion. > Like you, I also instantiate a view helper, then inject the PhpRenderer with > $helper->setView($view); You can also register another view helper by the > PhpRenderer's plugin manager: > > use Foo\View\Helper as FooHelper; > use Zend\View\Renderer\PhpRenderer; > > $helper = new FooHelper(); > $view = new PhpRenderer(); > $manager = $view->getHelperPluginManager(); > $manager->setService('myCustomHelper', $helper); This has solved the issue I was experiencing. Jonathan |
| Powered by Nabble | Edit this page |
