XmlTest.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Convert\Test\Unit;
  7. class XmlTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Framework\Convert\Xml
  11. */
  12. protected $_model;
  13. protected function setUp()
  14. {
  15. $this->_model = new \Magento\Framework\Convert\Xml();
  16. }
  17. public function testXmlToAssoc()
  18. {
  19. $xmlstr = $this->getXml();
  20. $result = $this->_model->xmlToAssoc(new \SimpleXMLElement($xmlstr));
  21. $this->assertEquals(
  22. [
  23. 'one' => '1',
  24. 'two' => ['three' => '3', 'four' => '4'],
  25. 'five' => [0 => '5', 1 => '6'],
  26. ],
  27. $result
  28. );
  29. }
  30. /**
  31. * @return string
  32. */
  33. protected function getXml()
  34. {
  35. return <<<XML
  36. <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  37. <_><one>1</one><two><three>3</three><four>4</four></two><five><five>5</five><five>6</five></five></_>
  38. XML;
  39. }
  40. }