X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2Ffeed%2FCachedPageTest.php;h=0bcc1442c7133bbf41bba1348213a9143352d328;hb=HEAD;hp=57f3b09be8ebcbc552b9a8e0fed455f9e90b878c;hpb=7b2ba6ef820335df682fbe3dcfaceef3a62cf4a5;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/feed/CachedPageTest.php b/tests/feed/CachedPageTest.php index 57f3b09b..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/feed-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,10 @@ 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/feed-rss', true); - new CachedPage(self::$testCacheDir, 'http://shaar.li/feed-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); } @@ -52,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

'); @@ -68,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

'); @@ -80,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

'); @@ -96,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( @@ -110,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( @@ -118,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()); + } }