createForm(); $expected = 'Sven'; $element = $form->getElement('name'); $element->setValue($expected); $result = $element->getValue(); $this->assertTrue($result === $expected); } // test getValue() w/ $_GET public function test_string_GET_1() { // this should work $form = $this->createForm(); $expected = $_GET['name'] = 'Sven'; $result = $form->getElement('name')->getValue(); $this->assertTrue($result === $expected); } // test getValue() w/ $_GET public function test_string_GET_2() { // this should not work, since no namespace is set $form = $this->createForm(); $_GET['home']['name'] = 'Sven'; $result = $form->getElement('name')->getValue(); $this->assertTrue(empty($result)); } // test name attribute serialization public function test_string_serialize() { $form = $this->createForm(); $expected = 'name="name"'; $element = $form->getElement('name'); $result = $element->serialize(); $this->assertTrue(strpos($result, $expected) !== false); } // COMBOBOX public function test_combobox_GET() { $form = $this->createForm(array('formname' => 'combobox')); $_GET['area'] = 'a01'; $element = $form->getElement('area'); $expected = 'a01'; $result = $element->getValue(); $this->assertTrue($result === $expected); } public function test_combobox_serialize() { $form = $this->createForm(array('formname' => 'combobox')); $expected = ''; $element = $form->getElement('area'); $result = self::stripElementId($element->serialize()); $this->assertTrue(strpos($result, $expected) !== false); } // ENUM public function test_enum_GET() { $form = $this->createForm(array('formname' => 'enum')); $_GET['area'] = 'a01'; $element = $form->getElement('area'); $expected = 'a01'; $result = $element->getValue(); $this->assertTrue($result === $expected); } public function test_enum_serialize() { $form = $this->createForm(array('formname' => 'enum')); $expected = ''; $element = $form->getElement('area'); $result = self::stripElementId($element->serialize()); $this->assertTrue($result === $expected); } // GROUP public function test_group_GET() { $form = $this->createForm(array('formname' => 'group')); $areaDefinition = array('values' => array(array('value' => '',),array('value' => 'a01',),),); $el = patForms::createElement('area', 'Enum', $areaDefinition); $group = $form->getElement('loginOptions'); $group->addElement($el); $_GET['area'] = 'a01'; $expected = array('area' => 'a01'); $result = $group->getValue(); $this->assertTrue($result === $expected); } public function test_group_serialize() { $form = $this->createForm(array('formname' => 'group')); $areaDefinition = array('values' => array(array('value' => '',),array('value' => 'a01',),),); $el = patForms::createElement('area', 'Enum', $areaDefinition); $group = $form->getElement('loginOptions'); $group->setRenderer(patForms::createRenderer('Array')); $group->addElement($el); $expected = ''; $element = $form->getElement('loginOptions'); $result = array_pop($element->serialize()); $result = self::stripElementId($result['element']); $this->assertTrue($result === $expected); } // HIDDEN public function test_hidden_GET() { $form = $this->createForm(array('formname' => 'hidden')); $_GET['area'] = 'a01'; $element = $form->getElement('area'); $expected = 'a01'; $result = $element->getValue(); $this->assertTrue($result === $expected); } public function test_hidden_serialize() { $form = $this->createForm(array('formname' => 'hidden')); $expected = ''; $element = $form->getElement('area'); $result = self::stripElementId($element->serialize()); $this->assertTrue($result === $expected); } // POOL public function test_pool_GET() { $form = $this->createForm(array('formname' => 'pool')); $_GET['mammalians']= array('and', 'deg'); $element = $form->getElement('mammalians'); $expected = array('and', 'deg'); $result = $element->getValue(); $this->assertTrue($result === $expected); } public function test_pool_serialize() { $form = $this->createForm(array('formname' => 'pool')); $expected = array( '!name="mammalians" id="mammalians"!', '!id="candidates_mammalians" name="candidates_mammalians"!', '!id="members_mammalians" name="members_mammalians"!', '!javascript:pool_mammalians.add\(\);!', '!javascript:pool_mammalians.remove\(\);!', '!pool_mammalians[\s]*=[\s]*new[\s]*pool\([\s]?\'mammalians\'[\s]?\);!', '!pool_mammalians.addCandidate!', '!pool_mammalians.init!', ); $element = $form->getElement('mammalians'); $result = $element->serialize(); $result = preg_replace($expected, ':FOUND:', $result); $this->assertTrue(substr_count($result, ':FOUND:') == 9); } // RADIO public function test_radio_GET() { $form = $this->createForm(array('formname' => 'radio')); $_GET['username'] = 'a02'; $element = $form->getElement('username'); $expected = 'a02'; $result = $element->getValue(); $this->assertTrue($result === $expected); } public function test_radio_serialize() { $form = $this->createForm(array('formname' => 'radio')); $expected = 'name="username"'; $element = $form->getElement('username'); $result = self::stripElementId($element->serialize()); $this->assertTrue(strpos($result, $expected) !== false); } public function test_radio_serialize_labelForId() { $form = $this->createForm(array('formname' => 'radio')); $expected = 'id="pfo'; $element = $form->getElement('username'); $result = $element->serialize(); $this->assertTrue(strpos($result, $expected) !== false); } // RADIOGROUP public function test_radiogroup_GET() { $form = $this->createForm(array('formname' => 'radiogroup')); $_GET['username'] = 'a02'; $element = $form->getElement('username'); $expected = 'a02'; $result = $element->getValue(); $this->assertTrue($result === $expected); } public function test_radiogroup_serialize() { $form = $this->createForm(array('formname' => 'radiogroup')); $expected = 'name="username"'; $element = $form->getElement('username'); $result = self::stripElementId($element->serialize()); $this->assertTrue(strpos($result, $expected) !== false); } // SET public function test_set_GET() { $form = $this->createForm(array('formname' => 'set')); $_GET['wishlist']= array('w1', 'w7'); $element = $form->getElement('wishlist'); $expected = array('w1', 'w7'); $result = $element->getValue(); $this->assertTrue($result === $expected); } public function test_set_serialize() { $form = $this->createForm(array('formname' => 'set')); $expected = 'name="wishlist[]"'; $element = $form->getElement('wishlist'); $result = $element->serialize(); $this->assertTrue(strpos($result, $expected) !== false); } // SWITCH public function test_switch_GET() { $form = $this->createForm(array('formname' => 'switch')); $_GET['enable'] = 'yes'; $element = $form->getElement('enable'); $expected = 'yes'; $result = $element->getValue(); $this->assertTrue($result === $expected); } public function test_switch_serialize() { $form = $this->createForm(array('formname' => 'switch')); $expected = ''; $element = $form->getElement('enable'); $result = self::stripElementId($element->serialize()); $this->assertTrue($result === $expected); } public function test_switch_serialize_labelForId() { $form = $this->createForm(array('formname' => 'switch')); $expected = 'id="pfo'; $element = $form->getElement('enable'); $result = $element->serialize(); $this->assertTrue(strpos($result, $expected) !== false); } } ?>