public function testAddAuthor() { $handle = 'test'; $author = new Author($handle); $this->registry->addAuthor($author); $this->assertSame($author, $this->registry->getAuthor($handle)); $this->assertSame(array($author), $this->registry->getAuthors()); }
public function testOnAuthorSetsAuthorsInTwigEnvironment() { $author = new Author('test'); $authors = new AuthorRegistry(); $authors->addAuthor($author); $generator = $this->getMock('Carew\\Plugin\\Authors\\Generator\\AuthorIndexGenerator', array(), array(), '', false); $generator->expects($this->any())->method('generateAuthorIndices')->will($this->returnValue(array())); $twig = $this->getMock('Twig_Environment'); $subscriber = new AuthorsEventSubscriber($authors, $generator, $twig); $twig->expects($this->once())->method('addGlobal')->with('authors', array($author)); $subscriber->onAuthors(new CarewEvent()); }
/** * @param Carew $carew */ public function register(Carew $carew) { $container = $carew->getContainer(); $registry = new AuthorRegistry(); $eventDispatcher = $carew->getEventDispatcher(); $config = $container->offsetGet('config'); if (isset($config['authors'])) { foreach ($config['authors'] as $handle => $attributes) { $registry->addAuthor(new Author($handle, $attributes)); } } $eventDispatcher->addSubscriber(new IndexesEventSubscriber($registry)); $eventDispatcher->addSubscriber(new AuthorsEventSubscriber($registry, new AuthorIndexGenerator($container['base_dir'], new Finder()), $container->offsetGet('twig'))); }
/** * @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()); }