Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
XmlTest.php
Go to the documentation of this file.
1 <?php
7 
8 class XmlTest extends \PHPUnit\Framework\TestCase
9 {
13  protected $_model;
14 
15  protected function setUp()
16  {
17  $this->_model = new \Magento\Framework\Convert\Xml();
18  }
19 
20  public function testXmlToAssoc()
21  {
22  $xmlstr = $this->getXml();
23  $result = $this->_model->xmlToAssoc(new \SimpleXMLElement($xmlstr));
24  $this->assertEquals(
25  [
26  'one' => '1',
27  'two' => ['three' => '3', 'four' => '4'],
28  'five' => [0 => '5', 1 => '6'],
29  ],
30  $result
31  );
32  }
33 
37  protected function getXml()
38  {
39  return <<<XML
40 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
41 <_><one>1</one><two><three>3</three><four>4</four></two><five><five>5</five><five>6</five></five></_>
42 XML;
43  }
44 }