view = $this->getView(); $this->element = $this->getElement(); $this->element->setView($this->view); } /** * 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() { require_once 'Zend/View.php'; $view = new Zend_View(); $view->addHelperPath('Zend/Dojo/View/Helper/', 'Zend_Dojo_View_Helper'); return $view; } public function getElement() { $element = new Zend_Dojo_Form_Element_NumberTextBox( 'foo', array( 'value' => 'some text', 'label' => 'NumberTextBox', 'class' => 'someclass', 'style' => 'width: 100px;', ) ); return $element; } public function testLocaleAccessorsShouldProxyToConstraints() { $this->assertNull($this->element->getLocale()); $this->assertNull($this->element->getConstraint('locale')); $this->element->setLocale('en-US'); $this->assertEquals('en-US', $this->element->getLocale()); $this->assertTrue($this->element->hasConstraint('locale')); $this->assertEquals('en-US', $this->element->dijitParams['constraints']['locale']); } public function testPatternAccessorsShouldProxyToConstraints() { $this->assertNull($this->element->getPattern()); $this->assertFalse($this->element->hasConstraint('pattern')); $this->element->setPattern('###0.#####'); $this->assertEquals('###0.#####', $this->element->getPattern()); $this->assertTrue($this->element->hasConstraint('pattern')); $this->assertEquals('###0.#####', $this->element->dijitParams['constraints']['pattern']); } public function testTypeAccessorsShouldProxyToConstraints() { $this->assertNull($this->element->getType()); $this->assertFalse($this->element->hasConstraint('type')); $this->element->setType('percent'); $this->assertEquals('percent', $this->element->getType()); $this->assertTrue($this->element->hasConstraint('type')); $this->assertEquals('percent', $this->element->dijitParams['constraints']['type']); } /** * @expectedException Zend_Form_Element_Exception */ public function testTypeMutatorShouldThrowExceptionWithInvalidType() { $this->element->setType('foobar'); } public function testPlacesAccessorsShouldProxyToConstraints() { $this->assertNull($this->element->getPlaces()); $this->assertFalse($this->element->hasConstraint('places')); $this->element->setPlaces(3); $this->assertEquals(3, $this->element->getPlaces()); $this->assertTrue($this->element->hasConstraint('places')); $this->assertEquals(3, $this->element->dijitParams['constraints']['places']); } public function testStrictAccessorsShouldProxyToConstraints() { $this->assertFalse($this->element->getStrict()); $this->assertFalse($this->element->hasConstraint('strict')); $this->element->setStrict(true); $this->assertTrue($this->element->getStrict()); $this->assertTrue($this->element->hasConstraint('strict')); $this->assertEquals('true', $this->element->dijitParams['constraints']['strict']); } public function testShouldRenderNumberTextBoxDijit() { $html = $this->element->render(); $this->assertContains('dojoType="dijit.form.NumberTextBox"', $html); } } // Call Zend_Dojo_Form_Element_NumberTextBoxTest::main() if this source file is executed directly. if (PHPUnit_MAIN_METHOD == "Zend_Dojo_Form_Element_NumberTextBoxTest::main") { Zend_Dojo_Form_Element_NumberTextBoxTest::main(); }