1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
--TEST--
Dom\Node::isDefaultNamespace()
--EXTENSIONS--
dom
--FILE--
<?php
$dom = Dom\HTMLDocument::createFromString(<<<HTML
<!DOCTYPE html>
<html>
<body>
<svg xmlns="http://www.w3.org/2000/svg" height="1"></svg>
<math></math>
</body>
</html>
HTML);
function dump($node) {
echo "svg NS: ";
var_dump($node->isDefaultNamespace('http://www.w3.org/2000/svg'));
echo "xhtml NS: ";
var_dump($node->isDefaultNamespace('http://www.w3.org/1999/xhtml'));
echo "mathml NS: ";
var_dump($node->isDefaultNamespace('http://www.w3.org/1998/Math/MathML'));
echo "empty NS: ";
var_dump($node->isDefaultNamespace(''));
}
echo "--- Document ---\n";
dump($dom);
echo "--- svg element ---\n";
dump($dom->getElementsByTagName('svg')[0]);
echo "--- math element ---\n";
dump($dom->getElementsByTagName('math')[0]);
echo "--- svg attribute ---\n";
dump($dom->getElementsByTagName('svg')[0]->attributes[0]);
echo "--- empty fragment ---\n";
dump($dom->createDocumentFragment());
echo "--- doctype ---\n";
dump($dom->doctype);
echo "--- detached attribute ---\n";
dump($dom->createAttribute('foo'));
echo "--- custom namespace with a prefix ---\n";
var_dump($dom->createElementNS('urn:a', 'q:name')->isDefaultNamespace('urn:a'));
echo "--- custom namespace with a prefix and with attributes ---\n";
$element = $dom->createElementNS('urn:a', 'q:name');
$element->setAttributeNS("urn:x", "x:foo", "");
$element->setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:q", "urn:test");
$element->setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", "urn:test2");
var_dump($element->isDefaultNamespace('urn:a'));
var_dump($element->isDefaultNamespace('urn:test'));
var_dump($element->isDefaultNamespace('urn:test2'));
echo "--- custom namespace without a prefix ---\n";
var_dump($dom->createElementNS('urn:a', 'name')->isDefaultNamespace('urn:a'));
?>
--EXPECT--
--- Document ---
svg NS: bool(false)
xhtml NS: bool(true)
mathml NS: bool(false)
empty NS: bool(false)
--- svg element ---
svg NS: bool(true)
xhtml NS: bool(false)
mathml NS: bool(false)
empty NS: bool(false)
--- math element ---
svg NS: bool(false)
xhtml NS: bool(false)
mathml NS: bool(true)
empty NS: bool(false)
--- svg attribute ---
svg NS: bool(true)
xhtml NS: bool(false)
mathml NS: bool(false)
empty NS: bool(false)
--- empty fragment ---
svg NS: bool(false)
xhtml NS: bool(false)
mathml NS: bool(false)
empty NS: bool(true)
--- doctype ---
svg NS: bool(false)
xhtml NS: bool(false)
mathml NS: bool(false)
empty NS: bool(true)
--- detached attribute ---
svg NS: bool(false)
xhtml NS: bool(false)
mathml NS: bool(false)
empty NS: bool(true)
--- custom namespace with a prefix ---
bool(false)
--- custom namespace with a prefix and with attributes ---
bool(false)
bool(false)
bool(true)
--- custom namespace without a prefix ---
bool(true)
|