示例#1
0
    $validParent = true;
    foreach ($node->children as $childNode) {
        if ($childNode->parent !== $node) {
            $validParent = false;
        }
    }
    (yield check($node->indexOf($secondChild) === 1, 'Second child not 1'));
    (yield check($node->indexOf($thirdChild) === 0, 'Third child not 0'));
    (yield check($validParent, 'Parent not correctly set'));
}, 'remove' => function () {
    $node = new Node('parent');
    $node->append(new Node('child-1'));
    $node->append($secondChild = new Node('child-2'));
    $node->append($thirdChild = new Node('child-3'));
    $notAChild = new Node('not-a-child');
    $node->remove($secondChild);
    (yield check($node->indexOf($secondChild) === false, 'Child still in parent node'));
    (yield check($secondChild->parent === null, 'Childs parent not null'));
    (yield check($node->indexOf($thirdChild) === 1, 'Third child not moved to 1'));
}, 'insertAfter' => function () {
    $node = new Node('parent');
    $node->append($firstChild = new Node('child-1'));
    $node->append($secondChild = new Node('child-2'));
    $node->insertAfter($firstChild, $thirdChild = new Node('child-3'));
    $notAChild = new Node('not-a-child');
    (yield check(count($node->children) === 3, 'Child count not 3'));
    (yield check($node->indexOf($thirdChild) === 1, 'Third child not 1'));
    (yield check($node->indexOf($secondChild) === 2, 'Second child not 2'));
}, 'insertBefore' => function () {
    $node = new Node('parent');
    $node->append($firstChild = new Node('child-1'));