mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-12 12:33:26 +00:00
Workaround for HttpKernel bug in API
This commit is contained in:
@@ -18,6 +18,8 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -731,6 +733,15 @@ return call_user_func(function() {
|
||||
return $response;
|
||||
});
|
||||
|
||||
/**
|
||||
* Temporary fix for https://github.com/fabpot/Silex/issues/438
|
||||
*/
|
||||
$app['dispatcher']->addListener(KernelEvents::RESPONSE, function(FilterResponseEvent $event){
|
||||
if ($event->getResponse() instanceof \API_V1_Response) {
|
||||
$event->getResponse()->setStatusCode($event->getResponse()->getOriginalStatusCode());
|
||||
}
|
||||
});
|
||||
|
||||
return $app;
|
||||
}
|
||||
);
|
||||
|
33
lib/classes/API/V1/Response.class.php
Normal file
33
lib/classes/API/V1/Response.class.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?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 Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* Used as a temporary fix for https://github.com/fabpot/Silex/issues/438
|
||||
*
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class API_V1_Response extends Response
|
||||
{
|
||||
private $originalStatusCode;
|
||||
|
||||
public function setOriginalStatusCode($code)
|
||||
{
|
||||
$this->originalStatusCode = $code;
|
||||
}
|
||||
|
||||
public function getOriginalStatusCode()
|
||||
{
|
||||
return $this->originalStatusCode;
|
||||
}
|
||||
}
|
@@ -358,12 +358,12 @@ class API_V1_result
|
||||
*/
|
||||
public function get_response()
|
||||
{
|
||||
$response = new Symfony\Component\HttpFoundation\Response(
|
||||
$response = new \API_V1_Response(
|
||||
$this->format()
|
||||
, $this->get_http_code()
|
||||
, array('Content-Type' => $this->get_content_type())
|
||||
);
|
||||
|
||||
$response->setOriginalStatusCode($this->get_http_code());
|
||||
$response->setCharset('UTF-8');
|
||||
|
||||
return $response;
|
||||
|
@@ -46,6 +46,8 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
protected static $adminApplication;
|
||||
protected static $databoxe_ids = array();
|
||||
|
||||
abstract public function getParameters(array $parameters = array());
|
||||
|
||||
abstract public function unserialize($data);
|
||||
|
||||
abstract public function getAcceptMimeType();
|
||||
@@ -111,7 +113,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
{
|
||||
$route = '/nothinghere';
|
||||
$this->setToken(self::$token);
|
||||
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('GET', $route, $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponseNotFound($this->client->getResponse());
|
||||
@@ -126,7 +128,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
public function testDataboxListRoute()
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
$this->client->request('GET', '/databoxes/list/', array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('GET', '/databoxes/list/', $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -166,7 +168,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
$account = \API_OAuth2_Account::create($appbox, self::$user, $nativeApp);
|
||||
$token = $account->get_token()->get_value();
|
||||
$this->setToken($token);
|
||||
$this->client->request('GET', '/databoxes/list/', array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('GET', '/databoxes/list/', $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
if (403 != $content['meta']['http_code']) {
|
||||
@@ -190,27 +192,27 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
|
||||
$this->client->request('GET', '/monitor/tasks/', array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('GET', '/monitor/tasks/', $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
$this->assertEquals(401, $content['meta']['http_code']);
|
||||
|
||||
$this->client->request('GET', '/monitor/task/1/', array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('GET', '/monitor/task/1/', $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
$this->assertEquals(401, $content['meta']['http_code']);
|
||||
|
||||
$this->client->request('POST', '/monitor/task/1/', array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('POST', '/monitor/task/1/', $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
$this->assertEquals(401, $content['meta']['http_code']);
|
||||
|
||||
$this->client->request('POST', '/monitor/task/1/start/', array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('POST', '/monitor/task/1/start/', $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
$this->assertEquals(401, $content['meta']['http_code']);
|
||||
|
||||
$this->client->request('POST', '/monitor/task/1/stop/', array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('POST', '/monitor/task/1/stop/', $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
$this->assertEquals(401, $content['meta']['http_code']);
|
||||
|
||||
$this->client->request('GET', '/monitor/phraseanet/', array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('GET', '/monitor/phraseanet/', $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
$this->assertEquals(401, $content['meta']['http_code']);
|
||||
}
|
||||
@@ -231,7 +233,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
$route = '/monitor/tasks/';
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
|
||||
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('GET', $route, $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -307,7 +309,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
$route = '/monitor/task/' . $idTask . '/';
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('PUT', 'DELETE'));
|
||||
|
||||
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('GET', $route, $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
$this->evaluateMeta200($content);
|
||||
@@ -343,7 +345,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
|
||||
$title = 'newTitle' . mt_rand();
|
||||
|
||||
$this->client->request('POST', $route, array('title' => $title), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('POST', $route, $this->getParameters(array('title' => $title)), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
$this->evaluateMeta200($content);
|
||||
@@ -364,7 +366,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
}
|
||||
$this->setToken(self::$adminToken);
|
||||
$this->client->followRedirects();
|
||||
$this->client->request('GET', '/monitor/task/0/', array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('GET', '/monitor/task/0/', $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
$this->evaluateMetaNotFound($content);
|
||||
}
|
||||
@@ -394,7 +396,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
$route = '/monitor/task/' . $idTask . '/start/';
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE'));
|
||||
|
||||
$this->client->request('POST', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('POST', $route, $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
$this->evaluateMeta200($content);
|
||||
@@ -433,7 +435,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
$route = '/monitor/task/' . $idTask . '/stop/';
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE'));
|
||||
|
||||
$this->client->request('POST', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('POST', $route, $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
$this->evaluateMeta200($content);
|
||||
@@ -461,7 +463,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
|
||||
$this->setToken(self::$adminToken);
|
||||
|
||||
$this->client->request('GET', '/monitor/phraseanet/', array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('GET', '/monitor/phraseanet/', $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -485,7 +487,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
|
||||
$route = '/records/' . static::$records['record_1']->get_sbas_id() . '/' . static::$records['record_1']->get_record_id() . '/';
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('GET', $route, $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -513,7 +515,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
$route = '/databoxes/' . $databox_id . '/collections/';
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
|
||||
$crawler = $this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$crawler = $this->client->request('GET', $route, $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
$this->evaluateMeta200($content);
|
||||
@@ -554,7 +556,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
$route = '/databoxes/' . $databox_id . '/status/';
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
|
||||
$crawler = $this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$crawler = $this->client->request('GET', $route, $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
$this->evaluateMeta200($content);
|
||||
@@ -611,7 +613,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
$route = '/databoxes/' . $databox_id . '/metadatas/';
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
|
||||
$crawler = $this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$crawler = $this->client->request('GET', $route, $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
$this->evaluateMeta200($content);
|
||||
@@ -685,7 +687,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
$route = '/databoxes/' . $databox_id . '/termsOfUse/';
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
|
||||
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('GET', $route, $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
$this->evaluateMeta200($content);
|
||||
@@ -713,7 +715,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
public function testRecordsSearchRoute()
|
||||
{
|
||||
$this->setToken(self::$token);
|
||||
$crawler = $this->client->request('POST', '/records/search/', array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$crawler = $this->client->request('POST', '/records/search/', $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -760,7 +762,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
$route = '/records/' . static::$records['record_1']->get_sbas_id() . '/' . static::$records['record_1']->get_record_id() . '/caption/';
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
|
||||
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('GET', $route, $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -787,7 +789,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
$route = '/records/' . static::$records['record_1']->get_sbas_id() . '/' . static::$records['record_1']->get_record_id() . '/metadatas/';
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
|
||||
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('GET', $route, $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -813,7 +815,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
$route = '/records/' . static::$records['record_1']->get_sbas_id() . '/' . static::$records['record_1']->get_record_id() . '/status/';
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
|
||||
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('GET', $route, $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -843,7 +845,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
$route = '/records/' . static::$records['record_1']->get_sbas_id() . '/' . static::$records['record_1']->get_record_id() . '/embed/';
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
|
||||
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('GET', $route, $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -871,7 +873,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
|
||||
$route = '/records/' . static::$records['record_1']->get_sbas_id() . '/' . static::$records['record_1']->get_record_id() . '/embed/';
|
||||
|
||||
$this->client->request('GET', $route, array('mimes' => array('image/jpg', 'image/jpeg')), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('GET', $route, $this->getParameters(array('mimes' => array('image/jpg', 'image/jpeg'))), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->assertArrayHasKey('embed', $content['response']);
|
||||
@@ -890,7 +892,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
|
||||
$route = '/records/' . static::$records['record_1']->get_sbas_id() . '/' . static::$records['record_1']->get_record_id() . '/embed/';
|
||||
|
||||
$this->client->request('GET', $route, array('devices' => array('nodevice')), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('GET', $route, $this->getParameters(array('devices' => array('nodevice'))), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->assertEquals(0, count($content['response']['embed']));
|
||||
@@ -906,7 +908,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
$route = '/records/' . static::$records['record_1']->get_sbas_id() . '/' . static::$records['record_1']->get_record_id() . '/related/';
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
|
||||
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('GET', $route, $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -960,7 +962,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE'));
|
||||
|
||||
$this->client->request('POST', $route, array('metadatas' => $toupdate), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('POST', $route, $this->getParameters(array('metadatas' => $toupdate)), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -1008,7 +1010,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE'));
|
||||
|
||||
|
||||
$crawler = $this->client->request('POST', $route, array('status' => $tochange), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$crawler = $this->client->request('POST', $route, $this->getParameters(array('status' => $tochange)), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
/**
|
||||
@@ -1031,7 +1033,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
}
|
||||
|
||||
|
||||
$crawler = $this->client->request('POST', $route, array('status' => $tochange), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$crawler = $this->client->request('POST', $route, $this->getParameters(array('status' => $tochange)), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
/**
|
||||
@@ -1075,7 +1077,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE'));
|
||||
|
||||
$this->client->request('POST', $route, array('base_id' => $base_id), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('POST', $route, $this->getParameters(array('base_id' => $base_id)), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -1098,7 +1100,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
$route = '/baskets/list/';
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
|
||||
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('GET', $route, $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -1122,7 +1124,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE'));
|
||||
|
||||
$this->client->request('POST', $route, array('name' => 'un Joli Nom'), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('POST', $route, $this->getParameters(array('name' => 'un Joli Nom')), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -1150,7 +1152,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
|
||||
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('GET', $route, $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -1189,7 +1191,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE'));
|
||||
|
||||
$crawler = $this->client->request('POST', $route, array('name' => 'un Joli Nom'), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$crawler = $this->client->request('POST', $route, $this->getParameters(array('name' => 'un Joli Nom')), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -1201,7 +1203,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
|
||||
$this->assertEquals($content['response']['basket']['name'], 'un Joli Nom');
|
||||
|
||||
$crawler = $this->client->request('POST', $route, array('name' => 'un Joli Nom'), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$crawler = $this->client->request('POST', $route, $this->getParameters(array('name' => 'un Joli Nom')), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -1215,7 +1217,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
|
||||
$this->assertEquals($content['response']['basket']['name'], 'un Joli Nom');
|
||||
|
||||
$crawler = $this->client->request('POST', $route, array('name' => '<strong>aéaa'), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$crawler = $this->client->request('POST', $route, $this->getParameters(array('name' => '<strong>aéaa')), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -1242,7 +1244,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE'));
|
||||
|
||||
$this->client->request('POST', $route, array('description' => 'une belle desc'), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('POST', $route, $this->getParameters(array('description' => 'une belle desc')), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -1268,7 +1270,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE'));
|
||||
|
||||
$this->client->request('POST', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('POST', $route, $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -1298,7 +1300,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
$params = $this->getAddRecordParameters();
|
||||
$params['status'] = '0b10000';
|
||||
|
||||
$this->client->request('POST', $route, $params, $this->getAddRecordFile(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('POST', $route, $this->getParameters($params), $this->getAddRecordFile(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -1321,7 +1323,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
$params = $this->getAddRecordParameters();
|
||||
$params['forceBehavior'] = '0';
|
||||
|
||||
$this->client->request('POST', $route, $params, $this->getAddRecordFile(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('POST', $route, $this->getParameters($params), $this->getAddRecordFile(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -1350,7 +1352,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
$params = $this->getAddRecordParameters();
|
||||
$params['forceBehavior'] = '1';
|
||||
|
||||
$this->client->request('POST', $route, $params, $this->getAddRecordFile(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('POST', $route, $this->getParameters($params), $this->getAddRecordFile(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -1377,7 +1379,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
$params = $this->getAddRecordParameters();
|
||||
$params['forceBehavior'] = '2';
|
||||
|
||||
$this->client->request('POST', $route, $params, $this->getAddRecordFile(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('POST', $route, $this->getParameters($params), $this->getAddRecordFile(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponseBadRequest($this->client->getResponse());
|
||||
@@ -1395,7 +1397,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
$params = $this->getAddRecordParameters();
|
||||
$params['base_id'] = self::$collection_no_access->get_base_id();
|
||||
|
||||
$this->client->request('POST', $route, $params, $this->getAddRecordFile(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('POST', $route, $this->getParameters($params), $this->getAddRecordFile(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponseForbidden($this->client->getResponse());
|
||||
@@ -1413,7 +1415,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
$params = $this->getAddRecordParameters();
|
||||
unset($params['base_id']);
|
||||
|
||||
$this->client->request('POST', $route, $params, $this->getAddRecordFile(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('POST', $route, $this->getParameters($params), $this->getAddRecordFile(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponseBadRequest($this->client->getResponse());
|
||||
@@ -1433,7 +1435,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
new \Symfony\Component\HttpFoundation\File\UploadedFile(__FILE__, 'upload.txt'),
|
||||
);
|
||||
|
||||
$this->client->request('POST', $route, $this->getAddRecordParameters(), array('file' => $file), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('POST', $route, $this->getParameters($this->getAddRecordParameters()), array('file' => $file), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponseBadRequest($this->client->getResponse());
|
||||
@@ -1445,7 +1447,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
$this->setToken(self::$token);
|
||||
$route = '/records/add/';
|
||||
|
||||
$this->client->request('POST', $route, $this->getAddRecordParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('POST', $route, $this->getParameters($this->getAddRecordParameters()), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponseBadRequest($this->client->getResponse());
|
||||
@@ -1468,7 +1470,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
|
||||
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('GET', $route, $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -1525,7 +1527,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
|
||||
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('GET', $route, $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -1584,7 +1586,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
|
||||
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('GET', $route, $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -1626,7 +1628,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
|
||||
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('GET', $route, $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponseForbidden($this->client->getResponse());
|
||||
@@ -1662,7 +1664,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
|
||||
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('GET', $route, $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponse200($this->client->getResponse());
|
||||
@@ -1705,7 +1707,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
|
||||
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('GET', $route, $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->assertArrayHasKey('offset_start', $content['response']);
|
||||
@@ -1738,7 +1740,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
|
||||
$this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE'));
|
||||
|
||||
$this->client->request('GET', $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request('GET', $route, $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->assertArrayHasKey('quarantine_item', $content['response']);
|
||||
@@ -1900,7 +1902,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
protected function evaluateNotFoundRoute($route, $methods)
|
||||
{
|
||||
foreach ($methods as $method) {
|
||||
$crawler = $this->client->request($method, $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$crawler = $this->client->request($method, $route, $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
|
||||
$this->evaluateResponseNotFound($this->client->getResponse());
|
||||
@@ -2004,7 +2006,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
protected function evaluateMethodNotAllowedRoute($route, $methods)
|
||||
{
|
||||
foreach ($methods as $method) {
|
||||
$crawler = $this->client->request($method, $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$crawler = $this->client->request($method, $route, $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
$this->evaluateResponseMethodNotAllowed($this->client->getResponse());
|
||||
$this->evaluateMetaMethodNotAllowed($content);
|
||||
@@ -2014,7 +2016,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
||||
protected function evaluateBadRequestRoute($route, $methods)
|
||||
{
|
||||
foreach ($methods as $method) {
|
||||
$this->client->request($method, $route, array(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$this->client->request($method, $route, $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||
$content = $this->unserialize($this->client->getResponse()->getContent());
|
||||
$this->evaluateResponseBadRequest($this->client->getResponse());
|
||||
$this->evaluateMetaBadRequest($content);
|
||||
|
60
tests/Alchemy/Phrasea/Application/ApiJSONPTest.php
Normal file
60
tests/Alchemy/Phrasea/Application/ApiJSONPTest.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Phrasea\Application;
|
||||
|
||||
require_once __DIR__ . '/../../../PhraseanetWebTestCaseAbstract.class.inc';
|
||||
require_once __DIR__ . '/ApiAbstract.inc';
|
||||
|
||||
use Silex\WebTestCase;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class ApiJsonApplication extends ApiAbstract
|
||||
{
|
||||
protected function evaluateResponseBadRequest(Response $response)
|
||||
{
|
||||
$this->assertEquals('UTF-8', $response->getCharset(), 'Test charset response');
|
||||
$this->assertEquals(200, $response->getStatusCode(), 'Test status code 400 ' . $response->getContent());
|
||||
}
|
||||
|
||||
protected function evaluateResponseForbidden(Response $response)
|
||||
{
|
||||
$this->assertEquals('UTF-8', $response->getCharset(), 'Test charset response');
|
||||
$this->assertEquals(200, $response->getStatusCode(), 'Test status code 403 ' . $response->getContent());
|
||||
}
|
||||
|
||||
protected function evaluateResponseNotFound(Response $response)
|
||||
{
|
||||
$this->assertEquals('UTF-8', $response->getCharset(), 'Test charset response');
|
||||
$this->assertEquals(200, $response->getStatusCode(), 'Test status code 404 ' . $response->getContent());
|
||||
}
|
||||
|
||||
protected function evaluateResponseMethodNotAllowed(Response $response)
|
||||
{
|
||||
$this->assertEquals('UTF-8', $response->getCharset(), 'Test charset response');
|
||||
$this->assertEquals(200, $response->getStatusCode(), 'Test status code 405 ' . $response->getContent());
|
||||
}
|
||||
|
||||
public function getParameters(array $parameters = array())
|
||||
{
|
||||
$parameters['callback'] = 'jsFunction';
|
||||
|
||||
return $parameters;
|
||||
}
|
||||
public function unserialize($data)
|
||||
{
|
||||
if(strpos($data, 'jsFunction(') !== 0) {
|
||||
$this->fail('Invalid JSONP response');
|
||||
}
|
||||
|
||||
if(substr($data, -1) !== ')') {
|
||||
$this->fail('Invalid JSONP response');
|
||||
}
|
||||
|
||||
return json_decode(substr($data, 11, -1), true);
|
||||
}
|
||||
|
||||
public function getAcceptMimeType()
|
||||
{
|
||||
return 'application/json';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user