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

Commit 25ad55f

Browse files
committed
Tests to ensure translator is only called once
Translator should only be called once on the element label. These tests make sure this is true whether or not the element has a label.
1 parent 5e99856 commit 25ad55f

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

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)