Make forms work for transitional doctypes.
[htmlpurifier.git] / tests / HTMLPurifier / HTMLModule / FormsTest.php
blob5bc4c99c3ae04e1329e81f5c15f25b53ae58f93f
1 <?php
3 class HTMLPurifier_HTMLModule_FormsTest extends HTMLPurifier_HTMLModuleHarness
6 function setUp() {
7 parent::setUp();
8 $this->config->set('HTML.Trusted', true);
9 $this->config->set('Attr.EnableID', true);
12 function testBasicUse() {
13 $this->config->set('HTML.Doctype', 'HTML 4.01 Strict');
14 $this->assertResult( // need support for label for later
16 <form action="http://somesite.com/prog/adduser" method="post">
17 <p>
18 <label>First name: </label>
19 <input type="text" id="firstname" /><br />
20 <label>Last name: </label>
21 <input type="text" id="lastname" /><br />
22 <label>email: </label>
23 <input type="text" id="email" /><br />
24 <input type="radio" name="sex" value="Male" /> Male<br />
25 <input type="radio" name="sex" value="Female" /> Female<br />
26 <input type="submit" value="Send" /> <input type="reset" />
27 </p>
28 </form>'
32 function testSelectOption() {
33 $this->config->set('HTML.Doctype', 'HTML 4.01 Strict');
34 $this->assertResult('
35 <form action="http://somesite.com/prog/component-select" method="post">
36 <p>
37 <select multiple="multiple" size="4" name="component-select">
38 <option selected="selected" value="Component_1_a">Component_1</option>
39 <option selected="selected" value="Component_1_b">Component_2</option>
40 <option>Component_3</option>
41 <option>Component_4</option>
42 <option>Component_5</option>
43 <option>Component_6</option>
44 <option>Component_7</option>
45 </select>
46 <input type="submit" value="Send" /><input type="reset" />
47 </p>
48 </form>
49 ');
52 function testSelectOptgroup() {
53 $this->config->set('HTML.Doctype', 'HTML 4.01 Strict');
54 $this->assertResult('
55 <form action="http://somesite.com/prog/someprog" method="post">
56 <p>
57 <select name="ComOS">
58 <option selected="selected" label="none" value="none">None</option>
59 <optgroup label="PortMaster 3">
60 <option label="3.7.1" value="pm3_3.7.1">PortMaster 3 with ComOS 3.7.1</option>
61 <option label="3.7" value="pm3_3.7">PortMaster 3 with ComOS 3.7</option>
62 <option label="3.5" value="pm3_3.5">PortMaster 3 with ComOS 3.5</option>
63 </optgroup>
64 <optgroup label="PortMaster 2">
65 <option label="3.7" value="pm2_3.7">PortMaster 2 with ComOS 3.7</option>
66 <option label="3.5" value="pm2_3.5">PortMaster 2 with ComOS 3.5</option>
67 </optgroup>
68 <optgroup label="IRX">
69 <option label="3.7R" value="IRX_3.7R">IRX with ComOS 3.7R</option>
70 <option label="3.5R" value="IRX_3.5R">IRX with ComOS 3.5R</option>
71 </optgroup>
72 </select>
73 </p>
74 </form>
75 ');
78 function testTextarea() {
79 $this->config->set('HTML.Doctype', 'HTML 4.01 Strict');
80 $this->assertResult('
81 <form action="http://somesite.com/prog/text-read" method="post">
82 <p>
83 <textarea name="thetext" rows="20" cols="80">
84 First line of initial text.
85 Second line of initial text.
86 </textarea>
87 <input type="submit" value="Send" /><input type="reset" />
88 </p>
89 </form>
90 ');
93 // label tests omitted
95 function testFieldset() {
96 $this->config->set('HTML.Doctype', 'HTML 4.01 Strict');
97 $this->assertResult('
98 <form action="..." method="post">
99 <fieldset>
100 <legend>Personal Information</legend>
101 Last Name: <input name="personal_lastname" type="text" tabindex="1" />
102 First Name: <input name="personal_firstname" type="text" tabindex="2" />
103 Address: <input name="personal_address" type="text" tabindex="3" />
104 ...more personal information...
105 </fieldset>
106 <fieldset>
107 <legend>Medical History</legend>
108 <input name="history_illness" type="checkbox" value="Smallpox" tabindex="20" />Smallpox
109 <input name="history_illness" type="checkbox" value="Mumps" tabindex="21" /> Mumps
110 <input name="history_illness" type="checkbox" value="Dizziness" tabindex="22" /> Dizziness
111 <input name="history_illness" type="checkbox" value="Sneezing" tabindex="23" /> Sneezing
112 ...more medical history...
113 </fieldset>
114 <fieldset>
115 <legend>Current Medication</legend>
116 Are you currently taking any medication?
117 <input name="medication_now" type="radio" value="Yes" tabindex="35" />Yes
118 <input name="medication_now" type="radio" value="No" tabindex="35" />No
120 If you are currently taking medication, please indicate
121 it in the space below:
122 <textarea name="current_medication" rows="20" cols="50" tabindex="40"></textarea>
123 </fieldset>
124 </form>
128 function testInputTransform() {
129 $this->config->set('HTML.Doctype', 'XHTML 1.0 Strict');
130 $this->assertResult('<input type="checkbox" />', '<input type="checkbox" value="" />');
133 function testTextareaTransform() {
134 $this->config->set('HTML.Doctype', 'HTML 4.01 Strict');
135 $this->assertResult('<textarea></textarea>', '<textarea cols="22" rows="3"></textarea>');
138 function testTextInFieldset() {
139 $this->config->set('HTML.Doctype', 'HTML 4.01 Strict');
140 $this->assertResult('<fieldset> <legend></legend>foo</fieldset>');
143 function testStrict() {
144 $this->config->set('HTML.Doctype', 'HTML 4.01 Strict');
145 $this->assertResult('<form action=""></form>', '');
148 function testLegacy() {
149 $this->assertResult('<form action=""></form>');
150 $this->assertResult('<form action=""><input align="left" /></form>');
155 // vim: et sw=4 sts=4