From 6b7c130499591fe529853fa6c00127951d7981bf Mon Sep 17 00:00:00 2001 From: Yves P Date: Thu, 21 Jul 2016 13:25:20 +0200 Subject: [PATCH 1/2] The Helpers list is composed with the helpers in the "helpers" property of the View object and with the helpers loaded in the registry using the `loadHelper()` method Add a test case to cover the new helper list generation behavior --- composer.json | 3 ++- src/View/TwigView.php | 4 +++- tests/View/TwigViewTest.php | 3 +++ tests/test_app/View/Helper/TestSecondHelper.php | 17 +++++++++++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 tests/test_app/View/Helper/TestSecondHelper.php diff --git a/composer.json b/composer.json index 699dd05..7bb09d7 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,8 @@ }, "autoload-dev": { "psr-4": { - "WyriHaximus\\CakePHP\\Tests\\TwigView\\": "tests/" + "WyriHaximus\\CakePHP\\Tests\\TwigView\\": "tests/", + "App\\": "tests/test_app/" } } } diff --git a/src/View/TwigView.php b/src/View/TwigView.php index af8bc77..829971d 100644 --- a/src/View/TwigView.php +++ b/src/View/TwigView.php @@ -164,7 +164,9 @@ protected function getLoader() protected function generateHelperList() { $registry = $this->helpers(); - $helpers = $registry->normalizeArray($this->helpers); + + $helpersList = array_merge($this->helpers, $registry->loaded()); + $helpers = $registry->normalizeArray($helpersList); foreach ($helpers as $properties) { list(, $class) = pluginSplit($properties['class']); $this->helperList[$class] = $this->{$class}; diff --git a/tests/View/TwigViewTest.php b/tests/View/TwigViewTest.php index 79d709c..3bb4a2a 100644 --- a/tests/View/TwigViewTest.php +++ b/tests/View/TwigViewTest.php @@ -143,11 +143,14 @@ public function testGenerateHelperList() $view = new TwigView(Phake::mock('Cake\Network\Request'), Phake::mock('Cake\Network\Response'), Phake::mock('Cake\Event\EventManager')); $view->TestHelper = 'foo:bar'; $view->helpers = $helpersArray; + $view->loadHelper('TestSecond'); + $view->TestSecond = 'bar:foo'; self::getMethod('generateHelperList')->invoke($view); $this->assertSame( [ 'TestHelper' => 'foo:bar', + 'TestSecond' => 'bar:foo', ], self::getProperty('helperList')->getValue($view) ); diff --git a/tests/test_app/View/Helper/TestSecondHelper.php b/tests/test_app/View/Helper/TestSecondHelper.php new file mode 100644 index 0000000..1d455f6 --- /dev/null +++ b/tests/test_app/View/Helper/TestSecondHelper.php @@ -0,0 +1,17 @@ + Date: Thu, 21 Jul 2016 14:09:33 +0200 Subject: [PATCH 2/2] Fix indentation --- tests/View/TwigViewTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/View/TwigViewTest.php b/tests/View/TwigViewTest.php index 3bb4a2a..7a8d426 100644 --- a/tests/View/TwigViewTest.php +++ b/tests/View/TwigViewTest.php @@ -140,10 +140,10 @@ public function testGenerateHelperList() ] ); - $view = new TwigView(Phake::mock('Cake\Network\Request'), Phake::mock('Cake\Network\Response'), Phake::mock('Cake\Event\EventManager')); - $view->TestHelper = 'foo:bar'; - $view->helpers = $helpersArray; - $view->loadHelper('TestSecond'); + $view = new TwigView(Phake::mock('Cake\Network\Request'), Phake::mock('Cake\Network\Response'), Phake::mock('Cake\Event\EventManager')); + $view->TestHelper = 'foo:bar'; + $view->helpers = $helpersArray; + $view->loadHelper('TestSecond'); $view->TestSecond = 'bar:foo'; self::getMethod('generateHelperList')->invoke($view);