createForm(array('namespace' => 'home')); $_GET['name'] = 'Sven'; $result = $form->getElement('name')->getValue(); $this->assertTrue(empty($result)); } // test getValue() w/ $_GET public function test_string_GET_2() { // this should work $form = $this->createForm(array('namespace' => 'home')); $expected = $_GET['home']['name'] = 'Sven'; $result = $form->getElement('name')->getValue(); $this->assertTrue($result === $expected); } // test getValue() w/ $_GET public function test_string_GET_3() { // this should work $form = $this->createForm(array('namespace' => 'addresses.home')); $expected = $_GET['addresses']['home']['name'] = 'Sven'; $result = $form->getElement('name')->getValue(); $this->assertTrue($result === $expected); } // test name attribute serialization public function test_string_serialize_1() { $form = $this->createForm(array('namespace' => 'home')); $expected = 'name="home[name]"'; $element = $form->getElement('name'); $result = $element->serialize(); $this->assertTrue(strpos($result, $expected) !== false); } // test name attribute serialization public function test_string_serialize_2() { $form = $this->createForm(array('namespace' => 'addresses.home')); $expected = 'name="addresses[home][name]"'; $element = $form->getElement('name'); $result = $element->serialize(); $this->assertTrue(strpos($result, $expected) !== false); } // test name attribute serialization w/ $_POST public function test_two_forms() { $_POST = array( 'addresses' => array( 'home' => array( 'name' => 'Sven@home', ), 'work' => array( 'name' => 'Sven@work', ), ), ); $form = $this->createForm(array('namespace' => 'addresses.home')); $element = $form->getElement('name'); $result = self::stripElementId($element->serialize()); $form = $this->createForm(array('namespace' => 'addresses.work')); $element = $form->getElement('name'); $result .= self::stripElementId($element->serialize()); $expected = '' . ''; $this->assertTrue($result === $expected); } // COMBOBOX public function test_combobox_GET() { $form = $this->createForm(array( 'namespace' => 'home', 'formname' => 'combobox')); $_GET = array('home' => array('area' => 'a01')); $element = $form->getElement('area'); $expected = 'a01'; $result = $element->getValue(); $this->assertTrue($result === $expected); } public function test_combobox_serialize() { $form = $this->createForm(array( 'namespace' => 'home', 'formname' => 'combobox')); $expected = 'name="home[area]"'; $element = $form->getElement('area'); $result = $element->serialize(); $this->assertTrue(strpos($result, $expected) !== false); } // ENUM public function test_enum_GET() { $form = $this->createForm(array( 'namespace' => 'home', 'formname' => 'enum')); $_GET = array('home' => array('area' => 'a01')); $element = $form->getElement('area'); $expected = 'a01'; $result = $element->getValue(); $this->assertTrue($result === $expected); } public function test_enum_serialize() { $form = $this->createForm(array( 'namespace' => 'home', 'formname' => 'enum')); $expected = 'name="home[area]"'; $element = $form->getElement('area'); $result = $element->serialize(); $this->assertTrue(strpos($result, $expected) !== false); } // GROUP public function test_group_GET() { $form = $this->createForm(array( 'namespace' => 'home', '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 = array('home' => array('area' => 'a01')); $expected = array('area' => 'a01'); $result = $group->getValue(); $this->assertTrue($result === $expected); } public function test_group_serialize() { $form = $this->createForm(array( 'namespace' => 'home', '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( 'namespace' => 'home', 'formname' => 'hidden')); $_GET = array('home' => array('area' => 'a01')); $element = $form->getElement('area'); $expected = 'a01'; $result = $element->getValue(); $this->assertTrue($result === $expected); } public function test_hidden_serialize() { $form = $this->createForm(array( 'namespace' => 'home', '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( 'namespace' => 'home', 'formname' => 'pool')); $_GET = array('home' => array('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( 'namespace' => 'home', 'formname' => 'pool')); $expected = array( 'name="home[mammalians]" id="home_mammalians"', 'id="candidates_home_mammalians" name="home[candidates_mammalians]"', 'id="members_home_mammalians" name="home[members_mammalians]"', 'javascript:pool_home_mammalians.add();', 'javascript:pool_home_mammalians.remove();', 'pool_home_mammalians = new pool(\'home_mammalians\');', 'pool_home_mammalians.addCandidate', 'pool_home_mammalians.init', ); $element = $form->getElement('mammalians'); $result = $element->serialize(); $result = str_replace($expected, ':FOUND:', $result); $this->assertTrue(substr_count($result, ':FOUND:') == 9); } // RADIO public function test_radio_GET() { $form = $this->createForm(array( 'namespace' => 'home', 'formname' => 'radio')); $_GET = array('home' => array('username' => 'a02')); $element = $form->getElement('username'); $expected = 'a02'; $result = $element->getValue(); $this->assertTrue($result === $expected); } public function test_radio_serialize() { $form = $this->createForm(array( 'namespace' => 'home', 'formname' => 'radio')); $expected = 'name="home[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( 'namespace' => 'home', 'formname' => 'radio')); $expected = 'id="home_pfo'; $element = $form->getElement('username'); $result = $element->serialize(); $this->assertTrue(strpos($result, $expected) !== false); } // RADIOGROUP public function test_radiogroup_GET() { $form = $this->createForm(array( 'namespace' => 'home', 'formname' => 'radiogroup')); $_GET = array('home' => array('username' => 'a02')); $element = $form->getElement('username'); $expected = 'a02'; $result = $element->getValue(); $this->assertTrue($result === $expected); } public function test_radiogroup_serialize() { $form = $this->createForm(array( 'namespace' => 'home', 'formname' => 'radiogroup')); $expected = 'name="home[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( 'namespace' => 'home', 'formname' => 'set')); $_GET = array('home' => array('wishlist' => 'w1')); $element = $form->getElement('wishlist'); $expected = 'w1'; $result = $element->getValue(); $this->assertTrue($result === $expected); } public function test_set_serialize() { $form = $this->createForm(array( 'namespace' => 'home', 'formname' => 'set')); $expected = 'name="home[wishlist][]"'; $element = $form->getElement('wishlist'); $result = $element->serialize(); $this->assertTrue(strpos($result, $expected) !== false); } // SWITCH public function test_switch_GET() { $form = $this->createForm(array( 'namespace' => 'home', 'formname' => 'switch')); $_GET = array('home' => array('enable' => 'yes')); $element = $form->getElement('enable'); $expected = 'yes'; $result = $element->getValue(); $this->assertTrue($result === $expected); } public function test_switch_serialize() { $form = $this->createForm(array( 'namespace' => 'home', 'formname' => 'switch')); $expected = 'name="home[enable]"'; $element = $form->getElement('enable'); $result = $element->serialize(); //dump(htmlentities($result)); $this->assertTrue(strpos($result, $expected) !== false); } public function test_switch_serialize_labelForId() { $form = $this->createForm(array( 'namespace' => 'home', 'formname' => 'switch')); $expected = 'id="home_pfo'; $element = $form->getElement('enable'); $result = $element->serialize(); $this->assertTrue(strpos($result, $expected) !== false); } } ?>