mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2024-11-23 10:05:32 +03:00
d62b977394
* refactor: ./tests * test: consolidate testsuites * refactor: move config setup into rssbridge.php Makes it easier to unit test. * lint
89 lines
1.8 KiB
PHP
89 lines
1.8 KiB
PHP
<?php
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class ListActionTest extends TestCase {
|
|
|
|
private $data;
|
|
|
|
/**
|
|
* @runInSeparateProcess
|
|
* @requires function xdebug_get_headers
|
|
*/
|
|
public function testHeaders() {
|
|
$this->initAction();
|
|
|
|
$this->assertContains(
|
|
'Content-Type: application/json',
|
|
xdebug_get_headers()
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @runInSeparateProcess
|
|
*/
|
|
public function testOutput() {
|
|
$this->initAction();
|
|
|
|
$items = json_decode($this->data, true);
|
|
|
|
$this->assertNotNull($items, 'invalid JSON output: ' . json_last_error_msg());
|
|
|
|
$this->assertArrayHasKey('total', $items, 'Missing "total" parameter');
|
|
$this->assertIsInt($items['total'], 'Invalid type');
|
|
|
|
$this->assertArrayHasKey('bridges', $items, 'Missing "bridges" array');
|
|
|
|
$this->assertEquals(
|
|
$items['total'],
|
|
count($items['bridges']),
|
|
'Item count doesn\'t match'
|
|
);
|
|
|
|
$bridgeFac = new BridgeFactory();
|
|
$bridgeFac->setWorkingDir(PATH_LIB_BRIDGES);
|
|
|
|
$this->assertEquals(
|
|
count($bridgeFac->getBridgeNames()),
|
|
count($items['bridges']),
|
|
'Number of bridges doesn\'t match'
|
|
);
|
|
|
|
$expectedKeys = array(
|
|
'status',
|
|
'uri',
|
|
'name',
|
|
'icon',
|
|
'parameters',
|
|
'maintainer',
|
|
'description'
|
|
);
|
|
|
|
$allowedStatus = array(
|
|
'active',
|
|
'inactive'
|
|
);
|
|
|
|
foreach($items['bridges'] as $bridge) {
|
|
foreach($expectedKeys as $key) {
|
|
$this->assertArrayHasKey($key, $bridge, 'Missing key "' . $key . '"');
|
|
}
|
|
|
|
$this->assertContains($bridge['status'], $allowedStatus, 'Invalid status value');
|
|
}
|
|
}
|
|
|
|
private function initAction() {
|
|
$actionFac = new ActionFactory();
|
|
$actionFac->setWorkingDir(PATH_LIB_ACTIONS);
|
|
|
|
$action = $actionFac->create('list');
|
|
$action->setUserData(array()); /* no user data required */
|
|
|
|
ob_start();
|
|
$action->execute();
|
|
$this->data = ob_get_contents();
|
|
ob_clean();
|
|
ob_end_flush();
|
|
}
|
|
}
|