From 01e48f269df59e02798dad4a698c125d76b0ed70 Mon Sep 17 00:00:00 2001 From: VirtualTam Date: Thu, 9 Jul 2015 22:14:39 +0200 Subject: CachedPage: move to a proper file, add tests Modifications - rename `pageCache` to `CachedPage` - move utilities to `Cache` - do not access globals - apply coding rules - update LinkDB and test code - add test coverage Signed-off-by: VirtualTam --- tests/CachedPageTest.php | 121 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 tests/CachedPageTest.php (limited to 'tests/CachedPageTest.php') diff --git a/tests/CachedPageTest.php b/tests/CachedPageTest.php new file mode 100644 index 00000000..e97af030 --- /dev/null +++ b/tests/CachedPageTest.php @@ -0,0 +1,121 @@ +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); + + $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); + + $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); + + $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); + + $this->assertFileNotExists(self::$filename); + $this->assertEquals( + null, + $page->cachedVersion() + ); + } +} -- cgit v1.2.3