Carew\Tests\Twig\NodeVisitor\PaginatorTest::testNodeVisitorAlterRenderDocumentAndAddSliceFilterAndPaginationNode PHP Метод

testNodeVisitorAlterRenderDocumentAndAddSliceFilterAndPaginationNode() публичный Метод

    public function testNodeVisitorAlterRenderDocumentAndAddSliceFilterAndPaginationNode()
    {
        $env = $this->createEnv();
        $stream = $env->parse($env->tokenize('{{ render_documents(paginate(collection)) }}'));
        // Transformed in "{{ render_documents(collection|slice(__offset_0__, 10), __pages_0__, __current_page_0__) }}"
        // render_documents(...)
        $nodeFunction = $stream->getNode('body')->getNode(0)->getNode('expr');
        $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_0__', $arguments->getNode(1)->getAttribute('name'));
        $this->assertInstanceOf('Twig_Node_Expression_Name', $arguments->getNode(2));
        $this->assertSame('__current_page_0__', $arguments->getNode(2)->getAttribute('name'));
        // collection|slice(__offset_0__, 10)
        $nodeFilter = $arguments->getNode(0);
        $this->assertInstanceOf('Twig_Node_Expression_Filter', $nodeFilter);
        $this->assertNodeFilterHasSlice($nodeFilter, 10);
        // Tests 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->assertFalse($paginationNode->hasNode(1));
        $this->assertSame(array(10), $paginationNode->getAttribute('maxesPerPage'));
    }