DirectLex_ErrorsTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. class HTMLPurifier_Lexer_DirectLex_ErrorsTest extends HTMLPurifier_ErrorsHarness
  3. {
  4. public function invoke($input)
  5. {
  6. $lexer = new HTMLPurifier_Lexer_DirectLex();
  7. $lexer->tokenizeHTML($input, $this->config, $this->context);
  8. }
  9. public function invokeAttr($input)
  10. {
  11. $lexer = new HTMLPurifier_Lexer_DirectLex();
  12. $lexer->parseAttributeString($input, $this->config, $this->context);
  13. }
  14. public function testExtractBody()
  15. {
  16. $this->expectErrorCollection(E_WARNING, 'Lexer: Extracted body');
  17. $this->invoke('<body>foo</body>');
  18. }
  19. public function testUnclosedComment()
  20. {
  21. $this->expectErrorCollection(E_WARNING, 'Lexer: Unclosed comment');
  22. $this->expectContext('CurrentLine', 1);
  23. $this->invoke('<!-- >');
  24. }
  25. public function testUnescapedLt()
  26. {
  27. $this->expectErrorCollection(E_NOTICE, 'Lexer: Unescaped lt');
  28. $this->expectContext('CurrentLine', 1);
  29. $this->invoke('< foo>');
  30. }
  31. public function testMissingGt()
  32. {
  33. $this->expectErrorCollection(E_WARNING, 'Lexer: Missing gt');
  34. $this->expectContext('CurrentLine', 1);
  35. $this->invoke('<a href=""');
  36. }
  37. // these are sub-errors, will only be thrown in context of collector
  38. public function testMissingAttributeKey1()
  39. {
  40. $this->expectErrorCollection(E_ERROR, 'Lexer: Missing attribute key');
  41. $this->invokeAttr('=""');
  42. }
  43. public function testMissingAttributeKey2()
  44. {
  45. $this->expectErrorCollection(E_ERROR, 'Lexer: Missing attribute key');
  46. $this->invokeAttr('foo="bar" =""');
  47. }
  48. public function testMissingEndQuote()
  49. {
  50. $this->expectErrorCollection(E_ERROR, 'Lexer: Missing end quote');
  51. $this->invokeAttr('src="foo');
  52. }
  53. }
  54. // vim: et sw=4 sts=4