Browse Source

More Feed tests; Linux fixes

- Adjusted some namespace case
- Included Linux test runner; should also work with macOS
- Made the PHP server run in the background on Windows
microsub
J. King 7 years ago
parent
commit
97a8f473a7
  1. 2
      lib/Feed.php
  2. 14
      tests/Feed/TestFeed.php
  3. 4
      tests/REST/NextCloudNews/TestNCNV1_2.php
  4. 10
      tests/REST/NextCloudNews/TestNCNVersionDiscovery.php
  5. 16
      tests/docroot/Feed/NextFetch/NotModified.php
  6. 7
      tests/test
  7. 4
      tests/test.bat

2
lib/Feed.php

@ -298,7 +298,7 @@ class Feed {
$offset = "30 minutes"; $offset = "30 minutes";
} else if($diff < (3 * 60 * 60)) { // less than three hours } else if($diff < (3 * 60 * 60)) { // less than three hours
$offset = "1 hour"; $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"; $offset = "1 day";
} else { } else {
$offset = "3 hours"; $offset = "3 hours";

14
tests/Feed/TestFeed.php

@ -18,6 +18,18 @@ class TestFeed extends \PHPUnit\Framework\TestCase {
Data::$conf = new Conf(); 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() { function testComputeNextFetchFrom304() {
// if less than half an hour, check in 15 minutes // if less than half an hour, check in 15 minutes
$exp = strtotime("now + 15 minutes"); $exp = strtotime("now + 15 minutes");
@ -53,7 +65,7 @@ class TestFeed extends \PHPUnit\Framework\TestCase {
$this->assertTime($exp, $f->nextFetch); $this->assertTime($exp, $f->nextFetch);
// otherwise check in three hours // otherwise check in three hours
$exp = strtotime("now + 3 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")); $f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http"));
$this->assertTime($exp, $f->nextFetch); $this->assertTime($exp, $f->nextFetch);
$t = strtotime("now - 35 hours"); $t = strtotime("now - 35 hours");

4
tests/REST/NextCloudNews/TestNCNV1_2.php

@ -1,8 +1,8 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace JKingWeb\Arsse; namespace JKingWeb\Arsse;
use JKingWeb\Arsse\Rest\Request; use JKingWeb\Arsse\REST\Request;
use JKingWeb\Arsse\Rest\Response; use JKingWeb\Arsse\REST\Response;
use JKingWeb\Arsse\Test\Result; use JKingWeb\Arsse\Test\Result;
use Phake; use Phake;

10
tests/REST/NextCloudNews/TestNCNVersionDiscovery.php

@ -1,8 +1,8 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace JKingWeb\Arsse; namespace JKingWeb\Arsse;
use JKingWeb\Arsse\Rest\Request; use JKingWeb\Arsse\REST\Request;
use JKingWeb\Arsse\Rest\Response; use JKingWeb\Arsse\REST\Response;
class TestNCNVersionDiscovery extends \PHPUnit\Framework\TestCase { class TestNCNVersionDiscovery extends \PHPUnit\Framework\TestCase {
@ -14,7 +14,7 @@ class TestNCNVersionDiscovery extends \PHPUnit\Framework\TestCase {
function testFetchVersionList() { function testFetchVersionList() {
$exp = new Response(200, ['apiLevels' => ['v1-2']]); $exp = new Response(200, ['apiLevels' => ['v1-2']]);
$h = new Rest\NextCloudNews\Versions(); $h = new REST\NextCloudNews\Versions();
$req = new Request("GET", "/"); $req = new Request("GET", "/");
$res = $h->dispatch($req); $res = $h->dispatch($req);
$this->assertEquals($exp, $res); $this->assertEquals($exp, $res);
@ -28,7 +28,7 @@ class TestNCNVersionDiscovery extends \PHPUnit\Framework\TestCase {
function testUseIncorrectMethod() { function testUseIncorrectMethod() {
$exp = new Response(405); $exp = new Response(405);
$h = new Rest\NextCloudNews\Versions(); $h = new REST\NextCloudNews\Versions();
$req = new Request("POST", "/"); $req = new Request("POST", "/");
$res = $h->dispatch($req); $res = $h->dispatch($req);
$this->assertEquals($exp, $res); $this->assertEquals($exp, $res);
@ -36,7 +36,7 @@ class TestNCNVersionDiscovery extends \PHPUnit\Framework\TestCase {
function testUseIncorrectPath() { function testUseIncorrectPath() {
$exp = new Response(501); $exp = new Response(501);
$h = new Rest\NextCloudNews\Versions(); $h = new REST\NextCloudNews\Versions();
$req = new Request("GET", "/ook"); $req = new Request("GET", "/ook");
$res = $h->dispatch($req); $res = $h->dispatch($req);
$this->assertEquals($exp, $res); $this->assertEquals($exp, $res);

16
tests/docroot/Feed/NextFetch/NotModified.php

@ -1,4 +1,12 @@
<?php return [ <?php
'code' => 304, if(array_key_exists("t", $_GET)) {
'lastMod' => (int) $_GET['t'], return [
]; 'code' => 304,
'lastMod' => (int) $_GET['t'],
];
} else {
return [
'code' => 304,
'cache' => fasel,
];
}

7
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

4
tests/test.bat

@ -1,10 +1,10 @@
@echo off @echo off
setlocal setlocal
set base=%~dp0 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" php "%base%\..\vendor\phpunit\phpunit\phpunit" -c "%base%\phpunit.xml"
timeout /nobreak /t 1 >nul timeout /nobreak /t 1 >nul
for /f "usebackq tokens=5" %%a in (`netstat -aon ^| find "LISTENING" ^| find ":8000"`) do ( 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 goto :eof
) )
Loading…
Cancel
Save