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

Commit

Permalink
Fixed rebase conflicts, added same functionality to renderCurrent and…
Browse files Browse the repository at this point in the history
… added tests
  • Loading branch information
Martin-P committed Apr 4, 2014
1 parent 13523e3 commit 7aa531e
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/Helper/FlashMessenger.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function render($namespace = PluginFlashMessenger::NAMESPACE_DEFAULT, arr
{
$flashMessenger = $this->getPluginFlashMessenger();
$messages = $flashMessenger->getMessagesFromNamespace($namespace);
return $this->renderMessages($namespace, $messages, $classes);
return $this->renderMessages($namespace, $messages, $classes, $autoEscape);
}

/**
Expand All @@ -120,11 +120,11 @@ public function render($namespace = PluginFlashMessenger::NAMESPACE_DEFAULT, arr
* @param array $classes
* @return string
*/
public function renderCurrent($namespace = PluginFlashMessenger::NAMESPACE_DEFAULT, array $classes = array())
public function renderCurrent($namespace = PluginFlashMessenger::NAMESPACE_DEFAULT, array $classes = array(), $autoEscape = null)
{
$flashMessenger = $this->getPluginFlashMessenger();
$messages = $flashMessenger->getCurrentMessagesFromNamespace($namespace);
return $this->renderMessages($namespace, $messages, $classes);
return $this->renderMessages($namespace, $messages, $classes, $autoEscape);
}

/**
Expand All @@ -134,7 +134,7 @@ public function renderCurrent($namespace = PluginFlashMessenger::NAMESPACE_DEFAU
* @param array $classes
* @return string
*/
protected function renderMessages($namespace = PluginFlashMessenger::NAMESPACE_DEFAULT, array $messages = array(), array $classes = array())
protected function renderMessages($namespace = PluginFlashMessenger::NAMESPACE_DEFAULT, array $messages = array(), array $classes = array(), $autoEscape = null)
{
// Prepare classes for opening tag
if (empty($classes)) {
Expand Down
63 changes: 62 additions & 1 deletion test/Helper/FlashMessengerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,13 @@ public function testCanSetAutoEscape()
$this->helper->setAutoEscape(false);
$this->assertFalse($this->helper->getAutoEscape());

$this->helper->SetAutoEscape(true);
$this->helper->setAutoEscape(true);
$this->assertTrue($this->helper->getAutoEscape());
}

/**
* @covers Zend\View\Helper\FlashMessenger::render
*/
public function testMessageIsEscapedByDefault()
{
$helper = new FlashMessenger;
Expand All @@ -469,6 +472,9 @@ public function testMessageIsEscapedByDefault()
$this->assertSame($displayAssertion, $display);
}

/**
* @covers Zend\View\Helper\FlashMessenger::render
*/
public function testMessageIsNotEscapedWhenAutoEscapeIsFalse()
{
$helper = new FlashMessenger;
Expand Down Expand Up @@ -518,4 +524,59 @@ public function testRenderUsesCurrentAutoEscapeByDefault()
$display = $this->helper->render(PluginFlashMessenger::NAMESPACE_DEFAULT);
$this->assertSame($displayAssertion, $display);
}

/**
* @covers Zend\View\Helper\FlashMessenger::renderCurrent
*/
public function testCurrentMessageIsEscapedByDefault()
{
$this->helper->addMessage('Foo<br />bar');

$displayAssertion = '<ul class="default"><li>Foo&lt;br /&gt;bar</li></ul>';
$display = $this->helper->renderCurrent(PluginFlashMessenger::NAMESPACE_DEFAULT);
$this->assertSame($displayAssertion, $display);
}

/**
* @covers Zend\View\Helper\FlashMessenger::renderCurrent
*/
public function testCurrentMessageIsNotEscapedWhenAutoEscapeIsFalse()
{
$this->helper->addMessage('Foo<br />bar');

$displayAssertion = '<ul class="default"><li>Foo<br />bar</li></ul>';
$display = $this->helper->setAutoEscape(false)
->renderCurrent(PluginFlashMessenger::NAMESPACE_DEFAULT);
$this->assertSame($displayAssertion, $display);
}

/**
* @covers Zend\View\Helper\FlashMessenger::renderCurrent
*/
public function testCanSetAutoEscapeOnRenderCurrent()
{
$this->helper->addMessage('Foo<br />bar');

$displayAssertion = '<ul class="default"><li>Foo<br />bar</li></ul>';
$display = $this->helper->renderCurrent(PluginFlashMessenger::NAMESPACE_DEFAULT, array(), false);
$this->assertSame($displayAssertion, $display);
}

/**
* @covers Zend\View\Helper\FlashMessenger::renderCurrent
*/
public function testRenderCurrentUsesCurrentAutoEscapeByDefault()
{
$this->helper->addMessage('Foo<br />bar');

$this->helper->setAutoEscape(false);
$displayAssertion = '<ul class="default"><li>Foo<br />bar</li></ul>';
$display = $this->helper->renderCurrent(PluginFlashMessenger::NAMESPACE_DEFAULT);
$this->assertSame($displayAssertion, $display);

$this->helper->setAutoEscape(true);
$displayAssertion = '<ul class="default"><li>Foo&lt;br /&gt;bar</li></ul>';
$display = $this->helper->renderCurrent(PluginFlashMessenger::NAMESPACE_DEFAULT);
$this->assertSame($displayAssertion, $display);
}
}

0 comments on commit 7aa531e

Please sign in to comment.