/**
  * @test
  */
 public function parentsFollowedByFirstMatchesInnermostNodeOnRootline()
 {
     $teaserText = $this->node->getNode('teaser/dummy42');
     $q = new FlowQuery(array($teaserText));
     $actual = iterator_to_array($q->parents('[someSpecialProperty]')->first());
     $expected = array($this->node->getNode('teaser'));
     $this->assertTrue($expected === $actual);
 }
 /**
  * @param NodeInterface $node A document node
  * @return string
  */
 public function render(NodeInterface $node)
 {
     $output = '/' . $node->getLabel();
     $flowQuery = new FlowQuery(array($node));
     $nodes = $flowQuery->parents('[instanceof TYPO3.Neos:Document]')->get();
     /** @var NodeInterface $node */
     foreach ($nodes as $node) {
         $output = '/' . $node->getLabel() . $output;
     }
     return $output;
 }
 /**
  * @param NodeInterface $node
  * @return array
  */
 protected function breadcrumbNodesForNode(NodeInterface $node)
 {
     $documentNodes = [];
     $flowQuery = new FlowQuery(array($node));
     $nodes = array_reverse($flowQuery->parents('[instanceof TYPO3.Neos:Document]')->get());
     /** @var NodeInterface $node */
     foreach ($nodes as $documentNode) {
         $documentNodes[] = $documentNode;
     }
     if ($node->getNodeType()->isOfType('TYPO3.Neos:Document')) {
         $documentNodes[] = $node;
     }
     return $documentNodes;
 }
 /**
  * @param NodeInterface $node A node
  * @return array of document nodes
  */
 public function render(NodeInterface $node)
 {
     $documentNodes = [];
     $flowQuery = new FlowQuery(array($node));
     $nodes = array_reverse($flowQuery->parents('[instanceof TYPO3.Neos:Document]')->get());
     /** @var NodeInterface $node */
     foreach ($nodes as $documentNode) {
         $documentNodes[] = $documentNode;
     }
     if ($node->getNodeType()->isOfType('TYPO3.Neos:Document')) {
         $documentNodes[] = $node;
     }
     $this->templateVariableContainer->add('documentNodes', $documentNodes);
     $content = $this->renderChildren();
     $this->templateVariableContainer->remove('documentNodes');
     return $content;
 }
 /**
  * {@inheritdoc}
  *
  * @param FlowQuery $flowQuery the FlowQuery object
  * @param array $arguments the arguments for this operation
  * @return void
  */
 public function evaluate(FlowQuery $flowQuery, array $arguments)
 {
     if (!isset($arguments[0]) || empty($arguments[0])) {
         throw new \TYPO3\Eel\FlowQuery\FlowQueryException('closest() requires a filter argument', 1332492263);
     }
     $output = array();
     foreach ($flowQuery->getContext() as $contextNode) {
         $contextNodeQuery = new FlowQuery(array($contextNode));
         $contextNodeQuery->pushOperation('first', array());
         $contextNodeQuery->pushOperation('filter', $arguments);
         $parentsQuery = new FlowQuery(array($contextNode));
         $contextNodeQuery->pushOperation('add', array($parentsQuery->parents($arguments[0])->get()));
         foreach ($contextNodeQuery as $result) {
             $output[$result->getPath()] = $result;
         }
     }
     $flowQuery->setContext(array_values($output));
 }
 /**
  * {@inheritdoc}
  *
  * @param FlowQuery $flowQuery
  * @param array $arguments
  * @return void
  */
 public function evaluate(FlowQuery $flowQuery, array $arguments)
 {
     $subject = $arguments[0];
     if (!isset($subject) || empty($subject)) {
         $flowQuery->setContext(array());
         return;
     }
     $filteredContext = array();
     $context = $flowQuery->getContext();
     if (is_string($subject)) {
         foreach ($context as $contextElement) {
             $contextElementQuery = new FlowQuery(array($contextElement));
             $contextElementQuery->pushOperation('children', $arguments);
             if ($contextElementQuery->count() > 0) {
                 $filteredContext[] = $contextElement;
             }
         }
     } else {
         if ($subject instanceof \TYPO3\Eel\FlowQuery\FlowQuery) {
             $elements = $subject->get();
         } elseif ($subject instanceof \Traversable) {
             $elements = iterator_to_array($subject);
         } elseif (is_object($subject)) {
             $elements = array($subject);
         } elseif (is_array($subject)) {
             $elements = $subject;
         } else {
             throw new \TYPO3\Eel\FlowQuery\FizzleException('supplied argument for has operation not supported', 1332489625);
         }
         foreach ($elements as $element) {
             if ($element instanceof NodeInterface) {
                 $parentsQuery = new FlowQuery(array($element));
                 /** @var NodeInterface $parent */
                 foreach ($parentsQuery->parents(array())->get() as $parent) {
                     /** @var NodeInterface $contextElement */
                     foreach ($context as $contextElement) {
                         if ($contextElement->getIdentifier() === $parent->getIdentifier()) {
                             $filteredContext[] = $contextElement;
                         }
                     }
                 }
             }
         }
         $filteredContext = array_unique($filteredContext);
     }
     $flowQuery->setContext($filteredContext);
 }