getPath() 공개 메소드

public getPath ( )
예제 #1
0
 public function testConstructor()
 {
     $document = new Document(new SplFileInfo(__FILE__, '.', '.'));
     $this->assertSame(file_get_contents(__FILE__), $document->getBody());
     $this->assertSame(file_get_contents(__FILE__), $document->getBodyDecorated());
     $this->assertSame('DocumentTest.php', $document->getPath());
 }
예제 #2
0
 /**
  * @dataProvider getOnPostTests
  */
 public function testOnPost($expected, $format)
 {
     $file = $this->prophesize('Symfony\\Component\\Finder\\SplFileInfo');
     $file->getBasename('.md')->willReturn('2010-09-09-foobar-bar');
     $file->__toString()->willReturn('');
     $document = new Document($file->reveal(), null, Document::TYPE_POST);
     $event = new CarewEvent($document);
     $extraction = new Optimization($format);
     $extraction->onDocument($event);
     $this->assertSame($expected, $document->getPath());
 }
예제 #3
0
파일: TwigTest.php 프로젝트: carew/carew
 public function testPreRenderWithPagination()
 {
     $posts = array();
     for ($i = 1; $i <= 20; ++$i) {
         $document = new Document();
         $document->setTitle('Post #' . $i);
         $posts[] = $document;
     }
     $document = new Document();
     $document->setLayout('default');
     $document->setPath('index.html');
     $document->setBody('{{ render_documents(paginate(carew.posts, 4)) }}');
     $this->getTwigGlobals()->fromArray(array('posts' => $posts));
     $event = new CarewEvent(array($document));
     $this->twigListenner->preRender($event);
     $documents = $event->getSubject();
     $this->assertCount(5, $documents);
     $lis = array();
     foreach (array_values($documents) as $key => $document) {
         $page = $key + 1;
         $path = 1 == $page ? 'index.html' : sprintf('index-page-%s.html', $page);
         $this->assertSame($path, $document->getPath());
         $crawler = new Crawler($document->getBody());
         $this->assertCount(2, $crawler->filter('ul'));
         $this->assertCount(4, $crawler->filter('ul')->eq(0)->filter('li'));
         foreach ($crawler->filter('ul')->eq(0)->filter('li') as $li) {
             $lis[] = trim($li->textContent);
         }
         $this->assertCount(5, $crawler->filter('ul')->eq(1)->filter('li'));
         for ($i = 1; $i <= 5; ++$i) {
             $class = $page == $i ? 'active' : null;
             $this->assertSame($class, $crawler->filter('ul')->eq(1)->filter('li')->eq($i - 1)->attr('class'), sprintf('Class "active" is present only when $i == $page, ($i = %s, $page = %s)', $i, $page));
             $this->assertSame('page ' . $i, $crawler->filter('ul')->eq(1)->filter('li')->eq($i - 1)->text(), sprintf('($i = %s, $page = %s)', $i, $page));
             $href = 1 == $i ? 'index.html' : sprintf('index-page-%s.html', $i);
             $this->assertSame($href, $crawler->filter('ul')->eq(1)->filter('li')->eq($i - 1)->filter('a')->attr('href'), sprintf('($i = %s, $page = %s)', $i, $page));
         }
     }
     sort($lis);
     $expected = 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($expected, $lis);
 }
예제 #4
0
파일: Twig.php 프로젝트: carew/carew
 private function setTwigGlobals(Document $document)
 {
     $twigGlobals = $this->twig->getGlobals();
     $globals = $twigGlobals['carew'];
     $globals->fromArray($document->getVars());
     $globals->relativeRoot = $document->getRootPath();
     $globals->currentPath = $document->getPath();
     $globals->document = $document;
     return $this;
 }
예제 #5
0
파일: Processor.php 프로젝트: carew/carew
 public function write(Document $document, $webDir)
 {
     $target = $webDir . '/' . $document->getPath();
     $this->filesystem->mkdir(dirname($target));
     file_put_contents($target, $document->getBodyDecorated());
 }
예제 #6
0
 private function onApi(Document $document)
 {
     $document->setPath(sprintf('api/%s', $document->getPath()));
 }