2019-02-06 20:34:51 +03:00
|
|
|
<?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');
|
2021-12-03 02:12:16 +03:00
|
|
|
$this->assertIsInt($items['total'], 'Invalid type');
|
2019-02-06 20:34:51 +03:00
|
|
|
|
|
|
|
$this->assertArrayHasKey('bridges', $items, 'Missing "bridges" array');
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
$items['total'],
|
|
|
|
count($items['bridges']),
|
|
|
|
'Item count doesn\'t match'
|
|
|
|
);
|
|
|
|
|
2019-06-18 20:21:28 +03:00
|
|
|
$bridgeFac = new BridgeFactory();
|
|
|
|
|
2019-02-06 20:34:51 +03:00
|
|
|
$this->assertEquals(
|
2019-06-18 20:21:28 +03:00
|
|
|
count($bridgeFac->getBridgeNames()),
|
2019-02-06 20:34:51 +03:00
|
|
|
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);
|
|
|
|
|
2022-04-13 22:04:10 +03:00
|
|
|
$action = $actionFac->create('list');
|
|
|
|
$action->setUserData(array()); /* no user data required */
|
2019-02-06 20:34:51 +03:00
|
|
|
|
|
|
|
ob_start();
|
2022-04-13 22:04:10 +03:00
|
|
|
$action->execute();
|
2019-02-06 20:34:51 +03:00
|
|
|
$this->data = ob_get_contents();
|
|
|
|
ob_clean();
|
|
|
|
ob_end_flush();
|
|
|
|
}
|
|
|
|
}
|