decorator = new Zend_Form_Decorator_Label(); } /** * Tears down the fixture, for example, close a network connection. * This method is called after a test is executed. * * @return void */ public function tearDown() { } public function getView() { $view = new Zend_View(); $view->addHelperPath(dirname(__FILE__) . '/../../../../library/Zend/View/Helper'); return $view; } public function testUsesPrependPlacementByDefault() { $this->assertEquals(Zend_Form_Decorator_Abstract::PREPEND, $this->decorator->getPlacement()); } public function testRenderReturnsOriginalContentWhenNoViewPresentInElement() { $element = new Zend_Form_Element('foo'); $this->decorator->setElement($element); $content = 'test content'; $this->assertSame($content, $this->decorator->render($content)); } public function testRenderReturnsOriginalContentWhenNoLabelPresentInElement() { $element = new Zend_Form_Element('foo'); $this->decorator->setElement($element); $content = 'test content'; $this->assertSame($content, $this->decorator->render($content)); } public function testRenderUsesElementIdIfSet() { $element = new Zend_Form_Element('foo'); $element->setAttrib('id', 'foobar') ->setView($this->getView()) ->setLabel('My Label'); $this->decorator->setElement($element); $content = 'test content'; $test = $this->decorator->render($content); $this->assertContains('for="foobar"', $test); } public function testRenderAddsOptionalClassForNonRequiredElements() { $element = new Zend_Form_Element('foo'); $element->setView($this->getView()) ->setLabel('My Label'); $this->decorator->setElement($element); $content = 'test content'; $test = $this->decorator->render($content); $this->assertRegexp('/]*?class="[^"]*optional/', $test, $test); $element->class = "bar"; $this->decorator->setOption('class', 'foo'); $test = $this->decorator->render($content); $this->assertNotRegexp('/]*?class="[^"]*bar/', $test, $test); $this->assertRegexp('/]*?class="[^"]*foo/', $test, $test); $this->assertRegexp('/]*?class="[^"]*optional/', $test, $test); } public function testRenderAddsRequiredClassForRequiredElements() { $element = new Zend_Form_Element('foo'); $element->setRequired(true) ->setView($this->getView()) ->setLabel('My Label'); $this->decorator->setElement($element); $content = 'test content'; $test = $this->decorator->render($content); $this->assertRegexp('/]*?class="[^"]*required/', $test, $test); $element->class = "bar"; $this->decorator->setOption('class', 'foo'); $test = $this->decorator->render($content); $this->assertNotRegexp('/]*?class="[^"]*bar/', $test, $test); $this->assertRegexp('/]*?class="[^"]*foo/', $test, $test); $this->assertRegexp('/]*?class="[^"]*required/', $test, $test); } public function testRenderAppendsRequiredClassToClassProvidedInRequiredElement() { $element = new Zend_Form_Element('foo'); $element->setRequired(true) ->setView($this->getView()) ->setLabel('My Label') ->setAttrib('class', 'bazbat'); $this->decorator->setElement($element); $content = 'test content'; $test = $this->decorator->render($content); $this->assertRegexp('/]*?class="[^"]*required/', $test, $test); $this->assertNotRegexp('/]*?class="[^"]*bazbat/', $test, $test); } public function testRenderUtilizesOptionalSuffixesAndPrefixesWhenRequested() { $element = new Zend_Form_Element('foo'); $element->setAttribs(array( 'optionalPrefix' => '-opt-prefix-', 'optionalSuffix' => '-opt-suffix-', 'requiredPrefix' => '-req-prefix-', 'requiredSuffix' => '-req-suffix-', )) ->setView($this->getView()) ->setLabel('My Label'); $this->decorator->setElement($element); $content = 'test content'; $test = $this->decorator->render($content); $this->assertNotContains('-req-prefix-', $test, $test); $this->assertNotContains('-req-suffix-', $test, $test); $this->assertContains('-opt-prefix-', $test, $test); $this->assertContains('-opt-suffix-', $test, $test); $this->assertRegexp('/-opt-prefix-[^-]*?My Label[^-]*-opt-suffix-/s', $test, $test); } public function testRenderUtilizesRequiredSuffixesAndPrefixesWhenRequested() { $element = new Zend_Form_Element('foo'); $element->setAttribs(array( 'optionalPrefix' => '-opt-prefix-', 'optionalSuffix' => '-opt-suffix-', 'requiredPrefix' => '-req-prefix-', 'requiredSuffix' => '-req-suffix-', )) ->setRequired(true) ->setView($this->getView()) ->setLabel('My Label'); $this->decorator->setElement($element); $content = 'test content'; $test = $this->decorator->render($content); $this->assertNotContains('-opt-prefix-', $test, $test); $this->assertNotContains('-opt-suffix-', $test, $test); $this->assertContains('-req-prefix-', $test, $test); $this->assertContains('-req-suffix-', $test, $test); $this->assertRegexp('/-req-prefix-[^-]*?My Label[^-]*-req-suffix-/s', $test, $test); } /** * @group ZF-3538 */ public function testRenderShouldNotUtilizeElementClass() { $element = new Zend_Form_Element('foo'); $element->setView($this->getView()) ->setLabel('My Label') ->setAttrib('class', 'foobar'); $this->decorator->setElement($element); $content = 'test content'; $test = $this->decorator->render($content); $this->assertNotRegexp('#]*(class="[^"]*foobar)[^"]*"#', $test, $test); } public function testRenderRendersLabel() { $element = new Zend_Form_Element('foo'); $element->setView($this->getView()) ->setLabel('My Label'); $this->decorator->setElement($element); $content = 'test content'; $test = $this->decorator->render($content); $this->assertContains($content, $test); $this->assertContains($element->getLabel(), $test); $this->assertContains('