mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 15:03:25 +00:00
refactor codes + add covers annotations
This commit is contained in:
@@ -7,21 +7,42 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var Symfony\Component\HttpKernel\Client
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
/**
|
||||
* @var API_OAuth2_Token
|
||||
*/
|
||||
protected static $token;
|
||||
protected static $account
|
||||
|
||||
/**
|
||||
* @var API_OAuth2_Account
|
||||
*/
|
||||
protected static $account;
|
||||
|
||||
/**
|
||||
* @var API_OAuth2_Application
|
||||
*/
|
||||
protected static $application;
|
||||
|
||||
/**
|
||||
* @var API_OAuth2_Token
|
||||
*/
|
||||
protected static $adminToken;
|
||||
protected static $adminAccount
|
||||
|
||||
/**
|
||||
* @var API_OAuth2_Account
|
||||
*/
|
||||
protected static $adminAccount;
|
||||
|
||||
/**
|
||||
* @var API_OAuth2_Application
|
||||
*/
|
||||
protected static $adminApplication;
|
||||
|
||||
protected static $databoxe_ids = array();
|
||||
protected static $need_records = 1;
|
||||
protected static $need_subdefs = true;
|
||||
|
||||
protected $savedToken;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
@@ -38,30 +59,33 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
{
|
||||
parent::setUpBeforeClass();
|
||||
|
||||
//create basic user token
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
|
||||
self::$application = API_OAuth2_Application::create($appbox, self::$user, 'test API v1');
|
||||
self::$account = API_OAuth2_Account::load_with_user($appbox, self::$application, self::$user);
|
||||
self::$token = $account->get_token()->get_value();
|
||||
self::$token = self::$account->get_token()->get_value();
|
||||
|
||||
//create admin user token
|
||||
$admins = User_Adapter::get_sys_admins();
|
||||
|
||||
self::$adminToken = null;
|
||||
|
||||
if(0 !== count($admins)){
|
||||
if (0 !== count($admins)) {
|
||||
$admin = User_Adapter::getInstance(key($admins), $appbox);
|
||||
self::$adminApplication = API_OAuth2_Application::create($appbox, $admin, 'test2 API v1');
|
||||
self::$adminAccount = API_OAuth2_Account::load_with_user($appbox, $application, $admin);
|
||||
$_GET['oauth_token'] = self::$adminAccount->get_token()->get_value();
|
||||
self::$adminAccount = API_OAuth2_Account::load_with_user($appbox, self::$adminApplication, $admin);
|
||||
self::$adminToken = self::$adminAccount->get_token()->get_value();
|
||||
}
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
//delete database entry
|
||||
self::$account->delete();
|
||||
self::$application->delete();
|
||||
|
||||
if(self::$adminToken){
|
||||
if (self::$adminToken) {
|
||||
self::$adminAccount->delete();
|
||||
self::$adminApplication->delete();
|
||||
}
|
||||
@@ -75,7 +99,8 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
public function testRouteNotFound()
|
||||
{
|
||||
$route = '/nothinghere';
|
||||
$crawler = $this->client->request('GET', $route);
|
||||
$this->setToken(self::$token);
|
||||
$this->client->request('GET', $route);
|
||||
$content = json_decode($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponseNotFound($this->client->getResponse());
|
||||
@@ -84,7 +109,8 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
public function testDatboxListRoute()
|
||||
{
|
||||
$crawler = $this->client->request('GET', '/databoxes/list/', array(), array(), array('HTTP_Accept' => 'application/json'));
|
||||
$this->setToken(self::$token);
|
||||
$this->client->request('GET', '/databoxes/list/', array(), array(), array('HTTP_Accept' => 'application/json'));
|
||||
$content = json_decode($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -123,14 +149,13 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
$account = API_OAuth2_Account::create($appbox, self::$user, $nativeApp);
|
||||
$token = $account->get_token()->get_value();
|
||||
$_GET['oauth_token'] = $token;
|
||||
$this->setToken($token);
|
||||
$this->client->request('GET', '/databoxes/list/', array(), array(), array('HTTP_Accept' => 'application/json'));
|
||||
$content = json_decode($this->client->getResponse()->getContent());
|
||||
|
||||
if (403 != $content->meta->http_code) {
|
||||
$fail = new \Exception('Result does not match expected 403, returns ' . $content->meta->http_code);
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$fail = $e;
|
||||
}
|
||||
@@ -147,12 +172,9 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
*/
|
||||
public function testAdminOnlyShedulerState()
|
||||
{
|
||||
$this->client->request('GET', '/monitor/scheduler/', array(), array(), array('HTTP_Accept' => 'application/json'));
|
||||
$content = json_decode($this->client->getResponse()->getContent());
|
||||
$this->setToken(self::$token);
|
||||
|
||||
$this->assertEquals(401, $content->meta->http_code);
|
||||
$this->client->request('GET', '/monitor/tasks/', array(), array(), array('HTTP_Accept' => 'application/json'));
|
||||
|
||||
$content = json_decode($this->client->getResponse()->getContent());
|
||||
$this->assertEquals(401, $content->meta->http_code);
|
||||
|
||||
@@ -177,36 +199,17 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
$this->assertEquals(401, $content->meta->http_code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Route GET /API/V1/monitor/scheduler
|
||||
*/
|
||||
public function testGetMonitorScheduler()
|
||||
{
|
||||
$_GET['oauth_token'] = self::$adminToken;
|
||||
$this->client->request('GET', '/monitor/scheduler/', array(), array(), array('HTTP_Accept' => 'application/json'));
|
||||
$content = json_decode($this->client->getResponse()->getContent());
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
$this->evaluateMetaJson200($content);
|
||||
$response = $content->response;
|
||||
$this->assertObjectHasAttribute('qdelay', $response);
|
||||
$this->assertObjectHasAttribute('status', $response);
|
||||
$this->assertObjectHasAttribute('pid', $response);
|
||||
$application->delete();
|
||||
$account->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Route GET /API/V1/monitor/task
|
||||
*
|
||||
* @cover API_V1_adapter::get_task_list
|
||||
*/
|
||||
public function testGetMonitorTasks()
|
||||
{
|
||||
$admins = User_Adapter::get_sys_admins();
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
$admin = User_Adapter::getInstance(key($admins), $appbox);
|
||||
$application = API_OAuth2_Application::create($appbox, $admin, 'test2 API v1');
|
||||
$account = API_OAuth2_Account::load_with_user($appbox, $application, $admin);
|
||||
$_GET['oauth_token'] = $account->get_token()->get_value();
|
||||
if (null === self::$adminToken) {
|
||||
$this->markTestSkipped('there is no user with admin rights');
|
||||
}
|
||||
$this->setToken(self::$adminToken);
|
||||
$this->client->request('GET', '/monitor/tasks/', array(), array(), array('HTTP_Accept' => 'application/json'));
|
||||
$content = json_decode($this->client->getResponse()->getContent());
|
||||
|
||||
@@ -216,74 +219,70 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
$task_manager = new \task_manager($appbox);
|
||||
$tasks = $task_manager->get_tasks();
|
||||
$this->assertEquals(count($tasks), count(get_object_vars($response)));
|
||||
$application->delete();
|
||||
$account->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Route GET /API/V1/monitor/task{idTask}
|
||||
*
|
||||
* @cover API_V1_adapter::get_task
|
||||
*/
|
||||
public function testGetMonitorTaskById()
|
||||
{
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
$task_manager = new \task_manager($appbox);
|
||||
$tasks = $task_manager->get_tasks();
|
||||
if (count($tasks) == 0) {
|
||||
|
||||
if (null === self::$adminToken) {
|
||||
$this->markTestSkipped('there is no user with admin rights');
|
||||
}
|
||||
|
||||
if ( ! count($tasks)) {
|
||||
$this->markTestSkipped('no tasks created for the current instance');
|
||||
}
|
||||
$admins = User_Adapter::get_sys_admins();
|
||||
$admin = User_Adapter::getInstance(key($admins), $appbox);
|
||||
$application = API_OAuth2_Application::create($appbox, $admin, 'test2 API v1');
|
||||
$account = API_OAuth2_Account::load_with_user($appbox, $application, $admin);
|
||||
$_GET['oauth_token'] = $account->get_token()->get_value();
|
||||
|
||||
$this->setToken(self::$adminToken);
|
||||
reset($tasks);
|
||||
$idTask = key($tasks);
|
||||
$this->client->request('GET', '/monitor/task/' . $idTask . '/', array(), array(), array('HTTP_Accept' => 'application/json'));
|
||||
$content = json_decode($this->client->getResponse()->getContent());
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
$this->evaluateMetaJson200($content);
|
||||
$application->delete();
|
||||
$account->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Route GET /API/V1/monitor/task/{idTask}
|
||||
*
|
||||
* @cover API_V1_adapter::get_task
|
||||
*/
|
||||
public function testUnknowGetMonitorTaskById()
|
||||
{
|
||||
$admins = User_Adapter::get_sys_admins();
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
$admin = User_Adapter::getInstance(key($admins), $appbox);
|
||||
$application = API_OAuth2_Application::create($appbox, $admin, 'test2 API v1');
|
||||
$account = API_OAuth2_Account::load_with_user($appbox, $application, $admin);
|
||||
$_GET['oauth_token'] = $account->get_token()->get_value();
|
||||
if (null === self::$adminToken) {
|
||||
$this->markTestSkipped('no tasks created for the current instance');
|
||||
}
|
||||
$this->setToken(self::$adminToken);
|
||||
$this->client->followRedirects();
|
||||
$this->client->request('GET', '/monitor/task/0', array(), array(), array('HTTP_Accept' => 'application/json'));
|
||||
$content = json_decode($this->client->getResponse()->getContent());
|
||||
$this->evaluateMetaJsonNotFound($content);
|
||||
$application->delete();
|
||||
$account->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Route GET /API/V1/monitor/task/{idTask}/start
|
||||
*
|
||||
* @cover API_V1_adapter::start_task
|
||||
*/
|
||||
public function testGetMonitorStartTask()
|
||||
{
|
||||
if (null === self::$adminToken) {
|
||||
$this->markTestSkipped('there is no user with admin rights');
|
||||
}
|
||||
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
$task_manager = new \task_manager($appbox);
|
||||
$tasks = $task_manager->get_tasks();
|
||||
if (count($tasks) == 0) {
|
||||
|
||||
if ( ! count($tasks)) {
|
||||
$this->markTestSkipped('no tasks created for the current instance');
|
||||
}
|
||||
$admins = User_Adapter::get_sys_admins();
|
||||
$admin = User_Adapter::getInstance(key($admins), $appbox);
|
||||
$application = API_OAuth2_Application::create($appbox, $admin, 'test2 API v1');
|
||||
$account = API_OAuth2_Account::load_with_user($appbox, $application, $admin);
|
||||
$_GET['oauth_token'] = $account->get_token()->get_value();
|
||||
|
||||
$this->setToken(self::$adminToken);
|
||||
reset($tasks);
|
||||
$idTask = key($tasks);
|
||||
$this->client->request('POST', '/monitor/task/' . $idTask . '/start/', array(), array(), array('HTTP_Accept' => 'application/json'));
|
||||
@@ -293,27 +292,28 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
$task_manager->get_tasks(true);
|
||||
$task = $task_manager->get_task($idTask);
|
||||
$this->assertEquals(\task_abstract::STATUS_TOSTART, $task->get_status());
|
||||
$application->delete();
|
||||
$account->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Route GET /API/V1/monitor/task/{idTask}/stop
|
||||
*
|
||||
* @cover API_V1_adapter::stop_task
|
||||
*/
|
||||
public function testGetMonitorStopTask()
|
||||
{
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
$task_manager = new \task_manager($appbox);
|
||||
|
||||
$tasks = $task_manager->get_tasks();
|
||||
if (count($tasks) == 0) {
|
||||
|
||||
if (null === self::$adminToken) {
|
||||
$this->markTestSkipped('there is no user with admin rights');
|
||||
}
|
||||
|
||||
if ( ! count($tasks)) {
|
||||
$this->markTestSkipped('no tasks created for the current instance');
|
||||
}
|
||||
$admins = User_Adapter::get_sys_admins();
|
||||
$admin = User_Adapter::getInstance(key($admins), $appbox);
|
||||
$application = API_OAuth2_Application::create($appbox, $admin, 'test2 API v1');
|
||||
$account = API_OAuth2_Account::load_with_user($appbox, $application, $admin);
|
||||
$_GET['oauth_token'] = $account->get_token()->get_value();
|
||||
|
||||
$this->setToken(self::$adminToken);
|
||||
reset($tasks);
|
||||
$idTask = key($tasks);
|
||||
$this->client->request('POST', '/monitor/task/' . $idTask . '/stop/', array(), array(), array('HTTP_Accept' => 'application/json'));
|
||||
@@ -323,33 +323,28 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
$task_manager->get_tasks(true);
|
||||
$task = $task_manager->get_task($idTask);
|
||||
$this->assertEquals(\task_abstract::STATUS_TOSTOP, $task->get_status());
|
||||
$application->delete();
|
||||
$account->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Route GET /API/V1/monitor/phraseanet
|
||||
*
|
||||
* @cover API_V1_adapter::get_phraseanet_monitor
|
||||
*/
|
||||
public function testgetMonitorPhraseanet()
|
||||
{
|
||||
$admins = User_Adapter::get_sys_admins();
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
$admin = User_Adapter::getInstance(key($admins), $appbox);
|
||||
$application = API_OAuth2_Application::create($appbox, $admin, 'test2 API v1');
|
||||
$account = API_OAuth2_Account::load_with_user($appbox, $application, $admin);
|
||||
$_GET['oauth_token'] = $account->get_token()->get_value();
|
||||
if (null === self::$adminToken) {
|
||||
$this->markTestSkipped('there is no user with admin rights');
|
||||
}
|
||||
|
||||
$this->setToken(self::$adminToken);
|
||||
|
||||
$this->client->request('GET', '/monitor/phraseanet/', array(), array(), array('HTTP_Accept' => 'application/json'));
|
||||
$content = json_decode($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
$this->evaluateMetaJson200($content);
|
||||
$response = $content->response;
|
||||
$this->assertObjectHasAttribute('global_values', $response);
|
||||
$this->assertObjectHasAttribute('cache', $response);
|
||||
$this->assertObjectHasAttribute('phraseanet', $response);
|
||||
$application->delete();
|
||||
$account->delete();
|
||||
$this->assertObjectHasAttribute('global_values', $content->response);
|
||||
$this->assertObjectHasAttribute('cache', $content->response);
|
||||
$this->assertObjectHasAttribute('phraseanet', $content->response);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -359,6 +354,7 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
public function testDataboxRecordRoute()
|
||||
{
|
||||
foreach (static::$databoxe_ids as $databox_id) {
|
||||
$this->setToken(self::$token);
|
||||
$databox = databox::get_instance($databox_id);
|
||||
|
||||
$collection = array_shift($databox->get_collections());
|
||||
@@ -387,6 +383,7 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
public function testDataboxCollectionRoute()
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
foreach (static::$databoxe_ids as $databox_id) {
|
||||
$route = '/databoxes/' . $databox_id . '/collections/';
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
@@ -421,6 +418,7 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
public function testDataboxStatusRoute()
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
foreach (static::$databoxe_ids as $databox_id) {
|
||||
$databox = databox::get_instance($databox_id);
|
||||
$ref_status = $databox->get_statusbits();
|
||||
@@ -467,6 +465,7 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
public function testDataboxMetadatasRoute()
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
foreach (static::$databoxe_ids as $databox_id) {
|
||||
$databox = databox::get_instance($databox_id);
|
||||
$ref_structure = $databox->get_meta_structure();
|
||||
@@ -509,8 +508,9 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
$this->assertTrue((strlen($metadatas->name) > 0));
|
||||
$this->assertTrue(is_string($metadatas->separator));
|
||||
|
||||
if ($metadatas->multivalue)
|
||||
if ($metadatas->multivalue) {
|
||||
$this->assertTrue((strlen($metadatas->separator) > 0));
|
||||
}
|
||||
|
||||
$this->assertTrue(is_string($metadatas->thesaurus_branch));
|
||||
$this->assertTrue(in_array($metadatas->type, array(databox_field::TYPE_DATE, databox_field::TYPE_STRING, databox_field::TYPE_NUMBER, databox_field::TYPE_TEXT)));
|
||||
@@ -543,13 +543,12 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
public function testDataboxTermsOfUseRoute()
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
foreach (static::$databoxe_ids as $databox_id) {
|
||||
$databox = databox::get_instance($databox_id);
|
||||
|
||||
$route = '/databoxes/' . $databox_id . '/termsOfUse/';
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
|
||||
$crawler = $this->client->request('GET', $route);
|
||||
$this->client->request('GET', $route);
|
||||
$content = json_decode($this->client->getResponse()->getContent());
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
$this->evaluateMetaJson200($content);
|
||||
@@ -581,8 +580,7 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
*/
|
||||
public function testRecordsSearchRoute()
|
||||
{
|
||||
|
||||
|
||||
$this->setToken(self::$token);
|
||||
$crawler = $this->client->request('POST', '/records/search/');
|
||||
$content = json_decode($this->client->getResponse()->getContent());
|
||||
|
||||
@@ -626,6 +624,7 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
public function testRecordsCaptionRoute()
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
foreach (static::$databoxe_ids as $databox_id) {
|
||||
$databox = databox::get_instance($databox_id);
|
||||
|
||||
@@ -658,6 +657,7 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
public function testRecordsMetadatasRoute()
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
foreach (static::$databoxe_ids as $databox_id) {
|
||||
$databox = databox::get_instance($databox_id);
|
||||
|
||||
@@ -671,7 +671,7 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
$route = '/records/' . $databox_id . '/' . $record_id . '/metadatas/';
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
|
||||
$crawler = $this->client->request('GET', $route);
|
||||
$this->client->request('GET', $route);
|
||||
$content = json_decode($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -690,6 +690,7 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
public function testRecordsStatusRoute()
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
foreach (static::$databoxe_ids as $databox_id) {
|
||||
$databox = databox::get_instance($databox_id);
|
||||
$collection = array_shift($databox->get_collections());
|
||||
@@ -721,9 +722,9 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
public function testRecordsEmbedRoute()
|
||||
{
|
||||
$keys = array_keys(self::$record_1->get_subdefs());
|
||||
$this->setToken(self::$token);
|
||||
|
||||
$record_id = self::$record_1->get_record_id();
|
||||
$record_id = self::$record_1->get_record_id();
|
||||
|
||||
$keys = array_keys($record->get_subdefs());
|
||||
|
||||
@@ -732,18 +733,18 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
$route = '/records/' . $databox_id . '/' . $record_id . '/embed/';
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
|
||||
$this->client->request('GET', $route);
|
||||
$content = json_decode($this->client->getResponse()->getContent());
|
||||
$this->client->request('GET', $route);
|
||||
$content = json_decode($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
$this->evaluateMetaJson200($content);
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
$this->evaluateMetaJson200($content);
|
||||
|
||||
foreach ($content->response as $embed) {
|
||||
foreach ($keys as $key) {
|
||||
$this->assertObjectHasAttribute($key, $embed);
|
||||
$this->checkEmbed($key, $embed->$key, self::$record_1);
|
||||
foreach ($content->response as $embed) {
|
||||
foreach ($keys as $key) {
|
||||
$this->assertObjectHasAttribute($key, $embed);
|
||||
$this->checkEmbed($key, $embed->$key, self::$record_1);
|
||||
}
|
||||
}
|
||||
}
|
||||
$route = '/records/24892534/51654651553/embed/';
|
||||
$this->evaluateNotFoundRoute($route, array('GET'));
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
@@ -866,6 +867,7 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
public function testRecordsRelatedRoute()
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
foreach (static::$databoxe_ids as $databox_id) {
|
||||
$databox = databox::get_instance($databox_id);
|
||||
$collection = array_shift($databox->get_collections());
|
||||
@@ -899,7 +901,7 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
public function testRecordsSetMetadatas()
|
||||
{
|
||||
|
||||
$this->setToken(self::$token);
|
||||
foreach (static::$databoxe_ids as $databox_id) {
|
||||
$databox = databox::get_instance($databox_id);
|
||||
$collection = array_shift($databox->get_collections());
|
||||
@@ -912,8 +914,6 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
$route = '/records/' . $databox_id . '/' . $record_id . '/setmetadatas/';
|
||||
$caption = $record->get_caption();
|
||||
|
||||
|
||||
$old_datas = array();
|
||||
$toupdate = array();
|
||||
|
||||
foreach ($record->get_databox()->get_meta_structure()->get_elements() as $field) {
|
||||
@@ -934,7 +934,7 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE'));
|
||||
|
||||
$crawler = $this->client->request('POST', $route, array('metadatas' => $toupdate));
|
||||
$this->client->request('POST', $route, array('metadatas' => $toupdate));
|
||||
$content = json_decode($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -967,7 +967,7 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
public function testRecordsSetStatus()
|
||||
{
|
||||
|
||||
$this->setToken(self::$token);
|
||||
foreach (static::$databoxe_ids as $databox_id) {
|
||||
$databox = databox::get_instance($databox_id);
|
||||
$collection = array_shift($databox->get_collections());
|
||||
@@ -1030,6 +1030,7 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
public function testMoveRecordToColleciton()
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
foreach (static::$databoxe_ids as $databox_id) {
|
||||
$databox = databox::get_instance($databox_id);
|
||||
$collection = array_shift($databox->get_collections());
|
||||
@@ -1057,7 +1058,7 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE'));
|
||||
|
||||
$crawler = $this->client->request('POST', $route, array('base_id' => $base_id));
|
||||
$this->client->request('POST', $route, array('base_id' => $base_id));
|
||||
$content = json_decode($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -1068,11 +1069,11 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
public function testSearchBaskets()
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
$route = '/baskets/list/';
|
||||
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
|
||||
$crawler = $this->client->request('GET', $route);
|
||||
$this->client->request('GET', $route);
|
||||
$content = json_decode($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -1086,18 +1087,19 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
public function testAddBasket()
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
|
||||
$route = '/baskets/add/';
|
||||
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE'));
|
||||
|
||||
$crawler = $this->client->request('POST', $route, array('name' => 'un Joli Nom'));
|
||||
$this->client->request('POST', $route, array('name' => 'un Joli Nom'));
|
||||
$content = json_decode($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
$this->evaluateMetaJson200($content);
|
||||
|
||||
$this->assertEquals(1, count((array) $content->response));
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
$this->assertObjectHasAttribute("basket", $content->response);
|
||||
|
||||
foreach ($content->response->basket as $basket) {
|
||||
@@ -1108,8 +1110,7 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
public function testBasketContent()
|
||||
{
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
$usr_id = $appbox->get_session()->get_usr_id();
|
||||
$this->setToken(self::$token);
|
||||
|
||||
$basket = $this->insertOneBasket();
|
||||
|
||||
@@ -1117,7 +1118,7 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
|
||||
$crawler = $this->client->request('GET', $route);
|
||||
$this->client->request('GET', $route);
|
||||
$content = json_decode($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -1146,6 +1147,7 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
public function testSetBasketTitle()
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
|
||||
$basket = $this->insertOneBasket();
|
||||
|
||||
@@ -1199,13 +1201,15 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
public function testSetBasketDescription()
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
|
||||
$basket = $this->insertOneBasket();
|
||||
|
||||
$route = '/baskets/' . $basket->getId() . '/setdescription/';
|
||||
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE'));
|
||||
|
||||
$crawler = $this->client->request('POST', $route, array('description' => 'une belle desc'));
|
||||
$this->client->request('POST', $route, array('description' => 'une belle desc'));
|
||||
$content = json_decode($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -1223,13 +1227,15 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
public function testDeleteBasket()
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
|
||||
$baskets = $this->insertFiveBasket();
|
||||
|
||||
$route = '/baskets/' . $baskets[0]->getId() . '/delete/';
|
||||
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE'));
|
||||
|
||||
$crawler = $this->client->request('POST', $route);
|
||||
$this->client->request('POST', $route);
|
||||
$content = json_decode($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -1276,7 +1282,7 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
protected function evaluateBadRequestRoute($route, $methods)
|
||||
{
|
||||
foreach ($methods as $method) {
|
||||
$crawler = $this->client->request($method, $route);
|
||||
$this->client->request($method, $route);
|
||||
$content = json_decode($this->client->getResponse()->getContent());
|
||||
$this->evaluateResponseBadRequest($this->client->getResponse());
|
||||
$this->evaluateMetaJsonBadRequest($content);
|
||||
@@ -1362,10 +1368,10 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
$this->assertObjectHasAttribute('updated_on', $basket);
|
||||
$this->assertObjectHasAttribute('unread', $basket);
|
||||
|
||||
|
||||
if ( ! is_null($basket->pusher_usr_id)) {
|
||||
$this->assertTrue(is_int($basket->pusher_usr_id));
|
||||
}
|
||||
|
||||
$this->assertTrue(is_string($basket->name));
|
||||
$this->assertTrue(is_string($basket->description));
|
||||
$this->assertTrue(is_int($basket->ssel_id));
|
||||
@@ -1493,15 +1499,13 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
|
||||
}
|
||||
}
|
||||
|
||||
protected function setToken($token){
|
||||
$_GET['oauth_token'] = $token;
|
||||
protected function setToken($token)
|
||||
{
|
||||
$_GET['oauth_token'] = $token;
|
||||
}
|
||||
|
||||
protected function unsetToken(){
|
||||
unset($_GET['oauth_token']);
|
||||
}
|
||||
|
||||
protected function request(){
|
||||
|
||||
protected function unsetToken()
|
||||
{
|
||||
unset($_GET['oauth_token']);
|
||||
}
|
||||
}
|
||||
|
@@ -7,10 +7,41 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var Symfony\Component\HttpKernel\Client
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
/**
|
||||
* @var API_OAuth2_Token
|
||||
*/
|
||||
protected static $token;
|
||||
protected static $account_id;
|
||||
|
||||
/**
|
||||
* @var API_OAuth2_Account
|
||||
*/
|
||||
protected static $account;
|
||||
|
||||
/**
|
||||
* @var API_OAuth2_Application
|
||||
*/
|
||||
protected static $application;
|
||||
|
||||
/**
|
||||
* @var API_OAuth2_Token
|
||||
*/
|
||||
protected static $adminToken;
|
||||
|
||||
/**
|
||||
* @var API_OAuth2_Account
|
||||
*/
|
||||
protected static $adminAccount;
|
||||
|
||||
/**
|
||||
* @var API_OAuth2_Application
|
||||
*/
|
||||
protected static $adminApplication;
|
||||
protected static $databoxe_ids = array();
|
||||
protected static $need_records = 1;
|
||||
protected static $need_subdefs = true;
|
||||
@@ -25,12 +56,11 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
{
|
||||
parent::setUp();
|
||||
$this->client = $this->createClient();
|
||||
$_GET['oauth_token'] = self::$token;
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
unset($_GET['oauth_token']);
|
||||
$this->unsetToken();
|
||||
}
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
@@ -38,17 +68,34 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
parent::setUpBeforeClass();
|
||||
self::$yaml = new Symfony\Component\Yaml\Parser();
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
|
||||
self::$application = API_OAuth2_Application::create($appbox, self::$user, 'test API v1');
|
||||
$account = API_OAuth2_Account::load_with_user($appbox, self::$application, self::$user);
|
||||
self::$token = $account->get_token()->get_value();
|
||||
self::$account_id = $account->get_id();
|
||||
$_GET['oauth_token'] = self::$token;
|
||||
self::$account = API_OAuth2_Account::load_with_user($appbox, self::$application, self::$user);
|
||||
self::$token = self::$account->get_token()->get_value();
|
||||
|
||||
//create admin user token
|
||||
$admins = User_Adapter::get_sys_admins();
|
||||
|
||||
self::$adminToken = null;
|
||||
|
||||
if (0 !== count($admins)) {
|
||||
$admin = User_Adapter::getInstance(key($admins), $appbox);
|
||||
self::$adminApplication = API_OAuth2_Application::create($appbox, $admin, 'test2 API v1');
|
||||
self::$adminAccount = API_OAuth2_Account::load_with_user($appbox, self::$adminApplication, $admin);
|
||||
self::$adminToken = self::$adminAccount->get_token()->get_value();
|
||||
}
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
//delete database entry
|
||||
self::$account->delete();
|
||||
self::$application->delete();
|
||||
$_GET = array();
|
||||
|
||||
if (self::$adminToken) {
|
||||
self::$adminAccount->delete();
|
||||
self::$adminApplication->delete();
|
||||
}
|
||||
}
|
||||
|
||||
public function createApplication()
|
||||
@@ -58,7 +105,8 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
public function testRouteNotFound()
|
||||
{
|
||||
$route = '/nothinghere?oauth_token=' . self::$token;
|
||||
$route = '/nothinghere';
|
||||
$this->setToken(self::$token);
|
||||
$this->client->request('GET', $route, array(), array(), array("HTTP_CONTENT_TYPE" => "application/yaml", "HTTP_ACCEPT" => "application/yaml"));
|
||||
$content = self::$yaml->parse($this->client->getResponse()->getContent());
|
||||
$this->evaluateResponseNotFound($this->client->getResponse());
|
||||
@@ -67,7 +115,8 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
public function testDatboxListRoute()
|
||||
{
|
||||
$crawler = $this->client->request('GET', '/databoxes/list/?oauth_token=' . self::$token, array(), array(), array("HTTP_CONTENT_TYPE" => "application/yaml", "HTTP_ACCEPT" => "application/yaml"));
|
||||
$this->setToken(self::$token);
|
||||
$crawler = $this->client->request('GET', '/databoxes/list/', array(), array(), array("HTTP_CONTENT_TYPE" => "application/yaml", "HTTP_ACCEPT" => "application/yaml"));
|
||||
$content = self::$yaml->parse($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -106,14 +155,13 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
$account = API_OAuth2_Account::create($appbox, self::$user, $nativeApp);
|
||||
$token = $account->get_token()->get_value();
|
||||
$_GET['oauth_token'] = $token;
|
||||
$this->setToken($token);
|
||||
$this->client->request('GET', '/databoxes/list/?oauth_token=' . $token, array(), array(), array('HTTP_Accept' => 'application/yaml'));
|
||||
$content = $content = self::$yaml->parse($this->client->getResponse()->getContent());
|
||||
|
||||
if (403 != $content["meta"]["http_code"]) {
|
||||
$fail = new \Exception('Result does not match expected 403, returns ' . $content["meta"]["http_code"]);
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$fail = $e;
|
||||
}
|
||||
@@ -127,10 +175,7 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
public function testAdminOnlyShedulerState()
|
||||
{
|
||||
//Should be 401
|
||||
$this->client->request('GET', '/monitor/scheduler/', array(), array(), array('HTTP_Accept' => 'application/json'));
|
||||
$content = self::$yaml->parse($this->client->getResponse()->getContent());
|
||||
$this->assertEquals(401, $content["meta"]["http_code"]);
|
||||
$this->setToken(self::$token);
|
||||
//Should be 401
|
||||
$this->client->request('GET', '/monitor/tasks/', array(), array(), array('HTTP_Accept' => 'application/json'));
|
||||
$content = self::$yaml->parse($this->client->getResponse()->getContent());
|
||||
@@ -157,119 +202,89 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
$this->assertEquals(401, $content["meta"]["http_code"]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Route GET /API/V1/monitor/scheduler
|
||||
*
|
||||
*/
|
||||
public function testGetMonitorScheduler()
|
||||
{
|
||||
$admins = User_Adapter::get_sys_admins();
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
$admin = User_Adapter::getInstance(key($admins), $appbox);
|
||||
$application = API_OAuth2_Application::create($appbox, $admin, 'test2 API v1');
|
||||
$account = API_OAuth2_Account::load_with_user($appbox, $application, $admin);
|
||||
$_GET['oauth_token'] = $account->get_token()->get_value();
|
||||
$this->client->request('GET', '/monitor/scheduler/', array(), array(), array('HTTP_Accept' => 'application/json'));
|
||||
$content = self::$yaml->parse($this->client->getResponse()->getContent());
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
$this->evaluateMetaYaml200($content);
|
||||
$response = $content['response'];
|
||||
$this->assertArrayHasKey('qdelay', $response);
|
||||
$this->assertArrayHasKey('status', $response);
|
||||
$this->assertArrayHasKey('pid', $response);
|
||||
$application->delete();
|
||||
$account->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Route GET /API/V1/monitor/task
|
||||
*
|
||||
* @cover API_V1_adapter::get_task
|
||||
*/
|
||||
public function testGetMonitorTasks()
|
||||
{
|
||||
$admins = User_Adapter::get_sys_admins();
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
$admin = User_Adapter::getInstance(key($admins), $appbox);
|
||||
$application = API_OAuth2_Application::create($appbox, $admin, 'test2 API v1');
|
||||
$account = API_OAuth2_Account::load_with_user($appbox, $application, $admin);
|
||||
$_GET['oauth_token'] = $account->get_token()->get_value();
|
||||
if (null === self::$adminToken) {
|
||||
$this->markTestSkipped('there is no user with admin rights');
|
||||
}
|
||||
$this->setToken(self::$adminToken);
|
||||
$this->client->request('GET', '/monitor/tasks/', array(), array(), array('HTTP_Accept' => 'application/json'));
|
||||
$content = self::$yaml->parse($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
$this->evaluateMetaYaml200($content);
|
||||
$response = $content['response'];
|
||||
$task_manager = new \task_manager($appbox);
|
||||
$tasks = $task_manager->get_tasks();
|
||||
$this->assertEquals(count($tasks), count($response));
|
||||
$application->delete();
|
||||
$account->delete();
|
||||
$this->assertEquals(count($tasks), count($content['response']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Route GET /API/V1/monitor/task
|
||||
*
|
||||
* Route GET /API/V1/monitor/task{idTask}
|
||||
* @cover API_V1_adapter::get_task
|
||||
*/
|
||||
public function testGetMonitorTaskById()
|
||||
{
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
$task_manager = new \task_manager($appbox);
|
||||
$tasks = $task_manager->get_tasks();
|
||||
if (count($tasks) == 0) {
|
||||
|
||||
if (null === self::$adminToken) {
|
||||
$this->markTestSkipped('there is no user with admin rights');
|
||||
}
|
||||
|
||||
if ( ! count($tasks)) {
|
||||
$this->markTestSkipped('no tasks created for the current instance');
|
||||
}
|
||||
$admins = User_Adapter::get_sys_admins();
|
||||
$admin = User_Adapter::getInstance(key($admins), $appbox);
|
||||
$application = API_OAuth2_Application::create($appbox, $admin, 'test2 API v1');
|
||||
$account = API_OAuth2_Account::load_with_user($appbox, $application, $admin);
|
||||
$_GET['oauth_token'] = $account->get_token()->get_value();
|
||||
|
||||
$this->setToken(self::$adminToken);
|
||||
reset($tasks);
|
||||
$idTask = key($tasks);
|
||||
$this->client->request('GET', '/monitor/task/' . $idTask . '/', array(), array(), array('HTTP_Accept' => 'application/json'));
|
||||
$content = self::$yaml->parse($this->client->getResponse()->getContent());
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
$this->evaluateMetaYaml200($content);
|
||||
$application->delete();
|
||||
$account->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Route GET /API/V1/monitor/task
|
||||
*
|
||||
* Route GET /API/V1/monitor/task/{idTask}
|
||||
* @cover API_V1_adapter::get_task
|
||||
*/
|
||||
public function testUnknowGetMonitorTaskById()
|
||||
{
|
||||
$admins = User_Adapter::get_sys_admins();
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
$admin = User_Adapter::getInstance(key($admins), $appbox);
|
||||
$application = API_OAuth2_Application::create($appbox, $admin, 'test2 API v1');
|
||||
$account = API_OAuth2_Account::load_with_user($appbox, $application, $admin);
|
||||
$_GET['oauth_token'] = $account->get_token()->get_value();
|
||||
if (null === self::$adminToken) {
|
||||
$this->markTestSkipped('no tasks created for the current instance');
|
||||
}
|
||||
$this->setToken(self::$adminToken);
|
||||
$this->client->followRedirects();
|
||||
$this->client->request('GET', '/monitor/task/0', array(), array(), array('HTTP_Accept' => 'application/json'));
|
||||
$content = self::$yaml->parse($this->client->getResponse()->getContent());
|
||||
$this->evaluateMetaYamlNotFound($content);
|
||||
$application->delete();
|
||||
$account->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Route GET /API/V1/monitor/task/{idTask}/start
|
||||
*
|
||||
* @cover API_V1_adapter::start_task
|
||||
*/
|
||||
public function testGetMonitorStartTask()
|
||||
{
|
||||
if (null === self::$adminToken) {
|
||||
$this->markTestSkipped('there is no user with admin rights');
|
||||
}
|
||||
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
$task_manager = new \task_manager($appbox);
|
||||
$tasks = $task_manager->get_tasks();
|
||||
if (count($tasks) == 0) {
|
||||
|
||||
if ( ! count($tasks)) {
|
||||
$this->markTestSkipped('no tasks created for the current instance');
|
||||
}
|
||||
$admins = User_Adapter::get_sys_admins();
|
||||
$admin = User_Adapter::getInstance(key($admins), $appbox);
|
||||
$application = API_OAuth2_Application::create($appbox, $admin, 'test2 API v1');
|
||||
$account = API_OAuth2_Account::load_with_user($appbox, $application, $admin);
|
||||
$_GET['oauth_token'] = $account->get_token()->get_value();
|
||||
|
||||
$this->setToken(self::$adminToken);
|
||||
reset($tasks);
|
||||
$idTask = key($tasks);
|
||||
$this->client->request('POST', '/monitor/task/' . $idTask . '/start/', array(), array(), array('HTTP_Accept' => 'application/json'));
|
||||
@@ -279,27 +294,28 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
$task_manager->get_tasks(true);
|
||||
$task = $task_manager->get_task($idTask);
|
||||
$this->assertEquals(\task_abstract::STATUS_TOSTART, $task->get_status());
|
||||
$application->delete();
|
||||
$account->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Route GET /API/V1/monitor/task/{idTask}/stop
|
||||
*
|
||||
* @cover API_V1_adapter::stop_task
|
||||
*/
|
||||
public function testGetMonitorStopTask()
|
||||
{
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
$task_manager = new \task_manager($appbox);
|
||||
|
||||
$tasks = $task_manager->get_tasks();
|
||||
if (count($tasks) == 0) {
|
||||
|
||||
if (null === self::$adminToken) {
|
||||
$this->markTestSkipped('there is no user with admin rights');
|
||||
}
|
||||
|
||||
if ( ! count($tasks)) {
|
||||
$this->markTestSkipped('no tasks created for the current instance');
|
||||
}
|
||||
$admins = User_Adapter::get_sys_admins();
|
||||
$admin = User_Adapter::getInstance(key($admins), $appbox);
|
||||
$application = API_OAuth2_Application::create($appbox, $admin, 'test2 API v1');
|
||||
$account = API_OAuth2_Account::load_with_user($appbox, $application, $admin);
|
||||
$_GET['oauth_token'] = $account->get_token()->get_value();
|
||||
|
||||
$this->setToken(self::$adminToken);
|
||||
reset($tasks);
|
||||
$idTask = key($tasks);
|
||||
$this->client->request('POST', '/monitor/task/' . $idTask . '/stop/', array(), array(), array('HTTP_Accept' => 'application/json'));
|
||||
@@ -309,22 +325,19 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
$task_manager->get_tasks(true);
|
||||
$task = $task_manager->get_task($idTask);
|
||||
$this->assertEquals(\task_abstract::STATUS_TOSTOP, $task->get_status());
|
||||
$application->delete();
|
||||
$account->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Route GET /API/V1/monitor/phraseanet
|
||||
*
|
||||
* @cover API_V1_adapter::get_phraseanet_monitor
|
||||
*/
|
||||
public function testgetMonitorPhraseanet()
|
||||
{
|
||||
$admins = User_Adapter::get_sys_admins();
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
$admin = User_Adapter::getInstance(key($admins), $appbox);
|
||||
$application = API_OAuth2_Application::create($appbox, $admin, 'test2 API v1');
|
||||
$account = API_OAuth2_Account::load_with_user($appbox, $application, $admin);
|
||||
$_GET['oauth_token'] = $account->get_token()->get_value();
|
||||
if (null === self::$adminToken) {
|
||||
$this->markTestSkipped('there is no user with admin rights');
|
||||
}
|
||||
|
||||
$this->setToken(self::$adminToken);
|
||||
$this->client->request('GET', '/monitor/phraseanet/', array(), array(), array('HTTP_Accept' => 'application/json'));
|
||||
$content = self::$yaml->parse($this->client->getResponse()->getContent());
|
||||
|
||||
@@ -334,8 +347,6 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
$this->assertArrayHasKey('global_values', $response);
|
||||
$this->assertArrayHasKey('cache', $response);
|
||||
$this->assertArrayHasKey('phraseanet', $response);
|
||||
$application->delete();
|
||||
$account->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -344,6 +355,7 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
*/
|
||||
public function testDataboxRecordRoute()
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
|
||||
foreach (static::$databoxe_ids as $databox_id) {
|
||||
$databox = databox::get_instance($databox_id);
|
||||
@@ -353,7 +365,7 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
$record = record_adapter::create($collection, $system_file);
|
||||
$record_id = $record->get_record_id();
|
||||
$route = '/records/' . $databox_id . '/' . $record_id . '/?oauth_token=' . self::$token;
|
||||
$route = '/records/' . $databox_id . '/' . $record_id . '/';
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
$crawler = $this->client->request('GET', $route, array(), array(), array("HTTP_ACCEPT" => "application/yaml"));
|
||||
$content = self::$yaml->parse($this->client->getResponse()->getContent());
|
||||
@@ -363,18 +375,20 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
$this->evaluateGoodRecord($content["response"]["record"]);
|
||||
$record->delete();
|
||||
}
|
||||
$route = '/records/1234567890/1/?oauth_token=' . self::$token;
|
||||
$route = '/records/1234567890/1/';
|
||||
$this->evaluateNotFoundRoute($route, array('GET'));
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
$route = '/records/kjslkz84spm/sfsd5qfsd5/?oauth_token=' . self::$token;
|
||||
$route = '/records/kjslkz84spm/sfsd5qfsd5/';
|
||||
$this->evaluateBadRequestRoute($route, array('GET'));
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
}
|
||||
|
||||
public function testDataboxCollectionRoute()
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
|
||||
foreach (static::$databoxe_ids as $databox_id) {
|
||||
$route = '/databoxes/' . $databox_id . '/collections/?oauth_token=' . self::$token;
|
||||
$route = '/databoxes/' . $databox_id . '/collections/';
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
|
||||
$crawler = $this->client->request('GET', $route, array(), array(), array("HTTP_ACCEPT" => "application/yaml"));
|
||||
@@ -397,20 +411,22 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
$this->assertTrue(is_int($collection["record_amount"]));
|
||||
}
|
||||
}
|
||||
$route = '/databoxes/24892534/collections/?oauth_token=' . self::$token;
|
||||
$route = '/databoxes/24892534/collections/';
|
||||
$this->evaluateNotFoundRoute($route, array('GET'));
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
$route = '/databoxes/any_bad_id/collections/?oauth_token=' . self::$token;
|
||||
$route = '/databoxes/any_bad_id/collections/';
|
||||
$this->evaluateBadRequestRoute($route, array('GET'));
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
}
|
||||
|
||||
public function testDataboxStatusRoute()
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
|
||||
foreach (static::$databoxe_ids as $databox_id) {
|
||||
$databox = databox::get_instance($databox_id);
|
||||
$ref_status = $databox->get_statusbits();
|
||||
$route = '/databoxes/' . $databox_id . '/status/?oauth_token=' . self::$token;
|
||||
$route = '/databoxes/' . $databox_id . '/status/';
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
|
||||
$crawler = $this->client->request('GET', $route, array(), array(), array("HTTP_ACCEPT" => "application/yaml"));
|
||||
@@ -443,16 +459,18 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
$this->assertTrue($status["img_on"] === $ref_status[$status["bit"]]['img_on']);
|
||||
}
|
||||
}
|
||||
$route = '/databoxes/24892534/status/?oauth_token=' . self::$token;
|
||||
$route = '/databoxes/24892534/status/';
|
||||
$this->evaluateNotFoundRoute($route, array('GET'));
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
$route = '/databoxes/any_bad_id/status/?oauth_token=' . self::$token;
|
||||
$route = '/databoxes/any_bad_id/status/';
|
||||
$this->evaluateBadRequestRoute($route, array('GET'));
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
}
|
||||
|
||||
public function testDataboxMetadatasRoute()
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
|
||||
foreach (static::$databoxe_ids as $databox_id) {
|
||||
$databox = databox::get_instance($databox_id);
|
||||
$ref_structure = $databox->get_meta_structure();
|
||||
@@ -464,7 +482,7 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
}
|
||||
|
||||
$route = '/databoxes/' . $databox_id . '/metadatas/?oauth_token=' . self::$token;
|
||||
$route = '/databoxes/' . $databox_id . '/metadatas/';
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
|
||||
$crawler = $this->client->request('GET', $route, array(), array(), array("HTTP_ACCEPT" => "application/yaml"));
|
||||
@@ -519,20 +537,22 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
$this->assertTrue($element->get_metadata_namespace() === $metadatas["namespace"]);
|
||||
}
|
||||
}
|
||||
$route = '/databoxes/24892534/metadatas/?oauth_token=' . self::$token;
|
||||
$route = '/databoxes/24892534/metadatas/';
|
||||
$this->evaluateNotFoundRoute($route, array('GET'));
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
$route = '/databoxes/any_bad_id/metadatas/?oauth_token=' . self::$token;
|
||||
$route = '/databoxes/any_bad_id/metadatas/';
|
||||
$this->evaluateBadRequestRoute($route, array('GET'));
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
}
|
||||
|
||||
public function testDataboxTermsOfUseRoute()
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
|
||||
foreach (static::$databoxe_ids as $databox_id) {
|
||||
$databox = databox::get_instance($databox_id);
|
||||
|
||||
$route = '/databoxes/' . $databox_id . '/termsOfUse/?oauth_token=' . self::$token;
|
||||
$route = '/databoxes/' . $databox_id . '/termsOfUse/';
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
|
||||
$crawler = $this->client->request('GET', $route, array(), array(), array("HTTP_ACCEPT" => "application/yaml"));
|
||||
@@ -548,10 +568,10 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
$this->assertArrayHasKey('terms', $terms);
|
||||
}
|
||||
}
|
||||
$route = '/databoxes/24892534/termsOfUse/?oauth_token=' . self::$token;
|
||||
$route = '/databoxes/24892534/termsOfUse/';
|
||||
$this->evaluateNotFoundRoute($route, array('GET'));
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
$route = '/databoxes/any_bad_id/termsOfUse/?oauth_token=' . self::$token;
|
||||
$route = '/databoxes/any_bad_id/termsOfUse/';
|
||||
$this->evaluateBadRequestRoute($route, array('GET'));
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
}
|
||||
@@ -567,9 +587,9 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
*/
|
||||
public function testRecordsSearchRoute()
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
|
||||
|
||||
$crawler = $this->client->request('POST', '/records/search/?oauth_token=' . self::$token, array(), array(), array("HTTP_ACCEPT" => "application/yaml"));
|
||||
$crawler = $this->client->request('POST', '/records/search/', array(), array(), array("HTTP_ACCEPT" => "application/yaml"));
|
||||
$content = self::$yaml->parse($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -612,6 +632,7 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
public function testRecordsCaptionRoute()
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
foreach (static::$databoxe_ids as $databox_id) {
|
||||
$databox = databox::get_instance($databox_id);
|
||||
|
||||
@@ -622,7 +643,7 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
$record_id = $record->get_record_id();
|
||||
|
||||
$route = '/records/' . $databox_id . '/' . $record_id . '/caption/?oauth_token=' . self::$token;
|
||||
$route = '/records/' . $databox_id . '/' . $record_id . '/caption/';
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
|
||||
$crawler = $this->client->request('GET', $route, array(), array(), array("HTTP_ACCEPT" => "application/yaml"));
|
||||
@@ -634,16 +655,17 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
$this->evaluateRecordsCaptionResponse($content);
|
||||
$record->delete();
|
||||
}
|
||||
$route = '/records/24892534/51654651553/metadatas/?oauth_token=' . self::$token;
|
||||
$route = '/records/24892534/51654651553/metadatas/';
|
||||
$this->evaluateNotFoundRoute($route, array('GET'));
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
$route = '/records/any_bad_id/sfsd5qfsd5/metadatas/?oauth_token=' . self::$token;
|
||||
$route = '/records/any_bad_id/sfsd5qfsd5/metadatas/';
|
||||
$this->evaluateBadRequestRoute($route, array('GET'));
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
}
|
||||
|
||||
public function testRecordsMetadatasRoute()
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
foreach (static::$databoxe_ids as $databox_id) {
|
||||
$databox = databox::get_instance($databox_id);
|
||||
|
||||
@@ -654,7 +676,7 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
$record_id = $record->get_record_id();
|
||||
|
||||
$route = '/records/' . $databox_id . '/' . $record_id . '/metadatas/?oauth_token=' . self::$token;
|
||||
$route = '/records/' . $databox_id . '/' . $record_id . '/metadatas/';
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
|
||||
$crawler = $this->client->request('GET', $route, array(), array(), array("HTTP_ACCEPT" => "application/yaml"));
|
||||
@@ -666,16 +688,17 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
$this->evaluateRecordsMetadataResponse($content);
|
||||
$record->delete();
|
||||
}
|
||||
$route = '/records/24892534/51654651553/metadatas/?oauth_token=' . self::$token;
|
||||
$route = '/records/24892534/51654651553/metadatas/';
|
||||
$this->evaluateNotFoundRoute($route, array('GET'));
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
$route = '/records/any_bad_id/sfsd5qfsd5/metadatas/?oauth_token=' . self::$token;
|
||||
$route = '/records/any_bad_id/sfsd5qfsd5/metadatas/';
|
||||
$this->evaluateBadRequestRoute($route, array('GET'));
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
}
|
||||
|
||||
public function testRecordsStatusRoute()
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
foreach (static::$databoxe_ids as $databox_id) {
|
||||
$databox = databox::get_instance($databox_id);
|
||||
$collection = array_shift($databox->get_collections());
|
||||
@@ -685,7 +708,7 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
$record_id = $record->get_record_id();
|
||||
|
||||
$route = '/records/' . $databox_id . '/' . $record_id . '/status/?oauth_token=' . self::$token;
|
||||
$route = '/records/' . $databox_id . '/' . $record_id . '/status/';
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
|
||||
$crawler = $this->client->request('GET', $route, array(), array(), array("HTTP_ACCEPT" => "application/yaml"));
|
||||
@@ -697,16 +720,17 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
$this->evaluateRecordsStatusResponse($record, $content);
|
||||
$record->delete();
|
||||
}
|
||||
$route = '/records/24892534/51654651553/status/?oauth_token=' . self::$token;
|
||||
$route = '/records/24892534/51654651553/status/';
|
||||
$this->evaluateNotFoundRoute($route, array('GET'));
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
$route = '/records/any_bad_id/sfsd5qfsd5/status/?oauth_token=' . self::$token;
|
||||
$route = '/records/any_bad_id/sfsd5qfsd5/status/';
|
||||
$this->evaluateBadRequestRoute($route, array('GET'));
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
}
|
||||
|
||||
public function testRecordsEmbedRoute()
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
$keys = array_keys(self::$record_1->get_subdefs());
|
||||
|
||||
$route = '/records/' . self::$record_1->get_sbas_id() . '/' . self::$record_1->get_record_id() . '/embed/?oauth_token=' . self::$token;
|
||||
@@ -724,11 +748,10 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
$this->checkEmbed($key, $embed[$key], self::$record_1);
|
||||
}
|
||||
}
|
||||
|
||||
$route = '/records/24892534/51654651553/embed/?oauth_token=' . self::$token;
|
||||
$route = '/records/24892534/51654651553/embed/';
|
||||
$this->evaluateNotFoundRoute($route, array('GET'));
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
$route = '/records/any_bad_id/sfsd5qfsd5/embed/?oauth_token=' . self::$token;
|
||||
$route = '/records/any_bad_id/sfsd5qfsd5/embed/';
|
||||
$this->evaluateBadRequestRoute($route, array('GET'));
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
}
|
||||
@@ -848,6 +871,7 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
public function testRecordsRelatedRoute()
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
foreach (static::$databoxe_ids as $databox_id) {
|
||||
$databox = databox::get_instance($databox_id);
|
||||
$collection = array_shift($databox->get_collections());
|
||||
@@ -857,7 +881,7 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
$record_id = $record->get_record_id();
|
||||
|
||||
$route = '/records/' . $databox_id . '/' . $record_id . '/related/?oauth_token=' . self::$token;
|
||||
$route = '/records/' . $databox_id . '/' . $record_id . '/related/';
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
|
||||
$crawler = $this->client->request('GET', $route, array(), array(), array("HTTP_ACCEPT" => "application/yaml"));
|
||||
@@ -871,17 +895,17 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
}
|
||||
$record->delete();
|
||||
}
|
||||
$route = '/records/24892534/51654651553/related/?oauth_token=' . self::$token;
|
||||
$route = '/records/24892534/51654651553/related/';
|
||||
$this->evaluateNotFoundRoute($route, array('GET'));
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
$route = '/records/any_bad_id/sfsd5qfsd5/related/?oauth_token=' . self::$token;
|
||||
$route = '/records/any_bad_id/sfsd5qfsd5/related/';
|
||||
$this->evaluateBadRequestRoute($route, array('GET'));
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
}
|
||||
|
||||
public function testRecordsSetMetadatas()
|
||||
{
|
||||
|
||||
$this->setToken(self::$token);
|
||||
foreach (static::$databoxe_ids as $databox_id) {
|
||||
$databox = databox::get_instance($databox_id);
|
||||
$collection = array_shift($databox->get_collections());
|
||||
@@ -891,7 +915,7 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
$record_id = $record->get_record_id();
|
||||
|
||||
$route = '/records/' . $databox_id . '/' . $record_id . '/setmetadatas/?oauth_token=' . self::$token;
|
||||
$route = '/records/' . $databox_id . '/' . $record_id . '/setmetadatas/';
|
||||
$caption = $record->get_caption();
|
||||
|
||||
|
||||
@@ -966,7 +990,7 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
public function testRecordsSetStatus()
|
||||
{
|
||||
|
||||
$this->setToken(self::$token);
|
||||
foreach (static::$databoxe_ids as $databox_id) {
|
||||
$databox = databox::get_instance($databox_id);
|
||||
$collection = array_shift($databox->get_collections());
|
||||
@@ -976,7 +1000,7 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
$record_id = $record->get_record_id();
|
||||
|
||||
$route = '/records/' . $databox_id . '/' . $record_id . '/setstatus/?oauth_token=' . self::$token;
|
||||
$route = '/records/' . $databox_id . '/' . $record_id . '/setstatus/';
|
||||
|
||||
$record_status = strrev($record->get_status());
|
||||
$status_bits = $databox->get_statusbits();
|
||||
@@ -1026,6 +1050,7 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
public function testMoveRecordToColleciton()
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
foreach (static::$databoxe_ids as $databox_id) {
|
||||
$databox = databox::get_instance($databox_id);
|
||||
$collection = array_shift($databox->get_collections());
|
||||
@@ -1035,7 +1060,7 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
$record_id = $record->get_record_id();
|
||||
|
||||
$route = '/records/' . $databox_id . '/' . $record_id . '/setcollection/?oauth_token=' . self::$token;
|
||||
$route = '/records/' . $databox_id . '/' . $record_id . '/setcollection/';
|
||||
|
||||
$base_id = false;
|
||||
foreach ($databox->get_collections() as $collection) {
|
||||
@@ -1062,7 +1087,8 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
public function testSearchBaskets()
|
||||
{
|
||||
$route = '/baskets/list/?oauth_token=' . self::$token;
|
||||
$this->setToken(self::$token);
|
||||
$route = '/baskets/list/';
|
||||
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
|
||||
@@ -1080,7 +1106,8 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
public function testAddBasket()
|
||||
{
|
||||
$route = '/baskets/add/?oauth_token=' . self::$token;
|
||||
$this->setToken(self::$token);
|
||||
$route = '/baskets/add/';
|
||||
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE'));
|
||||
|
||||
@@ -1091,7 +1118,6 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
$this->evaluateMetaYaml200($content);
|
||||
|
||||
$this->assertEquals(1, count((array) $content["response"]));
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
$this->assertArrayHasKey("basket", $content["response"]);
|
||||
|
||||
foreach ($content["response"]["basket"] as $basket) {
|
||||
@@ -1102,9 +1128,10 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
public function testBasketContent()
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
$basket = $this->insertOneBasket();
|
||||
|
||||
$route = '/baskets/' . $basket->getId() . '/content/?oauth_token=' . self::$token;
|
||||
$route = '/baskets/' . $basket->getId() . '/content/';
|
||||
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
|
||||
@@ -1137,10 +1164,11 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
public function testSetBasketTitle()
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
|
||||
$basket = $this->insertOneBasket();
|
||||
|
||||
$route = '/baskets/' . $basket->getId() . '/setname/?oauth_token=' . self::$token;
|
||||
$route = '/baskets/' . $basket->getId() . '/setname/';
|
||||
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE'));
|
||||
|
||||
@@ -1190,9 +1218,11 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
public function testSetBasketDescription()
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
|
||||
$basket = $this->insertOneBasket();
|
||||
|
||||
$route = '/baskets/' . $basket->getId() . '/setdescription/?oauth_token=' . self::$token;
|
||||
$route = '/baskets/' . $basket->getId() . '/setdescription/';
|
||||
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE'));
|
||||
|
||||
@@ -1214,9 +1244,10 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
|
||||
public function testDeleteBasket()
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
$baskets = $this->insertFiveBasket();
|
||||
|
||||
$route = '/baskets/' . $baskets[0]->getId() . '/delete/?oauth_token=' . self::$token;
|
||||
$route = '/baskets/' . $baskets[0]->getId() . '/delete/';
|
||||
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE'));
|
||||
|
||||
@@ -1504,4 +1535,14 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
|
||||
$this->assertEquals($retrieved, $status["state"]);
|
||||
}
|
||||
}
|
||||
|
||||
protected function setToken($token)
|
||||
{
|
||||
$_GET['oauth_token'] = $token;
|
||||
}
|
||||
|
||||
protected function unsetToken()
|
||||
{
|
||||
unset($_GET['oauth_token']);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user