X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2Ffeed%2FCachedPageTest.php;h=1decfaf3b5c70fd00e31dd1200bcae62f5b892e2;hb=20ba77a2dc59d3a8d0cb1666267724bad864f62d;hp=0bcc1442c7133bbf41bba1348213a9143352d328;hpb=ff3b5dc5542ec150f0d9b447394364a15e9156d0;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/feed/CachedPageTest.php b/tests/feed/CachedPageTest.php index 0bcc1442..1decfaf3 100644 --- a/tests/feed/CachedPageTest.php +++ b/tests/feed/CachedPageTest.php @@ -7,17 +7,17 @@ namespace Shaarli\Feed; /** * Unitary tests for cached pages */ -class CachedPageTest extends \PHPUnit\Framework\TestCase +class CachedPageTest extends \Shaarli\TestCase { // test cache directory protected static $testCacheDir = 'sandbox/pagecache'; - protected static $url = 'http://shaar.li/?do=atom'; + protected static $url = 'http://shaar.li/feed/atom'; protected static $filename; /** * Create the cache directory if needed */ - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { if (!is_dir(self::$testCacheDir)) { mkdir(self::$testCacheDir); @@ -28,7 +28,7 @@ class CachedPageTest extends \PHPUnit\Framework\TestCase /** * Reset the page cache */ - public function setUp() + protected function setUp(): void { if (file_exists(self::$filename)) { unlink(self::$filename); @@ -40,10 +40,11 @@ class CachedPageTest extends \PHPUnit\Framework\TestCase */ public function testConstruct() { - new CachedPage(self::$testCacheDir, '', true); - new CachedPage(self::$testCacheDir, '', false); - new CachedPage(self::$testCacheDir, 'http://shaar.li/?do=rss', true); - new CachedPage(self::$testCacheDir, 'http://shaar.li/?do=atom', false); + new CachedPage(self::$testCacheDir, '', true, null); + new CachedPage(self::$testCacheDir, '', false, null); + new CachedPage(self::$testCacheDir, 'http://shaar.li/feed/rss', true, null); + new CachedPage(self::$testCacheDir, 'http://shaar.li/feed/atom', false, null); + $this->addToAssertionCount(1); } /** @@ -51,7 +52,7 @@ class CachedPageTest extends \PHPUnit\Framework\TestCase */ public function testCache() { - $page = new CachedPage(self::$testCacheDir, self::$url, true); + $page = new CachedPage(self::$testCacheDir, self::$url, true, null); $this->assertFileNotExists(self::$filename); $page->cache('

Some content

'); @@ -67,7 +68,7 @@ class CachedPageTest extends \PHPUnit\Framework\TestCase */ public function testShouldNotCache() { - $page = new CachedPage(self::$testCacheDir, self::$url, false); + $page = new CachedPage(self::$testCacheDir, self::$url, false, null); $this->assertFileNotExists(self::$filename); $page->cache('

Some content

'); @@ -79,7 +80,7 @@ class CachedPageTest extends \PHPUnit\Framework\TestCase */ public function testCachedVersion() { - $page = new CachedPage(self::$testCacheDir, self::$url, true); + $page = new CachedPage(self::$testCacheDir, self::$url, true, null); $this->assertFileNotExists(self::$filename); $page->cache('

Some content

'); @@ -95,7 +96,7 @@ class CachedPageTest extends \PHPUnit\Framework\TestCase */ public function testCachedVersionNoFile() { - $page = new CachedPage(self::$testCacheDir, self::$url, true); + $page = new CachedPage(self::$testCacheDir, self::$url, true, null); $this->assertFileNotExists(self::$filename); $this->assertEquals( @@ -109,7 +110,7 @@ class CachedPageTest extends \PHPUnit\Framework\TestCase */ public function testNoCachedVersion() { - $page = new CachedPage(self::$testCacheDir, self::$url, false); + $page = new CachedPage(self::$testCacheDir, self::$url, false, null); $this->assertFileNotExists(self::$filename); $this->assertEquals( @@ -117,4 +118,43 @@ class CachedPageTest extends \PHPUnit\Framework\TestCase $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()); + } }