xref: /dokuwiki/_test/tests/Form/ButtonElementTest.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 Gohr
8*98640fd3SAndreas Gohrclass ButtonElementTest extends \DokuWikiTest
9*98640fd3SAndreas Gohr{
10*98640fd3SAndreas Gohr
11*98640fd3SAndreas Gohr    function testSimple()
12*98640fd3SAndreas Gohr    {
13*98640fd3SAndreas Gohr        $form = new Form\Form();
14*98640fd3SAndreas Gohr        $form->addButton('foo', 'Hello <b>World</b>')->val('bam')->attr('type', 'submit');
15*98640fd3SAndreas Gohr
16*98640fd3SAndreas Gohr        $html = $form->toHTML();
17*98640fd3SAndreas Gohr        $pq = (new Document())->html($html);
18*98640fd3SAndreas Gohr
19*98640fd3SAndreas Gohr        $input = $pq->find('button[name=foo]');
20*98640fd3SAndreas Gohr        $this->assertTrue($input->count() == 1);
21*98640fd3SAndreas Gohr        $this->assertEquals('bam', $input->attr('value'));
22*98640fd3SAndreas Gohr        $this->assertEquals('submit', $input->attr('type'));
23*98640fd3SAndreas Gohr        $this->assertEquals('Hello <b>World</b>', $input->text()); // tags were escaped
24*98640fd3SAndreas Gohr
25*98640fd3SAndreas Gohr        $b = $input->find('b'); // no tags found
26*98640fd3SAndreas Gohr        $this->assertTrue($b->count() == 0);
27*98640fd3SAndreas Gohr    }
28*98640fd3SAndreas Gohr
29*98640fd3SAndreas Gohr    function testHtml()
30*98640fd3SAndreas Gohr    {
31*98640fd3SAndreas Gohr        $form = new Form\Form();
32*98640fd3SAndreas Gohr        $form->addButtonHTML('foo', 'Hello <b>World</b>')->val('bam')->attr('type', 'submit');
33*98640fd3SAndreas Gohr
34*98640fd3SAndreas Gohr        $html = $form->toHTML();
35*98640fd3SAndreas Gohr        $pq = (new Document())->html($html);
36*98640fd3SAndreas Gohr
37*98640fd3SAndreas Gohr        $input = $pq->find('button[name=foo]');
38*98640fd3SAndreas Gohr        $this->assertTrue($input->count() == 1);
39*98640fd3SAndreas Gohr        $this->assertEquals('bam', $input->attr('value'));
40*98640fd3SAndreas Gohr        $this->assertEquals('submit', $input->attr('type'));
41*98640fd3SAndreas Gohr        $this->assertEquals('Hello World', $input->text()); // tags are stripped here
42*98640fd3SAndreas Gohr
43*98640fd3SAndreas Gohr        $b = $input->find('b'); // tags found
44*98640fd3SAndreas Gohr        $this->assertTrue($b->count() == 1);
45*98640fd3SAndreas Gohr    }
46*98640fd3SAndreas Gohr}
47