Permalink
Browse files

Added Authors tests

  • Loading branch information...
weierophinney committed Apr 12, 2012
1 parent 081085d commit 9a387318571660dae5112675294a95f8bc105611
Showing with 65 additions and 0 deletions.
  1. +8 −0 src/PhlyBlog/Compiler/Listener/Authors.php
  2. +57 −0 test/PhlyBlog/Compiler/Listener/AuthorsTest.php
@@ -55,6 +55,10 @@ public function compile()
public function createAuthorPages($template = null)
{
+ if (!$this->entries) {
+ return;
+ }
+
if (null === $template) {
$template = $this->options->getByAuthorTemplate();
if (empty($template)) {
@@ -89,6 +93,10 @@ public function createAuthorPages($template = null)
public function createAuthorFeeds($type)
{
+ if (!$this->entries) {
+ return;
+ }
+
$type = strtolower($type);
if (!in_array($type, array('atom', 'rss'))) {
throw new InvalidArgumentException('Feed type must be "atom" or "rss"');
@@ -0,0 +1,57 @@
+<?php
+namespace PhlyBlog\Compiler\Listener;
+
+use PHPUnit_Framework_TestCase as TestCase;
+
+class AuthorsTest extends TestCase
+{
+ public function setUp()
+ {
+ TestHelper::injectScaffolds($this);
+ $this->authors = new Authors($this->view, $this->writer, $this->file, $this->options);
+ $this->compiler->events()->attach($this->authors);
+ }
+
+ public function testCreatesNoFilesPriorToCompilation()
+ {
+ $this->authors->compile();
+ $this->assertTrue(empty($this->writer->files));
+ }
+
+ public function testCreatesFilesFollowingCompilation()
+ {
+ $this->compiler->compile();
+ $this->authors->compile();
+
+ $this->assertFalse(empty($this->writer->files));
+
+ $filenameTemplate = $this->options->getByAuthorFilenameTemplate();
+ $filenameTemplate = str_replace('-p%d', '', $filenameTemplate);
+ $authorTitleTemplate = $this->options->getByAuthorTitle();
+ foreach ($this->expected['authors'] as $author) {
+ $filename = sprintf($filenameTemplate, $author['id']);
+ $this->assertArrayHasKey($filename, $this->writer->files);
+ $authorTitle = sprintf($authorTitleTemplate, $author['name']);
+ $this->assertContains($authorTitle, $this->writer->files[$filename]);
+ }
+ }
+
+ public function testCreatesFeedsFollowingCompilation()
+ {
+ $this->compiler->compile();
+ $this->authors->compile();
+
+ $this->assertFalse(empty($this->writer->files));
+
+ $filenameTemplate = $this->options->getAuthorFeedFilenameTemplate();
+ $authorTitleTemplate = $this->options->getAuthorFeedTitleTemplate();
+ foreach (array('atom', 'rss') as $type) {
+ foreach ($this->expected['authors'] as $author) {
+ $filename = sprintf($filenameTemplate, $author['id'], $type);
+ $this->assertArrayHasKey($filename, $this->writer->files);
+ $authorTitle = sprintf($authorTitleTemplate, $author['name']);
+ $this->assertContains($authorTitle, $this->writer->files[$filename]);
+ }
+ }
+ }
+}

0 comments on commit 9a38731

Please sign in to comment.