You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

167 lines
5.5KB

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