Ejemplo n.º 1
0
    $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'));
    $node->append($secondChild = new Node('child-2'));
    $node->insertBefore($secondChild, $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'));
}];
echo '<h1>Testing node functionality</h1>';
ob_start();
foreach ($tests as $name => $test) {
    echo '<h2>Testing ' . $name . ':</h2><br>';
    foreach ($test() as $result) {
        echo "{$result}<br>";
    }
}
Ejemplo n.º 2
0
 protected function handleBlock(Node $node)
 {
     if (!$node->name || $node->mode === 'ignore') {
         //Will be handled through compileBlock when the loop encounters it
         return $this;
     }
     //Find all other blocks with that name
     foreach ($this->_blocks as $block) {
         if ($block === $node || $block->name !== $node->name) {
             continue;
         }
         $mode = $block->mode;
         //detach from parent
         $block->parent->remove($block);
         switch ($mode) {
             default:
             case 'replace':
                 $node->children = [];
                 //WANTED FALLTHROUGH!
             //WANTED FALLTHROUGH!
             case 'append':
                 //Append to master block
                 foreach ($block->children as $child) {
                     $block->remove($child);
                     $node->append($child);
                 }
                 break;
             case 'prepend':
                 $last = null;
                 foreach ($block->children as $child) {
                     $block->remove($child);
                     if (!$last) {
                         $node->prepend($child);
                         $last = $child;
                         continue;
                     }
                     $node->insertAfter($last, $child);
                     $last = $child;
                 }
                 break;
         }
         $block->mode = 'ignore';
     }
 }