mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-11 12:03:14 +00:00
Refactor API tests, add tests for feeds
This commit is contained in:
@@ -413,7 +413,6 @@ return call_user_func(function() {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
$app->match('/records/add/', $bad_request_exception);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Route : /records/search/
|
* Route : /records/search/
|
||||||
@@ -742,6 +741,26 @@ return call_user_func(function() {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
$route = '/feeds/content/';
|
||||||
|
$app->get(
|
||||||
|
$route, function() use ($app) {
|
||||||
|
$result = $app['api']->get_publications($app['request'], $app['Core']->getAuthenticatedUser());
|
||||||
|
|
||||||
|
return $result->get_response();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
$route = '/feeds/entry/{entry_id}/';
|
||||||
|
$app->get(
|
||||||
|
$route, function($entry_id) use ($app) {
|
||||||
|
$result = $app['api']->get_feed_entry($app['request'], $entry_id, $app['Core']->getAuthenticatedUser());
|
||||||
|
|
||||||
|
return $result->get_response();
|
||||||
|
}
|
||||||
|
)->assert('entry_id', '\d+');
|
||||||
|
$app->get('/feeds/entry/{entry_id}/', $bad_request_exception);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Route : /feeds/PUBLICATION_ID/content/
|
* Route : /feeds/PUBLICATION_ID/content/
|
||||||
*
|
*
|
||||||
|
@@ -269,6 +269,9 @@ interface API_V1_Interface
|
|||||||
*/
|
*/
|
||||||
public function get_publication(Request $request, $publication_id, User_Adapter &$user);
|
public function get_publication(Request $request, $publication_id, User_Adapter &$user);
|
||||||
|
|
||||||
|
public function get_publications(Request $request, User_Adapter &$user);
|
||||||
|
|
||||||
|
public function get_feed_entry(Request $request, $entry, User_Adapter &$user);
|
||||||
/**
|
/**
|
||||||
* Route : /users/search/FORMAT/
|
* Route : /users/search/FORMAT/
|
||||||
*
|
*
|
||||||
@@ -290,6 +293,8 @@ interface API_V1_Interface
|
|||||||
*/
|
*/
|
||||||
public function get_user_acces(Request $request, $usr_id);
|
public function get_user_acces(Request $request, $usr_id);
|
||||||
|
|
||||||
|
public function add_record(Application $app, Request $request);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Route : /users/add/FORMAT/
|
* Route : /users/add/FORMAT/
|
||||||
*
|
*
|
||||||
|
@@ -9,6 +9,7 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Border\Manager as BorderManager;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Silex\Application;
|
use Silex\Application;
|
||||||
|
|
||||||
@@ -109,25 +110,31 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
|
|
||||||
$ret = array();
|
$ret = array();
|
||||||
foreach ($tasks as $task) {
|
foreach ($tasks as $task) {
|
||||||
$ret[$task->getID()] = array(
|
$ret[] = $this->list_task($task);
|
||||||
|
}
|
||||||
|
|
||||||
|
$result->set_datas(array('tasks' => $ret));
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function list_task(\task_abstract $task)
|
||||||
|
{
|
||||||
|
return array(
|
||||||
'id' => $task->getID(),
|
'id' => $task->getID(),
|
||||||
|
'name' => $task->getName(),
|
||||||
'state' => $task->getState(),
|
'state' => $task->getState(),
|
||||||
'pid' => $task->getPID(),
|
'pid' => $task->getPID(),
|
||||||
'title' => $task->getTitle(),
|
'title' => $task->getTitle(),
|
||||||
'last_exec_time' => $task->getLastExecTime()
|
'last_exec_time' => $task->getLastExecTime() ? $task->getLastExecTime()->format(DATE_ATOM) : null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$result->set_datas($ret);
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get informations about an identified task
|
* Get informations about an identified task
|
||||||
*
|
*
|
||||||
* @param \Silex\Application $app The API silex application
|
* @param \Silex\Application $app The API silex application
|
||||||
* @param type $task_id
|
* @param integer $task_id
|
||||||
* @return \API_V1_result
|
* @return \API_V1_result
|
||||||
*/
|
*/
|
||||||
public function get_task(Application $app, $taskId)
|
public function get_task(Application $app, $taskId)
|
||||||
@@ -136,24 +143,11 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
|
|
||||||
$appbox = \appbox::get_instance($app['Core']);
|
$appbox = \appbox::get_instance($app['Core']);
|
||||||
$taskManager = new task_manager($appbox);
|
$taskManager = new task_manager($appbox);
|
||||||
$ret = array();
|
|
||||||
try {
|
$ret = array(
|
||||||
$task = $taskManager->getTask($taskId);
|
'task' => $this->list_task($taskManager->getTask($taskId))
|
||||||
$ret['id'] = $task->getID();
|
);
|
||||||
$ret['state'] = $task->getState();
|
|
||||||
$ret['pid'] = $task->getPID();
|
|
||||||
$ret['title'] = $task->getTitle();
|
|
||||||
$ret['last_exec_time'] = $task->getLastExecTime();
|
|
||||||
} catch (\Exception_NotFound $e) {
|
|
||||||
$result->set_error_code(404);
|
|
||||||
$ret = array('success' => false);
|
|
||||||
} catch (\Exception_InvalidArgument $e) {
|
|
||||||
$result->set_error_code(400);
|
|
||||||
$ret = array('success' => false);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$result->set_error_code(500);
|
|
||||||
$ret = array('success' => false);
|
|
||||||
}
|
|
||||||
$result->set_datas($ret);
|
$result->set_datas($ret);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
@@ -163,7 +157,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
* Start a specified task
|
* Start a specified task
|
||||||
*
|
*
|
||||||
* @param \Silex\Application $app The API silex application
|
* @param \Silex\Application $app The API silex application
|
||||||
* @param type $task_id The task id
|
* @param integer $task_id The task id
|
||||||
* @return \API_V1_result
|
* @return \API_V1_result
|
||||||
*/
|
*/
|
||||||
public function start_task(Application $app, $taskId)
|
public function start_task(Application $app, $taskId)
|
||||||
@@ -172,21 +166,13 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
|
|
||||||
$appbox = \appbox::get_instance($app['Core']);
|
$appbox = \appbox::get_instance($app['Core']);
|
||||||
$taskManager = new \task_manager($appbox);
|
$taskManager = new \task_manager($appbox);
|
||||||
$ret = array('success' => true);
|
|
||||||
try {
|
|
||||||
$task = $taskManager->getTask($taskId);
|
$task = $taskManager->getTask($taskId);
|
||||||
|
if ( ! in_array($task->getState(), array(\task_abstract::STATE_TOSTART, \task_abstract::STATE_STARTED))) {
|
||||||
$task->setState(\task_abstract::STATE_TOSTART);
|
$task->setState(\task_abstract::STATE_TOSTART);
|
||||||
} catch (\Exception_NotFound $e) {
|
|
||||||
$result->set_error_code(404);
|
|
||||||
$ret = array('success' => false);
|
|
||||||
} catch (\Exception_InvalidArgument $e) {
|
|
||||||
$result->set_error_code(400);
|
|
||||||
$ret = array('success' => false);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$result->set_error_code(500);
|
|
||||||
$ret = array('success' => false);
|
|
||||||
}
|
}
|
||||||
$result->set_datas($ret);
|
|
||||||
|
$result->set_datas(array('task' => $this->list_task($task)));
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
@@ -195,7 +181,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
* Stop a specified task
|
* Stop a specified task
|
||||||
*
|
*
|
||||||
* @param \Silex\Application $app The API silex application
|
* @param \Silex\Application $app The API silex application
|
||||||
* @param type $task_id The task id
|
* @param integer $task_id The task id
|
||||||
* @return \API_V1_result
|
* @return \API_V1_result
|
||||||
*/
|
*/
|
||||||
public function stop_task(Application $app, $taskId)
|
public function stop_task(Application $app, $taskId)
|
||||||
@@ -204,21 +190,12 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
|
|
||||||
$appbox = \appbox::get_instance($app['Core']);
|
$appbox = \appbox::get_instance($app['Core']);
|
||||||
$taskManager = new \task_manager($appbox);
|
$taskManager = new \task_manager($appbox);
|
||||||
$ret = array();
|
|
||||||
try {
|
|
||||||
$task = $taskManager->getTask($taskId);
|
$task = $taskManager->getTask($taskId);
|
||||||
|
if ( ! in_array($task->getState(), array(\task_abstract::STATE_TOSTOP, \task_abstract::STATE_STOPPED))) {
|
||||||
$task->setState(\task_abstract::STATE_TOSTOP);
|
$task->setState(\task_abstract::STATE_TOSTOP);
|
||||||
} catch (\Exception_NotFound $e) {
|
|
||||||
$result->set_error_code(404);
|
|
||||||
$ret = array('success' => false);
|
|
||||||
} catch (\Exception_InvalidArgument $e) {
|
|
||||||
$result->set_error_code(400);
|
|
||||||
$ret = array('success' => false);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$result->set_error_code(500);
|
|
||||||
$ret = array('success' => false);
|
|
||||||
}
|
}
|
||||||
$result->set_datas($ret);
|
$result->set_datas(array('task' => $this->list_task($task)));
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
@@ -229,22 +206,19 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
* - autostart
|
* - autostart
|
||||||
*
|
*
|
||||||
* @param \Silex\Application $app Silex application
|
* @param \Silex\Application $app Silex application
|
||||||
* @param type $task_id the task id
|
* @param integer $task_id the task id
|
||||||
* @return \API_V1_result
|
* @return \API_V1_result
|
||||||
* @throws \Exception_InvalidArgument
|
* @throws \API_V1_exception_badrequest
|
||||||
*/
|
*/
|
||||||
public function set_task_property(Application $app, $taskId)
|
public function set_task_property(Application $app, $taskId)
|
||||||
{
|
{
|
||||||
$result = new API_V1_result($app['request'], $this);
|
$result = new API_V1_result($app['request'], $this);
|
||||||
|
|
||||||
$name = $app['request']->get('name');
|
$title = $app['request']->get('title');
|
||||||
$autostart = $app['request']->get('autostart');
|
$autostart = $app['request']->get('autostart');
|
||||||
|
|
||||||
$ret = array('success' => false);
|
if (null === $title && null === $autostart) {
|
||||||
|
throw new \API_V1_exception_badrequest();
|
||||||
try {
|
|
||||||
if (null === $name && null === $autostart) {
|
|
||||||
throw new \Exception_InvalidArgument();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$appbox = \appbox::get_instance($app['Core']);
|
$appbox = \appbox::get_instance($app['Core']);
|
||||||
@@ -253,26 +227,15 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
|
|
||||||
$task = $taskManager->getTask($taskId);
|
$task = $taskManager->getTask($taskId);
|
||||||
|
|
||||||
if ($name) {
|
if ($title) {
|
||||||
$task->setTitle($name);
|
$task->setTitle($title);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($autostart) {
|
if ($autostart) {
|
||||||
$task->setActive( ! ! $autostart);
|
$task->setActive( ! ! $autostart);
|
||||||
}
|
}
|
||||||
|
|
||||||
$ret = array('success' => true);
|
$result->set_datas(array('task' => $this->list_task($task)));
|
||||||
} catch (\Exception_NotFound $e) {
|
|
||||||
$result->set_error_code(404);
|
|
||||||
$ret = array('success' => false);
|
|
||||||
} catch (\Exception_InvalidArgument $e) {
|
|
||||||
$result->set_error_code(400);
|
|
||||||
$ret = array('success' => false);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$result->set_error_code(500);
|
|
||||||
$ret = array('success' => false);
|
|
||||||
}
|
|
||||||
$result->set_datas($ret);
|
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
@@ -711,10 +674,10 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
|
|
||||||
switch ($request->get('forceBehavior')) {
|
switch ($request->get('forceBehavior')) {
|
||||||
case '0' :
|
case '0' :
|
||||||
$behavior = \Alchemy\Phrasea\Border\Manager::FORCE_RECORD;
|
$behavior = BorderManager::FORCE_RECORD;
|
||||||
break;
|
break;
|
||||||
case '1' :
|
case '1' :
|
||||||
$behavior = \Alchemy\Phrasea\Border\Manager::FORCE_LAZARET;
|
$behavior = BorderManager::FORCE_LAZARET;
|
||||||
break;
|
break;
|
||||||
case null:
|
case null:
|
||||||
$behavior = null;
|
$behavior = null;
|
||||||
@@ -736,7 +699,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
}
|
}
|
||||||
if ($output instanceof \Entities\LazaretFile) {
|
if ($output instanceof \Entities\LazaretFile) {
|
||||||
$ret['entity'] = '1';
|
$ret['entity'] = '1';
|
||||||
$ret['reasons'] = $reasons;
|
$ret['reasons'] = $behavior === BorderManager::FORCE_LAZARET ? array() : $reasons;
|
||||||
$ret['lazaretFile'] = $this->list_lazaret_file($output);
|
$ret['lazaretFile'] = $this->list_lazaret_file($output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -776,7 +739,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
'sha256' => $file->getSha256(),
|
'sha256' => $file->getSha256(),
|
||||||
'uuid' => $file->getUuid(),
|
'uuid' => $file->getUuid(),
|
||||||
'forced' => $file->getForced(),
|
'forced' => $file->getForced(),
|
||||||
'checks' => $checks,
|
'checks' => $file->getForced() ? array() : $checks,
|
||||||
'created_on' => $file->getCreated()->format(DATE_ATOM),
|
'created_on' => $file->getCreated()->format(DATE_ATOM),
|
||||||
'updated_on' => $file->getUpdated()->format(DATE_ATOM),
|
'updated_on' => $file->getUpdated()->format(DATE_ATOM),
|
||||||
);
|
);
|
||||||
@@ -1495,13 +1458,15 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_feed_entry(Request $request, $entry, User_Adapter &$user)
|
public function get_feed_entry(Request $request, $entry_id, User_Adapter &$user)
|
||||||
{
|
{
|
||||||
$result = new API_V1_result($request, $this);
|
$result = new API_V1_result($request, $this);
|
||||||
|
|
||||||
$entry = Feed_Entry_Adapter::load_from_id($this->appbox, $id);
|
$entry = Feed_Entry_Adapter::load_from_id($this->appbox, $entry_id);
|
||||||
|
|
||||||
if ( ! $user->ACL()->has_access_to_base($entry->get_feed()->get_collection()->get_base_id())) {
|
$collection = $entry->get_feed()->get_collection();
|
||||||
|
|
||||||
|
if (null !== $collection && ! $user->ACL()->has_access_to_base($collection->get_base_id())) {
|
||||||
throw new \API_V1_exception_forbidden('You have not access to the parent feed');
|
throw new \API_V1_exception_forbidden('You have not access to the parent feed');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1561,10 +1526,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
$out[$entry->get_id()] = $this->list_publication_entry($entry);
|
$out[$entry->get_id()] = $this->list_publication_entry($entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
return array(
|
return $out;
|
||||||
'offset_start' => $offset_start
|
|
||||||
, 'entries' => $out
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1581,6 +1543,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
}
|
}
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
|
'id' => $entry->get_id(),
|
||||||
'author_email' => $entry->get_author_email(),
|
'author_email' => $entry->get_author_email(),
|
||||||
'author_name' => $entry->get_author_name(),
|
'author_name' => $entry->get_author_name(),
|
||||||
'created_on' => $entry->get_created_on()->format(DATE_ATOM),
|
'created_on' => $entry->get_created_on()->format(DATE_ATOM),
|
||||||
@@ -1588,6 +1551,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
'title' => $entry->get_title(),
|
'title' => $entry->get_title(),
|
||||||
'subtitle' => $entry->get_subtitle(),
|
'subtitle' => $entry->get_subtitle(),
|
||||||
'items' => $items,
|
'items' => $items,
|
||||||
|
'feed_url' => '/feeds/' . $entry->get_feed()->get_id() . '/content/',
|
||||||
'url' => '/feeds/entry/' . $entry->get_id() . '/',
|
'url' => '/feeds/entry/' . $entry->get_id() . '/',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1644,6 +1608,10 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
*/
|
*/
|
||||||
protected function list_embedable_media(media_subdef &$media, registryInterface &$registry)
|
protected function list_embedable_media(media_subdef &$media, registryInterface &$registry)
|
||||||
{
|
{
|
||||||
|
if ( ! $media->is_physically_present()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if ($media->get_permalink() instanceof media_Permalink_Adapter) {
|
if ($media->get_permalink() instanceof media_Permalink_Adapter) {
|
||||||
$permalink = $this->list_permalink($media->get_permalink(), $registry);
|
$permalink = $this->list_permalink($media->get_permalink(), $registry);
|
||||||
} else {
|
} else {
|
||||||
|
@@ -534,7 +534,7 @@ class caption_Field_Value implements cache_cacheableInterface
|
|||||||
*/
|
*/
|
||||||
public function get_cache_key($option = null)
|
public function get_cache_key($option = null)
|
||||||
{
|
{
|
||||||
return 'caption_fieldvalue_' . $this->record->get_serialize_key() . ($option ? '_' . $option : '');
|
return 'caption_fieldvalue_' . $this->id . '_' . $this->record->get_serialize_key() . ($option ? '_' . $option : '');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -749,6 +749,9 @@ class record_adapter implements record_Interface, cache_cacheableInterface
|
|||||||
|
|
||||||
foreach ($rs as $row) {
|
foreach ($rs as $row) {
|
||||||
switch (true) {
|
switch (true) {
|
||||||
|
case preg_match('/[0-9]?\.[0-9]+/', $row['value']):
|
||||||
|
$this->technical_datas[$row['name']] = (float) $row['value'];
|
||||||
|
break;
|
||||||
case ctype_digit($row['value']):
|
case ctype_digit($row['value']):
|
||||||
$this->technical_datas[$row['name']] = (int) $row['value'];
|
$this->technical_datas[$row['name']] = (int) $row['value'];
|
||||||
break;
|
break;
|
||||||
@@ -779,7 +782,6 @@ class record_adapter implements record_Interface, cache_cacheableInterface
|
|||||||
*/
|
*/
|
||||||
public function get_caption()
|
public function get_caption()
|
||||||
{
|
{
|
||||||
|
|
||||||
return new caption_record($this, $this->get_databox());
|
return new caption_record($this, $this->get_databox());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1337,7 +1339,6 @@ class record_adapter implements record_Interface, cache_cacheableInterface
|
|||||||
$record->delete_data_from_cache(record_adapter::CACHE_SUBDEFS);
|
$record->delete_data_from_cache(record_adapter::CACHE_SUBDEFS);
|
||||||
|
|
||||||
$record->insertTechnicalDatas();
|
$record->insertTechnicalDatas();
|
||||||
$record->rebuild_subdefs();
|
|
||||||
|
|
||||||
return $record;
|
return $record;
|
||||||
}
|
}
|
||||||
@@ -1363,6 +1364,12 @@ class record_adapter implements record_Interface, cache_cacheableInterface
|
|||||||
foreach ($document->readTechnicalDatas() as $name => $value) {
|
foreach ($document->readTechnicalDatas() as $name => $value) {
|
||||||
if (is_null($value)) {
|
if (is_null($value)) {
|
||||||
continue;
|
continue;
|
||||||
|
} elseif (is_bool($value)) {
|
||||||
|
if ($value) {
|
||||||
|
$value = 1;
|
||||||
|
} else {
|
||||||
|
$value = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$stmt->execute(array(
|
$stmt->execute(array(
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user