public function testNodeVisitorAlterRenderDocumentAndAddSliceFilterAndPaginationNodeWithManyPaginate()
{
$env = $this->createEnv();
$stream = $env->parse($env->tokenize('{{ render_documents(paginate(collection)) }} {{ render_documents(paginate(collection2, 6)) }}'));
// Transformed in :
// {{ render_documents(collection|slice(__offset_0__, 10), __pages_0__, __current_page_0__) }}
// {{ render_documents(collection2|slice(__offset_1__, 6), __pages_1__, __current_page_1__) }}
foreach (array(0 => array('nodeItem' => 0, 'maxPerPage' => 10), 1 => array('nodeItem' => 2, 'maxPerPage' => 6)) as $currentNumberOfPagination => $data) {
$nodeFunction = $stream->getNode('body')->getNode(0)->getNode($data['nodeItem'])->getNode('expr');
// render_documents(...)
$this->assertInstanceOf('Twig_Node_Expression_Function', $nodeFunction);
$this->assertSame('render_documents', $nodeFunction->getAttribute('name'));
$arguments = $nodeFunction->getNode('arguments');
$this->assertInstanceOf('Twig_Node_Expression_Name', $arguments->getNode(1));
$this->assertSame("__pages_{$currentNumberOfPagination}__", $arguments->getNode(1)->getAttribute('name'));
$this->assertInstanceOf('Twig_Node_Expression_Name', $arguments->getNode(2));
$this->assertSame("__current_page_{$currentNumberOfPagination}__", $arguments->getNode(2)->getAttribute('name'));
// collection|slice(__offset_0__, 10)
$nodeFilter = $arguments->getNode(0);
$this->assertInstanceOf('Twig_Node_Expression_Filter', $nodeFilter);
$this->assertNodeFilterHasSlice($nodeFilter, $data['maxPerPage'], $currentNumberOfPagination);
}
// Test on extra
$blocksNode = $stream->getNode('blocks');
$this->assertInstanceOf('Twig_Node', $blocksNode);
$paginationNode = $blocksNode->getNode('pagination');
$this->assertInstanceOf('Carew\\Twig\\Node\\Pagination', $paginationNode);
$this->assertInstanceOf('Twig_Node_Expression_Name', $paginationNode->getNode(0));
$this->assertSame('collection', $paginationNode->getNode(0)->getAttribute('name'));
$this->assertInstanceOf('Twig_Node_Expression_Name', $paginationNode->getNode(1));
$this->assertSame('collection2', $paginationNode->getNode(1)->getAttribute('name'));
$this->assertFalse($paginationNode->hasNode(2));
$this->assertSame(array(10, 6), $paginationNode->getAttribute('maxesPerPage'));
}