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.

106 lines
2.3KB

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