Permalink
Browse files

Merge branch 'release'

  • Loading branch information...
2 parents 0204690 + ae095f7 commit 049e6e3f161e013058869ca87940ebe3897799dc @weierophinney weierophinney committed Sep 13, 2012
Showing with 57 additions and 1 deletion.
  1. +15 −1 library/Zend/Form/View/Helper/FormRow.php
  2. +42 −0 tests/ZendTest/Form/View/Helper/FormRowTest.php
@@ -88,7 +88,14 @@ public function render(ElementInterface $element)
$elementString = $elementHelper->render($element);
- if (!empty($label)) {
+ if (isset($label) && '' !== $label) {
+ // Translate the label
+ if (null !== ($translator = $this->getTranslator())) {
+ $label = $translator->translate(
+ $label, $this->getTranslatorTextDomain()
+ );
+ }
+
$label = $escapeHtmlHelper($label);
$labelAttributes = $element->getLabelAttributes();
@@ -281,6 +288,13 @@ protected function getLabelHelper()
$this->labelHelper = new FormLabel();
}
+ if ($this->hasTranslator()) {
+ $this->labelHelper->setTranslator(
+ $this->getTranslator(),
+ $this->getTranslatorTextDomain()
+ );
+ }
+
return $this->labelHelper;
}
@@ -159,4 +159,46 @@ public function testInvokeWithNoElementChainsHelper()
{
$this->assertSame($this->helper, $this->helper->__invoke());
}
+
+ public function testLabelWillBeTranslated()
+ {
+ $element = new Element('foo');
+ $element->setLabel('The value for foo:');
+
+ $mockTranslator = $this->getMock('Zend\I18n\Translator\Translator');
+ $mockTranslator->expects($this->any())
+ ->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);
+
+ // Additional coverage when element's id is set
+ $element->setAttribute('id', 'foo');
+ $markup = $this->helper->__invoke($element);
+ $this->assertContains('>translated content<', $markup);
+ $this->assertContains('<label', $markup);
+ $this->assertContains('</label>', $markup);
+ }
+
+
+
+ public function testTranslatorMethods()
+ {
+ $translatorMock = $this->getMock('Zend\I18n\Translator\Translator');
+ $this->helper->setTranslator($translatorMock, 'foo');
+
+ $this->assertEquals($translatorMock, $this->helper->getTranslator());
+ $this->assertEquals('foo', $this->helper->getTranslatorTextDomain());
+ $this->assertTrue($this->helper->hasTranslator());
+ $this->assertTrue($this->helper->isTranslatorEnabled());
+
+ $this->helper->setTranslatorEnabled(false);
+ $this->assertFalse($this->helper->isTranslatorEnabled());
+ }
}

0 comments on commit 049e6e3

Please sign in to comment.