Exemple #1
0
    $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'));
    $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>";
    }
Exemple #2
0
 protected function compileConditional(Node $node)
 {
     $type = $node->conditionType;
     $subject = $node->subject;
     if ($subject === 'block') {
         $subject = '$__block';
     }
     if ($this->isVariable($subject)) {
         $subject = "isset({$subject}) ? {$subject} : false";
     }
     if ($type === 'unless') {
         $type = 'if';
         $subject = "!({$subject})";
     }
     $isPrevConditional = $node->prev() && $node->prev()->type === 'conditional';
     $isNextConditional = $node->next() && $node->next()->type === 'conditional' && $node->next()->conditionType !== 'if';
     $prefix = $isPrevConditional ? '' : '<?php ';
     $suffix = $isNextConditional ? '' : '?>';
     $phtml = $type === 'else' ? $this->createCode(' else {', $prefix) : $this->createCode("{$type} ({$subject}) {", $prefix);
     $phtml .= $this->compileChildren($node->children);
     $phtml .= $this->newLine() . $this->indent() . $this->createCode("}", '<?php ', $suffix);
     return $phtml;
 }