/** * @dataProvider getContentTypes * * @param string $contentType */ public function testOnIndexesAddsDocumentsToAuthors($contentType) { $author = new Author('seiffert'); $authors = new AuthorRegistry(); $authors->addAuthor($author); $subscriber = new IndexesEventSubscriber($authors); $document = new Document(); $document->setMetadatas(array('author' => 'seiffert')); $index = new Document(); $index->setVars(array($contentType => array($document))); $subscriber->onIndexes($this->createEvent(array($index))); $document->setMetadatas(array('author' => $author), true); $this->assertSame(array($document), $author->getDocuments()); }
/** * @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; }
/** * @dataProvider getPostRenderWithLayoutTests */ public function testPostRenderWithLayout($layout) { $document = new Document(); $document->setBody('Hello {{ name }}'); $document->setLayout($layout); $document->setVars(array('key' => 'value', 'currentPath' => 'should not appear')); $template = <<<EOL "{{ carew.document.body }}" "{{ carew.relativeRoot }}" "{{ carew.currentPath }}" "{{ carew.extra.foo }}" "{{ carew.extra.key }}" EOL; $this->twigLoader->setTemplate('default.html.twig', $template); $event = new CarewEvent(array($document)); $this->getTwigGlobals()->fromArray(array('foo' => 'bar', 'relativeRoot' => 'should not appear')); $this->twigListenner->postRender($event); $expected = <<<EOL "Hello {{ name }}" "." "" "bar" "value" EOL; $this->assertSame($expected, $document->getBodyDecorated()); }