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

Commit afb7a73

Browse files
committed
Merge pull request #20 from terpfear/patch-1
Stop FormRow from translating the label twice
2 parents 570f79c + ec3c63f commit afb7a73

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-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: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,45 @@ public function testTranslatorMethods()
248248
$this->assertFalse($this->helper->isTranslatorEnabled());
249249
}
250250

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

0 commit comments

Comments
 (0)