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_CheckBox( 'foo', array( 'label' => 'CheckBox', 'class' => 'someclass', 'style' => 'width: 100px;', ) ); return $element; } public function testCheckedFlagIsFalseByDefault() { $this->assertFalse($this->element->checked); } public function testCheckedAttributeNotRenderedByDefault() { $html = $this->element->render(); $this->assertNotContains('checked="checked"', $html); } public function testCheckedAttributeRenderedWhenCheckedFlagTrue() { $this->element->checked = true; $html = $this->element->render(); $this->assertContains('checked="checked"', $html); } public function testCheckedValueDefaultsToOne() { $this->assertEquals(1, $this->element->getCheckedValue()); } public function testUncheckedValueDefaultsToZero() { $this->assertEquals(0, $this->element->getUncheckedValue()); } public function testCanSetCheckedValue() { $this->testCheckedValueDefaultsToOne(); $this->element->setCheckedValue('foo'); $this->assertEquals('foo', $this->element->getCheckedValue()); } public function testCanSetUncheckedValue() { $this->testUncheckedValueDefaultsToZero(); $this->element->setUncheckedValue('foo'); $this->assertEquals('foo', $this->element->getUncheckedValue()); } public function testValueInitiallyUncheckedValue() { $this->assertEquals($this->element->getUncheckedValue(), $this->element->getValue()); } public function testSettingValueToCheckedValueSetsWithEquivalentValue() { $this->testValueInitiallyUncheckedValue(); $this->element->setValue($this->element->getCheckedValue()); $this->assertEquals($this->element->getCheckedValue(), $this->element->getValue()); } public function testSettingValueToAnythingOtherThanCheckedValueSetsAsUncheckedValue() { $this->testSettingValueToCheckedValueSetsWithEquivalentValue(); $this->element->setValue('bogus'); $this->assertEquals($this->element->getUncheckedValue(), $this->element->getValue()); } public function testSettingCheckedFlagToTrueSetsValueToCheckedValue() { $this->testValueInitiallyUncheckedValue(); $this->element->setChecked(true); $this->assertEquals($this->element->getCheckedValue(), $this->element->getValue()); } public function testSettingCheckedFlagToFalseSetsValueToUncheckedValue() { $this->testSettingCheckedFlagToTrueSetsValueToCheckedValue(); $this->element->setChecked(false); $this->assertEquals($this->element->getUncheckedValue(), $this->element->getValue()); } public function testSettingValueToCheckedValueMarksElementAsChecked() { $this->testValueInitiallyUncheckedValue(); $this->element->setValue($this->element->getCheckedValue()); $this->assertTrue($this->element->checked); } public function testSettingValueToUncheckedValueMarksElementAsNotChecked() { $this->testSettingValueToCheckedValueMarksElementAsChecked(); $this->element->setValue($this->element->getUncheckedValue()); $this->assertFalse($this->element->checked); } public function testIsCheckedShouldReflectCurrentCheckedStatus() { $this->element->setChecked(true); $this->assertTrue($this->element->isChecked()); $this->element->setChecked(false); $this->assertFalse($this->element->isChecked()); } public function testSetOptionsSetsInitialValueAccordingToCheckedAndUncheckedValues() { $options = array( 'checkedValue' => 'foo', 'uncheckedValue' => 'bar', ); $element = new Zend_Dojo_Form_Element_CheckBox('test', $options); $this->assertEquals($options['uncheckedValue'], $element->getValue()); } public function testSetOptionsSetsInitialValueAccordingToSubmittedValues() { $options = array( 'test1' => array( 'value' => 'foo', 'checkedValue' => 'foo', 'uncheckedValue' => 'bar', ), 'test2' => array( 'value' => 'bar', 'checkedValue' => 'foo', 'uncheckedValue' => 'bar', ), ); foreach ($options as $current) { $element = new Zend_Dojo_Form_Element_CheckBox('test', $current); $this->assertEquals($current['value'], $element->getValue()); $this->assertEquals($current['checkedValue'], $element->getCheckedValue()); $this->assertEquals($current['uncheckedValue'], $element->getUncheckedValue()); } } public function testShouldRenderCheckBoxDijit() { $html = $this->element->render(); $this->assertContains('dojoType="dijit.form.CheckBox"', $html); } /** * @group ZF-3879 */ public function testOptionsShouldNotBeRenderedAsElementAttribute() { $html = $this->element->render(); $this->assertNotContains('options="', $html, $html); } /** * @group ZF-4274 */ public function testCheckedValuesCanBePassedInConstructor() { $element = new Zend_Dojo_Form_Element_CheckBox('myCheckbox', array( 'checkedValue' => 'checkedVal', 'unCheckedValue' => 'UNCHECKED', )); $element->setView(new Zend_View()); $html = $element->render(); $this->assertContains('value="checkedVal"', $html, $html); } } // Call Zend_Dojo_Form_Element_CheckBoxTest::main() if this source file is executed directly. if (PHPUnit_MAIN_METHOD == "Zend_Dojo_Form_Element_CheckBoxTest::main") { Zend_Dojo_Form_Element_CheckBoxTest::main(); }