[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/_test/tests/Form/ -> InputElementTest.php (source)

   1  <?php
   2  
   3  namespace dokuwiki\test\Form;
   4  
   5  use dokuwiki\Form;
   6  use DOMWrap\Document;
   7  
   8  class InputElementTest extends \DokuWikiTest {
   9  
  10      function testDefaults() {
  11          $form = new Form\Form();
  12          $form->addTextInput('foo', 'label text')->val('this is text');
  13  
  14          $html = $form->toHTML();
  15          $pq = (new Document())->html($html);
  16  
  17          $input = $pq->find('input[name=foo]');
  18          $this->assertTrue($input->count() == 1);
  19          $this->assertEquals('this is text', $input->attr('value'));
  20          $this->assertEquals('text', $input->attr('type'));
  21  
  22          $label = $pq->find('label');
  23          $this->assertTrue($label->count() == 1);
  24          $this->assertEquals('label text', $label->find('span')->text());
  25      }
  26  
  27      /**
  28       * check that posted values overwrite preset default
  29       */
  30      function testPrefill() {
  31          global $INPUT;
  32          $INPUT->post->set('foo', 'a new text');
  33  
  34          $form = new Form\Form();
  35          $form->addTextInput('foo', 'label text')->val('this is text');
  36  
  37          $html = $form->toHTML();
  38          $pq = (new Document())->html($html);
  39  
  40          $input = $pq->find('input[name=foo]');
  41          $this->assertTrue($input->count() == 1);
  42          $this->assertEquals('a new text', $input->attr('value'));
  43      }
  44  
  45      function test_prefill_empty() {
  46          global $INPUT;
  47          $INPUT->post->set('foo', '');
  48  
  49          $form = new Form\Form();
  50          $form->addTextInput('foo', 'label text')->val('this is text');
  51  
  52          $html = $form->toHTML();
  53          $pq = (new Document())->html($html);
  54  
  55          $input = $pq->find('input[name=foo]');
  56          $this->assertTrue($input->count() == 1);
  57          $this->assertEquals('', $input->attr('value'));
  58      }
  59  
  60  
  61      function test_password() {
  62          $form = new Form\Form();
  63          $form->addPasswordInput('foo', 'label text')->val('this is text');
  64  
  65          $html = $form->toHTML();
  66          $pq = (new Document())->html($html);
  67  
  68          $input = $pq->find('input[name=foo]');
  69          $this->assertTrue($input->count() == 1);
  70          $this->assertEquals('this is text', $input->attr('value'));
  71          $this->assertEquals('password', $input->attr('type'));
  72  
  73          $label = $pq->find('label');
  74          $this->assertTrue($label->count() == 1);
  75          $this->assertEquals('label text', $label->find('span')->text());
  76      }
  77  }