FormsTest.php 5.4 KB

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