InputTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. class HTMLPurifier_AttrTransform_InputTest extends HTMLPurifier_AttrTransformHarness
  3. {
  4. function setUp() {
  5. parent::setUp();
  6. $this->obj = new HTMLPurifier_AttrTransform_Input();
  7. }
  8. function testEmptyInput() {
  9. $this->assertResult(array());
  10. }
  11. function testInvalidCheckedWithEmpty() {
  12. $this->assertResult(array('checked' => 'checked'), array());
  13. }
  14. function testInvalidCheckedWithPassword() {
  15. $this->assertResult(array(
  16. 'checked' => 'checked',
  17. 'type' => 'password'
  18. ), array(
  19. 'type' => 'password'
  20. ));
  21. }
  22. function testValidCheckedWithUcCheckbox() {
  23. $this->assertResult(array(
  24. 'checked' => 'checked',
  25. 'type' => 'CHECKBOX',
  26. 'value' => 'bar',
  27. ));
  28. }
  29. function testInvalidMaxlength() {
  30. $this->assertResult(array(
  31. 'maxlength' => '10',
  32. 'type' => 'checkbox',
  33. 'value' => 'foo',
  34. ), array(
  35. 'type' => 'checkbox',
  36. 'value' => 'foo',
  37. ));
  38. }
  39. function testValidMaxLength() {
  40. $this->assertResult(array(
  41. 'maxlength' => '10',
  42. ));
  43. }
  44. // these two are really bad test-cases
  45. function testSizeWithCheckbox() {
  46. $this->assertResult(array(
  47. 'type' => 'checkbox',
  48. 'value' => 'foo',
  49. 'size' => '100px',
  50. ), array(
  51. 'type' => 'checkbox',
  52. 'value' => 'foo',
  53. 'size' => '100',
  54. ));
  55. }
  56. function testSizeWithText() {
  57. $this->assertResult(array(
  58. 'type' => 'password',
  59. 'size' => '100px', // spurious value, to indicate no validation takes place
  60. ), array(
  61. 'type' => 'password',
  62. 'size' => '100px',
  63. ));
  64. }
  65. function testInvalidSrc() {
  66. $this->assertResult(array(
  67. 'src' => 'img.png',
  68. ), array());
  69. }
  70. function testMissingValue() {
  71. $this->assertResult(array(
  72. 'type' => 'checkbox',
  73. ), array(
  74. 'type' => 'checkbox',
  75. 'value' => '',
  76. ));
  77. }
  78. }
  79. // vim: et sw=4 sts=4