From fdb8d77b680840866f44bc1515710db60af94fc5 Mon Sep 17 00:00:00 2001 From: Tom N Harris Date: Mon, 30 Jul 2007 23:50:07 +0200 Subject: New structured forms and action events Replaces a number of *FORM_INJECTION events with a more flexible way of modifying forms. Forms are created with a Doku_Form class (inc/form.php) that can be manipulated by plugins prior to output. Plugins register a HTML_{$name}FORM_OUTPUT event which can modify the form object prior to output. Available forms are: LOGIN DRAFT CONFLICT REGISTER UPDATEPROFILE EDIT RESENDPWD Documentation for the Doku_Form class is in inc/form.php. darcs-hash:20070730215007-6942e-a0cf08197f939e224a2b28c40aec5431b118ea94.gz --- _test/cases/inc/form_form.test.php | 97 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 _test/cases/inc/form_form.test.php (limited to '_test') diff --git a/_test/cases/inc/form_form.test.php b/_test/cases/inc/form_form.test.php new file mode 100644 index 000000000..a409facda --- /dev/null +++ b/_test/cases/inc/form_form.test.php @@ -0,0 +1,97 @@ +startFieldset('Test'); + $form->addHidden('summary', 'changes &c'); + $form->addElement(form_makeTextField('t', 'v', 'Text', 'text__id', 'block')); + $form->addElement(form_makeCheckboxField('r', '1', 'Check', 'check__id', 'simple')); + $form->addElement(form_makeButton('submit', 'save', 'Save', array('accesskey'=>'s'))); + $form->addElement(form_makeButton('submit', 'cancel', 'Cancel')); + $form->endFieldset(); + return $form; + } + + function _realoutput() { + global $lang; + $realoutput = '
'; + $realoutput .= "\n"; + $realoutput .= '
'; + $realoutput .= "\n"; + $realoutput .= "
Test\n"; + $realoutput .= '
'; + $realoutput .= "\n"; + $realoutput .= ''; + $realoutput .= "\n"; + $realoutput .= ''; + $realoutput .= "\n"; + $realoutput .= ''; + $realoutput .= "\n"; + $realoutput .= "
\n
\n"; + return $realoutput; + } + + function test_form_print() { + $form = $this->_testform(); + ob_start(); + $form->printForm(); + $output = ob_get_contents(); + ob_end_clean(); + $this->assertEqual($output,$this->_realoutput()); + } + + function test_get_element_at() { + $form = $this->_testform(); + $e1 =& $form->getElementAt(1); + $this->assertEqual($e1, array('_elem'=>'textfield', + '_text'=>'Text', + '_class'=>'block', + 'id'=>'text__id', + 'name'=>'t', + 'value'=>'v')); + $e2 =& $form->getElementAt(99); + $this->assertEqual($e2, array('_elem'=>'closefieldset')); + } + + function test_find_element_by_type() { + $form = $this->_testform(); + $this->assertEqual($form->findElementByType('button'), 3); + $this->assertFalse($form->findElementByType('text')); + } + + function test_find_element_by_id() { + $form = $this->_testform(); + $this->assertEqual($form->findElementById('check__id'), 2); + $this->assertFalse($form->findElementById('dw__testform')); + } + + function test_find_element_by_attribute() { + $form = $this->_testform(); + $this->assertEqual($form->findElementByAttribute('value','Cancel'), 4); + $this->assertFalse($form->findElementByAttribute('name','cancel')); + } + + function test_close_fieldset() { + $form = new Doku_Form('dw__testform','/test'); + $form->startFieldset('Test'); + $form->addHidden('summary', 'changes &c'); + $form->addElement(form_makeTextField('t', 'v', 'Text', 'text__id', 'block')); + $form->addElement(form_makeCheckboxField('r', '1', 'Check', 'check__id', 'simple')); + $form->addElement(form_makeButton('submit', 'save', 'Save', array('accesskey'=>'s'))); + $form->addElement(form_makeButton('submit', 'cancel', 'Cancel')); + ob_start(); + $form->printForm(); + $output = ob_get_contents(); + ob_end_clean(); + $this->assertEqual($output,$this->_realoutput()); + } + +} -- cgit v1.2.3