HTMLPurifierTest.php 1.6 KB

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