mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 13:12:41 +00:00
More Feed tests: cache header handling
- Also made all SQLite tests skippable if the extension is not loaded - Fixed format of ETags in test server - Passed any CLI arguments to PHPUnit in the test runner
This commit is contained in:
parent
f04ba956a9
commit
ceeb23aea3
13 changed files with 61 additions and 13 deletions
|
@ -11,6 +11,9 @@ class TestDbDriverSQLite3 extends \PHPUnit\Framework\TestCase {
|
|||
protected $ch;
|
||||
|
||||
function setUp() {
|
||||
if(!extension_loaded("sqlite3")) {
|
||||
$this->markTestSkipped("SQLite extension not loaded");
|
||||
}
|
||||
$this->clearData();
|
||||
$conf = new Conf();
|
||||
$conf->dbDriver = Db\SQLite3\Driver::class;
|
||||
|
|
|
@ -9,6 +9,9 @@ class TestDbResultSQLite3 extends \PHPUnit\Framework\TestCase {
|
|||
protected $c;
|
||||
|
||||
function setUp() {
|
||||
if(!extension_loaded("sqlite3")) {
|
||||
$this->markTestSkipped("SQLite extension not loaded");
|
||||
}
|
||||
$c = new \SQLite3(":memory:");
|
||||
$c->enableExceptions(true);
|
||||
$this->c = $c;
|
||||
|
|
|
@ -11,6 +11,9 @@ class TestDbStatementSQLite3 extends \PHPUnit\Framework\TestCase {
|
|||
static protected $imp = Db\SQLite3\Statement::class;
|
||||
|
||||
function setUp() {
|
||||
if(!extension_loaded("sqlite3")) {
|
||||
$this->markTestSkipped("SQLite extension not loaded");
|
||||
}
|
||||
$c = new \SQLite3(":memory:");
|
||||
$c->enableExceptions(true);
|
||||
$this->c = $c;
|
||||
|
|
|
@ -16,6 +16,9 @@ class TestDbUpdateSQLite3 extends \PHPUnit\Framework\TestCase {
|
|||
const MINIMAL2 = "pragma user_version=2";
|
||||
|
||||
function setUp() {
|
||||
if(!extension_loaded("sqlite3")) {
|
||||
$this->markTestSkipped("SQLite extension not loaded");
|
||||
}
|
||||
$this->clearData();
|
||||
$this->vfs = vfsStream::setup("schemata", null, ['SQLite3' => []]);
|
||||
$conf = new Conf();
|
||||
|
|
|
@ -8,19 +8,10 @@ class TestFeed extends \PHPUnit\Framework\TestCase {
|
|||
use Test\Tools;
|
||||
|
||||
protected static $host = "http://localhost:8000/";
|
||||
protected static $serverUp = true;
|
||||
protected $base = "";
|
||||
|
||||
function time(string $t): string {
|
||||
return gmdate("D, d M Y H:i:s \G\M\T", strtotime($t));
|
||||
}
|
||||
|
||||
static function setUpBeforeClass() {
|
||||
if(!@file_get_contents(self::$host."IsUp")) self::$serverUp = false;
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
if(!self::$serverUp) {
|
||||
if(!@file_get_contents(self::$host."IsUp")) {
|
||||
$this->markTestSkipped("Test Web server is not accepting requests");
|
||||
}
|
||||
$this->base = self::$host."Feed/";
|
||||
|
@ -28,6 +19,23 @@ class TestFeed extends \PHPUnit\Framework\TestCase {
|
|||
Data::$conf = new Conf();
|
||||
}
|
||||
|
||||
function testHandleCacheHeaders() {
|
||||
$t = time();
|
||||
$e = "78567a";
|
||||
$f = new Feed(null, $this->base."Caching/304Random", $this->dateTransform($t, "http"), $e);
|
||||
$this->assertTime($t, $f->lastModified);
|
||||
$this->assertSame($e, $f->resource->getETag());
|
||||
$f = new Feed(null, $this->base."Caching/304ETagOnly", $this->dateTransform($t, "http"), $e);
|
||||
$this->assertTime($t, $f->lastModified);
|
||||
$this->assertSame($e, $f->resource->getETag());
|
||||
$f = new Feed(null, $this->base."Caching/304LastModOnly", $this->dateTransform($t, "http"), $e);
|
||||
$this->assertTime($t, $f->lastModified);
|
||||
$this->assertSame($e, $f->resource->getETag());
|
||||
$f = new Feed(null, $this->base."Caching/304None", $this->dateTransform($t, "http"), $e);
|
||||
$this->assertTime($t, $f->lastModified);
|
||||
$this->assertSame($e, $f->resource->getETag());
|
||||
}
|
||||
|
||||
function testComputeNextFetchOnError() {
|
||||
for($a = 0; $a < 100; $a++) {
|
||||
if($a < 3) {
|
||||
|
|
7
tests/docroot/Feed/Caching/304ETagOnly.php
Normal file
7
tests/docroot/Feed/Caching/304ETagOnly.php
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?php return [
|
||||
'code' => 304,
|
||||
'cache' => false,
|
||||
'fields' => [
|
||||
"ETag: ".$_SERVER['HTTP_IF_NONE_MATCH'],
|
||||
],
|
||||
];
|
7
tests/docroot/Feed/Caching/304LastModOnly.php
Normal file
7
tests/docroot/Feed/Caching/304LastModOnly.php
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?php return [
|
||||
'code' => 304,
|
||||
'cache' => false,
|
||||
'fields' => [
|
||||
'Last-Modified: '.$_SERVER['HTTP_IF_MODIFIED_SINCE'],
|
||||
],
|
||||
];
|
4
tests/docroot/Feed/Caching/304None.php
Normal file
4
tests/docroot/Feed/Caching/304None.php
Normal file
|
@ -0,0 +1,4 @@
|
|||
<?php return [
|
||||
'code' => 304,
|
||||
'cache' => false,
|
||||
];
|
7
tests/docroot/Feed/Caching/304Random.php
Normal file
7
tests/docroot/Feed/Caching/304Random.php
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?php return [
|
||||
'code' => 304,
|
||||
'lastMod' => random_int(0,2^31),
|
||||
'fields' => [
|
||||
"ETag: ".bin2hex(random_bytes(8)),
|
||||
],
|
||||
];
|
|
@ -6,6 +6,9 @@ use JKingWeb\Arsse\Db\SQLite3\Driver;
|
|||
|
||||
trait DriverSQLite3 {
|
||||
function setUpDriver() {
|
||||
if(!extension_loaded("sqlite3")) {
|
||||
$this->markTestSkipped("SQLite extension not loaded");
|
||||
}
|
||||
Data::$conf->dbSQLite3File = ":memory:";
|
||||
$this->drv = new Driver(true);
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ http_response_code((int) $response['code']);
|
|||
// if the response has a body, set the content type and (possibly) the ETag.
|
||||
if(strlen($response['content'])) {
|
||||
header("Content-Type: ".$response['mime']);
|
||||
if($response['cache']) header("ETag: ".md5($response['content']));
|
||||
if($response['cache']) header('ETag: "'.md5($response['content']).'"');
|
||||
}
|
||||
// if caching is enabled, set the last-modified date
|
||||
if($response['cache']) header("Last-Modified: ".gmdate("D, d M Y H:i:s \G\M\T", $response['lastMod']));
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#! /bin/sh
|
||||
base=`dirname "$0"`
|
||||
php -n -S localhost:8000 "$base/server.php" >/dev/null &
|
||||
php "$base/../vendor/phpunit/phpunit/phpunit" -c "$base/phpunit.xml"
|
||||
php "$base/../vendor/phpunit/phpunit/phpunit" -c "$base/phpunit.xml" $*
|
||||
sleep 1s
|
||||
pid=`lsof -n -i:8000 | grep -Eo "php\s+[0-9]+" | grep -Eo "[0-9]+"`
|
||||
kill $pid
|
|
@ -2,7 +2,7 @@
|
|||
setlocal
|
||||
set base=%~dp0
|
||||
start /b php -n -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
|
||||
for /f "usebackq tokens=5" %%a in (`netstat -aon ^| find "LISTENING" ^| find ":8000"`) do (
|
||||
taskkill /f /pid %%a >nul
|
||||
|
|
Loading…
Reference in a new issue