diff --git a/lib/Feed.php b/lib/Feed.php index ce2c803..9119912 100644 --- a/lib/Feed.php +++ b/lib/Feed.php @@ -298,7 +298,7 @@ class Feed { $offset = "30 minutes"; } else if($diff < (3 * 60 * 60)) { // less than three hours $offset = "1 hour"; - } else if($diff > (36 * 60 * 60)) { // more than 36 hours + } else if($diff >= (36 * 60 * 60)) { // more than 36 hours $offset = "1 day"; } else { $offset = "3 hours"; diff --git a/tests/Feed/TestFeed.php b/tests/Feed/TestFeed.php index caeac1a..0ae58d5 100644 --- a/tests/Feed/TestFeed.php +++ b/tests/Feed/TestFeed.php @@ -18,6 +18,18 @@ class TestFeed extends \PHPUnit\Framework\TestCase { Data::$conf = new Conf(); } + function testComputeNextFetchOnError() { + for($a = 0; $a < 100; $a++) { + if($a < 3) { + $this->assertTime("now + 5 minutes", Feed::nextFetchOnError($a)); + } else if($a < 15) { + $this->assertTime("now + 3 hours", Feed::nextFetchOnError($a)); + } else { + $this->assertTime("now + 1 day", Feed::nextFetchOnError($a)); + } + } + } + function testComputeNextFetchFrom304() { // if less than half an hour, check in 15 minutes $exp = strtotime("now + 15 minutes"); @@ -53,7 +65,7 @@ class TestFeed extends \PHPUnit\Framework\TestCase { $this->assertTime($exp, $f->nextFetch); // otherwise check in three hours $exp = strtotime("now + 3 hours"); - $t = strtotime("now - 6 hours"); + $t = strtotime("now - 3 hours"); $f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http")); $this->assertTime($exp, $f->nextFetch); $t = strtotime("now - 35 hours"); diff --git a/tests/REST/NextCloudNews/TestNCNV1_2.php b/tests/REST/NextCloudNews/TestNCNV1_2.php index d5f6782..bb9a417 100644 --- a/tests/REST/NextCloudNews/TestNCNV1_2.php +++ b/tests/REST/NextCloudNews/TestNCNV1_2.php @@ -1,8 +1,8 @@ ['v1-2']]); - $h = new Rest\NextCloudNews\Versions(); + $h = new REST\NextCloudNews\Versions(); $req = new Request("GET", "/"); $res = $h->dispatch($req); $this->assertEquals($exp, $res); @@ -28,7 +28,7 @@ class TestNCNVersionDiscovery extends \PHPUnit\Framework\TestCase { function testUseIncorrectMethod() { $exp = new Response(405); - $h = new Rest\NextCloudNews\Versions(); + $h = new REST\NextCloudNews\Versions(); $req = new Request("POST", "/"); $res = $h->dispatch($req); $this->assertEquals($exp, $res); @@ -36,7 +36,7 @@ class TestNCNVersionDiscovery extends \PHPUnit\Framework\TestCase { function testUseIncorrectPath() { $exp = new Response(501); - $h = new Rest\NextCloudNews\Versions(); + $h = new REST\NextCloudNews\Versions(); $req = new Request("GET", "/ook"); $res = $h->dispatch($req); $this->assertEquals($exp, $res); diff --git a/tests/docroot/Feed/NextFetch/NotModified.php b/tests/docroot/Feed/NextFetch/NotModified.php index 865659b..6a33b46 100644 --- a/tests/docroot/Feed/NextFetch/NotModified.php +++ b/tests/docroot/Feed/NextFetch/NotModified.php @@ -1,4 +1,12 @@ - 304, - 'lastMod' => (int) $_GET['t'], -]; \ No newline at end of file + 304, + 'lastMod' => (int) $_GET['t'], + ]; +} else { + return [ + 'code' => 304, + 'cache' => fasel, + ]; +} \ No newline at end of file diff --git a/tests/test b/tests/test new file mode 100644 index 0000000..809959c --- /dev/null +++ b/tests/test @@ -0,0 +1,7 @@ +#! /bin/sh +base=`dirname "$0"` +php -S localhost:8000 "$base/server.php" >/dev/null & +php "$base/../vendor/phpunit/phpunit/phpunit" -c "$base/phpunit.xml" +sleep 1s +pid=`netstat -tlpn 2>/dev/null | grep ":8000 " | grep -Eo "[0-9]+/php" | grep -Eo "[0-9]+"` +kill $pid \ No newline at end of file diff --git a/tests/test.bat b/tests/test.bat index 819b0aa..0392fdb 100644 --- a/tests/test.bat +++ b/tests/test.bat @@ -1,10 +1,10 @@ @echo off setlocal set base=%~dp0 -start php -S localhost:8000 "%base%\server.php" +start /b php -S localhost:8000 "%base%\server.php" >nul php "%base%\..\vendor\phpunit\phpunit\phpunit" -c "%base%\phpunit.xml" timeout /nobreak /t 1 >nul for /f "usebackq tokens=5" %%a in (`netstat -aon ^| find "LISTENING" ^| find ":8000"`) do ( - taskkill /pid %%a >nul + taskkill /f /pid %%a >nul goto :eof ) \ No newline at end of file