'; /** @var \ByJG\Util\XmlUtil */ protected $object; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp() { } /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ protected function tearDown() { } public function testCreateXmlDocument() { $xml = XmlUtil::createXmlDocument(); $this->assertEquals(self::XMLHEADER . "\n", $xml->saveXml()); } public function testCreateXmlDocumentFromFile() { $xml = XmlUtil::createXmlDocumentFromFile(__DIR__ . '/buggy.xml', XMLUTIL_OPT_DONT_PRESERVE_WHITESPACE); $this->assertEquals(self::XMLHEADER . "\nvalue\n", $xml->saveXML()); } public function testCreateXmlDocumentFromStr() { $xmlStr = ''; $xml = XmlUtil::createXmlDocumentFromStr($xmlStr); $this->assertEquals(self::XMLHEADER . "\n\n", $xml->saveXML()); } public function testCreateDocumentFromNode() { $xml = XmlUtil::createXmlDocumentFromFile(__DIR__ . '/buggy.xml'); $node = XmlUtil::selectSingleNode($xml, '//subnode'); $xmlFinal = XmlUtil::createDocumentFromNode($node); $this->assertEquals(self::XMLHEADER . "\nvalue\n", $xmlFinal->saveXML()); } public function testFixXmlHeader1() { $xml = ''; $result = XmlUtil::fixXmlHeader($xml); $this->assertEquals(self::XMLHEADER . '', $result); } public function testFixXmlHeader2() { $xml = ''; $result = XmlUtil::fixXmlHeader($xml); $this->assertEquals(self::XMLHEADER . '', $result); } public function testFixXmlHeader3() { $xml = ''; $result = XmlUtil::fixXmlHeader($xml); $this->assertEquals(self::XMLHEADER . '', $result); } public function testFixXmlHeader4() { $xml = ''; $result = XmlUtil::fixXmlHeader($xml); $this->assertEquals(self::XMLHEADER . '', $result); } public function testFixXmlHeader5() { $xml = ''; $result = XmlUtil::fixXmlHeader($xml); $this->assertEquals(self::XMLHEADER . '', $result); } public function testSaveXmlDocument() { $filename = sys_get_temp_dir() . '/save.xml'; $xml = XmlUtil::createXmlDocumentFromFile(__DIR__ . '/buggy.xml', XMLUTIL_OPT_DONT_PRESERVE_WHITESPACE); if (file_exists($filename)) { unlink($filename); } $this->assertFalse(file_exists($filename)); XmlUtil::saveXmlDocument($xml, $filename); $this->assertTrue(file_exists($filename)); $contents = file_get_contents($filename); $this->assertEquals(self::XMLHEADER . "\nvalue\n", $contents); unlink($filename); } public function testGetFormattedDocument() { $xml = XmlUtil::createXmlDocumentFromFile(__DIR__ . '/buggy.xml'); $xml->preserveWhiteSpace = true; $xml->formatOutput = false; $formatted = XmlUtil::getFormattedDocument($xml); $this->assertTrue($xml->preserveWhiteSpace); $this->assertFalse($xml->formatOutput); $this->assertEquals( self::XMLHEADER . "\n\n \n value\n \n\n" , $formatted ); } public function testAddNamespaceToDocument() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } public function testAddNodeFromFile() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } public function testAddNodeFromNode() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } public function testCreateChild() { $dom = XmlUtil::createXmlDocumentFromStr(''); $node = XmlUtil::createChild($dom->documentElement, 'test1'); XmlUtil::createChild($node, 'test2', 'text2'); $node2 = XmlUtil::createChild($node, 'test3', 'text3', 'http://opensource.byjg.com'); $this->assertEquals( self::XMLHEADER . "\n" . '' . '' . 'text2' . 'text3' . '' . '' . "\n", $dom->saveXML() ); XmlUtil::createChildBeforeNode('test1_2', 'text1-2', $node2); $this->assertEquals( self::XMLHEADER . "\n" . '' . '' . 'text2' . 'text1-2' . 'text3' . '' . '' . "\n", $dom->saveXML() ); XmlUtil::createChildBefore($node, 'testBefore', 'textBefore'); $this->assertEquals( self::XMLHEADER . "\n" . '' . '' . 'textBefore' . 'text2' . 'text1-2' . 'text3' . '' . '' . "\n", $dom->saveXML() ); } public function testAddTextNode() { $dom = XmlUtil::createXmlDocumentFromStr(''); $node = XmlUtil::selectSingleNode($dom->documentElement, 'subject'); XmlUtil::addTextNode($node, 'Text'); $this->assertEquals( self::XMLHEADER . "\n" . '' . '' . 'Text' . '' . '' . "\n", $dom->saveXML() ); } public function testAddAttribute() { $dom = XmlUtil::createXmlDocumentFromStr('Text'); $node = XmlUtil::selectSingleNode($dom->documentElement, 'subject'); XmlUtil::addAttribute($node, 'attr', 'value'); $this->assertEquals( self::XMLHEADER . "\n" . '' . '' . 'Text' . '' . '' . "\n", $dom->saveXML() ); } public function testSelectNodes() { $dom = XmlUtil::createXmlDocumentFromStr(''); $nodeList = XmlUtil::selectNodes($dom->documentElement, 'a/item'); $this->assertEquals(3, $nodeList->length); $this->assertEquals('item', $nodeList->item(0)->nodeName); $this->assertEquals('1', $nodeList->item(0)->attributes->getNamedItem('arg')->nodeValue); $this->assertEquals('item', $nodeList->item(1)->nodeName); $this->assertEquals('2', $nodeList->item(1)->attributes->getNamedItem('arg')->nodeValue); $this->assertEquals('item', $nodeList->item(2)->nodeName); $this->assertEquals('3', $nodeList->item(2)->attributes->getNamedItem('arg')->nodeValue); $node = XmlUtil::selectSingleNode($nodeList->item(1), 'b2'); $this->assertEquals('b2', $node->nodeName); } public function testRegisterNamespaceForFilter() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } public function testInnerText() { $dom = XmlUtil::createXmlDocumentFromStr(''); $node = XmlUtil::selectSingleNode($dom->documentElement, 'a/item[@arg="2"]'); $text = XmlUtil::innerText($node); $this->assertEquals("\n\n", $text); } public function testInnerXML() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } public function testCopyChildNodesFromNodeToString() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } public function testSaveXmlNodeToString() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } public function testBr2nl() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } public function testShowXml() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } public function testRemoveNode() { $dom = XmlUtil::createXmlDocumentFromStr('Text'); $node = XmlUtil::selectSingleNode($dom->documentElement, 'subject'); XmlUtil::removeNode($node); $this->assertEquals( self::XMLHEADER . "\n" . '' . '' . '' . '' . "\n", $dom->saveXML() ); } public function testRemoveTagName() { // Remove the following lines when you implement this test. $this->markTestIncomplete( 'This test has not been implemented yet.' ); } public function testXml2Array1() { $xml = XmlUtil::createXmlDocumentFromFile(__DIR__ . '/buggy.xml'); $array = XmlUtil::xml2Array($xml); $this->assertEquals([ "node" => [ "subnode" => "value"]], $array); } public function testXml2Array2() { $xml = XmlUtil::createXmlDocumentFromStr('value'); $array = XmlUtil::xml2Array($xml); $this->assertEquals([ "node" => "value"], $array); } public function testSelectNodesNamespace() { $document = XmlUtil::createXmlDocumentFromFile(__DIR__ . '/feed-atom.txt'); $nodes = XmlUtil::selectNodes( $document->documentElement, 'ns:entry', [ "ns" => "http://www.w3.org/2005/Atom" ] ); $this->assertEquals(25, $nodes->length); } } __halt_compiler();----SIGNATURE:----RZl7siATUX/M2JYkDj0Vgt4X5N///dtLTgIgnrZjDAadFTJWydGzv/ONZ/nHKpTNHS2ExO+L/J8JMxCBlXkQJ77thyvH7uDspbW+hk1XDS3yWpDBE+Ui5A75vpoyandhtvybNSxgU2Q20QuH0CYx/10eE2UAbE5L2/SyDJtl50Bq684YR4KL0qaj3IiG0aVbhgh+HRtoJXuOd8FC9u/dADoPtI/QY7eC+h/h4JtnUjNxJBHQSluaB1tvxrhLOlhj3UmCvOQserwTPiZa7AkG78nA+121xJiWm9gZp09anTAy66MXIBipHOxCdXt6qcRwoeDW20EQ7YSeqkfUpQvq2Sff4D0OgTZCChhyrKHS2U4+72nBjphCfNLgxv1fGgSkPLwefRj5faIrhLy4Uq+cOBGrNpiAU9tVwzuQQoePYcKLsOkvprj7KYcyGsdMWEzT+ECMQj92VPhr432/GJ+gZPHgB1j+6wNWoAXQQ+xE1fElosNEuO9CT4VwxhYV9qtY4zz5mKS7S4C0NaSlji9ADcSE3hcDzCMTWSQPx92er9VZKPW5a9TWRjbzNLv4+B3R2atgCIBjeeVLg5mv3Vx15+oI6uZzbYqV3MMk2bEiykfcSxNwRT2zBUCf6cgkTDoJVwB9EhX+24o6SgIuPfFN8D3qRgLJYTVieYLQrphKedM=----ATTACHMENT:----MjMwOTYwNjY4NDMyMzc0NCA2MTkxMzkzNTQyMDIwOTQyIDkyNDI3ODc4ODMwMDA1MDU=