[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/_test/tests/inc/ -> form_form.test.php (source)

   1  <?php
   2  
   3  class form_test extends DokuWikiTest {
   4  
   5    function _testform() {
   6      $form = new Doku_Form(array('id' => 'dw__testform', 'action' => '/test'));
   7      $form->startFieldset('Test');
   8      $form->addHidden('summary', 'changes &c');
   9      $form->addElement(form_makeTextField('t', 'v', 'Text', 'text__id', 'block'));
  10      $form->addElement(form_makeCheckboxField('r', '1', 'Check', 'check__id', 'simple'));
  11      $form->addElement(form_makeButton('submit', 'save', 'Save', array('accesskey'=>'s')));
  12      $form->addElement(form_makeButton('submit', 'cancel', 'Cancel'));
  13      $form->endFieldset();
  14      return $form;
  15    }
  16  
  17    function _realoutput() {
  18      global $lang;
  19      $realoutput  = '<form id="dw__testform" action="/test" method="post" ';
  20      $realoutput .= 'accept-charset="'.$lang['encoding'].'">';
  21      $realoutput .= "\n";
  22      $realoutput .= '<div class="no"><input type="hidden" name="sectok" value="'.getSecurityToken().'" />';
  23      $realoutput .= '<input type="hidden" name="summary" value="changes &amp;c" />';
  24      $realoutput .= "\n";
  25      $realoutput .= "<fieldset ><legend>Test</legend>\n";
  26      $realoutput .= '<label class="block" for="text__id"><span>Text</span> ';
  27      $realoutput .= '<input type="text" id="text__id" name="t" value="v" class="edit" /></label><br />';
  28      $realoutput .= "\n";
  29      $realoutput .= '<label class="simple" for="check__id">';
  30      $realoutput .= '<input type="checkbox" id="check__id" name="r" value="1" /> ';
  31      $realoutput .= '<span>Check</span></label>';
  32      $realoutput .= "\n";
  33      $realoutput .= '<button name="do[save]" type="submit" accesskey="s" title="Save [S]">Save</button>';
  34      $realoutput .= "\n";
  35      $realoutput .= '<button name="do[cancel]" type="submit">Cancel</button>';
  36      $realoutput .= "\n";
  37      $realoutput .= "</fieldset>\n</div></form>\n";
  38      return $realoutput;
  39    }
  40  
  41    function _ignoreTagWS($data){
  42      return preg_replace('/>\s+</','><',$data);
  43    }
  44  
  45    function test_form_print() {
  46      $form = $this->_testform();
  47      ob_start();
  48      $form->printForm();
  49      $output = ob_get_contents();
  50      ob_end_clean();
  51      $form->addHidden('sectok', getSecurityToken());
  52      $this->assertEquals($this->_ignoreTagWS($output),$this->_ignoreTagWS($this->_realoutput()));
  53    }
  54  
  55    function test_get_element_at() {
  56      $form = $this->_testform();
  57      $e1 =& $form->getElementAt(1);
  58      $this->assertEquals($e1, array('_elem'=>'textfield',
  59                                   '_text'=>'Text',
  60                                   '_class'=>'block',
  61                                   'id'=>'text__id',
  62                                   'name'=>'t',
  63                                   'value'=>'v',
  64                                   'class'=>'edit'));
  65      $e2 =& $form->getElementAt(99);
  66      $this->assertEquals($e2, array('_elem'=>'closefieldset'));
  67    }
  68  
  69    function test_find_element_by_type() {
  70      $form = $this->_testform();
  71      $this->assertEquals($form->findElementByType('button'), 3);
  72      $this->assertFalse($form->findElementByType('text'));
  73    }
  74  
  75    function test_find_element_by_id() {
  76      $form = $this->_testform();
  77      $this->assertEquals($form->findElementById('check__id'), 2);
  78      $this->assertFalse($form->findElementById('dw__testform'));
  79    }
  80  
  81    function test_find_element_by_attribute() {
  82      $form = $this->_testform();
  83      $this->assertEquals($form->findElementByAttribute('value','Cancel'), 4);
  84      $this->assertFalse($form->findElementByAttribute('name','cancel'));
  85    }
  86  
  87    function test_close_fieldset() {
  88      $form = new Doku_Form(array('id' => 'dw__testform', 'action' => '/test'));
  89      $form->startFieldset('Test');
  90      $form->addHidden('summary', 'changes &c');
  91      $form->addElement(form_makeTextField('t', 'v', 'Text', 'text__id', 'block'));
  92      $form->addElement(form_makeCheckboxField('r', '1', 'Check', 'check__id', 'simple'));
  93      $form->addElement(form_makeButton('submit', 'save', 'Save', array('accesskey'=>'s')));
  94      $form->addElement(form_makeButton('submit', 'cancel', 'Cancel'));
  95      ob_start();
  96      $form->printForm();
  97      $output = ob_get_contents();
  98      ob_end_clean();
  99      $this->assertEquals($this->_ignoreTagWS($output),$this->_ignoreTagWS($this->_realoutput()));
 100    }
 101  
 102  }