Skip to content

Commit

Permalink
Merge pull request #31 from HavokInspiration/accessing-helpers-fix
Browse files Browse the repository at this point in the history
Update the TwigView::generateHelperList() method
  • Loading branch information
WyriHaximus authored Jul 22, 2016
2 parents 6a2570c + d8e4878 commit 3ca1a44
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
},
"autoload-dev": {
"psr-4": {
"WyriHaximus\\CakePHP\\Tests\\TwigView\\": "tests/"
"WyriHaximus\\CakePHP\\Tests\\TwigView\\": "tests/",
"App\\": "tests/test_app/"
}
}
}
4 changes: 3 additions & 1 deletion src/View/TwigView.php
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
9 changes: 6 additions & 3 deletions tests/View/TwigViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,17 @@ 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 = 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)
);
Expand Down
17 changes: 17 additions & 0 deletions tests/test_app/View/Helper/TestSecondHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

/**
* This file is part of TwigView.
*
** (c) 2014 Cees-Jan Kiewiet
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\View\Helper;

use Cake\View\Helper;

class TestSecondHelper extends Helper
{
}

0 comments on commit 3ca1a44

Please sign in to comment.