--TEST--
DOMElement::insertAdjacentText()
--EXTENSIONS--
dom
--FILE--
loadXML('foo
');
echo "--- Edge cases ---\n";
try {
$dom->createElement('free')->insertAdjacentText("bogus", "bogus");
} catch (DOMException $e) {
echo $e->getMessage(), "\n";
}
function testNormalCases($dom, $uppercase) {
$container = $dom->documentElement;
$p = $container->firstElementChild;
$transform = fn ($s) => $uppercase ? strtoupper($s) : $s;
$p->insertAdjacentText("beforebegin", 'A');
echo $dom->saveXML();
$p->insertAdjacentText("afterbegin", 'B');
echo $dom->saveXML();
$p->insertAdjacentText("beforeend", 'C');
echo $dom->saveXML();
$p->insertAdjacentText("afterend", 'D');
echo $dom->saveXML();
}
echo "--- Normal cases uppercase ---\n";
testNormalCases(clone $dom, true);
echo "--- Normal cases lowercase ---\n";
testNormalCases($dom, false);
echo "--- Normal cases starting from empty element ---\n";
$empty = $dom->createElement('empty');
$empty->insertAdjacentText("afterbegin", 'A');
echo $dom->saveXML($empty), "\n";
$AText = $empty->firstChild;
$empty->insertAdjacentText("afterbegin", 'B');
echo $dom->saveXML($empty), "\n";
var_dump($AText->textContent);
?>
--EXPECT--
--- Edge cases ---
Syntax Error
--- Normal cases uppercase ---
Afoo
ABfoo
ABfooC
ABfooC
D
--- Normal cases lowercase ---
Afoo
ABfoo
ABfooC
ABfooC
D
--- Normal cases starting from empty element ---
A
BA
string(1) "A"