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

Commit

Permalink
Merge branch 'hotfix/20' into develop
Browse files Browse the repository at this point in the history
Forward port #20
  • Loading branch information
weierophinney committed Apr 7, 2016
2 parents dd06523 + 8e309f9 commit 8b53e9a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/View/Helper/FormRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public function render(ElementInterface $element, $labelPosition = null)
) {
$labelOpen = '';
$labelClose = '';
$label = $labelHelper($element);
$label = $labelHelper->openTag($element) . $label . $labelHelper->closeTag();
} else {
$labelOpen = $labelHelper->openTag($labelAttributes);
$labelClose = $labelHelper->closeTag();
Expand Down
40 changes: 40 additions & 0 deletions test/View/Helper/FormRowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace ZendTest\Form\View\Helper;

use PHPUnit_Framework_TestCase as TestCase;
use Zend\I18n\Translator\TranslatorInterface;
use Zend\Form\Element;
use Zend\Form\Element\Captcha;
use Zend\Form\View\HelperConfig;
Expand Down Expand Up @@ -248,6 +249,45 @@ public function testTranslatorMethods()
$this->assertFalse($this->helper->isTranslatorEnabled());
}

public function testLabelWillBeTranslatedOnceWithoutId()
{
$element = new Element('foo');
$element->setLabel('The value for foo:');

$mockTranslator = $this->getMock(TranslatorInterface::class);
$mockTranslator->expects($this->exactly(1))
->method('translate')
->will($this->returnValue('translated content'));

$this->helper->setTranslator($mockTranslator);
$this->assertTrue($this->helper->hasTranslator());

$markup = $this->helper->__invoke($element);
$this->assertContains('>translated content<', $markup);
$this->assertContains('<label', $markup);
$this->assertContains('</label>', $markup);
}

public function testLabelWillBeTranslatedOnceWithId()
{
$element = new Element('foo');
$element->setLabel('The value for foo:');
$element->setAttribute('id', 'foo');

$mockTranslator = $this->getMock(TranslatorInterface::class);
$mockTranslator->expects($this->exactly(1))
->method('translate')
->will($this->returnValue('translated content'));

$this->helper->setTranslator($mockTranslator);
$this->assertTrue($this->helper->hasTranslator());

$markup = $this->helper->__invoke($element);
$this->assertContains('>translated content<', $markup);
$this->assertContains('<label', $markup);
$this->assertContains('</label>', $markup);
}

public function testSetLabelPositionInputNullRaisesException()
{
$this->setExpectedException('Zend\Form\Exception\InvalidArgumentException');
Expand Down

0 comments on commit 8b53e9a

Please sign in to comment.