J. King
8 years ago
6 changed files with 66 additions and 8 deletions
@ -1,11 +1,25 @@ |
|||||
<?php |
<?php |
||||
declare(strict_types=1); |
declare(strict_types=1); |
||||
namespace JKingWeb\NewsSync\REST\NextCloudNews; |
namespace JKingWeb\NewsSync\REST\NextCloudNews; |
||||
|
use JKingWeb\NewsSync\REST\Response; |
||||
|
|
||||
class Versions implements \JKingWeb\NewsSync\REST\Handler { |
class Versions implements \JKingWeb\NewsSync\REST\Handler { |
||||
function __construct(\JKingWeb\NewsSync\RuntimeData $data) { |
function __construct(\JKingWeb\NewsSync\RuntimeData $data) { |
||||
} |
} |
||||
|
|
||||
function dispatch(\JKingWeb\NewsSync\REST\Request $req): \JKingWeb\NewsSync\REST\Response { |
function dispatch(\JKingWeb\NewsSync\REST\Request $req): \JKingWeb\NewsSync\REST\Response { |
||||
|
$path = $req->url; |
||||
|
$query = ""; |
||||
|
if(strpos($path, "?") !== false) { |
||||
|
list($path, $query) = explode("?", $path); |
||||
|
} |
||||
|
if($req->method != "GET") { |
||||
|
return new Response(405); |
||||
|
} |
||||
|
if(preg_match("<^/?$>",$path)) { |
||||
|
return new Response(200, ['v1-2']); |
||||
|
} else { |
||||
|
return new Response(404); |
||||
|
} |
||||
} |
} |
||||
} |
} |
@ -0,0 +1,23 @@ |
|||||
|
<?php |
||||
|
declare(strict_types=1); |
||||
|
namespace JKingWeb\NewsSync; |
||||
|
use JKingWeb\NewsSync\Rest\Request; |
||||
|
use JKingWeb\NewsSync\Rest\Response; |
||||
|
|
||||
|
|
||||
|
class TestNCNVersionDiscovery extends \PHPUnit\Framework\TestCase { |
||||
|
use Test\Tools; |
||||
|
|
||||
|
function setUp() { |
||||
|
$conf = new Conf(); |
||||
|
$this->data = new Test\RuntimeData($conf); |
||||
|
} |
||||
|
|
||||
|
function testVersionList() { |
||||
|
$exp = new Response(200, ['v1-2']); |
||||
|
$req = new Request("GET", "/"); |
||||
|
$h = new Rest\NextCloudNews\Versions($this->data); |
||||
|
$res = $h->dispatch($req); |
||||
|
$this->assertEquals($exp, $res); |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue