summaryrefslogtreecommitdiff
path: root/_test/tests/inc/form/inputelement.test.php
blob: 3257d2a892a0ef700e6eec138c15633f12c01aa4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php

use dokuwiki\Form;

class form_inputelement_test extends DokuWikiTest {

    function test_defaults() {
        $form = new Form\Form();
        $form->addTextInput('foo', 'label text')->val('this is text');

        $html = $form->toHTML();
        $pq = phpQuery::newDocumentXHTML($html);

        $input = $pq->find('input[name=foo]');
        $this->assertTrue($input->length == 1);
        $this->assertEquals('this is text', $input->val());
        $this->assertEquals('text', $input->attr('type'));

        $label = $pq->find('label');
        $this->assertTrue($label->length == 1);
        $this->assertEquals('label text', $label->find('span')->text());
    }

    /**
     * check that posted values overwrite preset default
     */
    function test_prefill() {
        global $INPUT;
        $INPUT->post->set('foo', 'a new text');

        $form = new Form\Form();
        $form->addTextInput('foo', 'label text')->val('this is text');

        $html = $form->toHTML();
        $pq = phpQuery::newDocumentXHTML($html);

        $input = $pq->find('input[name=foo]');
        $this->assertTrue($input->length == 1);
        $this->assertEquals('a new text', $input->val());
    }

    function test_password() {
        $form = new Form\Form();
        $form->addPasswordInput('foo', 'label text')->val('this is text');

        $html = $form->toHTML();
        $pq = phpQuery::newDocumentXHTML($html);

        $input = $pq->find('input[name=foo]');
        $this->assertTrue($input->length == 1);
        $this->assertEquals('this is text', $input->val());
        $this->assertEquals('password', $input->attr('type'));

        $label = $pq->find('label');
        $this->assertTrue($label->length == 1);
        $this->assertEquals('label text', $label->find('span')->text());
    }
}