J. King
7 years ago
9 changed files with 184 additions and 36 deletions
@ -0,0 +1,39 @@ |
|||
<?php |
|||
declare(strict_types=1); |
|||
namespace JKingWeb\Arsse; |
|||
use JKingWeb\Arsse\Rest\Request; |
|||
use JKingWeb\Arsse\Rest\Response; |
|||
use JKingWeb\Arsse\Test\Result; |
|||
use Phake; |
|||
|
|||
|
|||
class TestNCNV1_2 extends \PHPUnit\Framework\TestCase { |
|||
use Test\Tools; |
|||
|
|||
protected $h; |
|||
|
|||
function setUp() { |
|||
$this->clearData(); |
|||
// create a mock user manager |
|||
Data::$user = Phake::mock(User::class); |
|||
Phake::when(Data::$user)->authHTTP->thenReturn(true); |
|||
Data::$user->id = "john.doe@example.com"; |
|||
// create a mock database interface |
|||
Data::$db = Phake::mock(Database::Class); |
|||
$this->h = new REST\NextCloudNews\V1_2(); |
|||
} |
|||
|
|||
function tearDown() { |
|||
$this->clearData(); |
|||
} |
|||
|
|||
function testListFolders() { |
|||
$list = [ |
|||
['id' => 1, 'name' => "Software", 'parent' => null], |
|||
['id' => 12, 'name' => "Hardware", 'parent' => null], |
|||
]; |
|||
Phake::when(Data::$db)->folderList(Data::$user->id, null, false)->thenReturn(new Result($list)); |
|||
$exp = new Response(200, ['folders' => $list]); |
|||
$this->assertEquals($exp, $this->h->dispatch(new Request("GET", "/folders"))); |
|||
} |
|||
} |
@ -0,0 +1,73 @@ |
|||
<?php |
|||
declare(strict_types=1); |
|||
namespace JKingWeb\Arsse\Test; |
|||
|
|||
class Result implements \JKingWeb\Arsse\Db\Result { |
|||
protected $st; |
|||
protected $set; |
|||
protected $pos = 0; |
|||
protected $cur = null; |
|||
protected $rows = 0; |
|||
protected $id = 0; |
|||
|
|||
// actual public methods |
|||
|
|||
public function getValue() { |
|||
$arr = $this->next(); |
|||
if($this->valid()) { |
|||
$keys = array_keys($arr); |
|||
return $arr[array_shift($keys)]; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
public function getRow() { |
|||
$arr = $this->next(); |
|||
return ($this->valid() ? $arr : null); |
|||
} |
|||
|
|||
public function getAll(): array { |
|||
return $this->set; |
|||
} |
|||
|
|||
public function changes() { |
|||
return $this->rows; |
|||
} |
|||
|
|||
public function lastId() { |
|||
return $this->id; |
|||
} |
|||
|
|||
// constructor/destructor |
|||
|
|||
public function __construct(array $result, int $changes = 0, int $lastID = 0) { |
|||
$this->set = $result; |
|||
$this->rows = $changes; |
|||
$this->id = $lastID; |
|||
} |
|||
|
|||
public function __destruct() { |
|||
} |
|||
|
|||
// PHP iterator methods |
|||
|
|||
public function valid() { |
|||
return !is_null(key($this->set)); |
|||
} |
|||
|
|||
public function next() { |
|||
return next($this->set); |
|||
} |
|||
|
|||
public function current() { |
|||
return current($this->set); |
|||
} |
|||
|
|||
public function key() { |
|||
return key($this->set); |
|||
} |
|||
|
|||
public function rewind() { |
|||
rewind($this->set); |
|||
} |
|||
} |
Loading…
Reference in new issue