13 public function testUnsetSelf($xmlData)
16 $xml = simplexml_load_file($xmlData[0], $xmlData[1]);
17 $this->assertTrue(isset($xml->node3->node4));
18 $xml->node3->unsetSelf();
19 $this->assertFalse(isset($xml->node3->node4));
20 $this->assertFalse(isset($xml->node3));
21 $this->assertTrue(isset($xml->node1));
29 public function testGetParent($xmlData)
32 $xml = simplexml_load_file($xmlData[0], $xmlData[1]);
33 $this->assertTrue($xml->getName() ==
'root');
43 [[
__DIR__ .
'/_files/data.xml', \Magento\Framework\Simplexml\Element::class]]
47 public function testAsNiceXmlMixedData()
51 $xml = simplexml_load_string($dataFile, \
Magento\Framework\Simplexml\Element::class);
55 <node_1
id=
"1">Value 1
57 <node_1_1_1>Value 1.1.1</node_1_1_1>
61 <node_2_1>Value 2.1</node_2_1>
66 $this->assertEquals($expected, $xml->asNiceXml());
69 public function testAppendChild()
72 $baseXml = simplexml_load_string(
'<root/>', \
Magento\Framework\Simplexml\Element::class);
74 $appendXml = simplexml_load_string(
75 '<node_a attr="abc"><node_b innerAttribute="xyz">text</node_b></node_a>',
76 \
Magento\Framework\Simplexml\Element::class
78 $baseXml->appendChild($appendXml);
80 $expectedXml =
'<root><node_a attr="abc"><node_b innerAttribute="xyz">text</node_b></node_a></root>';
81 $this->assertXmlStringEqualsXmlString($expectedXml, $baseXml->asNiceXml());
84 public function testSetNode()
86 $path =
'/node1/node2';
89 $xml = simplexml_load_string(
'<root/>', \
Magento\Framework\Simplexml\Element::class);
90 $this->assertEmpty($xml->xpath(
'/root/node1/node2'));
92 $this->assertNotEmpty($xml->xpath(
'/root/node1/node2'));
93 $this->assertEquals(
$value, (
string)$xml->xpath(
'/root/node1/node2')[0]);
104 $xml = simplexml_load_string(
'<root name="test2" data=""/>', \
Magento\Framework\Simplexml\Element::class);
105 $this->assertEquals($xml->getAttribute(
'name'),
'test2');
106 $this->assertNull($xml->getAttribute(
'new'));
108 $this->assertEquals($xml->getAttribute(
$name),
$value);
119 [
'data',
'some-data']
setAttributeDataProvider()
defined('TESTS_BP')||define('TESTS_BP' __DIR__
if(!isset($_GET['name'])) $name