working on test coverage for ext/dom, here's 17 more tests

This commit is contained in:
Knut Urdalen 2011-06-28 20:17:15 +00:00
parent 1b416caeb1
commit 819be8a3b2
17 changed files with 411 additions and 0 deletions

View File

@ -0,0 +1,15 @@
--TEST--
DOMDocument::loadHTML() should fail if no parameter is given
--CREDITS--
Knut Urdalen <knut@php.net>
--SKIPIF--
<?php
require_once('skipif.inc');
?>
--FILE--
<?php
$doc = new DOMDocument();
$doc->loadHTML();
?>
--EXPECTF--
Warning: DOMDocument::loadHTML() expects exactly 1 parameter, 0 given in %s on line %d

View File

@ -0,0 +1,15 @@
--TEST--
DOMDocument::loadHTML() should fail if empty string provided as input
--CREDITS--
Knut Urdalen <knut@php.net>
--SKIPIF--
<?php
require_once('skipif.inc');
?>
--FILE--
<?php
$doc = new DOMDocument();
$doc->loadHTML('');
?>
--EXPECTF--
Warning: DOMDocument::loadHTML(): Empty string supplied as input in %s on line %d

View File

@ -0,0 +1,39 @@
--TEST--
DOMDocument::relaxNGValidateSource()
--CREDITS--
Knut Urdalen <knut@php.net>
--SKIPIF--
<?php
require_once('skipif.inc');
?>
--FILE--
<?php
$rng = <<< RNG
<?xml version="1.0" encoding="UTF-8"?>
<grammar ns="" xmlns="http://relaxng.org/ns/structure/1.0"
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<start>
<element name="apple">
<element name="pear">
<data type="NCName"/>
</element>
</element>
</start>
</grammar>
RNG;
$good_xml = <<< GOOD_XML
<?xml version="1.0"?>
<apple>
<pear>Pear</pear>
</apple>
GOOD_XML;
$doc = new DOMDocument();
$doc->loadXML($good_xml);
$result = $doc->relaxNGValidateSource($rng);
var_dump($result);
?>
--EXPECTF--
bool(true)

View File

@ -0,0 +1,41 @@
--TEST--
DOMDocument::relaxNGValidateSource() should fail if document doesn't validate
--CREDITS--
Knut Urdalen <knut@php.net>
--SKIPIF--
<?php
require_once('skipif.inc');
?>
--FILE--
<?php
$rng = <<< RNG
<?xml version="1.0" encoding="UTF-8"?>
<grammar ns="" xmlns="http://relaxng.org/ns/structure/1.0"
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<start>
<element name="apple">
<element name="pear">
<data type="NCName"/>
</element>
</element>
</start>
</grammar>
RNG;
$bad_xml = <<< BAD_XML
<?xml version="1.0"?>
<apple>
<pear>Pear</pear>
<pear>Pear</pear>
</apple>
BAD_XML;
$doc = new DOMDocument();
$doc->loadXML($bad_xml);
$result = $doc->relaxNGValidateSource($rng);
var_dump($result);
?>
--EXPECTF--
Warning: DOMDocument::relaxNGValidateSource(): Did not expect element pear there in %s on line %d
bool(false)

View File

@ -0,0 +1,39 @@
--TEST--
DOMDocument::relaxNGValidateSource() should fail on invalid RNG schema
--CREDITS--
Knut Urdalen <knut@php.net>
--SKIPIF--
<?php
require_once('skipif.inc');
?>
--FILE--
<?php
$rng = <<< RNG
<?xml version="1.0" encoding="UTF-8"?>
<grammar ns="" xmlns="http://relaxng.org/ns/structure/1.0"
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<start>
<element name="apple">
</element>
</start>
</grammar>
RNG;
$xml = <<< XML
<?xml version="1.0"?>
<apple>
<pear>Pear</pear>
</apple>
XML;
$doc = new DOMDocument();
$doc->loadXML($xml);
$result = $doc->relaxNGValidateSource($rng);
var_dump($result);
?>
--EXPECTF--
Warning: DOMDocument::relaxNGValidateSource(): xmlRelaxNGParseElement: element has no content in %s on line %d
Warning: DOMDocument::relaxNGValidateSource(): Invalid RelaxNG in %s on line %d
bool(false)

View File

@ -0,0 +1,24 @@
--TEST--
DOMDocument::relaxNGValidate()
--CREDITS--
Knut Urdalen <knut@php.net>
--SKIPIF--
<?php
require_once('skipif.inc');
?>
--FILE--
<?php
$rng = dirname(__FILE__).'/DOMDocument_relaxNGValidate_basic.rng';
$xml = <<< XML
<?xml version="1.0"?>
<apple>
<pear>Pear</pear>
</apple>
XML;
$doc = new DOMDocument();
$doc->loadXML($xml);
$result = $doc->relaxNGValidate($rng);
var_dump($result);
?>
--EXPECTF--
bool(true)

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<grammar ns="" xmlns="http://relaxng.org/ns/structure/1.0"
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<start>
<element name="apple">
<element name="pear">
<data type="NCName"/>
</element>
</element>
</start>
</grammar>

View File

@ -0,0 +1,26 @@
--TEST--
DOMDocument::relaxNGValidate() should fail if document doesn't validate
--CREDITS--
Knut Urdalen <knut@php.net>
--SKIPIF--
<?php
require_once('skipif.inc');
?>
--FILE--
<?php
$rng = dirname(__FILE__).'/DOMDocument_relaxNGValidate_basic.rng';
$xml = <<< XML
<?xml version="1.0"?>
<apple>
<pear>Pear</pear>
<pear>Pear</pear>
</apple>
XML;
$doc = new DOMDocument();
$doc->loadXML($xml);
$result = $doc->relaxNGValidate($rng);
var_dump($result);
?>
--EXPECTF--
Warning: DOMDocument::relaxNGValidate(): Did not expect element pear there in %s on line %d
bool(false)

View File

@ -0,0 +1,25 @@
--TEST--
DOMDocument::relaxNGValidate() should fail on invalid RelaxNG file source
--CREDITS--
Knut Urdalen <knut@php.net>
--SKIPIF--
<?php
require_once('skipif.inc');
?>
--FILE--
<?php
$rng = dirname(__FILE__).'/foo.rng';
$xml = <<< XML
<?xml version="1.0"?>
<apple>
<pear>Pear</pear>
<pear>Pear</pear>
</apple>
XML;
$doc = new DOMDocument();
$doc->loadXML($xml);
$result = $doc->relaxNGValidate($rng);
var_dump($result);
?>
--EXPECTF--

View File

@ -0,0 +1,18 @@
--TEST--
DOMImplementation::createDocumentType()
--SKIPIF--
<?php
include('skipif.inc');
?>
--FILE--
<?php
$imp = new DOMImplementation();
$doctype = $imp->createDocumentType("html",
"-//W3C//DTD XHTML 1.0 Strict//EN",
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd");
$doc = $imp->createDocument(null, 'html', $doctype);
echo $doc->saveHTML();
?>
--EXPECTF--
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html></html>

View File

@ -0,0 +1,14 @@
--TEST--
DOMImplementation::createDocument()
--SKIPIF--
<?php
include('skipif.inc');
?>
--FILE--
<?php
$x = new DOMImplementation();
$doc = $x->createDocument(null, 'html');
echo $doc->saveHTML();
?>
--EXPECTF--
<html></html>

View File

@ -0,0 +1,15 @@
--TEST--
DOMImplementation::hasFeature()
--SKIPIF--
<?php
include('skipif.inc');
?>
--FILE--
<?php
$imp = new DOMImplementation();
var_dump($imp->hasFeature('Core', '1.0'));
var_dump($imp->hasFeature('XML', '2.0'));
?>
--EXPECTF--
bool(true)
bool(true)

View File

@ -0,0 +1,38 @@
--TEST--
DOMNode::C14NFile()
--SKIPIF--
<?php
include('skipif.inc');
?>
--FILE--
<?php
$xml = <<< XML
<?xml version="1.0" ?>
<books>
<book>
<title>The Grapes of Wrath</title>
<author>John Steinbeck</author>
</book>
<book>
<title>The Pearl</title>
<author>John Steinbeck</author>
</book>
</books>
XML;
$output = dirname(__FILE__).'/DOMNode_C14NFile_basic.tmp';
$doc = new DOMDocument();
$doc->loadXML($xml);
$node = $doc->getElementsByTagName('title')->item(0);
var_dump($node->C14NFile($output));
$content = file_get_contents($output);
var_dump($content);
?>
--CLEAN--
<?php
$output = dirname(__FILE__).'/DOMNode_C14NFile_basic.tmp';
unlink($output);
?>
--EXPECTF--
int(34)
string(34) "<title>The Grapes of Wrath</title>"

View File

@ -0,0 +1,29 @@
--TEST--
DOMNode::C14N()
--SKIPIF--
<?php
include('skipif.inc');
?>
--FILE--
<?php
$xml = <<< XML
<?xml version="1.0" ?>
<books>
<book>
<title>The Grapes of Wrath</title>
<author>John Steinbeck</author>
</book>
<book>
<title>The Pearl</title>
<author>John Steinbeck</author>
</book>
</books>
XML;
$doc = new DOMDocument();
$doc->loadXML($xml);
$node = $doc->getElementsByTagName('title')->item(0);
var_dump($node->C14N());
?>
--EXPECTF--
string(34) "<title>The Grapes of Wrath</title>"

View File

@ -0,0 +1,19 @@
--TEST--
DOMNode::getLineNo()
--SKIPIF--
<?php
include('skipif.inc');
?>
--FILE--
<?php
$file = dirname(__FILE__).'/book.xml';
$doc = new DOMDocument();
$doc->load($file);
$nodes = $doc->getElementsByTagName('title');
foreach($nodes as $node) {
var_dump($node->getLineNo());
}
?>
--EXPECTF--
int(4)
int(8)

View File

@ -0,0 +1,19 @@
--TEST--
DOMNode::getNodePath()
--SKIPIF--
<?php
include('skipif.inc');
?>
--FILE--
<?php
$file = dirname(__FILE__).'/book.xml';
$doc = new DOMDocument();
$doc->load($file);
$nodes = $doc->getElementsByTagName('title');
foreach($nodes as $node) {
var_dump($node->getNodePath());
}
?>
--EXPECTF--
string(20) "/books/book[1]/title"
string(20) "/books/book[2]/title"

View File

@ -0,0 +1,24 @@
--TEST--
DOMNode::insertBefore() should fail if node belongs to another document
--CREDITS--
Knut Urdalen <knut@php.net>
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
$doc1 = new DOMDocument();
$doc2 = new DOMDocument();
$node_in_doc1 = $doc1->createElement("foo");
$node_in_doc2 = $doc2->createElement("bar");
try {
$node_in_doc2->insertBefore($node_in_doc1);
} catch(DOMException $e) {
echo $e->getMessage();
}
?>
--EXPECTF--
Wrong Document Error