|
10 | 10 | namespace ZendTest\Form\View\Helper;
|
11 | 11 |
|
12 | 12 | use PHPUnit_Framework_TestCase as TestCase;
|
| 13 | +use Zend\I18n\Translator\TranslatorInterface; |
13 | 14 | use Zend\Form\Element;
|
14 | 15 | use Zend\Form\Element\Captcha;
|
15 | 16 | use Zend\Form\View\HelperConfig;
|
@@ -248,6 +249,45 @@ public function testTranslatorMethods()
|
248 | 249 | $this->assertFalse($this->helper->isTranslatorEnabled());
|
249 | 250 | }
|
250 | 251 |
|
| 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 | + |
251 | 291 | public function testSetLabelPositionInputNullRaisesException()
|
252 | 292 | {
|
253 | 293 | $this->setExpectedException('Zend\Form\Exception\InvalidArgumentException');
|
|
0 commit comments