NativeParserCrawlerTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\DomCrawler\Tests;
  11. class NativeParserCrawlerTest extends AbstractCrawlerTest
  12. {
  13. public function getDoctype(): string
  14. {
  15. return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
  16. }
  17. public function testAddHtmlContentWithErrors()
  18. {
  19. $internalErrors = libxml_use_internal_errors(true);
  20. $crawler = $this->createCrawler();
  21. $crawler->addHtmlContent(<<<'EOF'
  22. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  23. <html>
  24. <head>
  25. </head>
  26. <body>
  27. <nav><a href="#"><a href="#"></nav>
  28. </body>
  29. </html>
  30. EOF
  31. , 'UTF-8');
  32. $errors = libxml_get_errors();
  33. $this->assertCount(1, $errors);
  34. $this->assertEquals("Tag nav invalid\n", $errors[0]->message);
  35. libxml_clear_errors();
  36. libxml_use_internal_errors($internalErrors);
  37. }
  38. public function testAddXmlContentWithErrors()
  39. {
  40. $internalErrors = libxml_use_internal_errors(true);
  41. $crawler = $this->createCrawler();
  42. $crawler->addXmlContent(<<<'EOF'
  43. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  44. <html>
  45. <head>
  46. </head>
  47. <body>
  48. <nav><a href="#"><a href="#"></nav>
  49. </body>
  50. </html>
  51. EOF
  52. , 'UTF-8');
  53. $this->assertGreaterThan(1, libxml_get_errors());
  54. libxml_clear_errors();
  55. libxml_use_internal_errors($internalErrors);
  56. }
  57. }