Permalink
Browse files

Tested ByMonth listener

  • Loading branch information...
1 parent 8ae2222 commit 8e5cf81a95c4017eb6ac9ca44a9d73893bbfd70b @weierophinney weierophinney committed Apr 12, 2012
Showing with 58 additions and 0 deletions.
  1. +58 −0 test/PhlyBlog/Compiler/Listener/ByMonthTest.php
@@ -0,0 +1,58 @@
+<?php
+namespace PhlyBlog\Compiler\Listener;
+
+use DateTime;
+use DateTimezone;
+use PHPUnit_Framework_TestCase as TestCase;
+
+class ByYearTest extends TestCase
+{
+ public function setUp()
+ {
+ TestHelper::injectScaffolds($this);
+ $this->byMonth = new ByMonth($this->view, $this->writer, $this->file, $this->options);
+ $this->compiler->events()->attach($this->byMonth);
+
+ $this->months = array();
+ $self = $this;
+ $this->compiler->events()->attach('compile', function($e) use ($self) {
+ $entry = $e->getEntry();
+ if ($entry->isDraft() || !$entry->isPublic()) {
+ return;
+ }
+
+ $created = $entry->getCreated();
+ $tz = $entry->getTimezone();
+ $date = new DateTime();
+ $date->setTimezone(new DateTimezone($tz));
+ $date->setTimestamp($created);
+ $month = $date->format('Y/m');
+ $self->months[$month] = $date;
+ });
+ }
+
+ public function testCreatesNoFilesPriorToCompilation()
+ {
+ $this->byMonth->compile();
+ $this->assertTrue(empty($this->writer->files));
+ }
+
+ public function testCreatesFilesFollowingCompilation()
+ {
+ $this->compiler->compile();
+ $this->byMonth->compile();
+
+ $this->assertFalse(empty($this->writer->files));
+ $this->assertFalse(empty($this->months));
+
+ $filenameTemplate = $this->options->getByMonthFilenameTemplate();
+ $filenameTemplate = str_replace('-p%d', '', $filenameTemplate);
+ $monthTitleTemplate = $this->options->getByMonthTitle();
+ foreach ($this->months as $month => $date) {
+ $filename = sprintf($filenameTemplate, $month);
+ $this->assertArrayHasKey($filename, $this->writer->files);
+ $monthTitle = sprintf($monthTitleTemplate, $date->format('F Y'));
+ $this->assertContains($monthTitle, $this->writer->files[$filename]);
+ }
+ }
+}

0 comments on commit 8e5cf81

Please sign in to comment.