mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-14 21:43:18 +00:00
Merge branch '3.7'
This commit is contained in:
@@ -21,6 +21,7 @@ dev:
|
|||||||
#Assign your phraseanet application connection
|
#Assign your phraseanet application connection
|
||||||
#Connections are defined in connexions.yml configuration file
|
#Connections are defined in connexions.yml configuration file
|
||||||
database: main_connexion
|
database: main_connexion
|
||||||
|
api-timers: true
|
||||||
|
|
||||||
#Assign your template engine service & ORM service
|
#Assign your template engine service & ORM service
|
||||||
#Services are defined in service.yml configuration file
|
#Services are defined in service.yml configuration file
|
||||||
|
@@ -12,6 +12,11 @@
|
|||||||
namespace Alchemy\Phrasea\Application;
|
namespace Alchemy\Phrasea\Application;
|
||||||
|
|
||||||
use Alchemy\Phrasea\Application as PhraseaApplication;
|
use Alchemy\Phrasea\Application as PhraseaApplication;
|
||||||
|
use Alchemy\Phrasea\Core\PhraseaEvents;
|
||||||
|
use Alchemy\Phrasea\Core\Event\ApiLoadEndEvent;
|
||||||
|
use Alchemy\Phrasea\Core\Event\ApiLoadStartEvent;
|
||||||
|
use Alchemy\Phrasea\Core\Event\ApiOAuth2StartEvent;
|
||||||
|
use Alchemy\Phrasea\Core\Event\ApiOAuth2EndEvent;
|
||||||
use Silex\Application as SilexApplication;
|
use Silex\Application as SilexApplication;
|
||||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
@@ -22,6 +27,10 @@ use Symfony\Component\HttpFoundation\Request;
|
|||||||
return call_user_func(function($environment = 'prod') {
|
return call_user_func(function($environment = 'prod') {
|
||||||
|
|
||||||
$app = new PhraseaApplication($environment);
|
$app = new PhraseaApplication($environment);
|
||||||
|
|
||||||
|
$app->register(new \API_V1_Timer());
|
||||||
|
$app['dispatcher']->dispatch(PhraseaEvents::API_LOAD_START, new ApiLoadStartEvent());
|
||||||
|
|
||||||
$app->disableCookies();
|
$app->disableCookies();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -48,6 +57,7 @@ return call_user_func(function($environment = 'prod') {
|
|||||||
* @ throws \API_V1_exception_forbidden
|
* @ throws \API_V1_exception_forbidden
|
||||||
*/
|
*/
|
||||||
$app->before(function($request) use ($app) {
|
$app->before(function($request) use ($app) {
|
||||||
|
$app['dispatcher']->dispatch(PhraseaEvents::API_OAUTH2_START, new ApiOAuth2StartEvent());
|
||||||
$oauth2_adapter = new \API_OAuth2_Adapter($app);
|
$oauth2_adapter = new \API_OAuth2_Adapter($app);
|
||||||
$oauth2_adapter->verifyAccessToken();
|
$oauth2_adapter->verifyAccessToken();
|
||||||
|
|
||||||
@@ -62,6 +72,7 @@ return call_user_func(function($environment = 'prod') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($app->isAuthenticated()) {
|
if ($app->isAuthenticated()) {
|
||||||
|
$app['dispatcher']->dispatch(PhraseaEvents::API_OAUTH2_END, new ApiOAuth2EndEvent());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,6 +81,7 @@ return call_user_func(function($environment = 'prod') {
|
|||||||
|
|
||||||
$app->openAccount($auth, $oauth2_adapter->get_ses_id());
|
$app->openAccount($auth, $oauth2_adapter->get_ses_id());
|
||||||
$oauth2_adapter->remember_this_ses_id($app['session']->get('session_id'));
|
$oauth2_adapter->remember_this_ses_id($app['session']->get('session_id'));
|
||||||
|
$app['dispatcher']->dispatch(PhraseaEvents::API_OAUTH2_END, new ApiOAuth2EndEvent());
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}, 256);
|
}, 256);
|
||||||
@@ -752,5 +764,7 @@ return call_user_func(function($environment = 'prod') {
|
|||||||
return $response;
|
return $response;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$app['dispatcher']->dispatch(PhraseaEvents::API_LOAD_END, new ApiLoadEndEvent());
|
||||||
|
|
||||||
return $app;
|
return $app;
|
||||||
}, isset($environment) ? $environment : null);
|
}, isset($environment) ? $environment : null);
|
||||||
|
@@ -11,8 +11,11 @@
|
|||||||
|
|
||||||
namespace Alchemy\Phrasea\Application;
|
namespace Alchemy\Phrasea\Application;
|
||||||
|
|
||||||
use Silex\Application as SilexApplication;
|
|
||||||
use Alchemy\Phrasea\Application as PhraseaApplication;
|
use Alchemy\Phrasea\Application as PhraseaApplication;
|
||||||
|
use Alchemy\Phrasea\Core\PhraseaEvents;
|
||||||
|
use Alchemy\Phrasea\Core\Event\ApiLoadEndEvent;
|
||||||
|
use Alchemy\Phrasea\Core\Event\ApiLoadStartEvent;
|
||||||
|
use Silex\Application as SilexApplication;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
return call_user_func(function($environment = 'prod') {
|
return call_user_func(function($environment = 'prod') {
|
||||||
@@ -20,6 +23,9 @@ return call_user_func(function($environment = 'prod') {
|
|||||||
$app = new PhraseaApplication($environment);
|
$app = new PhraseaApplication($environment);
|
||||||
$app->disableCookies();
|
$app->disableCookies();
|
||||||
|
|
||||||
|
$app->register(new \API_V1_Timer());
|
||||||
|
$app['dispatcher']->dispatch(PhraseaEvents::API_LOAD_START, new ApiLoadStartEvent());
|
||||||
|
|
||||||
$app->get('/', function(Request $request, SilexApplication $app) {
|
$app->get('/', function(Request $request, SilexApplication $app) {
|
||||||
$apiAdapter = new \API_V1_adapter($app);
|
$apiAdapter = new \API_V1_adapter($app);
|
||||||
|
|
||||||
@@ -45,5 +51,7 @@ return call_user_func(function($environment = 'prod') {
|
|||||||
))->get_response();
|
))->get_response();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$app['dispatcher']->dispatch(PhraseaEvents::API_LOAD_END, new ApiLoadEndEvent());
|
||||||
|
|
||||||
return $app;
|
return $app;
|
||||||
}, isset($environment) ? $environment : null);
|
}, isset($environment) ? $environment : null);
|
||||||
|
@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Controller;
|
|||||||
|
|
||||||
use Alchemy\Phrasea\Application as PhraseaApplication;
|
use Alchemy\Phrasea\Application as PhraseaApplication;
|
||||||
use Silex\Application;
|
use Silex\Application;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -28,8 +29,7 @@ class Permalink extends AbstractDelivery
|
|||||||
|
|
||||||
$that = $this;
|
$that = $this;
|
||||||
|
|
||||||
$controllers->get('/v1/{label}/{sbas_id}/{record_id}/{key}/{subdef}/view/', function($label, $sbas_id, $record_id, $key, $subdef, PhraseaApplication $app) {
|
$deliverPermaview = function($sbas_id, $record_id, $key, $subdef, PhraseaApplication $app) {
|
||||||
|
|
||||||
$databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id);
|
$databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id);
|
||||||
|
|
||||||
$record = \media_Permalink_Adapter::challenge_token($app, $databox, $key, $record_id, $subdef);
|
$record = \media_Permalink_Adapter::challenge_token($app, $databox, $key, $record_id, $subdef);
|
||||||
@@ -47,9 +47,9 @@ class Permalink extends AbstractDelivery
|
|||||||
);
|
);
|
||||||
|
|
||||||
return $app['twig']->render('overview.html.twig', $params);
|
return $app['twig']->render('overview.html.twig', $params);
|
||||||
})->assert('sbas_id', '\d+')->assert('record_id', '\d+');
|
};
|
||||||
|
|
||||||
$controllers->get('/v1/{label}/{sbas_id}/{record_id}/{key}/{subdef}/', function(Application $app, $label, $sbas_id, $record_id, $key, $subdef) use ($that) {
|
$deliverPermalink = function(Application $app, $sbas_id, $record_id, $key, $subdef) use ($that) {
|
||||||
$databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id);
|
$databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id);
|
||||||
$record = \media_Permalink_Adapter::challenge_token($app, $databox, $key, $record_id, $subdef);
|
$record = \media_Permalink_Adapter::challenge_token($app, $databox, $key, $record_id, $subdef);
|
||||||
|
|
||||||
@@ -93,6 +93,26 @@ class Permalink extends AbstractDelivery
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $that->deliverContent($app['request'], $record, $subdef, $watermark, $stamp, $app);
|
return $that->deliverContent($app['request'], $record, $subdef, $watermark, $stamp, $app);
|
||||||
|
};
|
||||||
|
|
||||||
|
$controllers->get('/v1/{sbas_id}/{record_id}/{subdef}/', function (PhraseaApplication $app, Request $request, $sbas_id, $record_id, $subdef) use ($deliverPermaview) {
|
||||||
|
$key = $request->query->get('token');
|
||||||
|
|
||||||
|
return $deliverPermaview($sbas_id, $record_id, $key, $subdef, $app);
|
||||||
|
})->assert('sbas_id', '\d+')->assert('record_id', '\d+');
|
||||||
|
|
||||||
|
$controllers->get('/v1/{label}/{sbas_id}/{record_id}/{key}/{subdef}/view/', function(PhraseaApplication $app, $label, $sbas_id, $record_id, $key, $subdef) use ($deliverPermaview) {
|
||||||
|
return $deliverPermaview($sbas_id, $record_id, $key, $subdef, $app);
|
||||||
|
})->assert('sbas_id', '\d+')->assert('record_id', '\d+');
|
||||||
|
|
||||||
|
$controllers->get('/v1/{sbas_id}/{record_id}/{subdef}/{label}', function (PhraseaApplication $app, Request $request, $sbas_id, $record_id, $subdef, $label) use ($deliverPermalink) {
|
||||||
|
$key = $request->query->get('token');
|
||||||
|
|
||||||
|
return $deliverPermalink($app, $sbas_id, $record_id, $key, $subdef);
|
||||||
|
})->assert('sbas_id', '\d+')->assert('record_id', '\d+');
|
||||||
|
|
||||||
|
$controllers->get('/v1/{label}/{sbas_id}/{record_id}/{key}/{subdef}/', function(PhraseaApplication $app, $label, $sbas_id, $record_id, $key, $subdef) use ($deliverPermalink) {
|
||||||
|
return $deliverPermalink($app, $sbas_id, $record_id, $key, $subdef);
|
||||||
})->assert('sbas_id', '\d+')->assert('record_id', '\d+');
|
})->assert('sbas_id', '\d+')->assert('record_id', '\d+');
|
||||||
|
|
||||||
return $controllers;
|
return $controllers;
|
||||||
|
@@ -224,7 +224,6 @@ class Query implements ControllerProviderInterface
|
|||||||
|
|
||||||
$json['results'] = $app['twig']->render($template, array(
|
$json['results'] = $app['twig']->render($template, array(
|
||||||
'results' => $result,
|
'results' => $result,
|
||||||
'GV_social_tools' => $app['phraseanet.registry']->get('GV_social_tools'),
|
|
||||||
'highlight' => $result->getQuery(),
|
'highlight' => $result->getQuery(),
|
||||||
'searchEngine' => $app['phraseanet.SE'],
|
'searchEngine' => $app['phraseanet.SE'],
|
||||||
'suggestions' => $prop
|
'suggestions' => $prop
|
||||||
|
@@ -204,7 +204,10 @@ class Configuration
|
|||||||
|
|
||||||
public function setConfigurations($configurations)
|
public function setConfigurations($configurations)
|
||||||
{
|
{
|
||||||
return $this->specifications->setConfigurations($configurations);
|
$this->specifications->setConfigurations($configurations);
|
||||||
|
$this->configuration = new ParameterBag($configurations[$this->environment]);
|
||||||
|
|
||||||
|
return $this->getConfigurations();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setServices($services)
|
public function setServices($services)
|
||||||
|
23
lib/Alchemy/Phrasea/Core/Event/ApiLoadEndEvent.php
Normal file
23
lib/Alchemy/Phrasea/Core/Event/ApiLoadEndEvent.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Phraseanet
|
||||||
|
*
|
||||||
|
* (c) 2005-2013 Alchemy
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Alchemy\Phrasea\Core\Event;
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Core\PhraseaEvents;
|
||||||
|
use Symfony\Component\EventDispatcher\Event as SfEvent;
|
||||||
|
|
||||||
|
class ApiLoadEndEvent extends SfEvent
|
||||||
|
{
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return PhraseaEvents::API_LOAD_END;
|
||||||
|
}
|
||||||
|
}
|
23
lib/Alchemy/Phrasea/Core/Event/ApiLoadStartEvent.php
Normal file
23
lib/Alchemy/Phrasea/Core/Event/ApiLoadStartEvent.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Phraseanet
|
||||||
|
*
|
||||||
|
* (c) 2005-2013 Alchemy
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Alchemy\Phrasea\Core\Event;
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Core\PhraseaEvents;
|
||||||
|
use Symfony\Component\EventDispatcher\Event as SfEvent;
|
||||||
|
|
||||||
|
class ApiLoadStartEvent extends SfEvent
|
||||||
|
{
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return PhraseaEvents::API_LOAD_START;
|
||||||
|
}
|
||||||
|
}
|
23
lib/Alchemy/Phrasea/Core/Event/ApiOAuth2EndEvent.php
Normal file
23
lib/Alchemy/Phrasea/Core/Event/ApiOAuth2EndEvent.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Phraseanet
|
||||||
|
*
|
||||||
|
* (c) 2005-2013 Alchemy
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Alchemy\Phrasea\Core\Event;
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Core\PhraseaEvents;
|
||||||
|
use Symfony\Component\EventDispatcher\Event as SfEvent;
|
||||||
|
|
||||||
|
class ApiOAuth2EndEvent extends SfEvent
|
||||||
|
{
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return PhraseaEvents::API_OAUTH2_END;
|
||||||
|
}
|
||||||
|
}
|
23
lib/Alchemy/Phrasea/Core/Event/ApiOAuth2StartEvent.php
Normal file
23
lib/Alchemy/Phrasea/Core/Event/ApiOAuth2StartEvent.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Phraseanet
|
||||||
|
*
|
||||||
|
* (c) 2005-2013 Alchemy
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Alchemy\Phrasea\Core\Event;
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Core\PhraseaEvents;
|
||||||
|
use Symfony\Component\EventDispatcher\Event as SfEvent;
|
||||||
|
|
||||||
|
class ApiOAuth2StartEvent extends SfEvent
|
||||||
|
{
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return PhraseaEvents::API_OAUTH2_START;
|
||||||
|
}
|
||||||
|
}
|
23
lib/Alchemy/Phrasea/Core/Event/ApiResultEvent.php
Normal file
23
lib/Alchemy/Phrasea/Core/Event/ApiResultEvent.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Phraseanet
|
||||||
|
*
|
||||||
|
* (c) 2005-2013 Alchemy
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Alchemy\Phrasea\Core\Event;
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Core\PhraseaEvents;
|
||||||
|
use Symfony\Component\EventDispatcher\Event as SfEvent;
|
||||||
|
|
||||||
|
class ApiResultEvent extends SfEvent
|
||||||
|
{
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return PhraseaEvents::API_RESULT;
|
||||||
|
}
|
||||||
|
}
|
@@ -14,4 +14,9 @@ namespace Alchemy\Phrasea\Core;
|
|||||||
final class PhraseaEvents
|
final class PhraseaEvents
|
||||||
{
|
{
|
||||||
const LOGOUT = 'phrasea.logout';
|
const LOGOUT = 'phrasea.logout';
|
||||||
|
const API_OAUTH2_START = 'api.oauth2.start';
|
||||||
|
const API_OAUTH2_END = 'api.oauth2.end';
|
||||||
|
const API_LOAD_START = 'api.load.start';
|
||||||
|
const API_LOAD_END = 'api.load.end';
|
||||||
|
const API_RESULT = 'api.result';
|
||||||
}
|
}
|
||||||
|
53
lib/classes/API/V1/Timer.class.php
Normal file
53
lib/classes/API/V1/Timer.class.php
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Silex\Application;
|
||||||
|
use Silex\ServiceProviderInterface;
|
||||||
|
use Alchemy\Phrasea\Core\PhraseaEvents;
|
||||||
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
use Symfony\Component\EventDispatcher\Event;
|
||||||
|
use Symfony\Component\HttpKernel\KernelEvents;
|
||||||
|
|
||||||
|
class API_V1_Timer implements ServiceProviderInterface
|
||||||
|
{
|
||||||
|
private $app;
|
||||||
|
private $starting;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->starting = microtime(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function register(Application $app)
|
||||||
|
{
|
||||||
|
$app['api.timers'] = new ArrayCollection();
|
||||||
|
$app['api.timers.start'] = $this->starting;
|
||||||
|
|
||||||
|
$callback = function (Event $event) use ($app) {
|
||||||
|
$name = $event->getName();
|
||||||
|
$n = 1;
|
||||||
|
while(isset($app['api.timers']->{$name})) {
|
||||||
|
$n++;
|
||||||
|
$name = $event->getName() . '#' . $n;
|
||||||
|
}
|
||||||
|
$app['api.timers']->add(array(
|
||||||
|
'name' => $name,
|
||||||
|
'memory' => memory_get_usage(),
|
||||||
|
'time' => microtime(true) - $app['api.timers.start'],
|
||||||
|
));
|
||||||
|
};
|
||||||
|
|
||||||
|
$app['dispatcher']->addListener(KernelEvents::CONTROLLER, $callback, -999999);
|
||||||
|
$app['dispatcher']->addListener(KernelEvents::REQUEST, $callback, 999999);
|
||||||
|
$app['dispatcher']->addListener(KernelEvents::REQUEST, $callback, -999999);
|
||||||
|
$app['dispatcher']->addListener(KernelEvents::RESPONSE, $callback, -999999);
|
||||||
|
$app['dispatcher']->addListener(KernelEvents::EXCEPTION, $callback, 999999);
|
||||||
|
$app['dispatcher']->addListener(PhraseaEvents::API_OAUTH2_START, $callback);
|
||||||
|
$app['dispatcher']->addListener(PhraseaEvents::API_OAUTH2_END, $callback);
|
||||||
|
$app['dispatcher']->addListener(PhraseaEvents::API_LOAD_END, $callback);
|
||||||
|
$app['dispatcher']->addListener(PhraseaEvents::API_RESULT, $callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function boot(Application $app)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@@ -64,7 +64,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
*/
|
*/
|
||||||
public function get_error_message(Request $request, $error, $message)
|
public function get_error_message(Request $request, $error, $message)
|
||||||
{
|
{
|
||||||
$result = new API_V1_result($request, $this);
|
$result = new API_V1_result($this->app, $request, $this);
|
||||||
$result->set_error_message($error, $message);
|
$result->set_error_message($error, $message);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
@@ -78,7 +78,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
*/
|
*/
|
||||||
public function get_error_code(Request $request, $code)
|
public function get_error_code(Request $request, $code)
|
||||||
{
|
{
|
||||||
$result = new API_V1_result($request, $this);
|
$result = new API_V1_result($this->app, $request, $this);
|
||||||
$result->set_error_code($code);
|
$result->set_error_code($code);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
@@ -102,7 +102,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
*/
|
*/
|
||||||
public function get_scheduler(Application $app)
|
public function get_scheduler(Application $app)
|
||||||
{
|
{
|
||||||
$result = new \API_V1_result($app['request'], $this);
|
$result = new \API_V1_result($app, $app['request'], $this);
|
||||||
|
|
||||||
$taskManager = $app['task-manager'];
|
$taskManager = $app['task-manager'];
|
||||||
$ret = $taskManager->getSchedulerState();
|
$ret = $taskManager->getSchedulerState();
|
||||||
@@ -129,7 +129,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
*/
|
*/
|
||||||
public function get_task_list(Application $app)
|
public function get_task_list(Application $app)
|
||||||
{
|
{
|
||||||
$result = new \API_V1_result($app['request'], $this);
|
$result = new \API_V1_result($app, $app['request'], $this);
|
||||||
|
|
||||||
$taskManager = $app['task-manager'];
|
$taskManager = $app['task-manager'];
|
||||||
$tasks = $taskManager->getTasks();
|
$tasks = $taskManager->getTasks();
|
||||||
@@ -168,7 +168,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
*/
|
*/
|
||||||
public function get_task(Application $app, $taskId)
|
public function get_task(Application $app, $taskId)
|
||||||
{
|
{
|
||||||
$result = new \API_V1_result($app['request'], $this);
|
$result = new \API_V1_result($app, $app['request'], $this);
|
||||||
|
|
||||||
$taskManager = $app['task-manager'];
|
$taskManager = $app['task-manager'];
|
||||||
|
|
||||||
@@ -190,7 +190,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
*/
|
*/
|
||||||
public function start_task(Application $app, $taskId)
|
public function start_task(Application $app, $taskId)
|
||||||
{
|
{
|
||||||
$result = new \API_V1_result($app['request'], $this);
|
$result = new \API_V1_result($app, $app['request'], $this);
|
||||||
|
|
||||||
$taskManager = $app['task-manager'];
|
$taskManager = $app['task-manager'];
|
||||||
|
|
||||||
@@ -213,7 +213,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
*/
|
*/
|
||||||
public function stop_task(Application $app, $taskId)
|
public function stop_task(Application $app, $taskId)
|
||||||
{
|
{
|
||||||
$result = new API_V1_result($app['request'], $this);
|
$result = new API_V1_result($app, $app['request'], $this);
|
||||||
|
|
||||||
$taskManager = $app['task-manager'];
|
$taskManager = $app['task-manager'];
|
||||||
|
|
||||||
@@ -238,7 +238,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
*/
|
*/
|
||||||
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, $app['request'], $this);
|
||||||
|
|
||||||
$title = $app['request']->get('title');
|
$title = $app['request']->get('title');
|
||||||
$autostart = $app['request']->get('autostart');
|
$autostart = $app['request']->get('autostart');
|
||||||
@@ -499,7 +499,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
*/
|
*/
|
||||||
public function get_phraseanet_monitor(Application $app)
|
public function get_phraseanet_monitor(Application $app)
|
||||||
{
|
{
|
||||||
$result = new API_V1_result($app['request'], $this);
|
$result = new API_V1_result($app, $app['request'], $this);
|
||||||
|
|
||||||
$ret = array_merge(
|
$ret = array_merge(
|
||||||
$this->get_config_info($app), $this->get_cache_info($app), $this->get_gv_info($app)
|
$this->get_config_info($app), $this->get_cache_info($app), $this->get_gv_info($app)
|
||||||
@@ -519,7 +519,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
*/
|
*/
|
||||||
public function get_databoxes(Request $request)
|
public function get_databoxes(Request $request)
|
||||||
{
|
{
|
||||||
$result = new API_V1_result($request, $this);
|
$result = new API_V1_result($this->app, $request, $this);
|
||||||
|
|
||||||
$result->set_datas(array("databoxes" => $this->list_databoxes()));
|
$result->set_datas(array("databoxes" => $this->list_databoxes()));
|
||||||
|
|
||||||
@@ -536,7 +536,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
*/
|
*/
|
||||||
public function get_databox_collections(Request $request, $databox_id)
|
public function get_databox_collections(Request $request, $databox_id)
|
||||||
{
|
{
|
||||||
$result = new API_V1_result($request, $this);
|
$result = new API_V1_result($this->app, $request, $this);
|
||||||
|
|
||||||
$result->set_datas(
|
$result->set_datas(
|
||||||
array(
|
array(
|
||||||
@@ -559,7 +559,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
*/
|
*/
|
||||||
public function get_databox_status(Request $request, $databox_id)
|
public function get_databox_status(Request $request, $databox_id)
|
||||||
{
|
{
|
||||||
$result = new API_V1_result($request, $this);
|
$result = new API_V1_result($this->app, $request, $this);
|
||||||
|
|
||||||
$result->set_datas(
|
$result->set_datas(
|
||||||
array(
|
array(
|
||||||
@@ -583,7 +583,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
*/
|
*/
|
||||||
public function get_databox_metadatas(Request $request, $databox_id)
|
public function get_databox_metadatas(Request $request, $databox_id)
|
||||||
{
|
{
|
||||||
$result = new API_V1_result($request, $this);
|
$result = new API_V1_result($this->app, $request, $this);
|
||||||
|
|
||||||
$result->set_datas(
|
$result->set_datas(
|
||||||
array(
|
array(
|
||||||
@@ -608,7 +608,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
*/
|
*/
|
||||||
public function get_databox_terms(Request $request, $databox_id)
|
public function get_databox_terms(Request $request, $databox_id)
|
||||||
{
|
{
|
||||||
$result = new API_V1_result($request, $this);
|
$result = new API_V1_result($this->app, $request, $this);
|
||||||
|
|
||||||
$result->set_datas(
|
$result->set_datas(
|
||||||
array(
|
array(
|
||||||
@@ -622,7 +622,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
|
|
||||||
public function caption_records(Request $request, $databox_id, $record_id)
|
public function caption_records(Request $request, $databox_id, $record_id)
|
||||||
{
|
{
|
||||||
$result = new API_V1_result($request, $this);
|
$result = new API_V1_result($this->app, $request, $this);
|
||||||
|
|
||||||
$record = $this->app['phraseanet.appbox']->get_databox($databox_id)->get_record($record_id);
|
$record = $this->app['phraseanet.appbox']->get_databox($databox_id)->get_record($record_id);
|
||||||
$fields = $record->get_caption()->get_fields();
|
$fields = $record->get_caption()->get_fields();
|
||||||
@@ -728,7 +728,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
$ret['url'] = '/quarantine/item/' . $output->getId() . '/';
|
$ret['url'] = '/quarantine/item/' . $output->getId() . '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = new API_V1_result($request, $this);
|
$result = new API_V1_result($this->app, $request, $this);
|
||||||
|
|
||||||
$result->set_datas($ret);
|
$result->set_datas($ret);
|
||||||
|
|
||||||
@@ -758,7 +758,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
$ret[] = $this->list_lazaret_file($lazaretFile);
|
$ret[] = $this->list_lazaret_file($lazaretFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = new API_V1_result($request, $this);
|
$result = new API_V1_result($this->app, $request, $this);
|
||||||
|
|
||||||
$result->set_datas(array(
|
$result->set_datas(array(
|
||||||
'offset_start' => $offset_start,
|
'offset_start' => $offset_start,
|
||||||
@@ -784,7 +784,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
|
|
||||||
$ret = array('quarantine_item' => $this->list_lazaret_file($lazaretFile));
|
$ret = array('quarantine_item' => $this->list_lazaret_file($lazaretFile));
|
||||||
|
|
||||||
$result = new API_V1_result($request, $this);
|
$result = new API_V1_result($this->app, $request, $this);
|
||||||
|
|
||||||
$result->set_datas($ret);
|
$result->set_datas($ret);
|
||||||
|
|
||||||
@@ -834,7 +834,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
*/
|
*/
|
||||||
public function search(Request $request)
|
public function search(Request $request)
|
||||||
{
|
{
|
||||||
$result = new API_V1_result($request, $this);
|
$result = new API_V1_result($this->app, $request, $this);
|
||||||
|
|
||||||
list($ret, $search_result) = $this->prepare_search_request($request);
|
list($ret, $search_result) = $this->prepare_search_request($request);
|
||||||
|
|
||||||
@@ -867,7 +867,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
*/
|
*/
|
||||||
public function search_records(Request $request)
|
public function search_records(Request $request)
|
||||||
{
|
{
|
||||||
$result = new API_V1_result($request, $this);
|
$result = new API_V1_result($this->app, $request, $this);
|
||||||
|
|
||||||
list($ret, $search_result) = $this->prepare_search_request($request);
|
list($ret, $search_result) = $this->prepare_search_request($request);
|
||||||
|
|
||||||
@@ -935,7 +935,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
*/
|
*/
|
||||||
public function get_record_related(Request $request, $databox_id, $record_id)
|
public function get_record_related(Request $request, $databox_id, $record_id)
|
||||||
{
|
{
|
||||||
$result = new API_V1_result($request, $this);
|
$result = new API_V1_result($this->app, $request, $this);
|
||||||
|
|
||||||
$that = $this;
|
$that = $this;
|
||||||
$baskets = array_map(function ($basket) use ($that) {
|
$baskets = array_map(function ($basket) use ($that) {
|
||||||
@@ -971,7 +971,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
*/
|
*/
|
||||||
public function get_record_metadatas(Request $request, $databox_id, $record_id)
|
public function get_record_metadatas(Request $request, $databox_id, $record_id)
|
||||||
{
|
{
|
||||||
$result = new API_V1_result($request, $this);
|
$result = new API_V1_result($this->app, $request, $this);
|
||||||
|
|
||||||
$record = $this->app['phraseanet.appbox']->get_databox($databox_id)->get_record($record_id);
|
$record = $this->app['phraseanet.appbox']->get_databox($databox_id)->get_record($record_id);
|
||||||
|
|
||||||
@@ -995,7 +995,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
*/
|
*/
|
||||||
public function get_record_status(Request $request, $databox_id, $record_id)
|
public function get_record_status(Request $request, $databox_id, $record_id)
|
||||||
{
|
{
|
||||||
$result = new API_V1_result($request, $this);
|
$result = new API_V1_result($this->app, $request, $this);
|
||||||
|
|
||||||
$record = $this->app['phraseanet.appbox']
|
$record = $this->app['phraseanet.appbox']
|
||||||
->get_databox($databox_id)
|
->get_databox($databox_id)
|
||||||
@@ -1026,7 +1026,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
public function get_record_embed(Request $request, $databox_id, $record_id)
|
public function get_record_embed(Request $request, $databox_id, $record_id)
|
||||||
{
|
{
|
||||||
|
|
||||||
$result = new API_V1_result($request, $this);
|
$result = new API_V1_result($this->app, $request, $this);
|
||||||
|
|
||||||
$record = $this->app['phraseanet.appbox']->get_databox($databox_id)->get_record($record_id);
|
$record = $this->app['phraseanet.appbox']->get_databox($databox_id)->get_record($record_id);
|
||||||
|
|
||||||
@@ -1056,7 +1056,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
public function get_story_embed(Request $request, $databox_id, $record_id)
|
public function get_story_embed(Request $request, $databox_id, $record_id)
|
||||||
{
|
{
|
||||||
|
|
||||||
$result = new API_V1_result($request, $this);
|
$result = new API_V1_result($this->app, $request, $this);
|
||||||
|
|
||||||
$record = $this->app['phraseanet.appbox']
|
$record = $this->app['phraseanet.appbox']
|
||||||
->get_databox($databox_id)
|
->get_databox($databox_id)
|
||||||
@@ -1078,7 +1078,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
|
|
||||||
public function set_record_metadatas(Request $request, $databox_id, $record_id)
|
public function set_record_metadatas(Request $request, $databox_id, $record_id)
|
||||||
{
|
{
|
||||||
$result = new API_V1_result($request, $this);
|
$result = new API_V1_result($this->app, $request, $this);
|
||||||
$record = $this->app['phraseanet.appbox']->get_databox($databox_id)->get_record($record_id);
|
$record = $this->app['phraseanet.appbox']->get_databox($databox_id)->get_record($record_id);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -1105,7 +1105,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
|
|
||||||
public function set_record_status(Request $request, $databox_id, $record_id)
|
public function set_record_status(Request $request, $databox_id, $record_id)
|
||||||
{
|
{
|
||||||
$result = new API_V1_result($request, $this);
|
$result = new API_V1_result($this->app, $request, $this);
|
||||||
$databox = $this->app['phraseanet.appbox']->get_databox($databox_id);
|
$databox = $this->app['phraseanet.appbox']->get_databox($databox_id);
|
||||||
$record = $databox->get_record($record_id);
|
$record = $databox->get_record($record_id);
|
||||||
$status_bits = $databox->get_statusbits();
|
$status_bits = $databox->get_statusbits();
|
||||||
@@ -1159,7 +1159,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
*/
|
*/
|
||||||
public function set_record_collection(Request $request, $databox_id, $record_id)
|
public function set_record_collection(Request $request, $databox_id, $record_id)
|
||||||
{
|
{
|
||||||
$result = new API_V1_result($request, $this);
|
$result = new API_V1_result($this->app, $request, $this);
|
||||||
$databox = $this->app['phraseanet.appbox']->get_databox($databox_id);
|
$databox = $this->app['phraseanet.appbox']->get_databox($databox_id);
|
||||||
$record = $databox->get_record($record_id);
|
$record = $databox->get_record($record_id);
|
||||||
|
|
||||||
@@ -1185,7 +1185,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
*/
|
*/
|
||||||
public function get_record(Request $request, $databox_id, $record_id)
|
public function get_record(Request $request, $databox_id, $record_id)
|
||||||
{
|
{
|
||||||
$result = new API_V1_result($request, $this);
|
$result = new API_V1_result($this->app, $request, $this);
|
||||||
$databox = $this->app['phraseanet.appbox']->get_databox($databox_id);
|
$databox = $this->app['phraseanet.appbox']->get_databox($databox_id);
|
||||||
try {
|
try {
|
||||||
$record = $databox->get_record($record_id);
|
$record = $databox->get_record($record_id);
|
||||||
@@ -1209,7 +1209,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
*/
|
*/
|
||||||
public function get_story(Request $request, $databox_id, $story_id)
|
public function get_story(Request $request, $databox_id, $story_id)
|
||||||
{
|
{
|
||||||
$result = new API_V1_result($request, $this);
|
$result = new API_V1_result($this->app, $request, $this);
|
||||||
$databox = $this->app['phraseanet.appbox']->get_databox($databox_id);
|
$databox = $this->app['phraseanet.appbox']->get_databox($databox_id);
|
||||||
try {
|
try {
|
||||||
$story = $databox->get_record($story_id);
|
$story = $databox->get_record($story_id);
|
||||||
@@ -1231,7 +1231,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
*/
|
*/
|
||||||
public function search_baskets(Request $request)
|
public function search_baskets(Request $request)
|
||||||
{
|
{
|
||||||
$result = new API_V1_result($request, $this);
|
$result = new API_V1_result($this->app, $request, $this);
|
||||||
|
|
||||||
$usr_id = $session = $this->app['phraseanet.user']->get_id();
|
$usr_id = $session = $this->app['phraseanet.user']->get_id();
|
||||||
|
|
||||||
@@ -1269,7 +1269,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
*/
|
*/
|
||||||
public function create_basket(Request $request)
|
public function create_basket(Request $request)
|
||||||
{
|
{
|
||||||
$result = new API_V1_result($request, $this);
|
$result = new API_V1_result($this->app, $request, $this);
|
||||||
|
|
||||||
$name = $request->get('name');
|
$name = $request->get('name');
|
||||||
|
|
||||||
@@ -1318,7 +1318,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
*/
|
*/
|
||||||
public function get_basket(Request $request, $basket_id)
|
public function get_basket(Request $request, $basket_id)
|
||||||
{
|
{
|
||||||
$result = new API_V1_result($request, $this);
|
$result = new API_V1_result($this->app, $request, $this);
|
||||||
|
|
||||||
$repository = $this->app['EM']->getRepository('\Entities\Basket');
|
$repository = $this->app['EM']->getRepository('\Entities\Basket');
|
||||||
|
|
||||||
@@ -1415,7 +1415,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
*/
|
*/
|
||||||
public function set_basket_title(Request $request, $basket_id)
|
public function set_basket_title(Request $request, $basket_id)
|
||||||
{
|
{
|
||||||
$result = new API_V1_result($request, $this);
|
$result = new API_V1_result($this->app, $request, $this);
|
||||||
|
|
||||||
$name = $request->get('name');
|
$name = $request->get('name');
|
||||||
|
|
||||||
@@ -1443,7 +1443,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
*/
|
*/
|
||||||
public function set_basket_description(Request $request, $basket_id)
|
public function set_basket_description(Request $request, $basket_id)
|
||||||
{
|
{
|
||||||
$result = new API_V1_result($request, $this);
|
$result = new API_V1_result($this->app, $request, $this);
|
||||||
|
|
||||||
$desc = $request->get('description');
|
$desc = $request->get('description');
|
||||||
|
|
||||||
@@ -1471,7 +1471,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
*/
|
*/
|
||||||
public function search_publications(Request $request, User_Adapter $user)
|
public function search_publications(Request $request, User_Adapter $user)
|
||||||
{
|
{
|
||||||
$result = new API_V1_result($request, $this);
|
$result = new API_V1_result($this->app, $request, $this);
|
||||||
|
|
||||||
$coll = Feed_Collection::load_all($this->app, $user);
|
$coll = Feed_Collection::load_all($this->app, $user);
|
||||||
|
|
||||||
@@ -1504,7 +1504,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
*/
|
*/
|
||||||
public function get_publication(Request $request, $publication_id, User_Adapter $user)
|
public function get_publication(Request $request, $publication_id, User_Adapter $user)
|
||||||
{
|
{
|
||||||
$result = new API_V1_result($request, $this);
|
$result = new API_V1_result($this->app, $request, $this);
|
||||||
|
|
||||||
$feed = Feed_Adapter::load_with_user($this->app, $user, $publication_id);
|
$feed = Feed_Adapter::load_with_user($this->app, $user, $publication_id);
|
||||||
|
|
||||||
@@ -1527,7 +1527,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
|
|
||||||
public function get_publications(Request $request, User_Adapter $user)
|
public function get_publications(Request $request, User_Adapter $user)
|
||||||
{
|
{
|
||||||
$result = new API_V1_result($request, $this);
|
$result = new API_V1_result($this->app, $request, $this);
|
||||||
|
|
||||||
$feed = Feed_Aggregate::load_with_user($this->app, $user);
|
$feed = Feed_Aggregate::load_with_user($this->app, $user);
|
||||||
|
|
||||||
@@ -1550,7 +1550,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
|
|
||||||
public function get_feed_entry(Request $request, $entry_id, 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($this->app, $request, $this);
|
||||||
|
|
||||||
$entry = Feed_Entry_Adapter::load_from_id($this->app, $entry_id);
|
$entry = Feed_Entry_Adapter::load_from_id($this->app, $entry_id);
|
||||||
|
|
||||||
@@ -1729,8 +1729,9 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
'is_activated' => $permalink->get_is_activated(),
|
'is_activated' => $permalink->get_is_activated(),
|
||||||
'label' => $permalink->get_label(),
|
'label' => $permalink->get_label(),
|
||||||
'updated_on' => $permalink->get_last_modified()->format(DATE_ATOM),
|
'updated_on' => $permalink->get_last_modified()->format(DATE_ATOM),
|
||||||
'page_url' => $permalink->get_page($registry),
|
'page_url' => $permalink->get_page(),
|
||||||
'url' => $permalink->get_url($registry)
|
'download_url' => $permalink->get_url() . '&download',
|
||||||
|
'url' => $permalink->get_url()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -9,19 +9,16 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Alchemy\Phrasea\Core\Event\ApiResultEvent;
|
||||||
|
use Alchemy\Phrasea\Core\PhraseaEvents;
|
||||||
|
use Silex\Application;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @package APIv1
|
|
||||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
|
||||||
* @link www.phraseanet.com
|
|
||||||
*/
|
|
||||||
class API_V1_result
|
class API_V1_result
|
||||||
{
|
{
|
||||||
|
protected $app;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
@@ -103,10 +100,11 @@ class API_V1_result
|
|||||||
*
|
*
|
||||||
* @return API_V1_result
|
* @return API_V1_result
|
||||||
*/
|
*/
|
||||||
public function __construct(Request $request, API_V1_adapter $api)
|
public function __construct(Application $app, Request $request, API_V1_adapter $api)
|
||||||
{
|
{
|
||||||
$date = new DateTime();
|
$date = new DateTime();
|
||||||
|
|
||||||
|
$this->app = $app;
|
||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
$this->api_version = $api->get_version();
|
$this->api_version = $api->get_version();
|
||||||
$this->response_time = $date->format(DATE_ATOM);
|
$this->response_time = $date->format(DATE_ATOM);
|
||||||
@@ -197,6 +195,14 @@ class API_V1_result
|
|||||||
, 'response' => $this->response
|
, 'response' => $this->response
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->app['dispatcher']->dispatch(PhraseaEvents::API_RESULT, new ApiResultEvent());
|
||||||
|
|
||||||
|
$conf = $this->app['phraseanet.configuration']->getPhraseanet();
|
||||||
|
|
||||||
|
if ($conf->has('api-timers') && true === $conf->get('api-timers')) {
|
||||||
|
$ret['timers'] = $this->app['api.timers']->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
$return_value = false;
|
$return_value = false;
|
||||||
|
|
||||||
switch ($this->response_type) {
|
switch ($this->response_type) {
|
||||||
|
@@ -10,6 +10,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
use Alchemy\Phrasea\Application;
|
use Alchemy\Phrasea\Application;
|
||||||
|
use Alchemy\Phrasea\Exception\RuntimeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -145,30 +146,29 @@ class media_Permalink_Adapter implements media_Permalink_Interface, cache_cachea
|
|||||||
*/
|
*/
|
||||||
public function get_url()
|
public function get_url()
|
||||||
{
|
{
|
||||||
return sprintf('%spermalink/v1/%s/%d/%d/%s/%s/'
|
return sprintf('%spermalink/v1/%d/%d/%s/%s.%s?token=%s',
|
||||||
, $this->app['phraseanet.registry']->get('GV_ServerName')
|
$this->app['phraseanet.registry']->get('GV_ServerName'),
|
||||||
, $this->get_label()
|
$this->media_subdef->get_sbas_id(),
|
||||||
, $this->media_subdef->get_sbas_id()
|
$this->media_subdef->get_record_id(),
|
||||||
, $this->media_subdef->get_record_id()
|
$this->media_subdef->get_name(),
|
||||||
, $this->get_token()
|
$this->get_label(),
|
||||||
, $this->media_subdef->get_name()
|
pathinfo($this->media_subdef->get_record()->get_original_name(), PATHINFO_EXTENSION),
|
||||||
|
$this->get_token()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param registryInterface $registry
|
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_page(registryInterface $registry)
|
public function get_page()
|
||||||
{
|
{
|
||||||
return sprintf('%spermalink/v1/%s/%d/%d/%s/%s/view/'
|
return sprintf('%spermalink/v1/%d/%d/%s/?token=%s',
|
||||||
, $registry->get('GV_ServerName')
|
$this->app['phraseanet.registry']->get('GV_ServerName'),
|
||||||
, $this->get_label()
|
$this->media_subdef->get_sbas_id(),
|
||||||
, $this->media_subdef->get_sbas_id()
|
$this->media_subdef->get_record_id(),
|
||||||
, $this->media_subdef->get_record_id()
|
$this->media_subdef->get_name(),
|
||||||
, $this->get_token()
|
$this->get_token()
|
||||||
, $this->media_subdef->get_name()
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,7 +225,7 @@ class media_Permalink_Adapter implements media_Permalink_Interface, cache_cachea
|
|||||||
*/
|
*/
|
||||||
public function set_label($label)
|
public function set_label($label)
|
||||||
{
|
{
|
||||||
$label = trim($label);
|
$label = trim($label) ? trim($label) : 'untitled';
|
||||||
while (strpos($label, ' ') !== false)
|
while (strpos($label, ' ') !== false)
|
||||||
$label = str_replace(' ', ' ', $label);
|
$label = str_replace(' ', ' ', $label);
|
||||||
|
|
||||||
@@ -334,13 +334,21 @@ class media_Permalink_Adapter implements media_Permalink_Interface, cache_cachea
|
|||||||
, ':activated' => '1'
|
, ':activated' => '1'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$error = null;
|
||||||
$stmt = $databox->get_connection()->prepare($sql);
|
$stmt = $databox->get_connection()->prepare($sql);
|
||||||
$stmt->execute($params);
|
try {
|
||||||
|
$stmt->execute($params);
|
||||||
|
} catch (\PDOException $e) {
|
||||||
|
$error = $e;
|
||||||
|
}
|
||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
unset($stmt);
|
|
||||||
|
if ($error) {
|
||||||
|
throw new RuntimeException('Permalink already exists', $e->getCode(), $e);
|
||||||
|
}
|
||||||
|
|
||||||
$permalink = self::getPermalink($app, $databox, $media_subdef);
|
$permalink = self::getPermalink($app, $databox, $media_subdef);
|
||||||
$permalink->set_label(strip_tags($media_subdef->get_record()->get_title()));
|
$permalink->set_label(strip_tags($media_subdef->get_record()->get_title(false, null, true)));
|
||||||
|
|
||||||
return $permalink;
|
return $permalink;
|
||||||
}
|
}
|
||||||
|
@@ -22,7 +22,7 @@ interface media_Permalink_Interface
|
|||||||
|
|
||||||
public function get_url();
|
public function get_url();
|
||||||
|
|
||||||
public function get_page(registryInterface $registry);
|
public function get_page();
|
||||||
|
|
||||||
public function get_id();
|
public function get_id();
|
||||||
|
|
||||||
|
64
lib/classes/patch/379.class.php
Normal file
64
lib/classes/patch/379.class.php
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Phraseanet
|
||||||
|
*
|
||||||
|
* (c) 2005-2012 Alchemy
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Application;
|
||||||
|
|
||||||
|
class patch_379 implements patchInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $release = '3.7.9';
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var Array
|
||||||
|
*/
|
||||||
|
private $concern = array(base::DATA_BOX);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function get_release()
|
||||||
|
{
|
||||||
|
return $this->release;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function require_all_upgrades()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return Array
|
||||||
|
*/
|
||||||
|
public function concern()
|
||||||
|
{
|
||||||
|
return $this->concern;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param base $databox
|
||||||
|
*/
|
||||||
|
public function apply(base $appbox, Application $app)
|
||||||
|
{
|
||||||
|
$sql = 'UPDATE permalinks SET label = "untitled" WHERE label = ""';
|
||||||
|
$stmt = $appbox->get_connection()->prepare($sql);
|
||||||
|
$stmt->execute();
|
||||||
|
$stmt->closeCursor();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@@ -30,13 +30,15 @@
|
|||||||
{% trans 'action : print' %}
|
{% trans 'action : print' %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% if record.is_grouping() is empty %}
|
{% if registry.get('GV_social_tools') == 'all' or (registry.get('GV_social_tools') == 'publishers' and user.ACL().has_right_on_sbas(record.get_sbas_id(), 'bas_chupub')) %}
|
||||||
<div title="" class="context-menu-item">
|
{% if record.is_grouping() is empty %}
|
||||||
<div class="context-menu-item-inner"
|
<div title="" class="context-menu-item">
|
||||||
onclick="shareThis('{{record.get_base_id}}','{{record.get_record_id}}');">
|
<div class="context-menu-item-inner"
|
||||||
{% trans 'reponses:: partager' %}
|
onclick="shareThis('{{record.get_base_id}}','{{record.get_record_id}}');">
|
||||||
|
{% trans 'reponses:: partager' %}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
@@ -2135,11 +2135,18 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
|||||||
$this->assertEquals($subdef->get_permalink()->get_page(self::$DI['app']['phraseanet.registry']), $permalink['page_url']);
|
$this->assertEquals($subdef->get_permalink()->get_page(self::$DI['app']['phraseanet.registry']), $permalink['page_url']);
|
||||||
$this->checkUrlCode200($permalink['page_url']);
|
$this->checkUrlCode200($permalink['page_url']);
|
||||||
$this->assertPermalinkHeaders($permalink['page_url'], $subdef);
|
$this->assertPermalinkHeaders($permalink['page_url'], $subdef);
|
||||||
|
|
||||||
$this->assertArrayHasKey("url", $permalink);
|
$this->assertArrayHasKey("url", $permalink);
|
||||||
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $permalink['url']);
|
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $permalink['url']);
|
||||||
$this->assertEquals($subdef->get_permalink()->get_url(), $permalink['url']);
|
$this->assertEquals($subdef->get_permalink()->get_url(), $permalink['url']);
|
||||||
$this->checkUrlCode200($permalink['url']);
|
$this->checkUrlCode200($permalink['url']);
|
||||||
$this->assertPermalinkHeaders($permalink['url'], $subdef, "url");
|
$this->assertPermalinkHeaders($permalink['url'], $subdef, "url");
|
||||||
|
|
||||||
|
$this->assertArrayHasKey("download_url", $permalink);
|
||||||
|
$this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $permalink['download_url']);
|
||||||
|
$this->assertEquals($subdef->get_permalink()->get_url() . '&download', $permalink['download_url']);
|
||||||
|
$this->checkUrlCode200($permalink['download_url']);
|
||||||
|
$this->assertPermalinkHeaders($permalink['download_url'], $subdef, "download_url");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2157,6 +2164,10 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
|||||||
$this->assertTrue(strpos($headers['content_type'], $subdef->get_mime()) === 0, 'Verify that header ' . $headers['content_type'] . ' contains subdef mime type ' . $subdef->get_mime());
|
$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"]);
|
$this->assertEquals($subdef->get_size(), $headers["download_content_length"]);
|
||||||
break;
|
break;
|
||||||
|
case "download_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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -22,7 +22,7 @@ class ApplicationOverviewTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac
|
|||||||
function testDatafilesNonExistentSubdef()
|
function testDatafilesNonExistentSubdef()
|
||||||
{
|
{
|
||||||
self::$DI['client']->request('GET', '/datafiles/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/asubdefthatdoesnotexists/');
|
self::$DI['client']->request('GET', '/datafiles/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/asubdefthatdoesnotexists/');
|
||||||
|
|
||||||
$this->assertNotFoundResponse(self::$DI['client']->getResponse());
|
$this->assertNotFoundResponse(self::$DI['client']->getResponse());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,6 +72,7 @@ class ApplicationOverviewTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac
|
|||||||
function testPermalinkAuthenticated()
|
function testPermalinkAuthenticated()
|
||||||
{
|
{
|
||||||
$this->assertTrue(self::$DI['app']->isAuthenticated());
|
$this->assertTrue(self::$DI['app']->isAuthenticated());
|
||||||
|
$this->get_a_permalinkBCcompatibility();
|
||||||
$this->get_a_permalink();
|
$this->get_a_permalink();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,6 +80,7 @@ class ApplicationOverviewTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac
|
|||||||
{
|
{
|
||||||
self::$DI['app']->closeAccount();
|
self::$DI['app']->closeAccount();
|
||||||
$this->assertFalse(self::$DI['app']->isAuthenticated());
|
$this->assertFalse(self::$DI['app']->isAuthenticated());
|
||||||
|
$this->get_a_permalinkBCcompatibility();
|
||||||
$this->get_a_permalink();
|
$this->get_a_permalink();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,11 +116,11 @@ class ApplicationOverviewTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac
|
|||||||
$this->assertEquals(200, $response->getStatusCode());
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function get_a_permalink()
|
protected function get_a_permalinkBCcompatibility()
|
||||||
{
|
{
|
||||||
$token = self::$DI['record_1']->get_preview()->get_permalink()->get_token();
|
$token = self::$DI['record_1']->get_preview()->get_permalink()->get_token();
|
||||||
$url = '/permalink/v1/whateverIwannt/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/' . $token . '/preview/';
|
$url = '/permalink/v1/whateverIwannt/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/' . $token . '/preview/';
|
||||||
|
|
||||||
$crawler = self::$DI['client']->request('GET', $url);
|
$crawler = self::$DI['client']->request('GET', $url);
|
||||||
$response = self::$DI['client']->getResponse();
|
$response = self::$DI['client']->getResponse();
|
||||||
|
|
||||||
@@ -129,4 +131,23 @@ class ApplicationOverviewTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac
|
|||||||
$response = self::$DI['client']->getResponse();
|
$response = self::$DI['client']->getResponse();
|
||||||
$this->assertEquals(200, $response->getStatusCode());
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function get_a_permalink()
|
||||||
|
{
|
||||||
|
$token = self::$DI['record_1']->get_preview()->get_permalink()->get_token();
|
||||||
|
$url = '/permalink/v1/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/preview/whateverIwannt.jpg?token=' . $token . '';
|
||||||
|
|
||||||
|
$crawler = self::$DI['client']->request('GET', $url);
|
||||||
|
$response = self::$DI['client']->getResponse();
|
||||||
|
|
||||||
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
|
|
||||||
|
$url = '/permalink/v1/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/preview/?token=' . $token . '';
|
||||||
|
|
||||||
|
$crawler = self::$DI['client']->request('GET', $url);
|
||||||
|
$response = self::$DI['client']->getResponse();
|
||||||
|
|
||||||
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
|
$this->assertEquals('text/html; charset=UTF-8', $response->headers->get('Content-Type'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -559,7 +559,7 @@ class RssFeedTest extends \PhraseanetWebTestCaseAbstract
|
|||||||
$is_thumbnail = false;
|
$is_thumbnail = false;
|
||||||
$record = $entry_item->get_record();
|
$record = $entry_item->get_record();
|
||||||
|
|
||||||
if (substr($current_attributes["url"], 0 - strlen("/preview/")) == "/preview/") {
|
if (false !== strpos($current_attributes["url"], 'preview')) {
|
||||||
$ressource = $record->get_subdef('preview');
|
$ressource = $record->get_subdef('preview');
|
||||||
} else {
|
} else {
|
||||||
$ressource = $record->get_thumbnail();
|
$ressource = $record->get_thumbnail();
|
||||||
|
48
tests/classes/api/v1/api_v1_TimerTest.php
Normal file
48
tests/classes/api/v1/api_v1_TimerTest.php
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Core\PhraseaEvents;
|
||||||
|
use Silex\Application;
|
||||||
|
use Symfony\Component\EventDispatcher\Event;
|
||||||
|
|
||||||
|
class API_V1_TimerTest extends PhraseanetPHPUnitAbstract
|
||||||
|
{
|
||||||
|
public function testRegister()
|
||||||
|
{
|
||||||
|
$start = microtime(true);
|
||||||
|
|
||||||
|
$app = new Application();
|
||||||
|
$dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
|
||||||
|
$dispatcher->expects($this->exactly(9))
|
||||||
|
->method('addListener');
|
||||||
|
$app['dispatcher'] = $dispatcher;
|
||||||
|
$app->register(new API_V1_Timer());
|
||||||
|
|
||||||
|
$this->assertInstanceOf('Doctrine\Common\Collections\ArrayCollection', $app['api.timers']);
|
||||||
|
$this->assertGreaterThan($start, $app['api.timers.start']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testTriggerEvent()
|
||||||
|
{
|
||||||
|
$app = new Application();
|
||||||
|
$app->register(new API_V1_Timer());
|
||||||
|
|
||||||
|
$app['dispatcher']->dispatch(PhraseaEvents::API_RESULT, new Event());
|
||||||
|
|
||||||
|
$timers = $app['api.timers']->toArray();
|
||||||
|
|
||||||
|
$this->assertCount(1, $timers);
|
||||||
|
|
||||||
|
$timer = array_pop($timers);
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('name', $timer);
|
||||||
|
$this->assertArrayHasKey('memory', $timer);
|
||||||
|
$this->assertArrayHasKey('time', $timer);
|
||||||
|
|
||||||
|
$this->assertEquals(PhraseaEvents::API_RESULT, $timer['name']);
|
||||||
|
$this->assertGreaterThan(0, $timer['time']);
|
||||||
|
$this->assertGreaterThan(400000, $timer['memory']);
|
||||||
|
}
|
||||||
|
}
|
@@ -13,6 +13,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
|
|||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
self::$DI['app']->register(new \API_V1_Timer());
|
||||||
$this->object = new API_V1_adapter(self::$DI['app']);
|
$this->object = new API_V1_adapter(self::$DI['app']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -11,14 +11,31 @@ class API_V1_resultTest extends PhraseanetPHPUnitAuthenticatedAbstract
|
|||||||
*/
|
*/
|
||||||
protected $api;
|
protected $api;
|
||||||
|
|
||||||
|
protected $app;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
$this->app = require __DIR__ . '/../../../lib/Alchemy/Phrasea/Application/Api.php';
|
||||||
|
|
||||||
|
$conf = $this->app['Core']->getConfiguration();
|
||||||
|
$confs = $conf->getConfigurations();
|
||||||
|
$confs[$conf->getEnvironnement()]['phraseanet']['api-timers'] = true;
|
||||||
|
|
||||||
|
$this->app['Core']->getConfiguration()->setConfigurations($confs);
|
||||||
|
|
||||||
$this->api = $this->getMock("API_V1_adapter", array("get_version"), array(), "", false);
|
$this->api = $this->getMock("API_V1_adapter", array("get_version"), array(), "", false);
|
||||||
$this->api->expects($this->any())->method("get_version")->will($this->returnValue("my_super_version1.0"));
|
$this->api->expects($this->any())->method("get_version")->will($this->returnValue("my_super_version1.0"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFormat()
|
protected function assertIsTimer($timer)
|
||||||
|
{
|
||||||
|
$this->assertObjectHasAttribute('name', $timer);
|
||||||
|
$this->assertObjectHasAttribute('memory', $timer);
|
||||||
|
$this->assertObjectHasAttribute('time', $timer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFormatJson()
|
||||||
{
|
{
|
||||||
$server = array(
|
$server = array(
|
||||||
"HTTP_ACCEPT" => "application/json"
|
"HTTP_ACCEPT" => "application/json"
|
||||||
@@ -29,7 +46,7 @@ class API_V1_resultTest extends PhraseanetPHPUnitAuthenticatedAbstract
|
|||||||
);
|
);
|
||||||
$request = new Request(array("callback" => ""), array(), array(), array(), array(), $server);
|
$request = new Request(array("callback" => ""), array(), array(), array(), array(), $server);
|
||||||
|
|
||||||
$api_result = new API_V1_result($request, $this->api);
|
$api_result = new API_V1_result($this->app, $request, $this->api);
|
||||||
$return = $api_result->format();
|
$return = $api_result->format();
|
||||||
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $return);
|
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $return);
|
||||||
$response = json_decode($return);
|
$response = json_decode($return);
|
||||||
@@ -43,6 +60,13 @@ class API_V1_resultTest extends PhraseanetPHPUnitAuthenticatedAbstract
|
|||||||
$this->checkResponseFieldMeta($response, "api_version", "my_super_version1.0", PHPUnit_Framework_Constraint_IsType::TYPE_STRING);
|
$this->checkResponseFieldMeta($response, "api_version", "my_super_version1.0", PHPUnit_Framework_Constraint_IsType::TYPE_STRING);
|
||||||
$this->checkResponseFieldMeta($response, "request", "GET my/base/path/my/request/uri", PHPUnit_Framework_Constraint_IsType::TYPE_STRING);
|
$this->checkResponseFieldMeta($response, "request", "GET my/base/path/my/request/uri", PHPUnit_Framework_Constraint_IsType::TYPE_STRING);
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute("timers", $response);
|
||||||
|
$this->assertCount(2, $response->timers);
|
||||||
|
|
||||||
|
foreach ($response->timers as $timer) {
|
||||||
|
$this->assertIsTimer($timer);
|
||||||
|
}
|
||||||
|
|
||||||
$date = new \DateTime();
|
$date = new \DateTime();
|
||||||
$now = $date->format('U');
|
$now = $date->format('U');
|
||||||
|
|
||||||
@@ -66,6 +90,16 @@ class API_V1_resultTest extends PhraseanetPHPUnitAuthenticatedAbstract
|
|||||||
$this->assertObjectHasAttribute("error_details", $response->meta);
|
$this->assertObjectHasAttribute("error_details", $response->meta);
|
||||||
$this->assertNull($response->meta->error_details);
|
$this->assertNull($response->meta->error_details);
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute("timers", $response);
|
||||||
|
$this->assertCount(2, $response->timers);
|
||||||
|
|
||||||
|
foreach ($response->timers as $timer) {
|
||||||
|
$this->assertIsTimer($timer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFormatYaml()
|
||||||
|
{
|
||||||
$server = array(
|
$server = array(
|
||||||
"HTTP_ACCEPT" => "application/yaml"
|
"HTTP_ACCEPT" => "application/yaml"
|
||||||
, 'REQUEST_METHOD' => 'GET'
|
, 'REQUEST_METHOD' => 'GET'
|
||||||
@@ -75,7 +109,7 @@ class API_V1_resultTest extends PhraseanetPHPUnitAuthenticatedAbstract
|
|||||||
);
|
);
|
||||||
$request = new Request(array("callback" => ""), array(), array(), array(), array(), $server);
|
$request = new Request(array("callback" => ""), array(), array(), array(), array(), $server);
|
||||||
|
|
||||||
$api_result = new API_V1_result($request, $this->api);
|
$api_result = new API_V1_result($this->app, $request, $this->api);
|
||||||
$return = $api_result->format();
|
$return = $api_result->format();
|
||||||
$sfYaml = new Symfony\Component\Yaml\Parser();
|
$sfYaml = new Symfony\Component\Yaml\Parser();
|
||||||
$response = $sfYaml->parse($return);
|
$response = $sfYaml->parse($return);
|
||||||
@@ -111,7 +145,12 @@ class API_V1_resultTest extends PhraseanetPHPUnitAuthenticatedAbstract
|
|||||||
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $response["meta"]["charset"]);
|
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $response["meta"]["charset"]);
|
||||||
$this->assertEquals("UTF-8", $response["meta"]["charset"]);
|
$this->assertEquals("UTF-8", $response["meta"]["charset"]);
|
||||||
|
|
||||||
|
$this->assertArrayHasKey("timers", $response);
|
||||||
|
$this->assertCount(2, $response['timers']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFormatJsonP()
|
||||||
|
{
|
||||||
$server = array(
|
$server = array(
|
||||||
"HTTP_ACCEPT" => "application/yaml"
|
"HTTP_ACCEPT" => "application/yaml"
|
||||||
, 'REQUEST_METHOD' => 'GET'
|
, 'REQUEST_METHOD' => 'GET'
|
||||||
@@ -121,14 +160,22 @@ class API_V1_resultTest extends PhraseanetPHPUnitAuthenticatedAbstract
|
|||||||
);
|
);
|
||||||
$request = new Request(array("callback" => "my_callback_function"), array(), array(), array(), array(), $server);
|
$request = new Request(array("callback" => "my_callback_function"), array(), array(), array(), array(), $server);
|
||||||
|
|
||||||
$api_result = new API_V1_result($request, $this->api);
|
$api_result = new API_V1_result($this->app, $request, $this->api);
|
||||||
$return = $api_result->format();
|
$return = $api_result->format();
|
||||||
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $return);
|
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $return);
|
||||||
$this->assertRegexp("/my_callback_function\(\{.+\}\)/", $return);
|
$this->assertRegexp("/my_callback_function\(\{.+\}\)/", $return);
|
||||||
|
$response = json_decode(substr($return, 21, strlen($return) - 22));
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute("timers", $response);
|
||||||
|
$this->assertCount(2, $response->timers);
|
||||||
|
|
||||||
|
foreach ($response->timers as $timer) {
|
||||||
|
$this->assertIsTimer($timer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @depends testFormat
|
* @depends testFormatJson
|
||||||
*/
|
*/
|
||||||
public function testSet_datas()
|
public function testSet_datas()
|
||||||
{
|
{
|
||||||
@@ -141,7 +188,7 @@ class API_V1_resultTest extends PhraseanetPHPUnitAuthenticatedAbstract
|
|||||||
);
|
);
|
||||||
$request = new Request(array("callback" => ""), array(), array(), array(), array(), $server);
|
$request = new Request(array("callback" => ""), array(), array(), array(), array(), $server);
|
||||||
|
|
||||||
$api_result = new API_V1_result($request, $this->api);
|
$api_result = new API_V1_result($this->app, $request, $this->api);
|
||||||
$api_result->set_datas(array("pirouette" => "cacahuete", "black" => true, "bob" => array("bob")));
|
$api_result->set_datas(array("pirouette" => "cacahuete", "black" => true, "bob" => array("bob")));
|
||||||
$response = json_decode($api_result->format());
|
$response = json_decode($api_result->format());
|
||||||
$this->checkResponseFieldResponse($response, "pirouette", "cacahuete", PHPUnit_Framework_Constraint_IsType::TYPE_STRING);
|
$this->checkResponseFieldResponse($response, "pirouette", "cacahuete", PHPUnit_Framework_Constraint_IsType::TYPE_STRING);
|
||||||
@@ -161,7 +208,7 @@ class API_V1_resultTest extends PhraseanetPHPUnitAuthenticatedAbstract
|
|||||||
$request = new Request(array("callback" => ""), array(), array(), array(), array(), $server);
|
$request = new Request(array("callback" => ""), array(), array(), array(), array(), $server);
|
||||||
|
|
||||||
$data = array("pirouette" => "cacahuete", "black" => true, "bob" => array("bob"));
|
$data = array("pirouette" => "cacahuete", "black" => true, "bob" => array("bob"));
|
||||||
$api_result = new API_V1_result($request, $this->api);
|
$api_result = new API_V1_result($this->app, $request, $this->api);
|
||||||
$api_result->set_datas($data);
|
$api_result->set_datas($data);
|
||||||
|
|
||||||
$this->assertEquals($data, $api_result->get_datas());
|
$this->assertEquals($data, $api_result->get_datas());
|
||||||
@@ -179,7 +226,7 @@ class API_V1_resultTest extends PhraseanetPHPUnitAuthenticatedAbstract
|
|||||||
$request = new Request(array("callback" => ""), array(), array(), array(), array(), $server);
|
$request = new Request(array("callback" => ""), array(), array(), array(), array(), $server);
|
||||||
|
|
||||||
$data = array();
|
$data = array();
|
||||||
$api_result = new API_V1_result($request, $this->api);
|
$api_result = new API_V1_result($this->app, $request, $this->api);
|
||||||
$api_result->set_datas($data);
|
$api_result->set_datas($data);
|
||||||
|
|
||||||
$this->assertEquals($data, $api_result->get_datas());
|
$this->assertEquals($data, $api_result->get_datas());
|
||||||
@@ -203,60 +250,60 @@ class API_V1_resultTest extends PhraseanetPHPUnitAuthenticatedAbstract
|
|||||||
{
|
{
|
||||||
$server = array("HTTP_ACCEPT" => "application/json");
|
$server = array("HTTP_ACCEPT" => "application/json");
|
||||||
$request = new Request(array("callback" => ""), array(), array(), array(), array(), $server);
|
$request = new Request(array("callback" => ""), array(), array(), array(), array(), $server);
|
||||||
$api_result = new API_V1_result($request, $this->api);
|
$api_result = new API_V1_result($this->app, $request, $this->api);
|
||||||
$this->assertEquals("application/json", $api_result->get_content_type());
|
$this->assertEquals("application/json", $api_result->get_content_type());
|
||||||
|
|
||||||
$server = array("HTTP_ACCEPT" => "application/yaml");
|
$server = array("HTTP_ACCEPT" => "application/yaml");
|
||||||
$request = new Request(array("callback" => ""), array(), array(), array(), array(), $server);
|
$request = new Request(array("callback" => ""), array(), array(), array(), array(), $server);
|
||||||
$api_result = new API_V1_result($request, $this->api);
|
$api_result = new API_V1_result($this->app, $request, $this->api);
|
||||||
$this->assertEquals('application/yaml', $api_result->get_content_type());
|
$this->assertEquals('application/yaml', $api_result->get_content_type());
|
||||||
|
|
||||||
$server = array("HTTP_ACCEPT" => "text/yaml");
|
$server = array("HTTP_ACCEPT" => "text/yaml");
|
||||||
$request = new Request(array("callback" => ""), array(), array(), array(), array(), $server);
|
$request = new Request(array("callback" => ""), array(), array(), array(), array(), $server);
|
||||||
$api_result = new API_V1_result($request, $this->api);
|
$api_result = new API_V1_result($this->app, $request, $this->api);
|
||||||
$this->assertEquals('application/yaml', $api_result->get_content_type());
|
$this->assertEquals('application/yaml', $api_result->get_content_type());
|
||||||
|
|
||||||
$server = array("HTTP_ACCEPT" => "");
|
$server = array("HTTP_ACCEPT" => "");
|
||||||
$request = new Request(array("callback" => "hello"), array(), array(), array(), array(), $server);
|
$request = new Request(array("callback" => "hello"), array(), array(), array(), array(), $server);
|
||||||
$api_result = new API_V1_result($request, $this->api);
|
$api_result = new API_V1_result($this->app, $request, $this->api);
|
||||||
$this->assertEquals('text/javascript', $api_result->get_content_type());
|
$this->assertEquals('text/javascript', $api_result->get_content_type());
|
||||||
|
|
||||||
$server = array("HTTP_ACCEPT" => "unknow");
|
$server = array("HTTP_ACCEPT" => "unknow");
|
||||||
$request = new Request(array("callback" => ""), array(), array(), array(), array(), $server);
|
$request = new Request(array("callback" => ""), array(), array(), array(), array(), $server);
|
||||||
$api_result = new API_V1_result($request, $this->api);
|
$api_result = new API_V1_result($this->app, $request, $this->api);
|
||||||
$this->assertEquals("application/json", $api_result->get_content_type());
|
$this->assertEquals("application/json", $api_result->get_content_type());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @depends testFormat
|
* @depends testFormatJson
|
||||||
*/
|
*/
|
||||||
public function testSet_error_message()
|
public function testSet_error_message()
|
||||||
{
|
{
|
||||||
$api_result = new API_V1_result(new Request(), $this->api);
|
$api_result = new API_V1_result($this->app, new Request(), $this->api);
|
||||||
$api_result->set_error_message(API_V1_result::ERROR_BAD_REQUEST, 'detaillage');
|
$api_result->set_error_message(API_V1_result::ERROR_BAD_REQUEST, 'detaillage');
|
||||||
$this->assertErrorMessage($api_result, 400, API_V1_result::ERROR_BAD_REQUEST, API_V1_exception_badrequest::get_details(), 'detaillage');
|
$this->assertErrorMessage($api_result, 400, API_V1_result::ERROR_BAD_REQUEST, API_V1_exception_badrequest::get_details(), 'detaillage');
|
||||||
|
|
||||||
$api_result = new API_V1_result(new Request(), $this->api);
|
$api_result = new API_V1_result($this->app, new Request(), $this->api);
|
||||||
$api_result->set_error_message(API_V1_result::ERROR_UNAUTHORIZED, 'detaillage');
|
$api_result->set_error_message(API_V1_result::ERROR_UNAUTHORIZED, 'detaillage');
|
||||||
$this->assertErrorMessage($api_result, 401, API_V1_result::ERROR_UNAUTHORIZED, API_V1_exception_unauthorized::get_details(), 'detaillage');
|
$this->assertErrorMessage($api_result, 401, API_V1_result::ERROR_UNAUTHORIZED, API_V1_exception_unauthorized::get_details(), 'detaillage');
|
||||||
|
|
||||||
$api_result = new API_V1_result(new Request(), $this->api);
|
$api_result = new API_V1_result($this->app, new Request(), $this->api);
|
||||||
$api_result->set_error_message(API_V1_result::ERROR_FORBIDDEN, 'detaillage');
|
$api_result->set_error_message(API_V1_result::ERROR_FORBIDDEN, 'detaillage');
|
||||||
$this->assertErrorMessage($api_result, 403, API_V1_result::ERROR_FORBIDDEN, API_V1_exception_forbidden::get_details(), 'detaillage');
|
$this->assertErrorMessage($api_result, 403, API_V1_result::ERROR_FORBIDDEN, API_V1_exception_forbidden::get_details(), 'detaillage');
|
||||||
|
|
||||||
$api_result = new API_V1_result(new Request(), $this->api);
|
$api_result = new API_V1_result($this->app, new Request(), $this->api);
|
||||||
$api_result->set_error_message(API_V1_result::ERROR_NOTFOUND, 'detaillage');
|
$api_result->set_error_message(API_V1_result::ERROR_NOTFOUND, 'detaillage');
|
||||||
$this->assertErrorMessage($api_result, 404, API_V1_result::ERROR_NOTFOUND, API_V1_exception_notfound::get_details(), 'detaillage');
|
$this->assertErrorMessage($api_result, 404, API_V1_result::ERROR_NOTFOUND, API_V1_exception_notfound::get_details(), 'detaillage');
|
||||||
|
|
||||||
$api_result = new API_V1_result(new Request(), $this->api);
|
$api_result = new API_V1_result($this->app, new Request(), $this->api);
|
||||||
$api_result->set_error_message(API_V1_result::ERROR_METHODNOTALLOWED, 'detaillage');
|
$api_result->set_error_message(API_V1_result::ERROR_METHODNOTALLOWED, 'detaillage');
|
||||||
$this->assertErrorMessage($api_result, 405, API_V1_result::ERROR_METHODNOTALLOWED, API_V1_exception_methodnotallowed::get_details(), 'detaillage');
|
$this->assertErrorMessage($api_result, 405, API_V1_result::ERROR_METHODNOTALLOWED, API_V1_exception_methodnotallowed::get_details(), 'detaillage');
|
||||||
|
|
||||||
$api_result = new API_V1_result(new Request(), $this->api);
|
$api_result = new API_V1_result($this->app, new Request(), $this->api);
|
||||||
$api_result->set_error_message(API_V1_result::ERROR_INTERNALSERVERERROR, 'detaillage');
|
$api_result->set_error_message(API_V1_result::ERROR_INTERNALSERVERERROR, 'detaillage');
|
||||||
$this->assertErrorMessage($api_result, 500, API_V1_result::ERROR_INTERNALSERVERERROR, API_V1_exception_internalservererror::get_details(), 'detaillage');
|
$this->assertErrorMessage($api_result, 500, API_V1_result::ERROR_INTERNALSERVERERROR, API_V1_exception_internalservererror::get_details(), 'detaillage');
|
||||||
|
|
||||||
$api_result = new API_V1_result(new Request(), $this->api);
|
$api_result = new API_V1_result($this->app, new Request(), $this->api);
|
||||||
$api_result->set_error_message(OAUTH2_ERROR_INVALID_REQUEST, 'detaillage');
|
$api_result->set_error_message(OAUTH2_ERROR_INVALID_REQUEST, 'detaillage');
|
||||||
$this->assertErrorMessage($api_result, 200, OAUTH2_ERROR_INVALID_REQUEST, NULL, 'detaillage');
|
$this->assertErrorMessage($api_result, 200, OAUTH2_ERROR_INVALID_REQUEST, NULL, 'detaillage');
|
||||||
}
|
}
|
||||||
@@ -289,73 +336,73 @@ class API_V1_resultTest extends PhraseanetPHPUnitAuthenticatedAbstract
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @depends testFormat
|
* @depends testFormatJson
|
||||||
*/
|
*/
|
||||||
public function testSet_error_code()
|
public function testSet_error_code()
|
||||||
{
|
{
|
||||||
$api_result = new API_V1_result(new Request(), $this->api);
|
$api_result = new API_V1_result($this->app, new Request(), $this->api);
|
||||||
$api_result->set_error_code(400);
|
$api_result->set_error_code(400);
|
||||||
$this->assertErrorMessage($api_result, 400, API_V1_result::ERROR_BAD_REQUEST, API_V1_exception_badrequest::get_details(), null);
|
$this->assertErrorMessage($api_result, 400, API_V1_result::ERROR_BAD_REQUEST, API_V1_exception_badrequest::get_details(), null);
|
||||||
|
|
||||||
$api_result = new API_V1_result(new Request(), $this->api);
|
$api_result = new API_V1_result($this->app, new Request(), $this->api);
|
||||||
$api_result->set_error_code(401);
|
$api_result->set_error_code(401);
|
||||||
$this->assertErrorMessage($api_result, 401, API_V1_result::ERROR_UNAUTHORIZED, API_V1_exception_unauthorized::get_details(), null);
|
$this->assertErrorMessage($api_result, 401, API_V1_result::ERROR_UNAUTHORIZED, API_V1_exception_unauthorized::get_details(), null);
|
||||||
|
|
||||||
$api_result = new API_V1_result(new Request(), $this->api);
|
$api_result = new API_V1_result($this->app, new Request(), $this->api);
|
||||||
$api_result->set_error_code(403);
|
$api_result->set_error_code(403);
|
||||||
$this->assertErrorMessage($api_result, 403, API_V1_result::ERROR_FORBIDDEN, API_V1_exception_forbidden::get_details(), null);
|
$this->assertErrorMessage($api_result, 403, API_V1_result::ERROR_FORBIDDEN, API_V1_exception_forbidden::get_details(), null);
|
||||||
|
|
||||||
$api_result = new API_V1_result(new Request(), $this->api);
|
$api_result = new API_V1_result($this->app, new Request(), $this->api);
|
||||||
$api_result->set_error_code(404);
|
$api_result->set_error_code(404);
|
||||||
$this->assertErrorMessage($api_result, 404, API_V1_result::ERROR_NOTFOUND, API_V1_exception_notfound::get_details(), null);
|
$this->assertErrorMessage($api_result, 404, API_V1_result::ERROR_NOTFOUND, API_V1_exception_notfound::get_details(), null);
|
||||||
|
|
||||||
$api_result = new API_V1_result(new Request(), $this->api);
|
$api_result = new API_V1_result($this->app, new Request(), $this->api);
|
||||||
$api_result->set_error_code(405);
|
$api_result->set_error_code(405);
|
||||||
$this->assertErrorMessage($api_result, 405, API_V1_result::ERROR_METHODNOTALLOWED, API_V1_exception_methodnotallowed::get_details(), null);
|
$this->assertErrorMessage($api_result, 405, API_V1_result::ERROR_METHODNOTALLOWED, API_V1_exception_methodnotallowed::get_details(), null);
|
||||||
|
|
||||||
$api_result = new API_V1_result(new Request(), $this->api);
|
$api_result = new API_V1_result($this->app, new Request(), $this->api);
|
||||||
$api_result->set_error_code(500);
|
$api_result->set_error_code(500);
|
||||||
$this->assertErrorMessage($api_result, 500, API_V1_result::ERROR_INTERNALSERVERERROR, API_V1_exception_internalservererror::get_details(), null);
|
$this->assertErrorMessage($api_result, 500, API_V1_result::ERROR_INTERNALSERVERERROR, API_V1_exception_internalservererror::get_details(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGet_http_code()
|
public function testGet_http_code()
|
||||||
{
|
{
|
||||||
$api_result = new API_V1_result(new Request(), $this->api);
|
$api_result = new API_V1_result($this->app, new Request(), $this->api);
|
||||||
$api_result->set_error_code(400);
|
$api_result->set_error_code(400);
|
||||||
$this->assertEquals(400, $api_result->get_http_code());
|
$this->assertEquals(400, $api_result->get_http_code());
|
||||||
|
|
||||||
$api_result = new API_V1_result(new Request(), $this->api);
|
$api_result = new API_V1_result($this->app, new Request(), $this->api);
|
||||||
$api_result->set_error_code(401);
|
$api_result->set_error_code(401);
|
||||||
$this->assertEquals(401, $api_result->get_http_code());
|
$this->assertEquals(401, $api_result->get_http_code());
|
||||||
|
|
||||||
$api_result = new API_V1_result(new Request(), $this->api);
|
$api_result = new API_V1_result($this->app, new Request(), $this->api);
|
||||||
$api_result->set_error_code(403);
|
$api_result->set_error_code(403);
|
||||||
$this->assertEquals(403, $api_result->get_http_code());
|
$this->assertEquals(403, $api_result->get_http_code());
|
||||||
|
|
||||||
$api_result = new API_V1_result(new Request(), $this->api);
|
$api_result = new API_V1_result($this->app, new Request(), $this->api);
|
||||||
$api_result->set_error_code(404);
|
$api_result->set_error_code(404);
|
||||||
$this->assertEquals(404, $api_result->get_http_code());
|
$this->assertEquals(404, $api_result->get_http_code());
|
||||||
|
|
||||||
$api_result = new API_V1_result(new Request(), $this->api);
|
$api_result = new API_V1_result($this->app, new Request(), $this->api);
|
||||||
$api_result->set_error_code(405);
|
$api_result->set_error_code(405);
|
||||||
$this->assertEquals(405, $api_result->get_http_code());
|
$this->assertEquals(405, $api_result->get_http_code());
|
||||||
|
|
||||||
$api_result = new API_V1_result(new Request(), $this->api);
|
$api_result = new API_V1_result($this->app, new Request(), $this->api);
|
||||||
$api_result->set_error_code(500);
|
$api_result->set_error_code(500);
|
||||||
$this->assertEquals(500, $api_result->get_http_code());
|
$this->assertEquals(500, $api_result->get_http_code());
|
||||||
|
|
||||||
$api_result = new API_V1_result(new Request(array("callback" => "my_callback")), $this->api);
|
$api_result = new API_V1_result($this->app, new Request(array("callback" => "my_callback")), $this->api);
|
||||||
$api_result->set_error_code(400);
|
$api_result->set_error_code(400);
|
||||||
$this->assertEquals(200, $api_result->get_http_code());
|
$this->assertEquals(200, $api_result->get_http_code());
|
||||||
|
|
||||||
$api_result = new API_V1_result(new Request(array("callback" => "my_callback")), $this->api);
|
$api_result = new API_V1_result($this->app, new Request(array("callback" => "my_callback")), $this->api);
|
||||||
$api_result->set_error_code(500);
|
$api_result->set_error_code(500);
|
||||||
$this->assertEquals(500, $api_result->get_http_code());
|
$this->assertEquals(500, $api_result->get_http_code());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSet_http_code()
|
public function testSet_http_code()
|
||||||
{
|
{
|
||||||
$api_result = new API_V1_result(new Request(), $this->api);
|
$api_result = new API_V1_result($this->app, new Request(), $this->api);
|
||||||
$api_result->set_http_code(500);
|
$api_result->set_http_code(500);
|
||||||
$this->assertEquals(500, $api_result->get_http_code());
|
$this->assertEquals(500, $api_result->get_http_code());
|
||||||
|
|
||||||
@@ -366,7 +413,7 @@ class API_V1_resultTest extends PhraseanetPHPUnitAuthenticatedAbstract
|
|||||||
$api_result->set_http_code(403);
|
$api_result->set_http_code(403);
|
||||||
$this->assertEquals(403, $api_result->get_http_code());
|
$this->assertEquals(403, $api_result->get_http_code());
|
||||||
|
|
||||||
$api_result = new API_V1_result(new Request(array("callback" => "my_callback")), $this->api);
|
$api_result = new API_V1_result($this->app, new Request(array("callback" => "my_callback")), $this->api);
|
||||||
$api_result->set_http_code(500);
|
$api_result->set_http_code(500);
|
||||||
$this->assertEquals(500, $api_result->get_http_code());
|
$this->assertEquals(500, $api_result->get_http_code());
|
||||||
|
|
||||||
|
@@ -7,13 +7,19 @@ class media_Permalink_AdapterTest extends PhraseanetPHPUnitAbstract
|
|||||||
*/
|
*/
|
||||||
static $object;
|
static $object;
|
||||||
|
|
||||||
public static function setUpBeforeClass()
|
public function setUp()
|
||||||
{
|
{
|
||||||
parent::setUpBeforeClass();
|
parent::setUp();
|
||||||
$databox = self::$DI['record_1']->get_databox();
|
$databox = self::$DI['record_1']->get_databox();
|
||||||
static::$object = media_Permalink_Adapter::getPermalink(self::$DI['app'], $databox, self::$DI['record_1']->get_subdef('document'));
|
static::$object = media_Permalink_Adapter::getPermalink(self::$DI['app'], $databox, self::$DI['record_1']->get_subdef('document'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGet_label()
|
||||||
|
{
|
||||||
|
$this->assertInternalType('string', static::$object->get_label());
|
||||||
|
$this->assertEquals('test001', static::$object->get_label());
|
||||||
|
}
|
||||||
|
|
||||||
public function testGetPermalink()
|
public function testGetPermalink()
|
||||||
{
|
{
|
||||||
$this->assertTrue((static::$object instanceof media_Permalink_Adapter));
|
$this->assertTrue((static::$object instanceof media_Permalink_Adapter));
|
||||||
@@ -34,105 +40,65 @@ class media_Permalink_AdapterTest extends PhraseanetPHPUnitAbstract
|
|||||||
static::$object->set_label('coucou les chicos');
|
static::$object->set_label('coucou les chicos');
|
||||||
$this->assertEquals('coucou-les-chicos', static::$object->get_label());
|
$this->assertEquals('coucou-les-chicos', static::$object->get_label());
|
||||||
static::$object->set_label('');
|
static::$object->set_label('');
|
||||||
$this->assertEquals('', static::$object->get_label());
|
$this->assertEquals('untitled', static::$object->get_label());
|
||||||
static::$object->set_label('JE ANp ra&é"\/,;:!§/.?%µ*ù$]@^\[{#~234567890°+\'(-è_çà');
|
static::$object->set_label('JE ANp ra&é"\/,;:!§/.?%µ*ù$]@^\[{#~234567890°+\'(-è_çà');
|
||||||
$this->assertEquals('JE-ANp-raeu234567890-e_ca', static::$object->get_label());
|
$this->assertEquals('JE-ANp-raeu234567890-e_ca', static::$object->get_label());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGet_url()
|
public function testGet_url()
|
||||||
{
|
{
|
||||||
$url = self::$DI['app']['phraseanet.registry']->get('GV_ServerName') . 'permalink/v1/' . static::$object->get_label() . '/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/' .
|
$url = self::$DI['app']['phraseanet.registry']->get('GV_ServerName') . 'permalink/v1/'
|
||||||
static::$object->get_token() . '/document/';
|
. self::$DI['record_1']->get_sbas_id() . '/'
|
||||||
|
. self::$DI['record_1']->get_record_id()
|
||||||
|
. '/document/' . static::$object->get_label()
|
||||||
|
. '.' . pathinfo(self::$DI['record_1']->get_original_name(), PATHINFO_EXTENSION)
|
||||||
|
. '?token=' . static::$object->get_token();
|
||||||
|
|
||||||
$this->assertEquals($url, static::$object->get_url(self::$DI['app']['phraseanet.registry']));
|
$this->assertEquals($url, static::$object->get_url(self::$DI['app']['phraseanet.registry']));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @todo Implement testGet_page().
|
|
||||||
*/
|
|
||||||
public function testGet_page()
|
public function testGet_page()
|
||||||
{
|
{
|
||||||
// Remove the following lines when you implement this test.
|
$url = self::$DI['app']['phraseanet.registry']->get('GV_ServerName') . 'permalink/v1/'
|
||||||
$this->markTestIncomplete(
|
. self::$DI['record_1']->get_sbas_id() . '/'
|
||||||
'This test has not been implemented yet.'
|
. self::$DI['record_1']->get_record_id()
|
||||||
);
|
. '/document/'
|
||||||
|
. '?token=' . static::$object->get_token();
|
||||||
|
|
||||||
|
$this->assertEquals($url, static::$object->get_page());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @todo Implement testGet_id().
|
|
||||||
*/
|
|
||||||
public function testGet_id()
|
public function testGet_id()
|
||||||
{
|
{
|
||||||
// Remove the following lines when you implement this test.
|
$this->assertInternalType('integer', static::$object->get_id());
|
||||||
$this->markTestIncomplete(
|
|
||||||
'This test has not been implemented yet.'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @todo Implement testGet_token().
|
|
||||||
*/
|
|
||||||
public function testGet_token()
|
public function testGet_token()
|
||||||
{
|
{
|
||||||
// Remove the following lines when you implement this test.
|
$this->assertInternalType('string', static::$object->get_token());
|
||||||
$this->markTestIncomplete(
|
|
||||||
'This test has not been implemented yet.'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @todo Implement testGet_is_activated().
|
|
||||||
*/
|
|
||||||
public function testGet_is_activated()
|
public function testGet_is_activated()
|
||||||
{
|
{
|
||||||
// Remove the following lines when you implement this test.
|
$this->assertInternalType('boolean', static::$object->get_is_activated());
|
||||||
$this->markTestIncomplete(
|
|
||||||
'This test has not been implemented yet.'
|
|
||||||
);
|
|
||||||
$this->assertTrue(is_bool(static::$object->get_is_activated));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @todo Implement testGet_created_on().
|
|
||||||
*/
|
|
||||||
public function testGet_created_on()
|
public function testGet_created_on()
|
||||||
{
|
{
|
||||||
// Remove the following lines when you implement this test.
|
$this->assertInstanceOf('DateTime', static::$object->get_created_on());
|
||||||
$this->markTestIncomplete(
|
|
||||||
'This test has not been implemented yet.'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @todo Implement testGet_last_modified().
|
|
||||||
*/
|
|
||||||
public function testGet_last_modified()
|
public function testGet_last_modified()
|
||||||
{
|
{
|
||||||
// Remove the following lines when you implement this test.
|
$this->assertInstanceOf('DateTime', static::$object->get_last_modified());
|
||||||
$this->markTestIncomplete(
|
|
||||||
'This test has not been implemented yet.'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @todo Implement testGet_label().
|
* @expectedException Alchemy\Phrasea\Exception\RuntimeException
|
||||||
*/
|
*/
|
||||||
public function testGet_label()
|
public function testCreateAPermalinkAlreadyCreated()
|
||||||
{
|
{
|
||||||
// Remove the following lines when you implement this test.
|
$databox = self::$DI['record_1']->get_databox();
|
||||||
$this->markTestIncomplete(
|
media_Permalink_Adapter::create(self::$DI['app'], $databox, self::$DI['record_1']->get_subdef('document'));
|
||||||
'This test has not been implemented yet.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @todo Implement testCreate().
|
|
||||||
*/
|
|
||||||
public function testCreate()
|
|
||||||
{
|
|
||||||
// Remove the following lines when you implement this test.
|
|
||||||
$this->markTestIncomplete(
|
|
||||||
'This test has not been implemented yet.'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user