|
| 1 | +--TEST-- |
| 2 | +Reflected attribute writes keep attribute children with live wrappers |
| 3 | +--EXTENSIONS-- |
| 4 | +dom |
| 5 | +--FILE-- |
| 6 | +<?php |
| 7 | + |
| 8 | +function check(string $label, $doc, Closure $write): void { |
| 9 | + $element = $doc->documentElement; |
| 10 | + $text = $element->getAttributeNode('class')->firstChild; |
| 11 | + |
| 12 | + $write($element); |
| 13 | + |
| 14 | + echo $label, ": detached: "; |
| 15 | + var_dump($text->parentNode === null); |
| 16 | + echo $label, ": text: "; |
| 17 | + var_dump($text->textContent); |
| 18 | + echo $label, ": new value: "; |
| 19 | + var_dump($element->getAttribute('class')); |
| 20 | +} |
| 21 | + |
| 22 | +$doc = new DOMDocument(); |
| 23 | +$doc->loadXML('<root class="old"/>'); |
| 24 | +check('legacy className', $doc, static fn ($element) => $element->className = 'new'); |
| 25 | + |
| 26 | +$doc = Dom\XMLDocument::createFromString('<root class="old"/>'); |
| 27 | +check('modern className', $doc, static fn ($element) => $element->className = 'new'); |
| 28 | + |
| 29 | +$doc = Dom\XMLDocument::createFromString('<root class="old"/>'); |
| 30 | +check('classList value', $doc, static fn ($element) => $element->classList->value = 'new'); |
| 31 | + |
| 32 | +$doc = Dom\XMLDocument::createFromString('<root class="old"/>'); |
| 33 | +check('classList update', $doc, static fn ($element) => $element->classList->add('new')); |
| 34 | + |
| 35 | +$doc = Dom\XMLDocument::createFromString('<root class="old"/>'); |
| 36 | +$element = $doc->documentElement; |
| 37 | +$element->id = 'old'; |
| 38 | +$text = $element->getAttributeNode('id')->firstChild; |
| 39 | +$element->id = 'new'; |
| 40 | +echo "id: detached: "; |
| 41 | +var_dump($text->parentNode === null); |
| 42 | +echo "id: text: "; |
| 43 | +var_dump($text->textContent); |
| 44 | +echo "id: new value: "; |
| 45 | +var_dump($element->id); |
| 46 | + |
| 47 | +?> |
| 48 | +--EXPECT-- |
| 49 | +legacy className: detached: bool(true) |
| 50 | +legacy className: text: string(3) "old" |
| 51 | +legacy className: new value: string(3) "new" |
| 52 | +modern className: detached: bool(true) |
| 53 | +modern className: text: string(3) "old" |
| 54 | +modern className: new value: string(3) "new" |
| 55 | +classList value: detached: bool(true) |
| 56 | +classList value: text: string(3) "old" |
| 57 | +classList value: new value: string(3) "new" |
| 58 | +classList update: detached: bool(true) |
| 59 | +classList update: text: string(3) "old" |
| 60 | +classList update: new value: string(7) "old new" |
| 61 | +id: detached: bool(true) |
| 62 | +id: text: string(3) "old" |
| 63 | +id: new value: string(3) "new" |
0 commit comments