ParserTest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Xml\Test\Unit;
  7. class ParserTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /** @var \Magento\Framework\Xml\Parser */
  10. protected $parser;
  11. protected function setUp()
  12. {
  13. if (!function_exists('libxml_set_external_entity_loader')) {
  14. $this->markTestSkipped('Skipped on HHVM. Will be fixed in MAGETWO-45033');
  15. }
  16. $this->parser = new \Magento\Framework\Xml\Parser();
  17. }
  18. public function testGetXml()
  19. {
  20. $this->assertEquals(
  21. ['data' => [
  22. 'nodes' => [
  23. 'text' => ' some text ',
  24. 'trim_spaces' => '',
  25. 'cdata' => ' Some data here <strong>html</strong> tags are <i>allowed</i> ',
  26. 'zero' => '0',
  27. 'null' => null,
  28. ]
  29. ]],
  30. $this->parser->load(__DIR__ . '/_files/data.xml')->xmlToArray()
  31. );
  32. }
  33. /**
  34. * @expectedException \Magento\Framework\Exception\LocalizedException
  35. * @expectedExceptionMessage DOMDocument::loadXML(): Opening and ending tag mismatch
  36. */
  37. public function testLoadXmlInvalid()
  38. {
  39. $sampleInvalidXml = '<?xml version="1.0"?><config></onfig>';
  40. $this->parser->initErrorHandler();
  41. $this->parser->loadXML($sampleInvalidXml);
  42. }
  43. }