Skip to content

Commit

Permalink
Added ByYear listener tests
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Apr 12, 2012
1 parent 9a38731 commit 8ae2222
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/PhlyBlog/Compiler/Listener/ByYearTest.php
@@ -0,0 +1,38 @@
<?php
namespace PhlyBlog\Compiler\Listener;

use PHPUnit_Framework_TestCase as TestCase;

class ByYearTest extends TestCase
{
public function setUp()
{
TestHelper::injectScaffolds($this);
$this->byYear = new ByYear($this->view, $this->writer, $this->file, $this->options);
$this->compiler->events()->attach($this->byYear);
}

public function testCreatesNoFilesPriorToCompilation()
{
$this->byYear->compile();
$this->assertTrue(empty($this->writer->files));
}

public function testCreatesFilesFollowingCompilation()
{
$this->compiler->compile();
$this->byYear->compile();

$this->assertFalse(empty($this->writer->files));

$filenameTemplate = $this->options->getByYearFilenameTemplate();
$filenameTemplate = str_replace('-p%d', '', $filenameTemplate);
$yearTitleTemplate = $this->options->getByYearTitle();
foreach ($this->expected['years'] as $year) {
$filename = sprintf($filenameTemplate, $year);
$this->assertArrayHasKey($filename, $this->writer->files);
$yearTitle = sprintf($yearTitleTemplate, $year);
$this->assertContains($yearTitle, $this->writer->files[$filename]);
}
}
}

0 comments on commit 8ae2222

Please sign in to comment.