createForm(); //$element = $form->getElement('name'); //$element = patForms_Element::convertElement($element, 'number'); $form->convertElement('name', 'number'); $element = $form->getElement('name'); $expected = 'patForms_Element_Number'; $result = get_class($element); $this->assertTrue($result === $expected); $expected = ''; $result = self::stripElementId($element->serialize()); $this->assertSameVerbose($expected, $result); } public function test_text_to_number_with_numeric_value() { patErrorManager::pushExpect(PATFORMS_ELEMENT_ERROR_VALUE_NOT_CONVERTABLE); $form = $this->createForm(); $element = $form->getElement('name'); $element->setValue('1000'); $element = patForms_Element::convertElement($element, 'number'); $expected = ''; $result = self::stripElementId($element->serialize()); $this->assertSameVerbose($expected, $result); } public function test_text_to_number_with_string_value() { // string value can't be converted to a number // we expect an error to be thrown patErrorManager::pushExpect(PATFORMS_ELEMENT_ERROR_VALUE_NOT_CONVERTABLE); $form = $this->createForm(); $element = $form->getElement('name'); $element->setValue('Sven'); $element = patForms_Element::convertElement($element, 'number'); $expected = PATFORMS_ELEMENT_ERROR_VALUE_NOT_CONVERTABLE; $result = array_pop(array_pop(patErrorManager::getExpect())); patErrorManager::clearExpect(); $this->assertSameVerbose($expected, $result); } public function test_enum_to_set() { // convert an empty text element to a number element $form = $this->createForm(array('formname' => 'enum')); $element = $form->getElement('area'); $element->setValue('a01'); $element = patForms_Element::convertElement($element, 'set'); $expected = 'patForms_Element_Set'; $result = get_class($element); $this->assertTrue($result === $expected); $expected = ''; $result = self::stripElementId($element->serialize()); $this->assertSameVerbose($expected, $result); } } ?>