setPath() 공개 메소드

public setPath ( $path )
예제 #1
0
 public function testOnApi()
 {
     $document = new Document(null, null, Document::TYPE_API);
     $document->setPath('foobar.html');
     $event = new CarewEvent($document);
     $extraction = new Optimization();
     $extraction->onDocument($event);
     $this->assertSame('api/foobar.html', $document->getPath());
 }
예제 #2
0
파일: TocTest.php 프로젝트: carew/carew
 public function testOnDocumentDoesNotLinkWithDoubleQuote()
 {
     $document = new Document();
     $document->setPath('index.html');
     $body = '<a href="https://google.com">"google.com"</a>';
     $document->setBody($body);
     $event = new CarewEvent($document);
     $toc = new Toc();
     $toc->onDocument($event);
     $this->assertSame($body, $document->getBody());
 }
 /**
  * @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;
 }
예제 #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);
 }
예제 #5
0
 public function testWrite()
 {
     $tmp = sys_get_temp_dir() . '/carew-test';
     static::deleteDir($tmp);
     $document = new Document(new SplFileInfo(__FILE__, '', ''));
     $document->setPath('foo/bar/file.html');
     $this->processor->write($document, $tmp);
     $this->assertFileEquals(__FILE__, $tmp . '/foo/bar/file.html');
     static::deleteDir($tmp);
 }
예제 #6
0
 /**
  * @dataProvider getGetRootPathTests
  */
 public function testGetRootPath($expected, $path)
 {
     $document = new Document();
     $document->setPath($path);
     $this->assertSame($expected, $document->getRootPath());
 }
예제 #7
0
파일: TwigTest.php 프로젝트: carew/carew
    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);
    }
예제 #8
0
 private function onApi(Document $document)
 {
     $document->setPath(sprintf('api/%s', $document->getPath()));
 }