summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Eckelmann <deckelmann@gmail.com>2012-04-07 22:43:19 +0200
committerDominik Eckelmann <deckelmann@gmail.com>2012-04-07 22:43:19 +0200
commitb268816aeb07f7b4aad25357b8c8b5f0409c2f84 (patch)
tree14b2baf21d371311518970aa302508fe95e8bfb0
parentb3cb5bcea1f6001d9609479a41e90d1a049d0523 (diff)
downloadrpg-b268816aeb07f7b4aad25357b8c8b5f0409c2f84.tar.gz
rpg-b268816aeb07f7b4aad25357b8c8b5f0409c2f84.tar.bz2
transformed form_form test to phpunit
-rw-r--r--_testing/unittests/inc/form_form.test.php104
1 files changed, 104 insertions, 0 deletions
diff --git a/_testing/unittests/inc/form_form.test.php b/_testing/unittests/inc/form_form.test.php
new file mode 100644
index 000000000..6bc042ba6
--- /dev/null
+++ b/_testing/unittests/inc/form_form.test.php
@@ -0,0 +1,104 @@
+<?php
+
+require_once DOKU_INC.'inc/init.php';
+
+class form_test extends PHPUnit_Framework_TestCase {
+
+ function _testform() {
+ $form = new Doku_Form(array('id' => 'dw__testform', 'action' => '/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'));
+ $form->endFieldset();
+ return $form;
+ }
+
+ function _realoutput() {
+ global $lang;
+ $realoutput = '<form id="dw__testform" action="/test" method="post" ';
+ $realoutput .= 'accept-charset="'.$lang['encoding'].'">';
+ $realoutput .= "\n";
+ $realoutput .= '<div class="no"><input type="hidden" name="sectok" value="'.getSecurityToken().'" />';
+ $realoutput .= '<input type="hidden" name="summary" value="changes &amp;c" />';
+ $realoutput .= "\n";
+ $realoutput .= "<fieldset ><legend>Test</legend>\n";
+ $realoutput .= '<label class="block" for="text__id"><span>Text</span> ';
+ $realoutput .= '<input type="text" id="text__id" name="t" value="v" class="edit" /></label><br />';
+ $realoutput .= "\n";
+ $realoutput .= '<label class="simple" for="check__id">';
+ $realoutput .= '<input type="checkbox" id="check__id" name="r" value="1" /> ';
+ $realoutput .= '<span>Check</span></label>';
+ $realoutput .= "\n";
+ $realoutput .= '<input name="do[save]" type="submit" value="Save" class="button" accesskey="s" title="Save [S]" />';
+ $realoutput .= "\n";
+ $realoutput .= '<input name="do[cancel]" type="submit" value="Cancel" class="button" />';
+ $realoutput .= "\n";
+ $realoutput .= "</fieldset>\n</div></form>\n";
+ return $realoutput;
+ }
+
+ function _ignoreTagWS($data){
+ return preg_replace('/>\s+</','><',$data);
+ }
+
+ function test_form_print() {
+ $form = $this->_testform();
+ ob_start();
+ $form->printForm();
+ $output = ob_get_contents();
+ ob_end_clean();
+ $form->addHidden('sectok', getSecurityToken());
+ $this->assertEquals($this->_ignoreTagWS($output),$this->_ignoreTagWS($this->_realoutput()));
+ }
+
+ function test_get_element_at() {
+ $form = $this->_testform();
+ $e1 =& $form->getElementAt(1);
+ $this->assertEquals($e1, array('_elem'=>'textfield',
+ '_text'=>'Text',
+ '_class'=>'block',
+ 'id'=>'text__id',
+ 'name'=>'t',
+ 'value'=>'v',
+ 'class'=>'edit'));
+ $e2 =& $form->getElementAt(99);
+ $this->assertEquals($e2, array('_elem'=>'closefieldset'));
+ }
+
+ function test_find_element_by_type() {
+ $form = $this->_testform();
+ $this->assertEquals($form->findElementByType('button'), 3);
+ $this->assertFalse($form->findElementByType('text'));
+ }
+
+ function test_find_element_by_id() {
+ $form = $this->_testform();
+ $this->assertEquals($form->findElementById('check__id'), 2);
+ $this->assertFalse($form->findElementById('dw__testform'));
+ }
+
+ function test_find_element_by_attribute() {
+ $form = $this->_testform();
+ $this->assertEquals($form->findElementByAttribute('value','Cancel'), 4);
+ $this->assertFalse($form->findElementByAttribute('name','cancel'));
+ }
+
+ function test_close_fieldset() {
+ $form = new Doku_Form(array('id' => 'dw__testform', 'action' => '/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->assertEquals($this->_ignoreTagWS($output),$this->_ignoreTagWS($this->_realoutput()));
+ }
+
+}