mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-15 14:03:27 +00:00
2306 lines
96 KiB
PHP
2306 lines
96 KiB
PHP
<?php
|
|
|
|
namespace Alchemy\Phrasea\Application;
|
|
|
|
require_once __DIR__ . '/../../../PhraseanetWebTestCaseAbstract.class.inc';
|
|
|
|
use Silex\WebTestCase;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
|
{
|
|
/**
|
|
*
|
|
* @var Symfony\Component\HttpKernel\Client
|
|
*/
|
|
protected $client;
|
|
|
|
/**
|
|
* @var \API_OAuth2_Token
|
|
*/
|
|
protected static $token;
|
|
|
|
/**
|
|
* @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();
|
|
|
|
abstract public function unserialize($data);
|
|
|
|
abstract public function getAcceptMimeType();
|
|
|
|
public function setUp()
|
|
{
|
|
parent::setUp();
|
|
$this->client = $this->createClient();
|
|
}
|
|
|
|
public function tearDown()
|
|
{
|
|
$this->unsetToken();
|
|
parent::tearDown();
|
|
}
|
|
|
|
public static function setUpBeforeClass()
|
|
{
|
|
parent::setUpBeforeClass();
|
|
$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 = 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();
|
|
|
|
if (self::$adminToken) {
|
|
self::$adminAccount->delete();
|
|
self::$adminApplication->delete();
|
|
}
|
|
parent::tearDownAfterClass();
|
|
}
|
|
|
|
public function createApplication()
|
|
{
|
|
$app = require __DIR__ . '/../../../../lib/Alchemy/Phrasea/Application/Api.php';
|
|
|
|
$app['debug'] = true;
|
|
unset($app['exception_handler']);
|
|
|
|
return $app;
|
|
}
|
|
|
|
public function testRouteNotFound()
|
|
{
|
|
$route = '/nothinghere';
|
|
$this->setToken(self::$token);
|
|
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->evaluateResponseNotFound($this->client->getResponse());
|
|
$this->evaluateMetaNotFound($content);
|
|
}
|
|
|
|
/**
|
|
* @covers \API_V1_adapter::get_databoxes
|
|
* @covers \API_V1_adapter::list_databoxes
|
|
* @covers \API_V1_adapter::list_databox
|
|
*/
|
|
public function testDataboxListRoute()
|
|
{
|
|
$this->setToken(self::$token);
|
|
$this->client->request('GET', '/databoxes/list/', array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
|
|
|
|
$this->assertArrayHasKey('databoxes', $content['response']);
|
|
foreach ($content['response']['databoxes'] as $databox) {
|
|
$this->assertTrue(is_array($databox), 'Une databox est un objet');
|
|
$this->assertArrayHasKey('databox_id', $databox);
|
|
$this->assertArrayHasKey('name', $databox);
|
|
$this->assertArrayHasKey('version', $databox);
|
|
static::$databoxe_ids[] = $databox['databox_id'];
|
|
}
|
|
}
|
|
|
|
public function testCheckNativeApp()
|
|
{
|
|
$appbox = \appbox::get_instance(\bootstrap::getCore());
|
|
|
|
$registry = $this->getMock('\\registry', array(), array(), '', false);
|
|
$registry
|
|
->expects($this->any())
|
|
->method('get')
|
|
->with($this->equalTo('GV_client_navigator'))
|
|
->will($this->returnValue(false));
|
|
$registryBkp = $this->app["Core"]->getRegistry();
|
|
|
|
$fail = null;
|
|
|
|
try {
|
|
|
|
$this->app["Core"]['Registry'] = $registry;
|
|
|
|
$nativeApp = \API_OAuth2_Application::load_from_client_id($appbox, \API_OAuth2_Application_Navigator::CLIENT_ID);
|
|
|
|
$account = \API_OAuth2_Account::create($appbox, self::$user, $nativeApp);
|
|
$token = $account->get_token()->get_value();
|
|
$this->setToken($token);
|
|
$this->client->request('GET', '/databoxes/list/', array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($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;
|
|
}
|
|
|
|
$this->app["Core"]['Registry'] = $registryBkp;
|
|
|
|
if ($fail) {
|
|
throw $fail;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Covers mustBeAdmin route middleware
|
|
*/
|
|
public function testAdminOnlyShedulerState()
|
|
{
|
|
$this->setToken(self::$token);
|
|
|
|
$this->client->request('GET', '/monitor/tasks/', array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
$this->assertEquals(401, $content['meta']['http_code']);
|
|
|
|
$this->client->request('GET', '/monitor/task/1/', array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
$this->assertEquals(401, $content['meta']['http_code']);
|
|
|
|
$this->client->request('POST', '/monitor/task/1/', array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
$this->assertEquals(401, $content['meta']['http_code']);
|
|
|
|
$this->client->request('POST', '/monitor/task/1/start/', array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
$this->assertEquals(401, $content['meta']['http_code']);
|
|
|
|
$this->client->request('POST', '/monitor/task/1/stop/', array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
$this->assertEquals(401, $content['meta']['http_code']);
|
|
|
|
$this->client->request('GET', '/monitor/phraseanet/', array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
$this->assertEquals(401, $content['meta']['http_code']);
|
|
}
|
|
|
|
/**
|
|
* Route GET /API/V1/monitor/task
|
|
* @covers API_V1_adapter::get_task_list
|
|
* @covers API_V1_adapter::list_task
|
|
*/
|
|
public function testGetMonitorTasks()
|
|
{
|
|
$appbox = \appbox::get_instance(\bootstrap::getCore());
|
|
if (null === self::$adminToken) {
|
|
$this->markTestSkipped('there is no user with admin rights');
|
|
}
|
|
$this->setToken(self::$adminToken);
|
|
|
|
$route = '/monitor/tasks/';
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
|
|
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
$response = $content['response'];
|
|
|
|
$task_manager = new \task_manager($appbox);
|
|
$tasks = $task_manager->getTasks();
|
|
$this->assertEquals(count($tasks), count($response['tasks']));
|
|
|
|
foreach ($response['tasks'] as $task) {
|
|
$this->evaluateGoodTask($task);
|
|
}
|
|
}
|
|
|
|
protected function evaluateGoodTask($task)
|
|
{
|
|
$this->assertArrayHasKey('id', $task);
|
|
$this->assertArrayHasKey('name', $task);
|
|
$this->assertArrayHasKey('state', $task);
|
|
$this->assertArrayHasKey('pid', $task);
|
|
$this->assertArrayHasKey('title', $task);
|
|
$this->assertArrayHasKey('last_exec_time', $task);
|
|
|
|
$this->assertInternalType('integer', $task['id']);
|
|
|
|
if ( ! is_null($task['pid'])) {
|
|
$this->assertInternalType('integer', $task['pid']);
|
|
}
|
|
|
|
$av_states = array(
|
|
\task_abstract::STATE_STARTED,
|
|
\task_abstract::STATE_STOPPED,
|
|
\task_abstract::STATE_OK,
|
|
\task_abstract::STATE_TODELETE,
|
|
\task_abstract::STATE_TORESTART,
|
|
\task_abstract::STATE_TOSTOP,
|
|
\task_abstract::STATE_TOSTART,
|
|
);
|
|
|
|
$this->assertContains($task['state'], $av_states);
|
|
$this->assertInternalType('string', $task['name']);
|
|
$this->assertInternalType('string', $task['title']);
|
|
|
|
if ( ! is_null($task['last_exec_time'])) {
|
|
$this->assertDateAtom($task['last_exec_time']);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Route GET /API/V1/monitor/task{idTask}
|
|
* @covers API_V1_adapter::get_task
|
|
* @covers API_V1_adapter::list_task
|
|
*/
|
|
public function testGetMonitorTaskById()
|
|
{
|
|
$appbox = \appbox::get_instance(\bootstrap::getCore());
|
|
$task_manager = new \task_manager($appbox);
|
|
$tasks = $task_manager->getTasks();
|
|
|
|
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');
|
|
}
|
|
|
|
$this->setToken(self::$adminToken);
|
|
reset($tasks);
|
|
$idTask = key($tasks);
|
|
|
|
$route = '/monitor/task/' . $idTask . '/';
|
|
$this->evaluateMethodNotAllowedRoute($route, array('PUT', 'DELETE'));
|
|
|
|
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
|
|
$this->assertArrayHasKey('task', $content['response']);
|
|
$this->evaluateGoodTask($content['response']['task']);
|
|
}
|
|
|
|
/**
|
|
* Route POST /API/V1/monitor/task{idTask}
|
|
* @covers API_V1_adapter::set_task_property
|
|
*/
|
|
public function testPostMonitorTaskById()
|
|
{
|
|
$appbox = \appbox::get_instance(\bootstrap::getCore());
|
|
$task_manager = new \task_manager($appbox);
|
|
$tasks = $task_manager->getTasks();
|
|
|
|
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');
|
|
}
|
|
|
|
$this->setToken(self::$adminToken);
|
|
reset($tasks);
|
|
$idTask = key($tasks);
|
|
|
|
$route = '/monitor/task/' . $idTask . '/';
|
|
$this->evaluateMethodNotAllowedRoute($route, array('PUT', 'DELETE'));
|
|
|
|
$title = 'newTitle' . mt_rand();
|
|
|
|
$this->client->request('POST', $route, array('title' => $title), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
|
|
$this->assertArrayHasKey('task', $content['response']);
|
|
$this->evaluateGoodTask($content['response']['task']);
|
|
$this->assertEquals($title, $content['response']['task']['title']);
|
|
}
|
|
|
|
/**
|
|
* Route GET /API/V1/monitor/task/{idTask}/
|
|
* @covers API_V1_adapter::get_task
|
|
*/
|
|
public function testUnknowGetMonitorTaskById()
|
|
{
|
|
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' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
$this->evaluateMetaNotFound($content);
|
|
}
|
|
|
|
/**
|
|
* Route POST /API/V1/monitor/task/{idTask}/start
|
|
* @covers API_V1_adapter::start_task
|
|
*/
|
|
public function testPostMonitorStartTask()
|
|
{
|
|
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->getTasks();
|
|
|
|
if ( ! count($tasks)) {
|
|
$this->markTestSkipped('no tasks created for the current instance');
|
|
}
|
|
|
|
$this->setToken(self::$adminToken);
|
|
reset($tasks);
|
|
$idTask = key($tasks);
|
|
|
|
$route = '/monitor/task/' . $idTask . '/start/';
|
|
$this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE'));
|
|
|
|
$this->client->request('POST', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
|
|
$this->assertArrayHasKey('task', $content['response']);
|
|
$this->evaluateGoodTask($content['response']['task']);
|
|
|
|
$task_manager->getTasks(true);
|
|
$task = $task_manager->getTask($idTask);
|
|
$this->assertContains($task->getState(), array(\task_abstract::STATE_TOSTART, \task_abstract::STATE_STARTED));
|
|
}
|
|
|
|
/**
|
|
* Route POST /API/V1/monitor/task/{idTask}/stop
|
|
* @covers API_V1_adapter::stop_task
|
|
*/
|
|
public function testPostMonitorStopTask()
|
|
{
|
|
$appbox = \appbox::get_instance(\bootstrap::getCore());
|
|
$task_manager = new \task_manager($appbox);
|
|
|
|
$tasks = $task_manager->getTasks();
|
|
|
|
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');
|
|
}
|
|
|
|
$this->setToken(self::$adminToken);
|
|
reset($tasks);
|
|
$idTask = key($tasks);
|
|
|
|
$route = '/monitor/task/' . $idTask . '/stop/';
|
|
$this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE'));
|
|
|
|
$this->client->request('POST', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
|
|
$this->assertArrayHasKey('task', $content['response']);
|
|
$this->evaluateGoodTask($content['response']['task']);
|
|
|
|
$task_manager->getTasks(true);
|
|
$task = $task_manager->getTask($idTask);
|
|
$this->assertContains($task->getState(), array(\task_abstract::STATE_TOSTOP, \task_abstract::STATE_STOPPED));
|
|
}
|
|
|
|
/**
|
|
* Route GET /API/V1/monitor/phraseanet
|
|
* @covers API_V1_adapter::get_phraseanet_monitor
|
|
* @covers API_V1_adapter::get_config_info
|
|
* @covers API_V1_adapter::get_cache_info
|
|
* @covers API_V1_adapter::get_gv_info
|
|
*/
|
|
public function testgetMonitorPhraseanet()
|
|
{
|
|
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' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
$this->assertArrayHasKey('global_values', $content['response']);
|
|
$this->assertArrayHasKey('cache', $content['response']);
|
|
$this->assertArrayHasKey('phraseanet', $content['response']);
|
|
|
|
$this->assertInternalType('array', $content['response']['global_values']);
|
|
$this->assertInternalType('array', $content['response']['cache']);
|
|
$this->assertInternalType('array', $content['response']['phraseanet']);
|
|
}
|
|
|
|
/**
|
|
* @covers \API_V1_adapter::get_record
|
|
* @covers \API_V1_adapter::list_record
|
|
*/
|
|
public function testDataboxRecordRoute()
|
|
{
|
|
$this->setToken(self::$token);
|
|
|
|
$route = '/records/' . static::$records['record_1']->get_sbas_id() . '/' . static::$records['record_1']->get_record_id() . '/';
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
|
|
$this->evaluateGoodRecord($content['response']['record']);
|
|
|
|
$route = '/records/1234567890/1/';
|
|
$this->evaluateNotFoundRoute($route, array('GET'));
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
$route = '/records/kjslkz84spm/sfsd5qfsd5/';
|
|
$this->evaluateBadRequestRoute($route, array('GET'));
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
}
|
|
|
|
/**
|
|
* @covers \API_V1_adapter::get_databox_collections
|
|
* @covers \API_V1_adapter::list_databox_collections
|
|
* @covers \API_V1_adapter::list_collection
|
|
*/
|
|
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'));
|
|
|
|
$crawler = $this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
|
|
$this->assertArrayHasKey('collections', $content['response']);
|
|
foreach ($content['response']['collections'] as $collection) {
|
|
$this->assertTrue(is_array($collection), 'Une collection est un objet');
|
|
$this->assertArrayHasKey('base_id', $collection);
|
|
$this->assertArrayHasKey('coll_id', $collection);
|
|
$this->assertArrayHasKey('name', $collection);
|
|
$this->assertArrayHasKey('record_amount', $collection);
|
|
$this->assertTrue(is_int($collection['base_id']));
|
|
$this->assertGreaterThan(0, $collection['base_id']);
|
|
$this->assertTrue(is_int($collection['coll_id']));
|
|
$this->assertGreaterThan(0, $collection['coll_id']);
|
|
$this->assertTrue(is_string($collection['name']));
|
|
$this->assertTrue(is_int($collection['record_amount']));
|
|
}
|
|
}
|
|
$route = '/databoxes/24892534/collections/';
|
|
$this->evaluateNotFoundRoute($route, array('GET'));
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
$route = '/databoxes/any_bad_id/collections/';
|
|
$this->evaluateBadRequestRoute($route, array('GET'));
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
}
|
|
|
|
/**
|
|
* @covers \API_V1_adapter::get_databox_status
|
|
* @covers \API_V1_adapter::list_databox_status
|
|
*/
|
|
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/';
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
|
|
$crawler = $this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
|
|
$this->assertArrayHasKey('status', $content['response']);
|
|
foreach ($content['response']['status'] as $status) {
|
|
$this->assertTrue(is_array($status), 'Un bloc status est un objet');
|
|
$this->assertArrayHasKey('bit', $status);
|
|
$this->assertTrue(is_int($status['bit']));
|
|
$this->assertGreaterThan(3, $status['bit']);
|
|
$this->assertLessThan(65, $status['bit']);
|
|
$this->assertArrayHasKey('label_on', $status);
|
|
$this->assertArrayHasKey('label_off', $status);
|
|
$this->assertArrayHasKey('img_on', $status);
|
|
$this->assertArrayHasKey('img_off', $status);
|
|
$this->assertArrayHasKey('searchable', $status);
|
|
$this->assertArrayHasKey('printable', $status);
|
|
$this->assertTrue(is_int($status['searchable']));
|
|
$this->assertTrue(in_array($status['searchable'], array(0, 1)));
|
|
$this->assertTrue($status['searchable'] === $ref_status[$status['bit']]['searchable']);
|
|
$this->assertTrue(is_int($status['printable']));
|
|
$this->assertTrue(in_array($status['printable'], array(0, 1)));
|
|
$this->assertTrue($status['printable'] === $ref_status[$status['bit']]['printable']);
|
|
$this->assertTrue($status['label_off'] === $ref_status[$status['bit']]['labeloff']);
|
|
$this->assertTrue($status['label_on'] === $ref_status[$status['bit']]['labelon']);
|
|
$this->assertTrue($status['img_off'] === $ref_status[$status['bit']]['img_off']);
|
|
$this->assertTrue($status['img_on'] === $ref_status[$status['bit']]['img_on']);
|
|
}
|
|
}
|
|
$route = '/databoxes/24892534/status/';
|
|
$this->evaluateNotFoundRoute($route, array('GET'));
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
$route = '/databoxes/any_bad_id/status/';
|
|
$this->evaluateBadRequestRoute($route, array('GET'));
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
}
|
|
|
|
/**
|
|
* @covers \API_V1_adapter::get_databox_metadatas
|
|
* @covers \API_V1_adapter::list_databox_metadatas_fields
|
|
* @covers \API_V1_adapter::list_databox_metadata_field_properties
|
|
*/
|
|
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();
|
|
|
|
try {
|
|
$ref_structure->get_element('idbarbouze');
|
|
$this->fail('An expected exception has not been raised.');
|
|
} catch (\Exception_Databox_FieldNotFound $e) {
|
|
|
|
}
|
|
|
|
$route = '/databoxes/' . $databox_id . '/metadatas/';
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
|
|
$crawler = $this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
$this->assertArrayHasKey('metadatas', $content['response']);
|
|
foreach ($content['response']['metadatas'] as $metadatas) {
|
|
$this->assertTrue(is_array($metadatas), 'Un bloc metadata est un objet');
|
|
$this->assertArrayHasKey('id', $metadatas);
|
|
$this->assertArrayHasKey('namespace', $metadatas);
|
|
$this->assertArrayHasKey('source', $metadatas);
|
|
$this->assertArrayHasKey('tagname', $metadatas);
|
|
$this->assertArrayHasKey('name', $metadatas);
|
|
$this->assertArrayHasKey('separator', $metadatas);
|
|
$this->assertArrayHasKey('thesaurus_branch', $metadatas);
|
|
$this->assertArrayHasKey('type', $metadatas);
|
|
$this->assertArrayHasKey('indexable', $metadatas);
|
|
$this->assertArrayHasKey('multivalue', $metadatas);
|
|
$this->assertArrayHasKey('readonly', $metadatas);
|
|
$this->assertArrayHasKey('required', $metadatas);
|
|
|
|
$this->assertTrue(is_int($metadatas['id']));
|
|
$this->assertTrue(is_string($metadatas['namespace']));
|
|
$this->assertTrue(is_string($metadatas['name']));
|
|
$this->assertTrue(is_null($metadatas['source']) || is_string($metadatas['source']));
|
|
$this->assertTrue(is_string($metadatas['tagname']));
|
|
$this->assertTrue((strlen($metadatas['name']) > 0));
|
|
$this->assertTrue(is_string($metadatas['separator']));
|
|
|
|
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)));
|
|
$this->assertTrue(is_bool($metadatas['indexable']));
|
|
$this->assertTrue(is_bool($metadatas['multivalue']));
|
|
$this->assertTrue(is_bool($metadatas['readonly']));
|
|
$this->assertTrue(is_bool($metadatas['required']));
|
|
|
|
$element = $ref_structure->get_element($metadatas['id']);
|
|
$this->assertTrue($element->is_indexable() === $metadatas['indexable']);
|
|
$this->assertTrue($element->is_required() === $metadatas['required']);
|
|
$this->assertTrue($element->is_readonly() === $metadatas['readonly']);
|
|
$this->assertTrue($element->is_multi() === $metadatas['multivalue']);
|
|
$this->assertTrue($element->get_type() === $metadatas['type']);
|
|
$this->assertTrue($element->get_tbranch() === $metadatas['thesaurus_branch']);
|
|
$this->assertTrue($element->get_separator() === $metadatas['separator']);
|
|
$this->assertTrue($element->get_name() === $metadatas['name']);
|
|
$this->assertTrue($element->get_tag()->getName() === $metadatas['tagname']);
|
|
$this->assertTrue($element->get_tag()->getTagname() === $metadatas['source']);
|
|
$this->assertTrue($element->get_tag()->getGroupName() === $metadatas['namespace']);
|
|
}
|
|
}
|
|
$route = '/databoxes/24892534/metadatas/';
|
|
$this->evaluateNotFoundRoute($route, array('GET'));
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
$route = '/databoxes/any_bad_id/metadatas/';
|
|
$this->evaluateBadRequestRoute($route, array('GET'));
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
}
|
|
|
|
/**
|
|
* @covers \API_V1_adapter::get_databox_terms
|
|
* @covers \API_V1_adapter::list_databox_terms
|
|
*
|
|
*/
|
|
public function testDataboxTermsOfUseRoute()
|
|
{
|
|
$this->setToken(self::$token);
|
|
foreach (static::$databoxe_ids as $databox_id) {
|
|
$route = '/databoxes/' . $databox_id . '/termsOfUse/';
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
|
|
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
|
|
$this->assertArrayHasKey('termsOfUse', $content['response']);
|
|
foreach ($content['response']['termsOfUse'] as $terms) {
|
|
$this->assertTrue(is_array($terms), 'Une bloc cgu est un objet');
|
|
$this->assertArrayHasKey('locale', $terms);
|
|
$this->assertTrue(in_array($terms['locale'], array('fr_FR', 'en_GB', 'ar_SA', 'de_DE', 'es_ES')));
|
|
$this->assertArrayHasKey('terms', $terms);
|
|
}
|
|
}
|
|
$route = '/databoxes/24892534/termsOfUse/';
|
|
$this->evaluateNotFoundRoute($route, array('GET'));
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
$route = '/databoxes/any_bad_id/termsOfUse/';
|
|
$this->evaluateBadRequestRoute($route, array('GET'));
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
}
|
|
|
|
/**
|
|
* @covers \API_V1_adapter::search_records
|
|
* @covers \API_V1_adapter::list_record
|
|
*/
|
|
public function testRecordsSearchRoute()
|
|
{
|
|
$this->setToken(self::$token);
|
|
$crawler = $this->client->request('POST', '/records/search/', array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
|
|
$response = $content['response'];
|
|
|
|
$this->assertArrayHasKey('total_pages', $response);
|
|
$this->assertArrayHasKey('current_page', $response);
|
|
$this->assertArrayHasKey('available_results', $response);
|
|
$this->assertArrayHasKey('total_results', $response);
|
|
$this->assertArrayHasKey('error', $response);
|
|
$this->assertArrayHasKey('warning', $response);
|
|
$this->assertArrayHasKey('query_time', $response);
|
|
$this->assertArrayHasKey('search_indexes', $response);
|
|
$this->assertArrayHasKey('suggestions', $response);
|
|
$this->assertArrayHasKey('results', $response);
|
|
$this->assertArrayHasKey('query', $response);
|
|
|
|
|
|
$this->assertTrue(is_int($response['total_pages']), 'Le nombre de page est un int');
|
|
$this->assertTrue(is_int($response['current_page']), 'Le nombre de la page courrante est un int');
|
|
$this->assertTrue(is_int($response['available_results']), 'Le nombre de results dispo est un int');
|
|
$this->assertTrue(is_int($response['total_results']), 'Le nombre de results est un int');
|
|
$this->assertTrue(is_string($response['error']), 'Error est une string');
|
|
$this->assertTrue(is_string($response['warning']), 'Warning est une string');
|
|
|
|
// $this->assertTrue(is_string($response['query_time']));
|
|
$this->assertTrue(is_string($response['search_indexes']));
|
|
$this->assertTrue(is_array($response['suggestions']));
|
|
$this->assertTrue(is_array($response['results']));
|
|
$this->assertTrue(is_string($response['query']));
|
|
|
|
foreach ($response['results'] as $record) {
|
|
$this->evaluateGoodRecord($record);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @covers \API_V1_adapter::caption_records
|
|
*/
|
|
public function testRecordsCaptionRoute()
|
|
{
|
|
$this->setToken(self::$token);
|
|
|
|
$this->injectMetadatas(static::$records['record_1']);
|
|
|
|
$route = '/records/' . static::$records['record_1']->get_sbas_id() . '/' . static::$records['record_1']->get_record_id() . '/caption/';
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
|
|
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
|
|
$this->evaluateRecordsCaptionResponse($content);
|
|
|
|
$route = '/records/24892534/51654651553/caption/';
|
|
$this->evaluateNotFoundRoute($route, array('GET'));
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
$route = '/records/any_bad_id/sfsd5qfsd5/caption/';
|
|
$this->evaluateBadRequestRoute($route, array('GET'));
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
}
|
|
|
|
/**
|
|
* @covers \API_V1_adapter::get_record_metadatas
|
|
* @covers \API_V1_adapter::list_record_caption
|
|
*/
|
|
public function testRecordsMetadatasRoute()
|
|
{
|
|
$this->setToken(self::$token);
|
|
|
|
$route = '/records/' . static::$records['record_1']->get_sbas_id() . '/' . static::$records['record_1']->get_record_id() . '/metadatas/';
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
|
|
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
|
|
$this->evaluateRecordsMetadataResponse($content);
|
|
|
|
$route = '/records/24892534/51654651553/metadatas/';
|
|
$this->evaluateNotFoundRoute($route, array('GET'));
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
$route = '/records/any_bad_id/sfsd5qfsd5/metadatas/';
|
|
$this->evaluateBadRequestRoute($route, array('GET'));
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
}
|
|
|
|
/**
|
|
* @covers \API_V1_adapter::get_record_status
|
|
*/
|
|
public function testRecordsStatusRoute()
|
|
{
|
|
$this->setToken(self::$token);
|
|
|
|
$route = '/records/' . static::$records['record_1']->get_sbas_id() . '/' . static::$records['record_1']->get_record_id() . '/status/';
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
|
|
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
|
|
$this->evaluateRecordsStatusResponse(static::$records['record_1'], $content);
|
|
|
|
$route = '/records/24892534/51654651553/status/';
|
|
$this->evaluateNotFoundRoute($route, array('GET'));
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
$route = '/records/any_bad_id/sfsd5qfsd5/status/';
|
|
$this->evaluateBadRequestRoute($route, array('GET'));
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
}
|
|
|
|
/**
|
|
* @covers \API_V1_adapter::get_record_embed
|
|
* @covers \API_V1_adapter::list_embedable_media
|
|
* @covers \API_V1_adapter::list_permalink
|
|
*/
|
|
public function testRecordsEmbedRoute()
|
|
{
|
|
$this->setToken(self::$token);
|
|
|
|
$keys = array_keys(static::$records['record_1']->get_subdefs());
|
|
|
|
$route = '/records/' . static::$records['record_1']->get_sbas_id() . '/' . static::$records['record_1']->get_record_id() . '/embed/';
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
|
|
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
|
|
foreach ($content['response'] as $embed) {
|
|
foreach ($keys as $key) {
|
|
$this->assertArrayHasKey($key, $embed);
|
|
$this->checkEmbed($key, $embed[$key], static::$records['record_1']);
|
|
}
|
|
}
|
|
$route = '/records/24892534/51654651553/embed/';
|
|
$this->evaluateNotFoundRoute($route, array('GET'));
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
$route = '/records/any_bad_id/sfsd5qfsd5/embed/';
|
|
$this->evaluateBadRequestRoute($route, array('GET'));
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
}
|
|
|
|
/**
|
|
* @covers \API_V1_adapter::get_record_embed
|
|
*/
|
|
public function testRecordsEmbedRouteMimeType()
|
|
{
|
|
$this->setToken(self::$token);
|
|
|
|
$route = '/records/' . static::$records['record_1']->get_sbas_id() . '/' . static::$records['record_1']->get_record_id() . '/embed/';
|
|
|
|
$this->client->request('GET', $route, array('mimes' => array('image/jpg', 'image/jpeg')), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
foreach ($content['response'] as $embed) {
|
|
foreach (array('thumbnail', 'preview') as $key) {
|
|
$this->assertArrayHasKey($key, $embed);
|
|
$this->checkEmbed($key, $embed[$key], static::$records['record_1']);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @covers \API_V1_adapter::get_record_related
|
|
*/
|
|
public function testRecordsEmbedRouteDevices()
|
|
{
|
|
$this->setToken(self::$token);
|
|
|
|
$route = '/records/' . static::$records['record_1']->get_sbas_id() . '/' . static::$records['record_1']->get_record_id() . '/embed/';
|
|
|
|
$this->client->request('GET', $route, array('devices' => array('nodevice')), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->assertEquals(0, count($content['response']['embed']));
|
|
}
|
|
|
|
/**
|
|
* @covers \API_V1_adapter::get_record_related
|
|
*/
|
|
public function testRecordsRelatedRoute()
|
|
{
|
|
$this->setToken(self::$token);
|
|
|
|
$route = '/records/' . static::$records['record_1']->get_sbas_id() . '/' . static::$records['record_1']->get_record_id() . '/related/';
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
|
|
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
$this->assertArrayHasKey("baskets", $content['response']);
|
|
|
|
foreach ($content['response']['baskets'] as $basket) {
|
|
$this->evaluateGoodBasket($basket);
|
|
}
|
|
|
|
$route = '/records/24892534/51654651553/related/';
|
|
$this->evaluateNotFoundRoute($route, array('GET'));
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
$route = '/records/any_bad_id/sfsd5qfsd5/related/';
|
|
$this->evaluateBadRequestRoute($route, array('GET'));
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
}
|
|
|
|
/**
|
|
* @covers \API_V1_adapter::set_record_metadatas
|
|
* @covers \API_V1_adapter::list_record_caption
|
|
* @covers \API_V1_adapter::list_record_caption_field
|
|
*/
|
|
public function testRecordsSetMetadatas()
|
|
{
|
|
$this->setToken(self::$token);
|
|
|
|
$file = new \Alchemy\Phrasea\Border\File(\MediaVorus\MediaVorus::guess(new \SplFileInfo(__DIR__ . '/../../../testfiles/test001.CR2')), self::$collection);
|
|
$record = \record_adapter::createFromFile($file);
|
|
|
|
$route = '/records/' . $record->get_sbas_id() . '/' . $record->get_record_id() . '/setmetadatas/';
|
|
$caption = $record->get_caption();
|
|
|
|
$toupdate = array();
|
|
|
|
foreach ($record->get_databox()->get_meta_structure()->get_elements() as $field) {
|
|
try {
|
|
$values = $record->get_caption()->get_field($field->get_name())->get_values();
|
|
$value = array_pop($values);
|
|
$meta_id = $value->getId();
|
|
} catch (\Exception $e) {
|
|
$meta_id = null;
|
|
}
|
|
|
|
$toupdate[$field->get_id()] = array(
|
|
'meta_id' => $meta_id
|
|
, 'meta_struct_id' => $field->get_id()
|
|
, 'value' => 'podom pom pom ' . $field->get_id()
|
|
);
|
|
}
|
|
|
|
$this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE'));
|
|
|
|
$this->client->request('POST', $route, array('metadatas' => $toupdate), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
|
|
$caption = $record->get_caption();
|
|
|
|
$this->assertEquals(count($caption->get_fields()), count($content['response']['metadatas']), 'Retrived metadatas are the same');
|
|
|
|
foreach ($caption->get_fields() as $field) {
|
|
foreach ($field->get_values() as $value) {
|
|
if ($field->is_readonly() === false && $field->is_multi() === false) {
|
|
$saved_value = $toupdate[$field->get_meta_struct_id()]['value'];
|
|
$this->assertEquals($value->getValue(), $saved_value);
|
|
}
|
|
}
|
|
}
|
|
|
|
$this->evaluateRecordsMetadataResponse($content);
|
|
|
|
foreach ($content['response']['metadatas'] as $metadata) {
|
|
if ( ! in_array($metadata['meta_id'], array_keys($toupdate)))
|
|
continue;
|
|
$saved_value = $toupdate[$metadata['meta_structure_id']]['value'];
|
|
$this->assertEquals($saved_value, $metadata['value']);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @covers \API_V1_adapter::set_record_status
|
|
* @covers \API_V1_adapter::list_record_status
|
|
*/
|
|
public function testRecordsSetStatus()
|
|
{
|
|
$this->setToken(self::$token);
|
|
|
|
$route = '/records/' . static::$records['record_1']->get_sbas_id() . '/' . static::$records['record_1']->get_record_id() . '/setstatus/';
|
|
|
|
$record_status = strrev(static::$records['record_1']->get_status());
|
|
$status_bits = static::$records['record_1']->get_databox()->get_statusbits();
|
|
|
|
$tochange = array();
|
|
foreach ($status_bits as $n => $datas) {
|
|
$tochange[$n] = substr($record_status, ($n - 1), 1) == '0' ? '1' : '0';
|
|
}
|
|
$this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE'));
|
|
|
|
|
|
$crawler = $this->client->request('POST', $route, array('status' => $tochange), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
/**
|
|
* Get fresh record_1
|
|
*/
|
|
static::$records['record_1'] = static::$records['record_1']->get_databox()->get_record(static::$records['record_1']->get_record_id());
|
|
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
|
|
$this->evaluateRecordsStatusResponse(static::$records['record_1'], $content);
|
|
|
|
$record_status = strrev(static::$records['record_1']->get_status());
|
|
foreach ($status_bits as $n => $datas) {
|
|
$this->assertEquals(substr($record_status, ($n - 1), 1), $tochange[$n]);
|
|
}
|
|
|
|
foreach ($tochange as $n => $value) {
|
|
$tochange[$n] = $value == '0' ? '1' : '0';
|
|
}
|
|
|
|
|
|
$crawler = $this->client->request('POST', $route, array('status' => $tochange), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
/**
|
|
* Get fresh record_1
|
|
*/
|
|
static::$records['record_1'] = static::$records['record_1']->get_databox()->get_record(static::$records['record_1']->get_record_id());
|
|
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
|
|
$this->evaluateRecordsStatusResponse(static::$records['record_1'], $content);
|
|
|
|
$record_status = strrev(static::$records['record_1']->get_status());
|
|
foreach ($status_bits as $n => $datas) {
|
|
$this->assertEquals(substr($record_status, ($n - 1), 1), $tochange[$n]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @covers \API_V1_adapter::set_record_collection
|
|
*/
|
|
public function testMoveRecordToCollection()
|
|
{
|
|
$file = new \Alchemy\Phrasea\Border\File(\MediaVorus\MediaVorus::guess(new \SplFileInfo(__DIR__ . '/../../../testfiles/test001.CR2')), self::$collection);
|
|
$record = \record_adapter::createFromFile($file);
|
|
|
|
$this->setToken(self::$token);
|
|
|
|
$route = '/records/' . $record->get_sbas_id() . '/' . $record->get_record_id() . '/setcollection/';
|
|
|
|
$base_id = false;
|
|
foreach ($record->get_databox()->get_collections() as $collection) {
|
|
if ($collection->get_base_id() != $record->get_base_id()) {
|
|
$base_id = $collection->get_base_id();
|
|
break;
|
|
}
|
|
}
|
|
if ( ! $base_id) {
|
|
continue;
|
|
}
|
|
|
|
$this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE'));
|
|
|
|
$this->client->request('POST', $route, array('base_id' => $base_id), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
|
|
$record->delete();
|
|
}
|
|
|
|
/**
|
|
* @covers \API_V1_adapter::search_baskets
|
|
* @covers \API_V1_adapter::list_baskets
|
|
* @covers \API_V1_adapter::list_basket
|
|
*/
|
|
public function testSearchBaskets()
|
|
{
|
|
$this->insertFiveBasket();
|
|
$this->insertOneValidationBasket();
|
|
|
|
$this->setToken(self::$token);
|
|
$route = '/baskets/list/';
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
|
|
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
$this->assertArrayHasKey("baskets", $content['response']);
|
|
|
|
foreach ($content['response']['baskets'] as $basket) {
|
|
$this->evaluateGoodBasket($basket);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @covers \API_V1_adapter::create_basket
|
|
* @covers \API_V1_adapter::list_basket
|
|
*/
|
|
public function testAddBasket()
|
|
{
|
|
$this->setToken(self::$token);
|
|
|
|
$route = '/baskets/add/';
|
|
|
|
$this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE'));
|
|
|
|
$this->client->request('POST', $route, array('name' => 'un Joli Nom'), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
|
|
$this->assertEquals(1, count($content['response']));
|
|
$this->assertArrayHasKey("basket", $content['response']);
|
|
|
|
foreach ($content['response']['basket'] as $basket) {
|
|
$this->evaluateGoodBasket($basket);
|
|
$this->assertEquals('un Joli Nom', $basket['name']);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @covers \API_V1_adapter::get_basket
|
|
* @covers \API_V1_adapter::list_basket_content
|
|
* @covers \API_V1_adapter::list_basket_element
|
|
*/
|
|
public function testBasketContent()
|
|
{
|
|
$this->setToken(self::$token);
|
|
|
|
$basketElement = $this->insertOneBasketElement();
|
|
$basket = $basketElement->getBasket();
|
|
|
|
$route = '/baskets/' . $basket->getId() . '/content/';
|
|
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
|
|
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
|
|
$this->assertEquals(1, count((array) $content['response']));
|
|
|
|
$this->assertArrayHasKey("basket_elements", $content['response']);
|
|
|
|
foreach ($content['response']['basket_elements'] as $basket_str) {
|
|
$this->evaluateGoodBasket($basket_str);
|
|
|
|
$this->assertEquals(count($basket->getElements()), count($basket_str['basket_elements']));
|
|
foreach ($basket_str['basket_elements'] as $basket_element) {
|
|
$this->assertArrayHasKey('basket_element_id', $basket_element);
|
|
$this->assertArrayHasKey('order', $basket_element);
|
|
$this->assertArrayHasKey('record', $basket_element);
|
|
$this->assertArrayHasKey('validation_item', $basket_element);
|
|
$this->assertTrue(is_bool($basket_element['validation_item']));
|
|
$this->assertTrue(is_int($basket_element['order']));
|
|
$this->assertTrue(is_int($basket_element['basket_element_id']));
|
|
$this->evaluateGoodRecord($basket_element['record']);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @covers \API_V1_adapter::set_basket_title
|
|
* @covers \API_V1_adapter::list_basket_content
|
|
* @covers \API_V1_adapter::list_basket_element
|
|
*/
|
|
public function testSetBasketTitle()
|
|
{
|
|
$this->setToken(self::$token);
|
|
|
|
$basket = $this->insertOneBasket();
|
|
|
|
$route = '/baskets/' . $basket->getId() . '/setname/';
|
|
|
|
$this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE'));
|
|
|
|
$crawler = $this->client->request('POST', $route, array('name' => 'un Joli Nom'), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
|
|
$this->assertEquals(1, count((array) $content['response']));
|
|
$this->assertArrayHasKey("basket", $content['response']);
|
|
foreach ($content['response']['basket'] as $basket_str) {
|
|
$this->evaluateGoodBasket($basket_str);
|
|
|
|
$this->assertEquals($basket_str['name'], 'un Joli Nom');
|
|
}
|
|
|
|
$crawler = $this->client->request('POST', $route, array('name' => '<i>un Joli Nom<i>'), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
|
|
$this->assertEquals(1, count((array) $content['response']));
|
|
|
|
$this->assertArrayHasKey("basket", $content['response']);
|
|
|
|
foreach ($content['response']['basket'] as $basket) {
|
|
$this->evaluateGoodBasket($basket_str);
|
|
|
|
$this->assertEquals($basket_str['name'], 'un Joli Nom');
|
|
}
|
|
|
|
$crawler = $this->client->request('POST', $route, array('name' => '<strong>aéaa'), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
|
|
$this->assertEquals(1, count((array) $content['response']));
|
|
$this->assertArrayHasKey("basket", $content['response']);
|
|
foreach ($content['response']['basket'] as $basket_str) {
|
|
$this->evaluateGoodBasket($basket_str);
|
|
$this->assertEquals($basket_str['name'], '<strong>aéaa');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @covers \API_V1_adapter::set_basket_description
|
|
* @covers \API_V1_adapter::list_basket_content
|
|
* @covers \API_V1_adapter::list_basket_element
|
|
*/
|
|
public function testSetBasketDescription()
|
|
{
|
|
$this->setToken(self::$token);
|
|
|
|
$basket = $this->insertOneBasket();
|
|
|
|
$route = '/baskets/' . $basket->getId() . '/setdescription/';
|
|
|
|
$this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE'));
|
|
|
|
$this->client->request('POST', $route, array('description' => 'une belle desc'), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
|
|
$this->assertEquals(1, count((array) $content['response']));
|
|
|
|
$this->assertArrayHasKey("basket", $content['response']);
|
|
foreach ($content['response']['basket'] as $basket_str) {
|
|
$this->evaluateGoodBasket($basket_str);
|
|
|
|
$this->assertEquals($basket_str['description'], 'une belle desc');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @covers \API_V1_adapter::delete_basket
|
|
*/
|
|
public function testDeleteBasket()
|
|
{
|
|
$this->setToken(self::$token);
|
|
|
|
$baskets = $this->insertFiveBasket();
|
|
|
|
$route = '/baskets/' . $baskets[0]->getId() . '/delete/';
|
|
|
|
$this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE'));
|
|
|
|
$this->client->request('POST', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
|
|
$this->assertArrayHasKey("baskets", $content['response']);
|
|
|
|
$found = false;
|
|
foreach ($content['response']['baskets'] as $basket) {
|
|
$this->evaluateGoodBasket($basket);
|
|
$found = true;
|
|
}
|
|
if ( ! $found) {
|
|
$this->fail('There should be four baskets left');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @covers \API_V1_adapter::add_record
|
|
* @covers \API_V1_adapter::list_record
|
|
*/
|
|
public function testAddRecord()
|
|
{
|
|
$this->setToken(self::$token);
|
|
$route = '/records/add/';
|
|
|
|
$params = $this->getAddRecordParameters();
|
|
$params['status'] = '0b10000';
|
|
|
|
$this->client->request('POST', $route, $params, $this->getAddRecordFile(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
/**
|
|
* check that there is a record or lazaret
|
|
*/
|
|
}
|
|
|
|
/**
|
|
* @covers \API_V1_adapter::add_record
|
|
* @covers \API_V1_adapter::list_record
|
|
*/
|
|
public function testAddRecordForceRecord()
|
|
{
|
|
$this->setToken(self::$token);
|
|
$route = '/records/add/';
|
|
|
|
$params = $this->getAddRecordParameters();
|
|
$params['forceBehavior'] = '0';
|
|
|
|
$this->client->request('POST', $route, $params, $this->getAddRecordFile(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
$datas = $content['response'];
|
|
|
|
$this->assertArrayHasKey('entity', $datas);
|
|
$this->assertArrayHasKey('record', $datas);
|
|
|
|
// if forced, there is no reason
|
|
$this->assertEquals('0', $datas['entity']);
|
|
|
|
$this->evaluateGoodRecord($datas['record']);
|
|
}
|
|
|
|
/**
|
|
* @covers \API_V1_adapter::add_record
|
|
* @covers \API_V1_adapter::list_lazaret_file
|
|
*/
|
|
public function testAddRecordForceLazaret()
|
|
{
|
|
$this->setToken(self::$token);
|
|
$route = '/records/add/';
|
|
|
|
$params = $this->getAddRecordParameters();
|
|
$params['forceBehavior'] = '1';
|
|
|
|
$this->client->request('POST', $route, $params, $this->getAddRecordFile(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
$datas = $content['response'];
|
|
|
|
$this->assertArrayHasKey('entity', $datas);
|
|
$this->assertArrayHasKey('reasons', $datas);
|
|
$this->assertArrayHasKey('lazaretFile', $datas);
|
|
|
|
// if forced, there is no reason
|
|
$this->assertEquals(array(), $datas['reasons']);
|
|
$this->assertEquals('1', $datas['entity']);
|
|
|
|
$this->checkLazaretFile($datas['lazaretFile']);
|
|
|
|
$this->assertEquals(array(), $datas['lazaretFile']['checks']);
|
|
$this->assertEquals(true, $datas['lazaretFile']['forced']);
|
|
$this->assertEquals(self::$core->getAuthenticatedUser()->get_id(), $datas['lazaretFile']['session']['usr_id']);
|
|
$this->assertEquals('upload.jpg', $datas['lazaretFile']['original_name']);
|
|
$this->assertEquals(self::$collection->get_base_id(), $datas['lazaretFile']['base_id']);
|
|
}
|
|
|
|
/**
|
|
* @covers \API_V1_adapter::add_record
|
|
*/
|
|
public function testAddRecordWrongBehavior()
|
|
{
|
|
$this->setToken(self::$token);
|
|
$route = '/records/add/';
|
|
|
|
$params = $this->getAddRecordParameters();
|
|
$params['forceBehavior'] = '2';
|
|
|
|
$this->client->request('POST', $route, $params, $this->getAddRecordFile(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->evaluateResponseBadRequest($this->client->getResponse());
|
|
$this->evaluateMetaBadRequest($content);
|
|
}
|
|
|
|
/**
|
|
* @covers \API_V1_adapter::add_record
|
|
*/
|
|
public function testAddRecordWrongBaseId()
|
|
{
|
|
$this->setToken(self::$token);
|
|
$route = '/records/add/';
|
|
|
|
$params = $this->getAddRecordParameters();
|
|
$params['base_id'] = self::$collection_no_access->get_base_id();
|
|
|
|
$this->client->request('POST', $route, $params, $this->getAddRecordFile(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->evaluateResponseForbidden($this->client->getResponse());
|
|
$this->evaluateMetaForbidden($content);
|
|
}
|
|
|
|
/**
|
|
* @covers \API_V1_adapter::add_record
|
|
*/
|
|
public function testAddRecordNoBaseId()
|
|
{
|
|
$this->setToken(self::$token);
|
|
$route = '/records/add/';
|
|
|
|
$params = $this->getAddRecordParameters();
|
|
unset($params['base_id']);
|
|
|
|
$this->client->request('POST', $route, $params, $this->getAddRecordFile(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->evaluateResponseBadRequest($this->client->getResponse());
|
|
$this->evaluateMetaBadRequest($content);
|
|
}
|
|
|
|
/**
|
|
* @covers \API_V1_adapter::add_record
|
|
*/
|
|
public function testAddRecordMultipleFiles()
|
|
{
|
|
$this->setToken(self::$token);
|
|
$route = '/records/add/';
|
|
|
|
$file = array(
|
|
new \Symfony\Component\HttpFoundation\File\UploadedFile(__FILE__, 'upload.txt'),
|
|
new \Symfony\Component\HttpFoundation\File\UploadedFile(__FILE__, 'upload.txt'),
|
|
);
|
|
|
|
$this->client->request('POST', $route, $this->getAddRecordParameters(), array('file' => $file), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->evaluateResponseBadRequest($this->client->getResponse());
|
|
$this->evaluateMetaBadRequest($content);
|
|
}
|
|
|
|
public function testAddRecordNofile()
|
|
{
|
|
$this->setToken(self::$token);
|
|
$route = '/records/add/';
|
|
|
|
$this->client->request('POST', $route, $this->getAddRecordParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->evaluateResponseBadRequest($this->client->getResponse());
|
|
$this->evaluateMetaBadRequest($content);
|
|
}
|
|
|
|
/**
|
|
* @covers \API_V1_adapter::search_publications
|
|
* @covers \API_V1_adapter::list_publication
|
|
*/
|
|
public function testFeedList()
|
|
{
|
|
$title = 'Yellow title';
|
|
$subtitle = 'Trololololo !';
|
|
|
|
$created_feed = \Feed_Adapter::create(\appbox::get_instance(self::$core), self::$user, $title, $subtitle);
|
|
|
|
$this->setToken(self::$token);
|
|
$route = '/feeds/list/';
|
|
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
|
|
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
|
|
$this->assertArrayHasKey('feeds', $content['response']);
|
|
|
|
$found = false;
|
|
foreach ($content['response']['feeds'] as $feed_id => $feed) {
|
|
|
|
$this->evaluateGoodFeed($feed);
|
|
|
|
if ($feed_id == $created_feed->get_id()) {
|
|
$found = true;
|
|
$this->assertEquals($title, $feed['title']);
|
|
$this->assertEquals($subtitle, $feed['subtitle']);
|
|
}
|
|
}
|
|
|
|
$created_feed->delete();
|
|
|
|
if ( ! $found) {
|
|
$this->fail('feed not found !');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @covers \API_V1_adapter::get_publications
|
|
* @covers \API_V1_adapter::list_aggregate_publications
|
|
* @covers \API_V1_adapter::list_publications_entries
|
|
* @covers \API_V1_adapter::list_publication_entry
|
|
* @covers \API_V1_adapter::list_publication_entry_item
|
|
* @covers \API_V1_adapter::list_record
|
|
*/
|
|
public function testFeedsContent()
|
|
{
|
|
$appbox = \appbox::get_instance(self::$core);
|
|
|
|
$title = 'Yellow title';
|
|
$subtitle = 'Trololololo !';
|
|
$entry_title = 'Superman';
|
|
$entry_subtitle = 'Wonder Woman';
|
|
$author = "W. Shakespeare";
|
|
$author_email = "gontran.bonheur@gmail.com";
|
|
|
|
$created_feed = \Feed_Adapter::create($appbox, self::$user, $title, $subtitle);
|
|
$publisher = \Feed_Publisher_Adapter::getPublisher($appbox, $created_feed, self::$user);
|
|
|
|
$created_entry = \Feed_Entry_Adapter::create($appbox, $created_feed, $publisher, $entry_title, $entry_subtitle, $author, $author_email);
|
|
$created_item = \Feed_Entry_Item::create($appbox, $created_entry, static::$records['record_1']);
|
|
|
|
|
|
$this->setToken(self::$token);
|
|
$route = '/feeds/content/';
|
|
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
|
|
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
|
|
|
|
$this->assertArrayHasKey('total_entries', $content['response']);
|
|
$this->assertArrayHasKey('offset_start', $content['response']);
|
|
$this->assertArrayHasKey('per_page', $content['response']);
|
|
$this->assertArrayHasKey('entries', $content['response']);
|
|
|
|
$found = false;
|
|
|
|
foreach ($content['response']['entries'] as $entry_id => $entry) {
|
|
$this->assertGoodEntry($entry);
|
|
|
|
if ($entry_id == $created_entry->get_id()) {
|
|
$found = true;
|
|
$this->assertEquals($author_email, $entry['author_email']);
|
|
$this->assertEquals($author, $entry['author_name']);
|
|
$this->assertEquals($entry_title, $entry['title']);
|
|
$this->assertEquals($entry_subtitle, $entry['subtitle']);
|
|
}
|
|
}
|
|
|
|
$created_feed->delete();
|
|
|
|
if ( ! $found) {
|
|
$this->fail('entry not found !');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @covers \API_V1_adapter::get_feed_entry
|
|
* @covers \API_V1_adapter::list_publication_entry
|
|
*/
|
|
public function testFeedEntry()
|
|
{
|
|
$appbox = \appbox::get_instance(self::$core);
|
|
|
|
$title = 'Yellow title';
|
|
$subtitle = 'Trololololo !';
|
|
$entry_title = 'Superman';
|
|
$entry_subtitle = 'Wonder Woman';
|
|
$author = "W. Shakespeare";
|
|
$author_email = "gontran.bonheur@gmail.com";
|
|
|
|
$created_feed = \Feed_Adapter::create($appbox, self::$user, $title, $subtitle);
|
|
$publisher = \Feed_Publisher_Adapter::getPublisher($appbox, $created_feed, self::$user);
|
|
|
|
$created_entry = \Feed_Entry_Adapter::create($appbox, $created_feed, $publisher, $entry_title, $entry_subtitle, $author, $author_email);
|
|
$created_item = \Feed_Entry_Item::create($appbox, $created_entry, static::$records['record_1']);
|
|
|
|
$this->setToken(self::$token);
|
|
$route = '/feeds/entry/' . $created_entry->get_id() . '/';
|
|
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
|
|
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
|
|
$this->assertArrayHasKey('entry', $content['response']);
|
|
$this->assertGoodEntry($content['response']['entry']);
|
|
|
|
$this->assertEquals($created_entry->get_id(), $content['response']['entry']['id']);
|
|
|
|
$created_feed->delete();
|
|
}
|
|
|
|
/**
|
|
* @covers \API_V1_adapter::get_feed_entry
|
|
* @covers \API_V1_adapter::list_publication_entry
|
|
*/
|
|
public function testFeedEntryNoAccess()
|
|
{
|
|
$appbox = \appbox::get_instance(self::$core);
|
|
|
|
$title = 'Yellow title';
|
|
$subtitle = 'Trololololo !';
|
|
$entry_title = 'Superman';
|
|
$entry_subtitle = 'Wonder Woman';
|
|
$author = "W. Shakespeare";
|
|
$author_email = "gontran.bonheur@gmail.com";
|
|
|
|
$created_feed = \Feed_Adapter::create($appbox, self::$user, $title, $subtitle);
|
|
$publisher = \Feed_Publisher_Adapter::getPublisher($appbox, $created_feed, self::$user);
|
|
|
|
$created_entry = \Feed_Entry_Adapter::create($appbox, $created_feed, $publisher, $entry_title, $entry_subtitle, $author, $author_email);
|
|
$created_item = \Feed_Entry_Item::create($appbox, $created_entry, static::$records['record_1']);
|
|
|
|
$created_feed->set_collection(self::$collection_no_access);
|
|
|
|
$this->setToken(self::$token);
|
|
$route = '/feeds/entry/' . $created_entry->get_id() . '/';
|
|
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
|
|
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->evaluateResponseForbidden($this->client->getResponse());
|
|
$this->evaluateMetaForbidden($content);
|
|
}
|
|
|
|
/**
|
|
* @covers \API_V1_adapter::get_publication
|
|
* @covers \API_V1_adapter::list_publications_entries
|
|
* @covers \API_V1_adapter::list_publication_entry
|
|
* @covers \API_V1_adapter::list_publication_entry_item
|
|
* @covers \API_V1_adapter::list_record
|
|
*/
|
|
public function testFeedContent()
|
|
{
|
|
$appbox = \appbox::get_instance(self::$core);
|
|
|
|
$title = 'Yellow title';
|
|
$subtitle = 'Trololololo !';
|
|
$entry_title = 'Superman';
|
|
$entry_subtitle = 'Wonder Woman';
|
|
$author = "W. Shakespeare";
|
|
$author_email = "gontran.bonheur@gmail.com";
|
|
|
|
$created_feed = \Feed_Adapter::create($appbox, self::$user, $title, $subtitle);
|
|
$publisher = \Feed_Publisher_Adapter::getPublisher($appbox, $created_feed, self::$user);
|
|
|
|
$created_entry = \Feed_Entry_Adapter::create($appbox, $created_feed, $publisher, $entry_title, $entry_subtitle, $author, $author_email);
|
|
$created_item = \Feed_Entry_Item::create($appbox, $created_entry, static::$records['record_1']);
|
|
|
|
$this->setToken(self::$token);
|
|
$route = '/feeds/' . $created_feed->get_id() . '/content/';
|
|
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
|
|
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->evaluateResponse200($this->client->getResponse());
|
|
$this->evaluateMeta200($content);
|
|
|
|
$this->assertArrayHasKey('feed', $content['response']);
|
|
$this->assertArrayHasKey('entries', $content['response']);
|
|
$this->evaluateGoodFeed($content['response']['feed']);
|
|
|
|
$found = false;
|
|
foreach ($content['response']['entries'] as $entry) {
|
|
$this->assertGoodEntry($entry);
|
|
|
|
if ($entry['id'] == $created_entry->get_id()) {
|
|
$this->assertEquals($entry_title, $entry['title']);
|
|
$this->assertEquals($entry_subtitle, $entry['subtitle']);
|
|
$found = true;
|
|
}
|
|
}
|
|
|
|
$this->assertEquals($created_feed->get_id(), $content['response']['feed']['id']);
|
|
|
|
$created_feed->delete();
|
|
|
|
if ( ! $found) {
|
|
$this->fail('Entry not found');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @covers list_lazaret_file
|
|
* @covers list_quarantine
|
|
* @covers list_quarantine_item
|
|
*/
|
|
public function testQuarantineList()
|
|
{
|
|
$this->setToken(self::$token);
|
|
$route = '/quarantine/list/';
|
|
|
|
$quarantineItemId = $this->getQuarantineItem()->getId();
|
|
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
|
|
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->assertArrayHasKey('offset_start', $content['response']);
|
|
$this->assertArrayHasKey('per_page', $content['response']);
|
|
$this->assertArrayHasKey('items', $content['response']);
|
|
|
|
$found = false;
|
|
foreach ($content['response']['items'] as $item) {
|
|
$this->evaluateGoodQuarantineItem($item);
|
|
if ($item['id'] == $quarantineItemId) {
|
|
$found = true;
|
|
}
|
|
}
|
|
|
|
if ( ! $found) {
|
|
$this->fail('should find the quarantine item');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @covers list_lazaret_file
|
|
* @covers list_quarantine_item
|
|
*/
|
|
public function testQuarantineContent()
|
|
{
|
|
$this->setToken(self::$token);
|
|
|
|
$quarantineItemId = $this->getQuarantineItem()->getId();
|
|
$route = '/quarantine/item/' . $quarantineItemId . '/';
|
|
|
|
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
|
|
|
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->assertArrayHasKey('item', $content['response']);
|
|
|
|
$this->evaluateGoodQuarantineItem($content['response']['item']);
|
|
$this->assertEquals($quarantineItemId, $content['response']['item']['id']);
|
|
}
|
|
|
|
protected function getQuarantineItem()
|
|
{
|
|
$lazaretSession = new \Entities\LazaretSession();
|
|
self::$core['EM']->persist($lazaretSession);
|
|
|
|
$quarantineItem;
|
|
$callback = function ($element, $visa, $code) use (&$quarantineItem) {
|
|
$quarantineItem = $element;
|
|
};
|
|
|
|
$tmpname = tempnam(sys_get_temp_dir(), 'test_quarantine');
|
|
copy(__DIR__ . '/../../../testfiles/iphone_pic.jpg', $tmpname);
|
|
|
|
$file = \Alchemy\Phrasea\Border\File::buildFromPathfile($tmpname, self::$collection);
|
|
self::$core['border-manager']->process($lazaretSession, $file, $callback, \Alchemy\Phrasea\Border\Manager::FORCE_LAZARET);
|
|
|
|
return $quarantineItem;
|
|
}
|
|
|
|
protected function evaluateGoodQuarantineItem($item)
|
|
{
|
|
$this->assertArrayHasKey('id', $item);
|
|
$this->assertArrayHasKey('session', $item);
|
|
$this->assertArrayHasKey('base_id', $item);
|
|
$this->assertArrayHasKey('original_name', $item);
|
|
$this->assertArrayHasKey('sha256', $item);
|
|
$this->assertArrayHasKey('uuid', $item);
|
|
$this->assertArrayHasKey('forced', $item);
|
|
$this->assertArrayHasKey('checks', $item);
|
|
$this->assertArrayHasKey('created_on', $item);
|
|
$this->assertArrayHasKey('updated_on', $item);
|
|
|
|
$this->assertInternalType('boolean', $item['forced']);
|
|
$this->assertDateAtom($item['updated_on']);
|
|
$this->assertDateAtom($item['created_on']);
|
|
}
|
|
|
|
protected function evaluateGoodFeed($feed)
|
|
{
|
|
$this->assertArrayHasKey('id', $feed);
|
|
$this->assertArrayHasKey('title', $feed);
|
|
$this->assertArrayHasKey('subtitle', $feed);
|
|
$this->assertArrayHasKey('total_entries', $feed);
|
|
$this->assertArrayHasKey('icon', $feed);
|
|
$this->assertArrayHasKey('public', $feed);
|
|
$this->assertArrayHasKey('is_mine', $feed);
|
|
$this->assertArrayHasKey('created_on', $feed);
|
|
$this->assertArrayHasKey('updated_on', $feed);
|
|
|
|
$this->assertInternalType('integer', $feed['id']);
|
|
$this->assertInternalType('string', $feed['title']);
|
|
$this->assertInternalType('string', $feed['subtitle']);
|
|
$this->assertInternalType('integer', $feed['total_entries']);
|
|
$this->assertInternalType('string', $feed['icon']);
|
|
$this->assertInternalType('boolean', $feed['public']);
|
|
$this->assertInternalType('boolean', $feed['is_mine']);
|
|
$this->assertInternalType('string', $feed['created_on']);
|
|
$this->assertInternalType('string', $feed['updated_on']);
|
|
|
|
$this->assertDateAtom($feed['created_on']);
|
|
$this->assertDateAtom($feed['updated_on']);
|
|
}
|
|
|
|
protected function assertGoodEntry($entry)
|
|
{
|
|
$this->assertArrayHasKey('id', $entry);
|
|
$this->assertArrayHasKey('author_email', $entry);
|
|
$this->assertArrayHasKey('author_name', $entry);
|
|
$this->assertArrayHasKey('created_on', $entry);
|
|
$this->assertArrayHasKey('updated_on', $entry);
|
|
$this->assertArrayHasKey('title', $entry);
|
|
$this->assertArrayHasKey('subtitle', $entry);
|
|
$this->assertArrayHasKey('items', $entry);
|
|
$this->assertArrayHasKey('url', $entry);
|
|
$this->assertArrayHasKey('feed_url', $entry);
|
|
|
|
$this->assertInternalType('string', $entry['author_email']);
|
|
$this->assertInternalType('string', $entry['author_name']);
|
|
$this->assertDateAtom($entry['created_on']);
|
|
$this->assertDateAtom($entry['updated_on']);
|
|
$this->assertInternalType('string', $entry['title']);
|
|
$this->assertInternalType('string', $entry['subtitle']);
|
|
$this->assertInternalType('array', $entry['items']);
|
|
|
|
foreach ($entry['items'] as $item) {
|
|
$this->assertInternalType('integer', $item['item_id']);
|
|
$this->evaluateGoodRecord($item['record']);
|
|
}
|
|
|
|
$this->assertRegExp('/\/feeds\/entry\/[0-9]+\//', $entry['url']);
|
|
$this->assertRegExp('/\/feeds\/[0-9]+\/content\//', $entry['feed_url']);
|
|
}
|
|
|
|
protected function getAddRecordParameters()
|
|
{
|
|
return array(
|
|
'base_id' => self::$collection->get_base_id()
|
|
);
|
|
}
|
|
|
|
protected function getAddRecordFile()
|
|
{
|
|
$file = tempnam(sys_get_temp_dir(), 'upload');
|
|
copy(__DIR__ . '/../../../testfiles/iphone_pic.jpg', $file);
|
|
|
|
return array(
|
|
'file' => new \Symfony\Component\HttpFoundation\File\UploadedFile($file, 'upload.jpg')
|
|
);
|
|
}
|
|
|
|
protected function checkLazaretFile($file)
|
|
{
|
|
$this->assertArrayHasKey('id', $file);
|
|
$this->assertArrayHasKey('session', $file);
|
|
$this->assertArrayHasKey('base_id', $file);
|
|
$this->assertArrayHasKey('original_name', $file);
|
|
$this->assertArrayHasKey('sha256', $file);
|
|
$this->assertArrayHasKey('uuid', $file);
|
|
$this->assertArrayHasKey('forced', $file);
|
|
$this->assertArrayHasKey('checks', $file);
|
|
$this->assertArrayHasKey('created_on', $file);
|
|
$this->assertArrayHasKey('updated_on', $file);
|
|
|
|
$this->assertInternalType('integer', $file['id']);
|
|
$this->assertInternalType('array', $file['session']);
|
|
$this->assertInternalType('integer', $file['base_id']);
|
|
$this->assertInternalType('string', $file['original_name']);
|
|
$this->assertInternalType('string', $file['sha256']);
|
|
$this->assertInternalType('string', $file['uuid']);
|
|
$this->assertInternalType('boolean', $file['forced']);
|
|
$this->assertInternalType('array', $file['checks']);
|
|
$this->assertInternalType('string', $file['updated_on']);
|
|
$this->assertInternalType('string', $file['created_on']);
|
|
|
|
$this->assertArrayHasKey('id', $file['session']);
|
|
$this->assertArrayHasKey('usr_id', $file['session']);
|
|
|
|
$this->assertRegExp('/[a-f0-9]{64}/i', $file['sha256']);
|
|
$this->assertRegExp('/[a-f0-9-]+/i', $file['uuid']);
|
|
|
|
foreach ($file['checks'] as $check) {
|
|
$this->assertInternalType('string', $check);
|
|
}
|
|
|
|
$this->assertDateAtom($file['updated_on']);
|
|
$this->assertDateAtom($file['created_on']);
|
|
}
|
|
|
|
protected function evaluateNotFoundRoute($route, $methods)
|
|
{
|
|
foreach ($methods as $method) {
|
|
$crawler = $this->client->request($method, $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
|
|
$this->evaluateResponseNotFound($this->client->getResponse());
|
|
$this->evaluateMetaNotFound($content);
|
|
}
|
|
}
|
|
|
|
protected function checkEmbed($subdef_name, $embed, \record_adapter $record)
|
|
{
|
|
$this->assertArrayHasKey("permalink", $embed);
|
|
$this->checkPermalink($embed['permalink'], $record->get_subdef($subdef_name));
|
|
$this->assertArrayHasKey("height", $embed);
|
|
$this->assertEquals($embed['height'], $record->get_subdef($subdef_name)->get_height());
|
|
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_INT, $embed['height']);
|
|
$this->assertArrayHasKey("width", $embed);
|
|
$this->assertEquals($embed['width'], $record->get_subdef($subdef_name)->get_width());
|
|
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_INT, $embed['width']);
|
|
$this->assertArrayHasKey("filesize", $embed);
|
|
$this->assertEquals($embed['filesize'], $record->get_subdef($subdef_name)->get_size());
|
|
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_INT, $embed['filesize']);
|
|
$this->assertArrayHasKey("player_type", $embed);
|
|
$this->assertEquals($embed['player_type'], $record->get_subdef($subdef_name)->get_type());
|
|
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $embed['player_type']);
|
|
$this->assertArrayHasKey("mime_type", $embed);
|
|
$this->assertEquals($embed['mime_type'], $record->get_subdef($subdef_name)->get_mime());
|
|
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $embed['mime_type']);
|
|
$this->assertArrayHasKey("devices", $embed);
|
|
$this->assertEquals($embed['devices'], $record->get_subdef($subdef_name)->getDevices());
|
|
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $embed['devices']);
|
|
}
|
|
|
|
protected function checkPermalink($permalink, \media_subdef $subdef)
|
|
{
|
|
if ($subdef->is_physically_present()) {
|
|
$this->assertNotNull($subdef->get_permalink());
|
|
$this->assertInternalType('array', $permalink);
|
|
$this->assertArrayHasKey("created_on", $permalink);
|
|
$now = new \Datetime($permalink['created_on']);
|
|
$interval = $now->diff($subdef->get_permalink()->get_created_on());
|
|
$this->assertTrue(abs($interval->format('U')) < 2);
|
|
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $permalink['created_on']);
|
|
$this->assertDateAtom($permalink['created_on']);
|
|
$this->assertArrayHasKey("id", $permalink);
|
|
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_INT, $permalink['id']);
|
|
$this->assertEquals($subdef->get_permalink()->get_id(), $permalink['id']);
|
|
$this->assertArrayHasKey("is_activated", $permalink);
|
|
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_BOOL, $permalink['is_activated']);
|
|
$this->assertEquals($subdef->get_permalink()->get_is_activated(), $permalink['is_activated']);
|
|
$this->assertArrayHasKey("label", $permalink);
|
|
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $permalink['label']);
|
|
$this->assertArrayHasKey("last_modified", $permalink);
|
|
$this->assertEquals($subdef->get_permalink()->get_last_modified()->format(DATE_ATOM), $permalink['last_modified']);
|
|
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $permalink['last_modified']);
|
|
$this->assertDateAtom($permalink['last_modified']);
|
|
$this->assertArrayHasKey("page_url", $permalink);
|
|
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $permalink['page_url']);
|
|
$this->assertEquals($subdef->get_permalink()->get_page(\registry::get_instance()), $permalink['page_url']);
|
|
$this->checkUrlCode200($permalink['page_url']);
|
|
$this->assertPermalinkHeaders($permalink['page_url'], $subdef);
|
|
$this->assertArrayHasKey("url", $permalink);
|
|
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $permalink['url']);
|
|
$this->assertEquals($subdef->get_permalink()->get_url(), $permalink['url']);
|
|
$this->checkUrlCode200($permalink['url']);
|
|
$this->assertPermalinkHeaders($permalink['url'], $subdef, "url");
|
|
}
|
|
}
|
|
|
|
protected function assertPermalinkHeaders($url, \media_subdef $subdef, $type_url = "page_url")
|
|
{
|
|
$headers = \http_query::getHttpHeaders($url);
|
|
$this->assertEquals(200, $headers["http_code"]);
|
|
|
|
switch ($type_url) {
|
|
case "page_url" :
|
|
$this->assertTrue(strpos($headers['content_type'], "text/html") === 0);
|
|
$this->assertNotEquals($subdef->get_size(), $headers["download_content_length"]);
|
|
break;
|
|
case "url" :
|
|
$this->assertTrue(strpos($headers['content_type'], $subdef->get_mime()) === 0, 'Verify that header ' . $headers['content_type'] . ' contains subdef mime type ' . $subdef->get_mime());
|
|
$this->assertEquals($subdef->get_size(), $headers["download_content_length"]);
|
|
break;
|
|
}
|
|
}
|
|
|
|
protected function checkUrlCode200($url)
|
|
{
|
|
$code = \http_query::getHttpCodeFromUrl(self::$core->getRegistry()->get('GV_ServerName'));
|
|
|
|
if ($code == 0) {
|
|
$this->markTestSkipped('Install does not seem to rely on a webserver');
|
|
}
|
|
|
|
$code = \http_query::getHttpCodeFromUrl($url);
|
|
$this->assertEquals(200, $code, sprintf('verification de url %s', $url));
|
|
}
|
|
|
|
protected function evaluateMethodNotAllowedRoute($route, $methods)
|
|
{
|
|
foreach ($methods as $method) {
|
|
$crawler = $this->client->request($method, $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
$this->evaluateResponseMethodNotAllowed($this->client->getResponse());
|
|
$this->evaluateMetaMethodNotAllowed($content);
|
|
}
|
|
}
|
|
|
|
protected function evaluateBadRequestRoute($route, $methods)
|
|
{
|
|
foreach ($methods as $method) {
|
|
$this->client->request($method, $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
|
$content = $this->unserialize($this->client->getResponse()->getContent());
|
|
$this->evaluateResponseBadRequest($this->client->getResponse());
|
|
$this->evaluateMetaBadRequest($content);
|
|
}
|
|
}
|
|
|
|
protected function evaluateMeta($content)
|
|
{
|
|
$this->assertTrue(is_array($content), 'La reponse est un objet');
|
|
$this->assertArrayHasKey('meta', $content);
|
|
$this->assertArrayHasKey('response', $content);
|
|
$this->assertTrue(is_array($content['meta']), 'Le bloc meta est un array');
|
|
$this->assertTrue(is_array($content['response']), 'Le bloc reponse est un array');
|
|
$this->assertEquals('1.2', $content['meta']['api_version']);
|
|
$this->assertNotNull($content['meta']['response_time']);
|
|
$this->assertEquals('UTF-8', $content['meta']['charset']);
|
|
}
|
|
|
|
protected function evaluateMeta200($content)
|
|
{
|
|
$this->evaluateMeta($content);
|
|
$this->assertEquals(200, $content['meta']['http_code']);
|
|
$this->assertNull($content['meta']['error_type']);
|
|
$this->assertNull($content['meta']['error_message']);
|
|
$this->assertNull($content['meta']['error_details']);
|
|
}
|
|
|
|
protected function evaluateMetaBadRequest($content)
|
|
{
|
|
$this->evaluateMeta($content);
|
|
$this->assertNotNull($content['meta']['error_type']);
|
|
$this->assertNotNull($content['meta']['error_message']);
|
|
$this->assertEquals(400, $content['meta']['http_code']);
|
|
}
|
|
|
|
protected function evaluateMetaForbidden($content)
|
|
{
|
|
$this->evaluateMeta($content);
|
|
$this->assertNotNull($content['meta']['error_type']);
|
|
$this->assertNotNull($content['meta']['error_message']);
|
|
$this->assertEquals(403, $content['meta']['http_code']);
|
|
}
|
|
|
|
protected function evaluateMetaNotFound($content)
|
|
{
|
|
$this->evaluateMeta($content);
|
|
$this->assertNotNull($content['meta']['error_type']);
|
|
$this->assertNotNull($content['meta']['error_message']);
|
|
$this->assertEquals(404, $content['meta']['http_code']);
|
|
}
|
|
|
|
protected function evaluateMetaMethodNotAllowed($content)
|
|
{
|
|
$this->evaluateMeta($content);
|
|
$this->assertNotNull($content['meta']['error_type']);
|
|
$this->assertNotNull($content['meta']['error_message']);
|
|
$this->assertEquals(405, $content['meta']['http_code']);
|
|
}
|
|
|
|
protected function evaluateResponse200(Response $response)
|
|
{
|
|
$this->assertEquals('UTF-8', $response->getCharset(), 'Test charset response');
|
|
$this->assertEquals(200, $response->getStatusCode(), 'Test status code 200 ' . $response->getContent());
|
|
}
|
|
|
|
protected function evaluateResponseBadRequest(Response $response)
|
|
{
|
|
$this->assertEquals('UTF-8', $response->getCharset(), 'Test charset response');
|
|
$this->assertEquals(400, $response->getStatusCode(), 'Test status code 400 ' . $response->getContent());
|
|
}
|
|
|
|
protected function evaluateResponseForbidden(Response $response)
|
|
{
|
|
$this->assertEquals('UTF-8', $response->getCharset(), 'Test charset response');
|
|
$this->assertEquals(403, $response->getStatusCode(), 'Test status code 403 ' . $response->getContent());
|
|
}
|
|
|
|
protected function evaluateResponseNotFound(Response $response)
|
|
{
|
|
$this->assertEquals('UTF-8', $response->getCharset(), 'Test charset response');
|
|
$this->assertEquals(404, $response->getStatusCode(), 'Test status code 404 ' . $response->getContent());
|
|
}
|
|
|
|
protected function evaluateResponseMethodNotAllowed(Response $response)
|
|
{
|
|
$this->assertEquals('UTF-8', $response->getCharset(), 'Test charset response');
|
|
$this->assertEquals(405, $response->getStatusCode(), 'Test status code 405 ' . $response->getContent());
|
|
}
|
|
|
|
protected function evaluateGoodBasket($basket)
|
|
{
|
|
$this->assertTrue(is_array($basket));
|
|
$this->assertArrayHasKey('created_on', $basket);
|
|
$this->assertArrayHasKey('description', $basket);
|
|
$this->assertArrayHasKey('name', $basket);
|
|
$this->assertArrayHasKey('pusher_usr_id', $basket);
|
|
$this->assertArrayHasKey('ssel_id', $basket);
|
|
$this->assertArrayHasKey('updated_on', $basket);
|
|
$this->assertArrayHasKey('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']));
|
|
$this->assertTrue(is_bool($basket['unread']));
|
|
$this->assertDateAtom($basket['created_on']);
|
|
$this->assertDateAtom($basket['updated_on']);
|
|
}
|
|
|
|
protected function evaluateGoodRecord($record)
|
|
{
|
|
$this->assertArrayHasKey('databox_id', $record);
|
|
$this->assertTrue(is_int($record['databox_id']));
|
|
$this->assertArrayHasKey('record_id', $record);
|
|
$this->assertTrue(is_int($record['record_id']));
|
|
$this->assertArrayHasKey('mime_type', $record);
|
|
$this->assertTrue(is_string($record['mime_type']));
|
|
$this->assertArrayHasKey('title', $record);
|
|
$this->assertTrue(is_string($record['title']));
|
|
$this->assertArrayHasKey('original_name', $record);
|
|
$this->assertTrue(is_string($record['original_name']));
|
|
$this->assertArrayHasKey('last_modification', $record);
|
|
$this->assertDateAtom($record['last_modification']);
|
|
$this->assertArrayHasKey('created_on', $record);
|
|
$this->assertDateAtom($record['created_on']);
|
|
$this->assertArrayHasKey('collection_id', $record);
|
|
$this->assertTrue(is_int($record['collection_id']));
|
|
$this->assertArrayHasKey('thumbnail', $record);
|
|
$this->assertArrayHasKey('sha256', $record);
|
|
$this->assertTrue(is_string($record['sha256']));
|
|
$this->assertArrayHasKey('technical_informations', $record);
|
|
$this->assertArrayHasKey('phrasea_type', $record);
|
|
$this->assertTrue(is_string($record['phrasea_type']));
|
|
$this->assertTrue(in_array($record['phrasea_type'], array('audio', 'document', 'image', 'video', 'flash', 'unknown')));
|
|
$this->assertArrayHasKey('uuid', $record);
|
|
$this->assertTrue(\uuid::is_valid($record['uuid']));
|
|
|
|
if ( ! is_null($record['thumbnail'])) {
|
|
$this->assertTrue(is_array($record['thumbnail']));
|
|
$this->assertArrayHasKey('player_type', $record['thumbnail']);
|
|
$this->assertTrue(is_string($record['thumbnail']['player_type']));
|
|
$this->assertArrayHasKey('permalink', $record['thumbnail']);
|
|
$this->assertArrayHasKey('mime_type', $record['thumbnail']);
|
|
$this->assertTrue(is_string($record['thumbnail']['mime_type']));
|
|
$this->assertArrayHasKey('height', $record['thumbnail']);
|
|
$this->assertTrue(is_int($record['thumbnail']['height']));
|
|
$this->assertArrayHasKey('width', $record['thumbnail']);
|
|
$this->assertTrue(is_int($record['thumbnail']['width']));
|
|
$this->assertArrayHasKey('filesize', $record['thumbnail']);
|
|
$this->assertTrue(is_int($record['thumbnail']['filesize']));
|
|
}
|
|
|
|
$this->assertTrue(is_array($record['technical_informations']));
|
|
|
|
foreach ($record['technical_informations'] as $key => $value) {
|
|
if (is_string($value)) {
|
|
$this->assertFalse(ctype_digit($value));
|
|
$this->assertEquals(0, preg_match('/[0-9]?\.[0-9]+/', $value));
|
|
} elseif (is_float($value)) {
|
|
$this->assertTrue(is_float($value));
|
|
} elseif (is_int($value)) {
|
|
$this->assertTrue(is_int($value));
|
|
} else {
|
|
$this->fail('unrecognized technical information');
|
|
}
|
|
}
|
|
}
|
|
|
|
protected function evaluateRecordsCaptionResponse($content)
|
|
{
|
|
foreach ($content['response'] as $field) {
|
|
$this->assertTrue(is_array($field), 'Un bloc field est un objet');
|
|
$this->assertArrayHasKey('meta_structure_id', $field);
|
|
$this->assertTrue(is_int($field['meta_structure_id']));
|
|
$this->assertArrayHasKey('name', $field);
|
|
$this->assertTrue(is_string($field['name']));
|
|
$this->assertArrayHasKey('value', $field);
|
|
$this->assertTrue(is_string($field['value']));
|
|
}
|
|
}
|
|
|
|
protected function evaluateRecordsMetadataResponse($content)
|
|
{
|
|
$this->assertArrayHasKey("metadatas", $content['response']);
|
|
foreach ($content['response']['metadatas'] as $meta) {
|
|
$this->assertTrue(is_array($meta), 'Un bloc meta est un objet');
|
|
$this->assertArrayHasKey('meta_id', $meta);
|
|
$this->assertTrue(is_int($meta['meta_id']));
|
|
$this->assertArrayHasKey('meta_structure_id', $meta);
|
|
$this->assertTrue(is_int($meta['meta_structure_id']));
|
|
$this->assertArrayHasKey('name', $meta);
|
|
$this->assertTrue(is_string($meta['name']));
|
|
$this->assertArrayHasKey('value', $meta);
|
|
|
|
if (is_array($meta['value'])) {
|
|
foreach ($meta['value'] as $val) {
|
|
$this->assertTrue(is_string($val));
|
|
}
|
|
} else {
|
|
$this->assertTrue(is_string($meta['value']));
|
|
}
|
|
}
|
|
}
|
|
|
|
protected function evaluateRecordsStatusResponse(\record_adapter $record, $content)
|
|
{
|
|
$status = $record->get_databox()->get_statusbits();
|
|
|
|
$r_status = strrev($record->get_status());
|
|
$this->assertArrayHasKey('status', $content['response']);
|
|
$this->assertEquals(count((array) $content['response']['status']), count($status));
|
|
foreach ($content['response']['status'] as $status) {
|
|
$this->assertTrue(is_array($status));
|
|
$this->assertArrayHasKey('bit', $status);
|
|
$this->assertArrayHasKey('state', $status);
|
|
$this->assertTrue(is_int($status['bit']));
|
|
$this->assertTrue(is_bool($status['state']));
|
|
|
|
$retrieved = ! ! substr($r_status, ($status['bit'] - 1), 1);
|
|
|
|
$this->assertEquals($retrieved, $status['state']);
|
|
}
|
|
}
|
|
|
|
protected function injectMetadatas(\record_adapter $record)
|
|
{
|
|
foreach ($record->get_databox()->get_meta_structure()->get_elements() as $field) {
|
|
try {
|
|
$values = $record->get_caption()->get_field($field->get_name())->get_values();
|
|
$value = array_pop($values);
|
|
$meta_id = $value->getId();
|
|
} catch (\Exception $e) {
|
|
$meta_id = null;
|
|
}
|
|
|
|
$toupdate[$field->get_id()] = array(
|
|
'meta_id' => $meta_id
|
|
, 'meta_struct_id' => $field->get_id()
|
|
, 'value' => 'podom pom pom ' . $field->get_id()
|
|
);
|
|
}
|
|
|
|
$record->set_metadatas($toupdate);
|
|
}
|
|
|
|
protected function setToken($token)
|
|
{
|
|
$_GET['oauth_token'] = $token;
|
|
}
|
|
|
|
protected function unsetToken()
|
|
{
|
|
unset($_GET['oauth_token']);
|
|
}
|
|
}
|