HTMLPurifierTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. class HTMLPurifierTest extends HTMLPurifier_Harness
  3. {
  4. protected $purifier;
  5. public function testNull()
  6. {
  7. $this->assertPurification("Null byte\0", "Null byte");
  8. }
  9. public function test_purifyArray()
  10. {
  11. $this->assertIdentical(
  12. $this->purifier->purifyArray(
  13. array('Good', '<b>Sketchy', 'foo' => '<script>bad</script>')
  14. ),
  15. array('Good', '<b>Sketchy</b>', 'foo' => '')
  16. );
  17. $this->assertIsA($this->purifier->context, 'array');
  18. }
  19. public function test_purifyArray_nested()
  20. {
  21. $this->assertIdentical(
  22. $this->purifier->purifyArray(
  23. array('Good', '<b>Sketchy', 'foo' => array('bar' => '<script>bad</script>'))
  24. ),
  25. array('Good', '<b>Sketchy</b>', 'foo' => array('bar' => ''))
  26. );
  27. }
  28. public function test_purifyArray_empty() {
  29. $purifiedEmptyArray = $this->purifier->purifyArray(array());
  30. $this->assertTrue(
  31. empty($purifiedEmptyArray)
  32. );
  33. }
  34. public function testGetInstance()
  35. {
  36. $purifier = HTMLPurifier::getInstance();
  37. $purifier2 = HTMLPurifier::getInstance();
  38. $this->assertReference($purifier, $purifier2);
  39. }
  40. public function testMakeAbsolute()
  41. {
  42. $this->config->set('URI.Base', 'http://example.com/bar/baz.php');
  43. $this->config->set('URI.MakeAbsolute', true);
  44. $this->assertPurification(
  45. '<a href="foo.txt">Foobar</a>',
  46. '<a href="http://example.com/bar/foo.txt">Foobar</a>'
  47. );
  48. }
  49. public function testDisableResources()
  50. {
  51. $this->config->set('URI.DisableResources', true);
  52. $this->assertPurification('<img src="foo.jpg" />', '');
  53. }
  54. public function test_addFilter_deprecated()
  55. {
  56. $this->expectError('HTMLPurifier->addFilter() is deprecated, use configuration directives in the Filter namespace or Filter.Custom');
  57. generate_mock_once('HTMLPurifier_Filter');
  58. $this->purifier->addFilter($mock = new HTMLPurifier_FilterMock());
  59. $mock->expectOnce('preFilter');
  60. $mock->expectOnce('postFilter');
  61. $this->purifier->purify('foo');
  62. }
  63. }
  64. // vim: et sw=4 sts=4