addToAssertionCount(1); } /** * Cache a page's content */ public function testCache() { $page = new CachedPage(self::$testCacheDir, self::$url, true, null); $this->assertFileNotExists(self::$filename); $page->cache('

Some content

'); $this->assertFileExists(self::$filename); $this->assertEquals( '

Some content

', file_get_contents(self::$filename) ); } /** * "Cache" a page's content - the page is not to be cached */ public function testShouldNotCache() { $page = new CachedPage(self::$testCacheDir, self::$url, false, null); $this->assertFileNotExists(self::$filename); $page->cache('

Some content

'); $this->assertFileNotExists(self::$filename); } /** * Return a page's cached content */ public function testCachedVersion() { $page = new CachedPage(self::$testCacheDir, self::$url, true, null); $this->assertFileNotExists(self::$filename); $page->cache('

Some content

'); $this->assertFileExists(self::$filename); $this->assertEquals( '

Some content

', $page->cachedVersion() ); } /** * Return a page's cached content - the file does not exist */ public function testCachedVersionNoFile() { $page = new CachedPage(self::$testCacheDir, self::$url, true, null); $this->assertFileNotExists(self::$filename); $this->assertEquals( null, $page->cachedVersion() ); } /** * Return a page's cached content - the page is not to be cached */ public function testNoCachedVersion() { $page = new CachedPage(self::$testCacheDir, self::$url, false, null); $this->assertFileNotExists(self::$filename); $this->assertEquals( null, $page->cachedVersion() ); } /** * Return a page's cached content within date period */ public function testCachedVersionInDatePeriod() { $period = new \DatePeriod( new \DateTime('yesterday'), new \DateInterval('P1D'), new \DateTime('tomorrow') ); $page = new CachedPage(self::$testCacheDir, self::$url, true, $period); $this->assertFileNotExists(self::$filename); $page->cache('

Some content

'); $this->assertFileExists(self::$filename); $this->assertEquals( '

Some content

', $page->cachedVersion() ); } /** * Return a page's cached content outside of date period */ public function testCachedVersionNotInDatePeriod() { $period = new \DatePeriod( new \DateTime('yesterday noon'), new \DateInterval('P1D'), new \DateTime('yesterday midnight') ); $page = new CachedPage(self::$testCacheDir, self::$url, true, $period); $this->assertFileNotExists(self::$filename); $page->cache('

Some content

'); $this->assertFileExists(self::$filename); $this->assertNull($page->cachedVersion()); } }