DirectLex_ErrorsTest.php 1.7 KB

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