Author: Victor Puertas (vpgugr@gmail.com)
Inheritance: implements Yosymfony\Spress\Core\Plugin\PluginInterface
 public function testListeners()
 {
     $plugin = new PluginTester('acme');
     $eventSubscriber = new EventSubscriber();
     $plugin->setListenerToStartEvent(function ($event) {
     });
     $plugin->setListenerToBeforeConvertEvent(function ($event) {
     });
     $plugin->setListenerToAfterConvertEvent(function ($event) {
     });
     $plugin->setListenerToBeforeRenderBlocksEvent(function ($event) {
     });
     $plugin->setListenerToAfterRenderBlocksEvent(function ($event) {
     });
     $plugin->setListenerToBeforeRenderPageEvent(function ($event) {
     });
     $plugin->setListenerToAfterRenderPageEvent(function ($event) {
     });
     $plugin->setListenerToFinishEvent(function ($event) {
     });
     $plugin->initialize($eventSubscriber);
     $this->assertCount(8, $eventSubscriber->getEventListeners());
     $this->assertArrayHasKey('spress.start', $eventSubscriber->getEventListeners());
     $this->assertArrayHasKey('spress.before_convert', $eventSubscriber->getEventListeners());
     $this->assertArrayHasKey('spress.after_convert', $eventSubscriber->getEventListeners());
     $this->assertArrayHasKey('spress.before_render_blocks', $eventSubscriber->getEventListeners());
     $this->assertArrayHasKey('spress.after_render_blocks', $eventSubscriber->getEventListeners());
     $this->assertArrayHasKey('spress.before_render_page', $eventSubscriber->getEventListeners());
     $this->assertArrayHasKey('spress.after_render_page', $eventSubscriber->getEventListeners());
     $this->assertArrayHasKey('spress.finish', $eventSubscriber->getEventListeners());
 }
 public function testParseSite()
 {
     $attributes = ['site_name' => 'My tests site'];
     $spressAttributes = ['version' => '2.0.0', 'version_id' => '20000', 'major_version' => '2', 'minor_version' => '0', 'release_version' => '0', 'extra_version' => 'dev'];
     $dw = new MemoryDataWriter();
     $testPlugin = new PluginTester('acme');
     $testPlugin->setListenerToBeforeRenderPageEvent(function ($event) {
         if ($event->getId() === 'about/index.html') {
             $this->assertStringEndsNotWith('</html>', $event->getContent());
         }
     });
     $testPlugin->setListenerToAfterRenderPageEvent(function ($event) {
         if ($event->getId() === 'about/index.html') {
             $this->assertStringEndsWith('</html>', $event->getContent());
         }
     });
     $cm = $this->getContentManager($dw, [$testPlugin]);
     $cm->parseSite($attributes, $spressAttributes);
     $this->assertCount(14, $dw->getItems());
     $this->assertTrue($dw->hasItem('about/index.html'));
     $this->assertTrue($dw->hasItem('about/me/index.html'));
     $this->assertTrue($dw->hasItem('index.html'));
     $this->assertTrue($dw->hasItem('LICENSE'));
     $this->assertTrue($dw->hasItem('category-1/category-2/2020/01/01/new-post-example/index.html'));
     $this->assertTrue($dw->hasItem('2013/08/12/post-example-2/index.html'));
     $this->assertTrue($dw->hasItem('books/2013/08/11/best-book/index.html'));
     $this->assertTrue($dw->hasItem('projects/index.html'));
     $this->assertTrue($dw->hasItem('robots.txt'));
     $this->assertTrue($dw->hasItem('sitemap.xml'));
     $this->assertTrue($dw->hasItem('pages/index.html'));
     $this->assertTrue($dw->hasItem('pages/page2/index.html'));
     $this->assertTrue($dw->hasItem('pages/page3/index.html'));
     $this->assertTrue($dw->hasItem('pages/page4/index.html'));
     $this->assertContains('<!DOCTYPE HTML>', $dw->getItem('about/index.html')->getContent());
     $this->assertContains('<!DOCTYPE HTML>', $dw->getItem('pages/index.html')->getContent());
     $this->assertContains('<!DOCTYPE HTML>', $dw->getItem('pages/page2/index.html')->getContent());
     $attributes = $dw->getItem('books/2013/08/11/best-book/index.html')->getAttributes();
     $this->assertArrayHasKey('author', $attributes);
     $this->assertArrayHasKey('categories', $attributes);
     $this->assertContains('books', $attributes['categories']);
     $this->assertEquals('Yo! Symfony', $attributes['author']);
 }
 public function testRelationships()
 {
     $dw = new MemoryDataWriter();
     $testPlugin = new PluginTester('acme');
     $testPlugin->setListenerToBeforeRenderPageEvent(function ($event) {
         if ($event->getId() === 'about/index.html') {
             $this->assertStringEndsNotWith('</html>', $event->getContent());
         }
     });
     $testPlugin->setListenerToAfterRenderPageEvent(function ($event) {
         if ($event->getId() === 'about/index.html') {
             $this->assertStringEndsWith('</html>', $event->getContent());
         }
     });
     $cm = $this->getContentManager($this->getFilesystemDataSourceManager(), $dw, [$testPlugin]);
     $cm->parseSite([], [], true);
     $item = $dw->getItem('category-1/category-2/2020/01/01/new-post-example/index.html');
     $relationshipCollection = $item->getRelationshipCollection();
     $this->assertEquals(1, $relationshipCollection->count());
     $this->assertEquals(1, count($relationshipCollection->get('next')));
     $item = current($relationshipCollection->get('next'));
     $relationshipCollection = $item->getRelationshipCollection();
     $this->assertEquals('posts/2016-02-02-spress-2.1.1-released.md', $item->getId());
     $this->assertEquals(2, $relationshipCollection->count());
     $this->assertEquals(1, count($relationshipCollection->get('prior')));
     $this->assertEquals(1, count($relationshipCollection->get('next')));
     $nextItem = current($relationshipCollection->get('next'));
     $priorItem = current($relationshipCollection->get('prior'));
     $this->assertEquals('posts/books/2013-09-19-new-book.md', $nextItem->getId());
     $this->assertEquals('posts/2013-08-12-post-example-1.md', $priorItem->getId());
     $item = current($relationshipCollection->get('next'));
     $relationshipCollection = $item->getRelationshipCollection();
     $this->assertEquals('posts/books/2013-09-19-new-book.md', $item->getId());
     $this->assertEquals(2, $relationshipCollection->count());
     $this->assertEquals(1, count($relationshipCollection->get('prior')));
     $this->assertEquals(1, count($relationshipCollection->get('next')));
     $nextItem = current($relationshipCollection->get('next'));
     $priorItem = current($relationshipCollection->get('prior'));
     $this->assertEquals('posts/2013-08-12-post-example-2.mkd', $nextItem->getId());
     $this->assertEquals('posts/2016-02-02-spress-2.1.1-released.md', $priorItem->getId());
     $item = current($relationshipCollection->get('next'));
     $relationshipCollection = $item->getRelationshipCollection();
     $this->assertEquals('posts/2013-08-12-post-example-2.mkd', $item->getId());
     $this->assertEquals(2, $relationshipCollection->count());
     $this->assertEquals(1, count($relationshipCollection->get('prior')));
     $this->assertEquals(1, count($relationshipCollection->get('next')));
     $nextItem = current($relationshipCollection->get('next'));
     $priorItem = current($relationshipCollection->get('prior'));
     $this->assertEquals('posts/books/2013-08-11-best-book.md', $nextItem->getId());
     $this->assertEquals('posts/books/2013-09-19-new-book.md', $priorItem->getId());
     $item = current($relationshipCollection->get('next'));
     $relationshipCollection = $item->getRelationshipCollection();
     $this->assertEquals('posts/books/2013-08-11-best-book.md', $item->getId());
     $this->assertEquals(1, $relationshipCollection->count());
     $this->assertEquals(1, count($relationshipCollection->get('prior')));
 }