xref: /dokuwiki/_test/tests/Form/FormTest.php (revision 98640fd3947e9ff996e1c9206b5f845465794486)
1*98640fd3SAndreas Gohr<?php
2*98640fd3SAndreas Gohr
3*98640fd3SAndreas Gohrnamespace dokuwiki\test\Form;
4*98640fd3SAndreas Gohr
5*98640fd3SAndreas Gohruse dokuwiki\Form;
6*98640fd3SAndreas Gohruse DOMWrap\Document;
7*98640fd3SAndreas Gohruse dokuwiki\test\Form\Form as TestForm;
8*98640fd3SAndreas Gohr
9*98640fd3SAndreas Gohrclass FormTest extends \DokuWikiTest
10*98640fd3SAndreas Gohr{
11*98640fd3SAndreas Gohr
12*98640fd3SAndreas Gohr    /**
13*98640fd3SAndreas Gohr     * checks that an empty form is initialized correctly
14*98640fd3SAndreas Gohr     */
15*98640fd3SAndreas Gohr    function testDefaults()
16*98640fd3SAndreas Gohr    {
17*98640fd3SAndreas Gohr        global $INPUT;
18*98640fd3SAndreas Gohr        global $ID;
19*98640fd3SAndreas Gohr        $ID = 'some:test';
20*98640fd3SAndreas Gohr        $INPUT->get->set('id', $ID);
21*98640fd3SAndreas Gohr        $INPUT->get->set('foo', 'bar');
22*98640fd3SAndreas Gohr
23*98640fd3SAndreas Gohr        $form = new Form\Form();
24*98640fd3SAndreas Gohr        $html = $form->toHTML();
25*98640fd3SAndreas Gohr        $pq = (new Document())->html($html);
26*98640fd3SAndreas Gohr
27*98640fd3SAndreas Gohr        $this->assertTrue($pq->find('form')->hasClass('doku_form'));
28*98640fd3SAndreas Gohr        $this->assertEquals(wl($ID, array('foo' => 'bar'), false, '&'), $pq->find('form')->attr('action'));
29*98640fd3SAndreas Gohr        $this->assertEquals('post', $pq->find('form')->attr('method'));
30*98640fd3SAndreas Gohr
31*98640fd3SAndreas Gohr        $this->assertTrue($pq->find('input[name=sectok]')->count() == 1);
32*98640fd3SAndreas Gohr    }
33*98640fd3SAndreas Gohr
34*98640fd3SAndreas Gohr    function testFieldsetBalance()
35*98640fd3SAndreas Gohr    {
36*98640fd3SAndreas Gohr        $form = new TestForm();
37*98640fd3SAndreas Gohr        $form->addFieldsetOpen();
38*98640fd3SAndreas Gohr        $form->addHTML('ignored');
39*98640fd3SAndreas Gohr        $form->addFieldsetClose();
40*98640fd3SAndreas Gohr        $form->balanceFieldsets();
41*98640fd3SAndreas Gohr
42*98640fd3SAndreas Gohr        $this->assertEquals(
43*98640fd3SAndreas Gohr            array(
44*98640fd3SAndreas Gohr                'fieldsetopen',
45*98640fd3SAndreas Gohr                'html',
46*98640fd3SAndreas Gohr                'fieldsetclose',
47*98640fd3SAndreas Gohr            ),
48*98640fd3SAndreas Gohr            $form->getElementTypeList()
49*98640fd3SAndreas Gohr        );
50*98640fd3SAndreas Gohr
51*98640fd3SAndreas Gohr        $form = new TestForm();
52*98640fd3SAndreas Gohr        $form->addHTML('ignored');
53*98640fd3SAndreas Gohr        $form->addFieldsetClose();
54*98640fd3SAndreas Gohr        $form->balanceFieldsets();
55*98640fd3SAndreas Gohr
56*98640fd3SAndreas Gohr        $this->assertEquals(
57*98640fd3SAndreas Gohr            array(
58*98640fd3SAndreas Gohr                'fieldsetopen',
59*98640fd3SAndreas Gohr                'html',
60*98640fd3SAndreas Gohr                'fieldsetclose',
61*98640fd3SAndreas Gohr            ),
62*98640fd3SAndreas Gohr            $form->getElementTypeList()
63*98640fd3SAndreas Gohr        );
64*98640fd3SAndreas Gohr
65*98640fd3SAndreas Gohr        $form = new TestForm();
66*98640fd3SAndreas Gohr        $form->addFieldsetOpen();
67*98640fd3SAndreas Gohr        $form->addHTML('ignored');
68*98640fd3SAndreas Gohr        $form->balanceFieldsets();
69*98640fd3SAndreas Gohr
70*98640fd3SAndreas Gohr        $this->assertEquals(
71*98640fd3SAndreas Gohr            array(
72*98640fd3SAndreas Gohr                'fieldsetopen',
73*98640fd3SAndreas Gohr                'html',
74*98640fd3SAndreas Gohr                'fieldsetclose',
75*98640fd3SAndreas Gohr            ),
76*98640fd3SAndreas Gohr            $form->getElementTypeList()
77*98640fd3SAndreas Gohr        );
78*98640fd3SAndreas Gohr
79*98640fd3SAndreas Gohr        $form = new TestForm();
80*98640fd3SAndreas Gohr        $form->addHTML('ignored');
81*98640fd3SAndreas Gohr        $form->addFieldsetClose();
82*98640fd3SAndreas Gohr        $form->addHTML('ignored');
83*98640fd3SAndreas Gohr        $form->addFieldsetOpen();
84*98640fd3SAndreas Gohr        $form->addHTML('ignored');
85*98640fd3SAndreas Gohr        $form->balanceFieldsets();
86*98640fd3SAndreas Gohr
87*98640fd3SAndreas Gohr        $this->assertEquals(
88*98640fd3SAndreas Gohr            array(
89*98640fd3SAndreas Gohr                'fieldsetopen',
90*98640fd3SAndreas Gohr                'html',
91*98640fd3SAndreas Gohr                'fieldsetclose',
92*98640fd3SAndreas Gohr                'html',
93*98640fd3SAndreas Gohr                'fieldsetopen',
94*98640fd3SAndreas Gohr                'html',
95*98640fd3SAndreas Gohr                'fieldsetclose',
96*98640fd3SAndreas Gohr            ),
97*98640fd3SAndreas Gohr            $form->getElementTypeList()
98*98640fd3SAndreas Gohr        );
99*98640fd3SAndreas Gohr    }
100*98640fd3SAndreas Gohr}
101