AttrValidator_ErrorsTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. class HTMLPurifier_AttrValidator_ErrorsTest extends HTMLPurifier_ErrorsHarness
  3. {
  4. public function setup() {
  5. parent::setup();
  6. $config = HTMLPurifier_Config::createDefault();
  7. $this->language = HTMLPurifier_LanguageFactory::instance()->create($config, $this->context);
  8. $this->context->register('Locale', $this->language);
  9. $this->collector = new HTMLPurifier_ErrorCollector($this->context);
  10. $this->context->register('Generator', new HTMLPurifier_Generator($config, $this->context));
  11. }
  12. protected function invoke($input) {
  13. $validator = new HTMLPurifier_AttrValidator();
  14. $validator->validateToken($input, $this->config, $this->context);
  15. }
  16. function testAttributesTransformedGlobalPre() {
  17. $def = $this->config->getHTMLDefinition(true);
  18. generate_mock_once('HTMLPurifier_AttrTransform');
  19. $transform = new HTMLPurifier_AttrTransformMock();
  20. $input = array('original' => 'value');
  21. $output = array('class' => 'value'); // must be valid
  22. $transform->setReturnValue('transform', $output, array($input, new AnythingExpectation(), new AnythingExpectation()));
  23. $def->info_attr_transform_pre[] = $transform;
  24. $token = new HTMLPurifier_Token_Start('span', $input, 1);
  25. $this->invoke($token);
  26. $result = $this->collector->getRaw();
  27. $expect = array(
  28. array(1, E_NOTICE, 'Attributes on <span> transformed from original to class', array()),
  29. );
  30. $this->assertIdentical($result, $expect);
  31. }
  32. function testAttributesTransformedLocalPre() {
  33. $this->config->set('HTML.TidyLevel', 'heavy');
  34. $input = array('align' => 'right');
  35. $output = array('style' => 'text-align:right;');
  36. $token = new HTMLPurifier_Token_Start('p', $input, 1);
  37. $this->invoke($token);
  38. $result = $this->collector->getRaw();
  39. $expect = array(
  40. array(1, E_NOTICE, 'Attributes on <p> transformed from align to style', array()),
  41. );
  42. $this->assertIdentical($result, $expect);
  43. }
  44. // too lazy to check for global post and global pre
  45. function testAttributeRemoved() {
  46. $token = new HTMLPurifier_Token_Start('p', array('foobar' => 'right'), 1);
  47. $this->invoke($token);
  48. $result = $this->collector->getRaw();
  49. $expect = array(
  50. array(1, E_ERROR, 'foobar attribute on <p> removed', array()),
  51. );
  52. $this->assertIdentical($result, $expect);
  53. }
  54. }
  55. // vim: et sw=4 sts=4