'; new SimpleXMLElement($invalidXML); } /** * @return array */ public function dataProviderForTestGetAttribute() { $xmlWithoutNamespace = << XML; $xmlWithHalfNamespace = << XML; $xmlWithFullNamespace = << XML; return [ [$xmlWithoutNamespace, null, ['foo' => 'bar', 'type' => 'test']], [$xmlWithHalfNamespace, null, ['foo' => 'bar', 'type' => null]], [$xmlWithFullNamespace, null, ['foo' => null, 'type' => null]], [$xmlWithoutNamespace, 'r', ['foo' => null, 'type' => null]], [$xmlWithHalfNamespace, 'r', ['foo' => null, 'type' => 'test']], [$xmlWithFullNamespace, 'r', ['foo' => 'bar', 'type' => 'test']], ]; } /** * @dataProvider dataProviderForTestGetAttribute * * @param string $xml * @param string|null $namespace * @param array $expectedAttributes * @return void */ public function testGetAttribute($xml, $namespace, $expectedAttributes) { $element = new SimpleXMLElement($xml); foreach ($expectedAttributes as $name => $expectedValue) { $value = $element->getAttribute($name, $namespace); $this->assertEquals($expectedValue, $value); } } /** * @return void */ public function testXPath() { $xml = << 0 1 XML; $element = new SimpleXMLElement($xml); $matchedElements = $element->xpath('//c'); $this->assertEquals(2, count($matchedElements)); $this->assertTrue($matchedElements[0] instanceof SimpleXMLElement, 'The SimpleXMLElement should be wrapped'); $this->assertEquals('A2', $matchedElements[1]->getAttribute('r')); } /** * @return void */ public function testRemoveNodeMatchingXPath() { $xml = << 0 1 XML; $element = new SimpleXMLElement($xml); $this->assertNotNull($element->getFirstChildByTagName('sheetData')); $element->removeNodesMatchingXPath('//sheetData'); $this->assertNull($element->getFirstChildByTagName('sheetData')); } }