setTitle() public method

public setTitle ( $title )
Ejemplo n.º 1
0
 public function testOnDocuments()
 {
     $documents = array();
     for ($i = 1; $i <= 20; ++$i) {
         $document = new Document(null, null, Document::TYPE_POST);
         $document->setTitle('Post #' . $i);
         $document->setTags('Tag #' . $i % 5);
         $documents[] = $document;
     }
     for ($i = 1; $i <= 20; ++$i) {
         $document = new Document(null, null, Document::TYPE_PAGE);
         $document->setTitle('Post #' . $i);
         $document->setTags('Tag #' . $i % 5);
         $documents[] = $document;
     }
     $processor = new Processor();
     $globals = $processor->processGlobals($documents);
     $event = new CarewEvent($documents, array('globals' => $globals));
     $tagFeed = new TagsFeed();
     $tagFeed->onDocuments($event);
     $documents = $event->getSubject();
     // 20 posts, 20 pages, 5 tags index
     $this->assertCount(45, $documents);
     $this->assertSame('tags/tag-1/feed/atom.xml', $documents['tags/Tag #1/feed/atom']->getPath());
 }
 /**
  * @param Author $author
  * @return Document[]
  */
 public function generateAuthorIndices(Author $author)
 {
     $indexes = array();
     foreach ($this->getLayouts() as $layout) {
         $file = $layout->getBasename();
         preg_match('#authors\\.(.+?)\\.twig$#', $file, $match);
         $format = $match[1];
         $document = new Document();
         $document->setLayout((string) $file);
         $document->setPath(sprintf('authors/%s.%s', $author->getHandle(), $format));
         $document->setTitle(sprintf('Author: %s (%s)', $author->get('name'), $author->getHandle()));
         $document->setVars(array('author' => $author));
         $indexes[] = $document;
     }
     return $indexes;
 }
Ejemplo n.º 3
0
 public function testOnDocuments()
 {
     $tags = new Tags();
     $documents = array();
     for ($i = 1; $i <= 20; ++$i) {
         $document = new Document();
         $document->setTitle('Post #' . $i);
         $document->setTags('Tag #' . $i % 5);
         $documents[] = $document;
     }
     $processor = new Processor();
     $globals = $processor->processGlobals($documents);
     $event = new CarewEvent($documents, array('globals' => $globals));
     $tags->onDocuments($event);
     $documents = $event->getSubject();
     // 20 post, 1 page for all tags, 5 tags
     $this->assertCount(26, $documents);
     $this->assertSame('tags/tag-1.html', $documents['tags/Tag #1']->getPath());
 }
Ejemplo n.º 4
0
 public function setUp()
 {
     $this->container = new \Pimple();
     $this->extension = new CarewExtension($this->container);
     $this->twig = new \Twig_Environment(new \Twig_Loader_Filesystem(array(__DIR__ . '/fixtures/theme1', __DIR__ . '/fixtures/theme2', __DIR__ . '/../../Twig/Resources/layouts')));
     $documents = array();
     for ($i = 1; $i <= 20; ++$i) {
         $document = new Document();
         $document->setTitle('Doc #' . $i);
         $document->setTags('Tag #' . $i % 5);
         $document->setFilePath('pages/page-' . $i);
         $document->setPath('pages/page-' . $i . '.html');
         $documents[$document->getFilePath()] = $document;
     }
     $processor = new Processor();
     $this->globals = $processor->processGlobals($documents);
     $this->documents = $documents;
     $this->twig->addGlobal('carew', $this->globals);
     $this->twig->addExtension($this->extension);
 }
Ejemplo n.º 5
0
    public function testPreRenderWithMultiplePagination()
    {
        $posts = array();
        for ($i = 1; $i <= 20; ++$i) {
            $document = new Document();
            $document->setTitle('Post #' . $i);
            $posts[] = $document;
        }
        $posts2 = array();
        for ($i = 1; $i <= 12; ++$i) {
            $document = new Document();
            $document->setTitle('Other Post #' . $i);
            $posts2[] = $document;
        }
        $document = new Document();
        $document->setLayout('default');
        $document->setPath('index.html');
        $document->setTitle('Index');
        $document->setBody(<<<'EOL'
{{ render_documents(paginate([carew.document], 4)) }}
{{ render_documents(paginate(carew.posts, 4)) }}
{{ render_documents(paginate(carew.extra.posts2, 6)) }}
EOL
);
        $event = new CarewEvent(array($document));
        $this->getTwigGlobals()->fromArray(array('posts' => $posts, 'posts2' => $posts2));
        $this->twigListenner->preRender($event);
        $documents = $event->getSubject();
        $this->assertCount(6, $documents);
        $lis1 = $lis2 = $lis3 = array();
        foreach (array_values($documents) as $key => $document) {
            $page = $key + 1;
            if (1 == $page) {
                $path = 'index.html';
            } elseif (in_array($page, array(2, 3, 4, 5))) {
                $path = sprintf('index-page-%s.html', $page);
            } elseif (6 == $page) {
                $path = 'index-2-page-6.html';
            }
            $crawler = new Crawler($document->getBody());
            $this->assertCount(5, $crawler->filter('ul'), 'key is: ' . $key);
            // First pagination (1 item by pages, 0 page (no need to paginate))
            $this->assertCount(1, $crawler->filter('ul')->eq(0)->filter('li'));
            foreach ($crawler->filter('ul')->eq(0)->filter('li') as $li) {
                $lis1[] = trim($li->textContent);
            }
            // Seconde pagination (4 items by pages, 5 pages)
            $this->assertCount(4, $crawler->filter('ul')->eq(1)->filter('li'));
            foreach ($crawler->filter('ul')->eq(1)->filter('li') as $li) {
                $lis2[] = trim($li->textContent);
            }
            $this->assertCount(5, $crawler->filter('ul')->eq(2)->filter('li'));
            for ($i = 1; $i <= 5; ++$i) {
                $this->assertSame('page ' . $i, $crawler->filter('ul')->eq(2)->filter('li')->eq($i - 1)->text(), sprintf('($i = %s, $page = %s)', $i, $page));
                $href = 1 == $i ? 'index.html' : sprintf('index-1-page-%s.html', $i);
                $this->assertSame($href, $crawler->filter('ul')->eq(2)->filter('li')->eq($i - 1)->filter('a')->attr('href'), sprintf('($i = %s, $page = %s)', $i, $page));
                if (6 == $page) {
                    continue;
                }
                $class = $page === $i ? 'active' : null;
                $this->assertSame($class, $crawler->filter('ul')->eq(2)->filter('li')->eq($i - 1)->attr('class'), sprintf('Class "active" is present only when $i == $page, ($i = %s, $page = %s, class = "%s")', $i, $page, $class));
            }
            // Third pagination (6 items by pages, 2 pages)
            $this->assertCount(6, $crawler->filter('ul')->eq(3)->filter('li'));
            foreach ($crawler->filter('ul')->eq(3)->filter('li') as $li) {
                $lis3[] = trim($li->textContent);
            }
            $this->assertCount(2, $crawler->filter('ul')->eq(4)->filter('li'));
            if (1 == $page) {
                $this->assertSame('active', $crawler->filter('ul')->eq(4)->filter('li')->eq(0)->attr('class'));
            } elseif (6 == $page) {
                $this->assertSame(null, $crawler->filter('ul')->eq(4)->filter('li')->eq(0)->attr('class'));
                $this->assertSame('active', $crawler->filter('ul')->eq(4)->filter('li')->eq(1)->attr('class'));
            }
            $this->assertSame('page 1', $crawler->filter('ul')->eq(4)->filter('li')->eq(0)->text());
            $this->assertSame('index.html', $crawler->filter('ul')->eq(4)->filter('li')->eq(0)->filter('a')->attr('href'));
            $this->assertSame('page 2', $crawler->filter('ul')->eq(4)->filter('li')->eq(1)->text());
            $this->assertSame('index-2-page-2.html', $crawler->filter('ul')->eq(4)->filter('li')->eq(1)->filter('a')->attr('href'));
        }
        $lis1 = array_unique($lis1);
        sort($lis1);
        $lis1Expected = array('Index');
        $this->assertSame($lis1Expected, $lis1);
        $lis2 = array_unique($lis2);
        sort($lis2);
        $lis2Expected = array('Post #1', 'Post #10', 'Post #11', 'Post #12', 'Post #13', 'Post #14', 'Post #15', 'Post #16', 'Post #17', 'Post #18', 'Post #19', 'Post #2', 'Post #20', 'Post #3', 'Post #4', 'Post #5', 'Post #6', 'Post #7', 'Post #8', 'Post #9');
        $this->assertSame($lis2Expected, $lis2);
    }