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

Commit 73aeb82

Browse files
committed
Merge branch 'hotfix/20'
Close #20
2 parents 570f79c + 8e309f9 commit 73aeb82

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/View/Helper/FormRow.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public function render(ElementInterface $element, $labelPosition = null)
199199
) {
200200
$labelOpen = '';
201201
$labelClose = '';
202-
$label = $labelHelper($element);
202+
$label = $labelHelper->openTag($element) . $label . $labelHelper->closeTag();
203203
} else {
204204
$labelOpen = $labelHelper->openTag($labelAttributes);
205205
$labelClose = $labelHelper->closeTag();

test/View/Helper/FormRowTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace ZendTest\Form\View\Helper;
1111

1212
use PHPUnit_Framework_TestCase as TestCase;
13+
use Zend\I18n\Translator\TranslatorInterface;
1314
use Zend\Form\Element;
1415
use Zend\Form\Element\Captcha;
1516
use Zend\Form\View\HelperConfig;
@@ -248,6 +249,45 @@ public function testTranslatorMethods()
248249
$this->assertFalse($this->helper->isTranslatorEnabled());
249250
}
250251

252+
public function testLabelWillBeTranslatedOnceWithoutId()
253+
{
254+
$element = new Element('foo');
255+
$element->setLabel('The value for foo:');
256+
257+
$mockTranslator = $this->getMock(TranslatorInterface::class);
258+
$mockTranslator->expects($this->exactly(1))
259+
->method('translate')
260+
->will($this->returnValue('translated content'));
261+
262+
$this->helper->setTranslator($mockTranslator);
263+
$this->assertTrue($this->helper->hasTranslator());
264+
265+
$markup = $this->helper->__invoke($element);
266+
$this->assertContains('>translated content<', $markup);
267+
$this->assertContains('<label', $markup);
268+
$this->assertContains('</label>', $markup);
269+
}
270+
271+
public function testLabelWillBeTranslatedOnceWithId()
272+
{
273+
$element = new Element('foo');
274+
$element->setLabel('The value for foo:');
275+
$element->setAttribute('id', 'foo');
276+
277+
$mockTranslator = $this->getMock(TranslatorInterface::class);
278+
$mockTranslator->expects($this->exactly(1))
279+
->method('translate')
280+
->will($this->returnValue('translated content'));
281+
282+
$this->helper->setTranslator($mockTranslator);
283+
$this->assertTrue($this->helper->hasTranslator());
284+
285+
$markup = $this->helper->__invoke($element);
286+
$this->assertContains('>translated content<', $markup);
287+
$this->assertContains('<label', $markup);
288+
$this->assertContains('</label>', $markup);
289+
}
290+
251291
public function testSetLabelPositionInputNullRaisesException()
252292
{
253293
$this->setExpectedException('Zend\Form\Exception\InvalidArgumentException');

0 commit comments

Comments
 (0)