DOMDocument_strictErrorChecking_variation.phpt 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. --TEST--
  2. DomDocument::$strictErrorChecking - ensure turning off actually works
  3. --CREDITS--
  4. Vincent Tsao <notes4vincent@gmail.com>
  5. (and Dan Convissor)
  6. # TestFest 2009 NYPHP
  7. --SKIPIF--
  8. <?php require_once('skipif.inc'); ?>
  9. --FILE--
  10. <?php
  11. echo "Load document\n";
  12. $doc = new DOMDocument;
  13. $doc->load(dirname(__FILE__)."/book.xml");
  14. echo "See if strictErrorChecking is on\n";
  15. var_dump($doc->strictErrorChecking);
  16. echo "Should throw DOMException when strictErrorChecking is on\n";
  17. try {
  18. $attr = $doc->createAttribute(0);
  19. } catch (DOMException $e) {
  20. echo "GOOD. DOMException thrown\n";
  21. echo $e->getMessage() ."\n";
  22. } catch (Exception $e) {
  23. echo "OOPS. Other exception thrown\n";
  24. }
  25. echo "Turn strictErrorChecking off\n";
  26. $doc->strictErrorChecking = false;
  27. echo "See if strictErrorChecking is off\n";
  28. var_dump($doc->strictErrorChecking);
  29. echo "Should raise PHP error because strictErrorChecking is off\n";
  30. try {
  31. $attr = $doc->createAttribute(0);
  32. } catch (DOMException $e) {
  33. echo "OOPS. DOMException thrown\n";
  34. echo $e->getMessage() ."\n";
  35. } catch (Exception $e) {
  36. echo "OOPS. Other exception thrown\n";
  37. }
  38. ?>
  39. --EXPECTF--
  40. Load document
  41. See if strictErrorChecking is on
  42. bool(true)
  43. Should throw DOMException when strictErrorChecking is on
  44. GOOD. DOMException thrown
  45. Invalid Character Error
  46. Turn strictErrorChecking off
  47. See if strictErrorChecking is off
  48. bool(false)
  49. Should raise PHP error because strictErrorChecking is off
  50. Warning: DOMDocument::createAttribute(): Invalid Character Error in %sDOMDocument_strictErrorChecking_variation.php on line %d