Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Show file tree
Hide file tree
Showing 11 changed files with 240 additions and 7 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@
"zendframework/zend-navigation": "Zend\\Navigation component",
"zendframework/zend-paginator": "Zend\\Paginator component",
"zendframework/zend-permissions-acl": "Zend\\Permissions\\Acl component",
"zendframework/zend-servicemanager": "Zend\\ServiceManager component",
"zendframework/zend-servicemanager": "self.version",
"zendframework/zend-uri": "Zend\\Uri component"
},
"extra": {
"branch-alias": {
"dev-master": "2.4-dev",
"dev-develop": "2.5-dev"
"dev-master": "2.1-dev",
"dev-develop": "2.2-dev"
}
},
"autoload-dev": {
Expand Down
6 changes: 4 additions & 2 deletions src/Helper/FlashMessenger.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class FlashMessenger extends AbstractTranslatorHelper implements ServiceLocatorA
/**
* Returns the flash messenger plugin controller
*
* @return FlashMessenger|FlashMessenger\Controller\Plugin\FlashMessenger
* @param string|null $namespace
* @return FlashMessenger|PluginFlashMessenger
*/
public function __invoke($namespace = null)
{
Expand Down Expand Up @@ -123,7 +124,7 @@ public function render($namespace = PluginFlashMessenger::NAMESPACE_DEFAULT, arr

// Generate markup
$markup = sprintf($this->getMessageOpenFormat(), ' class="' . implode(' ', $classes) . '"');
$markup .= implode($this->getMessageSeparatorString(), $messagesToPrint);
$markup .= implode(sprintf($this->getMessageSeparatorString(), ' class="' . implode(' ', $classes) . '"'), $messagesToPrint);
$markup .= $this->getMessageCloseString();

return $markup;
Expand Down Expand Up @@ -237,6 +238,7 @@ public function getPluginFlashMessenger()
/**
* Set the flash messenger plugin
*
* @param PluginFlashMessenger $pluginFlashMessenger
* @return FlashMessenger
*/
public function setPluginFlashMessenger(PluginFlashMessenger $pluginFlashMessenger)
Expand Down
6 changes: 5 additions & 1 deletion src/Helper/Navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,16 @@ public function findHelper($proxy, $strict = true)

$helper = $plugins->get($proxy);
$container = $this->getContainer();
$hash = spl_object_hash($container);
$hash = spl_object_hash($container) . spl_object_hash($helper);

if (!isset($this->injected[$hash])) {
$helper->setContainer();
$this->inject($helper);
$this->injected[$hash] = true;
} else {
if ($this->getInjectContainer()) {
$helper->setContainer($container);
}
}

return $helper;
Expand Down
1 change: 1 addition & 0 deletions src/Helper/Placeholder/Container/AbstractStandalone.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public function setEscaper(Escaper $escaper)
*
* Lazy-loads one if none available
*
* @param string|null $enc Encoding to use
* @return mixed
*/
public function getEscaper($enc = 'UTF-8')
Expand Down
2 changes: 1 addition & 1 deletion src/Renderer/JsonRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function setMergeUnnamedChildren($mergeUnnamedChildren)
* Set the JSONP callback function name
*
* @param string $callback
* @return JsonpModel
* @return JsonRenderer
*/
public function setJsonpCallback($callback)
{
Expand Down
42 changes: 42 additions & 0 deletions src/Renderer/PhpRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,48 @@
* Note: all private variables in this class are prefixed with "__". This is to
* mark them as part of the internal implementation, and thus prevent conflict
* with variables injected into the renderer.
*
* Convenience methods for build in helpers (@see __call):
*
* @method \Zend\View\Helper\BasePath basePath($file = null)
* @method \Zend\View\Helper\Cycle cycle(array $data = array(), $name = \Zend\View\Helper\Cycle::DEFAULT_NAME)
* @method \Zend\View\Helper\DeclareVars declareVars()
* @method \Zend\View\Helper\Doctype doctype($doctype = null)
* @method mixed escapeCss($value, $recurse = \Zend\View\Helper\Escaper\AbstractHelper::RECURSE_NONE)
* @method mixed escapeHtml($value, $recurse = \Zend\View\Helper\Escaper\AbstractHelper::RECURSE_NONE)
* @method mixed escapeHtmlAttr($value, $recurse = \Zend\View\Helper\Escaper\AbstractHelper::RECURSE_NONE)
* @method mixed escapeJs($value, $recurse = \Zend\View\Helper\Escaper\AbstractHelper::RECURSE_NONE)
* @method mixed escapeUrl($value, $recurse = \Zend\View\Helper\Escaper\AbstractHelper::RECURSE_NONE)
* @method \Zend\View\Helper\FlashMessenger flashMessenger($namespace = null)
* @method \Zend\View\Helper\Gravatar gravatar($email = "", $options = array(), $attribs = array())
* @method \Zend\View\Helper\HeadLink headLink(array $attributes = null, $placement = \Zend\View\Helper\Placeholder\Container\AbstractContainer::APPEND)
* @method \Zend\View\Helper\HeadMeta headMeta($content = null, $keyValue = null, $keyType = 'name', $modifiers = array(), $placement = \Zend\View\Helper\Placeholder\Container\AbstractContainer::APPEND)
* @method \Zend\View\Helper\HeadScript headScript($mode = \Zend\View\Helper\HeadScript::FILE, $spec = null, $placement = 'APPEND', array $attrs = array(), $type = 'text/javascript')
* @method \Zend\View\Helper\HeadStyle headStyle($content = null, $placement = 'APPEND', $attributes = array())
* @method \Zend\View\Helper\HeadTitle headTitle($title = null, $setType = null)
* @method string htmlFlash($data, array $attribs = array(), array $params = array(), $content = null)
* @method string htmlList(array $items, $ordered = false, $attribs = false, $escape = true)
* @method string htmlObject($data = null, $type = null, array $attribs = array(), array $params = array(), $content = null)
* @method string htmlPage($data, array $attribs = array(), array $params = array(), $content = null)
* @method string htmlQuicktime($data, array $attribs = array(), array $params = array(), $content = null)
* @method mixed|null identity()
* @method \Zend\View\Helper\InlineScript inlineScript($mode = \Zend\View\Helper\HeadScript::FILE, $spec = null, $placement = 'APPEND', array $attrs = array(), $type = 'text/javascript')
* @method string|void json($data, array $jsonOptions = array())
* @method \Zend\View\Helper\Layout layout($template = null)
* @method \Zend\View\Helper\Navigation navigation($container = null)
* @method string paginationControl(\Zend\Paginator\Paginator $paginator = null, $scrollingStyle = null, $partial = null, $params = null)
* @method string|\Zend\View\Helper\Partial partial($name = null, $values = null)
* @method string partialLoop($name = null, $values = null)
* @method \Zend\View\Helper\Placeholder\Container\AbstractContainer placeHolder($name = null)
* @method string renderChildModel($child)
* @method void renderToPlaceholder($script, $placeholder)
* @method string serverUrl($requestUri = null)
* @method string url($name = null, array $params = array(), $options = array(), $reuseMatchedParams = false)
* @method \Zend\View\Helper\ViewModel viewModel()
* @method \Zend\View\Helper\Navigation\Breadcrumbs breadCrumbs($container = null)
* @method \Zend\View\Helper\Navigation\Links links($container = null)
* @method \Zend\View\Helper\Navigation\Menu menu($container = null)
* @method \Zend\View\Helper\Navigation\Sitemap sitemap($container = null)
*/
class PhpRenderer implements Renderer, TreeRendererInterface
{
Expand Down
12 changes: 12 additions & 0 deletions src/Stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class Stream

/**
* Opens the script file and converts markup.
*
* @return bool
*/
public function stream_open($path, $mode, $options, &$opened_path)
{
Expand Down Expand Up @@ -92,6 +94,8 @@ public function url_stat()

/**
* Reads from the stream.
*
* @return string|false
*/
public function stream_read($count)
{
Expand All @@ -103,6 +107,8 @@ public function stream_read($count)

/**
* Tells the current position in the stream.
*
* @return int
*/
public function stream_tell()
{
Expand All @@ -112,6 +118,8 @@ public function stream_tell()

/**
* Tells if we are at the end of the stream.
*
* @return bool
*/
public function stream_eof()
{
Expand All @@ -121,6 +129,8 @@ public function stream_eof()

/**
* Stream statistics.
*
* @return array
*/
public function stream_stat()
{
Expand All @@ -130,6 +140,8 @@ public function stream_stat()

/**
* Seek to a specific point in the stream.
*
* @return bool
*/
public function stream_seek($offset, $whence)
{
Expand Down
4 changes: 4 additions & 0 deletions src/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ public function render(Model $model)
$event->setRenderer($renderer);
$results = $events->trigger(ViewEvent::EVENT_RENDERER_POST, $event);

// If EVENT_RENDERER or EVENT_RENDERER_POST changed the model, make sure
// we use this new model instead of the current $model
$model = $event->getModel();

// If we have children, render them first, but only if:
// a) the renderer does not implement TreeRendererInterface, or
// b) it does, but canRenderTrees() returns false
Expand Down
48 changes: 48 additions & 0 deletions test/Helper/FlashMessengerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,19 @@ public function testCanDisplayListOfMessagesCustomised()
$this->assertEquals($displayInfoAssertion, $displayInfo);
}

public function testCanDisplayListOfMessagesCustomisedSeparator()
{
$this->seedMessages();

$displayInfoAssertion = '<div><p class="foo-baz foo-bar">foo</p><p class="foo-baz foo-bar">bar</p></div>';
$displayInfo = $this->helper
->setMessageOpenFormat('<div><p%s>')
->setMessageSeparatorString('</p><p%s>')
->setMessageCloseString('</p></div>')
->render(PluginFlashMessenger::NAMESPACE_DEFAULT, array('foo-baz', 'foo-bar'));
$this->assertEquals($displayInfoAssertion, $displayInfo);
}

public function testCanDisplayListOfMessagesCustomisedByConfig()
{
$this->seedMessages();
Expand Down Expand Up @@ -184,6 +197,41 @@ public function testCanDisplayListOfMessagesCustomisedByConfig()
$this->assertEquals($displayInfoAssertion, $displayInfo);
}

public function testCanDisplayListOfMessagesCustomisedByConfigSeparator()
{
$this->seedMessages();

$config = array(
'view_helper_config' => array(
'flashmessenger' => array(
'message_open_format' => '<div><ul><li%s>',
'message_separator_string' => '</li><li%s>',
'message_close_string' => '</li></ul></div>',
),
),
);
$sm = new ServiceManager();
$sm->setService('Config', $config);
$helperPluginManager = new HelperPluginManager(new Config(array(
'factories' => array(
'flashmessenger' => 'Zend\View\Helper\Service\FlashMessengerFactory',
),
)));
$controllerPluginManager = new PluginManager(new Config(array(
'invokables' => array(
'flashmessenger' => 'Zend\Mvc\Controller\Plugin\FlashMessenger',
),
)));
$helperPluginManager->setServiceLocator($sm);
$controllerPluginManager->setServiceLocator($sm);
$sm->setService('ControllerPluginManager', $controllerPluginManager);
$helper = $helperPluginManager->get('flashmessenger');

$displayInfoAssertion = '<div><ul><li class="foo-baz foo-bar">foo</li><li class="foo-baz foo-bar">bar</li></ul></div>';
$displayInfo = $helper->render(PluginFlashMessenger::NAMESPACE_DEFAULT, array('foo-baz', 'foo-bar'));
$this->assertEquals($displayInfoAssertion, $displayInfo);
}

public function testCanTranslateMessages()
{
$mockTranslator = $this->getMock('Zend\I18n\Translator\Translator');
Expand Down
92 changes: 92 additions & 0 deletions test/Helper/Navigation/NavigationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ public function testDisablingContainerInjection()
$this->assertEquals($expected, $actual);
}

public function testMultipleNavigationsAndOneMenuDisplayedTwoTimes()
{
$expected = $this->_helper->setContainer($this->_nav1)->menu()->getContainer();
$this->_helper->setContainer($this->_nav2)->menu()->getContainer();
$actual = $this->_helper->setContainer($this->_nav1)->menu()->getContainer();

$this->assertEquals($expected, $actual);
}

public function testServiceManagerIsUsedToRetrieveContainer()
{
$container = new Container;
Expand Down Expand Up @@ -463,6 +472,89 @@ public function testMultipleNavigations()
$this->assertEquals($expected, $actual);
}

/**
* @group #3859
*/
public function testMultipleNavigationsWithDifferentHelpersAndDifferentContainers()
{
$sm = new ServiceManager();
$nav1 = new Container();
$nav2 = new Container();
$sm->setService('nav1', $nav1);
$sm->setService('nav2', $nav2);

$helper = new Navigation();
$helper->setServiceLocator($sm);

$menu = $helper('nav1')->menu();
$actual = spl_object_hash($nav1);
$expected = spl_object_hash($menu->getContainer());
$this->assertEquals($expected, $actual);

$breadcrumbs = $helper('nav2')->breadcrumbs();
$actual = spl_object_hash($nav2);
$expected = spl_object_hash($breadcrumbs->getContainer());
$this->assertEquals($expected, $actual);

$links = $helper()->links();
$expected = spl_object_hash($links->getContainer());
$this->assertEquals($expected, $actual);
}

/**
* @group #3859
*/
public function testMultipleNavigationsWithDifferentHelpersAndSameContainer()
{
$sm = new ServiceManager();
$nav1 = new Container();
$sm->setService('nav1', $nav1);

$helper = new Navigation();
$helper->setServiceLocator($sm);

// Tests
$menu = $helper('nav1')->menu();
$actual = spl_object_hash($nav1);
$expected = spl_object_hash($menu->getContainer());
$this->assertEquals($expected, $actual);

$breadcrumbs = $helper('nav1')->breadcrumbs();
$expected = spl_object_hash($breadcrumbs->getContainer());
$this->assertEquals($expected, $actual);

$links = $helper()->links();
$expected = spl_object_hash($links->getContainer());
$this->assertEquals($expected, $actual);
}

/**
* @group #3859
*/
public function testMultipleNavigationsWithSameHelperAndSameContainer()
{
$sm = new ServiceManager();
$nav1 = new Container();
$sm->setService('nav1', $nav1);

$helper = new Navigation();
$helper->setServiceLocator($sm);

// Test
$menu = $helper('nav1')->menu();
$actual = spl_object_hash($nav1);
$expected = spl_object_hash($menu->getContainer());
$this->assertEquals($expected, $actual);

$menu = $helper('nav1')->menu();
$expected = spl_object_hash($menu->getContainer());
$this->assertEquals($expected, $actual);

$menu = $helper()->menu();
$expected = spl_object_hash($menu->getContainer());
$this->assertEquals($expected, $actual);
}

/**
* Returns the contens of the expected $file, normalizes newlines
* @param string $file
Expand Down
Loading

0 comments on commit dd751f9

Please sign in to comment.