Merge branch '4.0'

This commit is contained in:
Benoît Burnichon
2016-03-11 21:50:23 +01:00
39 changed files with 279 additions and 265 deletions

View File

@@ -1,6 +1,11 @@
language: php language: php
sudo: require sudo: require
branches:
except:
- /^3\..*$/
- /^scrutinizer-.*$/
matrix: matrix:
fast_finish: true fast_finish: true
include: include:
@@ -37,8 +42,8 @@ before_install:
- echo "extension=zmq.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini - echo "extension=zmq.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
- yes | pecl install imagick-beta - yes | pecl install imagick-beta
install: install:
- if [[ $TRAVIS_PHP_VERSION = 5.* ]];then travis_retry composer install --optimize-autoloader --prefer-source; fi; - if [[ $TRAVIS_PHP_VERSION = 5.* ]];then travis_retry composer install --no-progress --no-interaction --optimize-autoloader; fi;
- if [[ $TRAVIS_PHP_VERSION = 7.* ]];then travis_retry composer remove --no-update phpunit/phpunit; travis_retry composer require --dev phpunit/phpunit --sort-packages --optimize-autoloader --update-with-dependencies --prefer-source; fi; - if [[ $TRAVIS_PHP_VERSION = 7.* ]];then travis_retry composer remove --no-update phpunit/phpunit; travis_retry composer require --dev phpunit/phpunit --sort-packages --optimize-autoloader --update-with-dependencies --no-progress --no-interaction; fi;
- travis_retry npm install - travis_retry npm install
before_script: before_script:
- mysql -e 'CREATE DATABASE update39_test;CREATE DATABASE ab_test;CREATE DATABASE db_test;SET @@global.sql_mode=STRICT_ALL_TABLES;SET @@global.max_allowed_packet=33554432;SET @@global.wait_timeout=999999;' - mysql -e 'CREATE DATABASE update39_test;CREATE DATABASE ab_test;CREATE DATABASE db_test;SET @@global.sql_mode=STRICT_ALL_TABLES;SET @@global.max_allowed_packet=33554432;SET @@global.wait_timeout=999999;'

View File

@@ -19,13 +19,14 @@ dependencies:
cache_directories: cache_directories:
- elasticsearch-1.6.0 # relative to the build directory - elasticsearch-1.6.0 # relative to the build directory
- node_modules - node_modules
- ~/.composer
pre: pre:
- yes '' | pecl install imagick - yes '' | pecl install imagick
- pecl install json - pecl install json
- yes '' | pecl install zmq-beta - yes '' | pecl install zmq-beta
- sed -i 's/^\(session.cache_limiter = \).*/\1""/' ~/.phpenv/versions/$(phpenv global)/etc/php.ini - sed -i 's/^\(session.cache_limiter = \).*/\1""/' ~/.phpenv/versions/$(phpenv global)/etc/php.ini
override: override:
- composer install --prefer-source --no-interaction - composer install --no-progress --no-interaction --optimize-autoloader
post: post:
- npm install - npm install
- if [[ ! -e elasticsearch-1.6.0 ]]; then wget --no-check-certificate https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.6.0.tar.gz && tar -xvf elasticsearch-1.6.0.tar.gz && elasticsearch-1.6.0/bin/plugin install elasticsearch/elasticsearch-analysis-icu/2.6.0; fi - if [[ ! -e elasticsearch-1.6.0 ]]; then wget --no-check-certificate https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.6.0.tar.gz && tar -xvf elasticsearch-1.6.0.tar.gz && elasticsearch-1.6.0/bin/plugin install elasticsearch/elasticsearch-analysis-icu/2.6.0; fi

View File

@@ -31,7 +31,7 @@ trait UserQueryAware
*/ */
public function getUserQueryFactory() public function getUserQueryFactory()
{ {
if (! is_callable($this->userQueryFactory)) { if (!is_callable($this->userQueryFactory)) {
throw new \LogicException('User Query factory was not set'); throw new \LogicException('User Query factory was not set');
} }
@@ -44,7 +44,7 @@ trait UserQueryAware
public function createUserQuery() public function createUserQuery()
{ {
$userQuery = call_user_func($this->getUserQueryFactory()); $userQuery = call_user_func($this->getUserQueryFactory());
if (! $userQuery instanceof \User_Query) { if (!$userQuery instanceof \User_Query) {
throw new \LogicException(sprintf( throw new \LogicException(sprintf(
'User Query factory does not create %s instance, got "%s" instead', 'User Query factory does not create %s instance, got "%s" instead',
\User_Query::class, \User_Query::class,

View File

@@ -19,7 +19,7 @@ class RouteLoader
'/admin/dashboard' => Providers\Admin\Dashboard::class, '/admin/dashboard' => Providers\Admin\Dashboard::class,
'/admin/databox' => Providers\Admin\Databox::class, '/admin/databox' => Providers\Admin\Databox::class,
'/admin/databoxes' => Providers\Admin\Databoxes::class, '/admin/databoxes' => Providers\Admin\Databoxes::class,
'/admin/fields' => Providers\Admin\Fields::class , '/admin/fields' => Providers\Admin\Fields::class,
'/admin/publications' => Providers\Admin\Feeds::class, '/admin/publications' => Providers\Admin\Feeds::class,
'/admin/plugins' => Providers\Admin\Plugins::class, '/admin/plugins' => Providers\Admin\Plugins::class,
'/admin/search-engine' => Providers\Admin\SearchEngine::class, '/admin/search-engine' => Providers\Admin\SearchEngine::class,
@@ -125,7 +125,7 @@ class RouteLoader
list($prefix, $providerKey) = $providerDefinition; list($prefix, $providerKey) = $providerDefinition;
} }
if (! $this->isValidProviderDefinition($app, $prefix, $providerKey)) { if (!$this->isValidProviderDefinition($app, $prefix, $providerKey)) {
continue; continue;
} }

View File

@@ -42,7 +42,7 @@ class Linkedin extends AbstractProvider
/** /**
* @param ClientInterface $client * @param ClientInterface $client
* *
* @return Github * @return Linkedin
*/ */
public function setGuzzleClient(ClientInterface $client) public function setGuzzleClient(ClientInterface $client)
{ {

View File

@@ -157,7 +157,7 @@ class Identity
public function get($property) public function get($property)
{ {
if (!array_key_exists($property, $this->data)) { if (!array_key_exists($property, $this->data)) {
throw new InvalidArgumentException(sprintf('Property %s does not exist', $property)); throw new InvalidArgumentException(sprintf('Property %s does not exist', $property));
} }
return $this->data[$property]; return $this->data[$property];
@@ -186,7 +186,7 @@ class Identity
public function remove($property) public function remove($property)
{ {
if (!array_key_exists($property, $this->data)) { if (!array_key_exists($property, $this->data)) {
throw new InvalidArgumentException(sprintf('Property %s does not exist', $property)); throw new InvalidArgumentException(sprintf('Property %s does not exist', $property));
} }
$value = $this->data[$property]; $value = $this->data[$property];

View File

@@ -40,7 +40,7 @@ class SuggestionFinder
$infos = $token->getIdentity(); $infos = $token->getIdentity();
if ($infos->has(Identity::PROPERTY_EMAIL)) { if ($infos->has(Identity::PROPERTY_EMAIL)) {
return $this->repository->findByEmail($infos->get(Identity::PROPERTY_EMAIL)); return $this->repository->findByEmail($infos->get(Identity::PROPERTY_EMAIL));
} }
return null; return null;

View File

@@ -75,11 +75,11 @@ class Metadata implements AttributeInterface
*/ */
public static function loadFromString(Application $app, $string) public static function loadFromString(Application $app, $string)
{ {
if ( ! $metadata = @unserialize($string)) { if (!$metadata = @unserialize($string)) {
throw new \InvalidArgumentException('Unable to load metadata from string'); throw new \InvalidArgumentException('Unable to load metadata from string');
} }
if (! $metadata instanceof ExiftoolMeta) { if (!$metadata instanceof ExiftoolMeta) {
throw new \InvalidArgumentException('Unable to load metadata from string'); throw new \InvalidArgumentException('Unable to load metadata from string');
} }

View File

@@ -31,7 +31,7 @@ class Story implements AttributeInterface
*/ */
public function __construct(\record_adapter $story) public function __construct(\record_adapter $story)
{ {
if ( ! $story->isStory()) { if (!$story->isStory()) {
throw new \InvalidArgumentException('Unable to fetch a story from string'); throw new \InvalidArgumentException('Unable to fetch a story from string');
} }
@@ -87,7 +87,7 @@ class Story implements AttributeInterface
throw new \InvalidArgumentException('Unable to fetch a story from string'); throw new \InvalidArgumentException('Unable to fetch a story from string');
} }
if ( ! $story->isStory()) { if (!$story->isStory()) {
throw new \InvalidArgumentException('Unable to fetch a story from string'); throw new \InvalidArgumentException('Unable to fetch a story from string');
} }

View File

@@ -58,7 +58,7 @@ abstract class AbstractChecker implements CheckerInterface
$this->databoxes = []; $this->databoxes = [];
foreach ($this->toIterator($databoxes) as $databox) { foreach ($this->toIterator($databoxes) as $databox) {
if (! $databox instanceof \databox) { if (!$databox instanceof \databox) {
throw new \InvalidArgumentException('Restrict to databoxes only accept databoxes as argument'); throw new \InvalidArgumentException('Restrict to databoxes only accept databoxes as argument');
} }
$this->databoxes[] = $databox; $this->databoxes[] = $databox;
@@ -86,7 +86,7 @@ abstract class AbstractChecker implements CheckerInterface
$this->collections = []; $this->collections = [];
foreach ($this->toIterator($collections) as $collection) { foreach ($this->toIterator($collections) as $collection) {
if (! $collection instanceof \collection) { if (!$collection instanceof \collection) {
throw new \InvalidArgumentException('Restrict to collections only accept collections as argument'); throw new \InvalidArgumentException('Restrict to collections only accept collections as argument');
} }
$this->collections[] = $collection; $this->collections[] = $collection;

View File

@@ -26,7 +26,7 @@ class Colorspace extends AbstractChecker
public function __construct(Application $app, array $options) public function __construct(Application $app, array $options)
{ {
if ( ! isset($options['colorspaces'])) { if (!isset($options['colorspaces'])) {
throw new \InvalidArgumentException('Missing "colorspaces" options'); throw new \InvalidArgumentException('Missing "colorspaces" options');
} }
@@ -42,7 +42,8 @@ class Colorspace extends AbstractChecker
$boolean = true; //bypass color if empty array $boolean = true; //bypass color if empty array
} elseif (method_exists($file->getMedia(), 'getColorSpace')) { } elseif (method_exists($file->getMedia(), 'getColorSpace')) {
$colorspace = null; $colorspace = null;
switch ($file->getMedia()->getColorSpace()) { switch ($file->getMedia()->getColorSpace())
{
case \MediaVorus\Media\Image::COLORSPACE_CMYK: case \MediaVorus\Media\Image::COLORSPACE_CMYK:
$colorspace = self::COLORSPACE_CMYK; $colorspace = self::COLORSPACE_CMYK;
break; break;

View File

@@ -22,7 +22,7 @@ class Extension extends AbstractChecker
public function __construct(Application $app, array $options) public function __construct(Application $app, array $options)
{ {
if ( ! isset($options['extensions'])) { if (!isset($options['extensions'])) {
throw new \InvalidArgumentException('Missing "extensions" options'); throw new \InvalidArgumentException('Missing "extensions" options');
} }

View File

@@ -31,7 +31,7 @@ class Filename extends AbstractChecker
*/ */
public function __construct(Application $app, array $options = []) public function __construct(Application $app, array $options = [])
{ {
if ( ! isset($options['sensitive'])) { if (!isset($options['sensitive'])) {
$options['sensitive'] = false; $options['sensitive'] = false;
} }
@@ -44,9 +44,9 @@ class Filename extends AbstractChecker
*/ */
public function check(EntityManager $em, File $file) public function check(EntityManager $em, File $file)
{ {
$boolean = ! count(\record_adapter::get_records_by_originalname( $boolean = empty(\record_adapter::get_records_by_originalname(
$file->getCollection()->get_databox(), $file->getOriginalName(), $this->sensitive, 0, 1 $file->getCollection()->get_databox(), $file->getOriginalName(), $this->sensitive, 0, 1
)); ));
return new Response($boolean, $this); return new Response($boolean, $this);
} }

View File

@@ -29,7 +29,7 @@ class MediaType extends AbstractChecker
public function __construct(Application $app, array $options) public function __construct(Application $app, array $options)
{ {
if ( ! isset($options['mediatypes'])) { if (!isset($options['mediatypes'])) {
throw new \InvalidArgumentException('Missing "mediatypes" options'); throw new \InvalidArgumentException('Missing "mediatypes" options');
} }

View File

@@ -33,7 +33,7 @@ class Sha256 extends AbstractChecker
*/ */
public function check(EntityManager $em, File $file) public function check(EntityManager $em, File $file)
{ {
$boolean = ! count($file->getCollection()->get_databox()->getRecordRepository()->findBySha256($file->getSha256())); $boolean = empty($file->getCollection()->get_databox()->getRecordRepository()->findBySha256($file->getSha256()));
return new Response($boolean, $this); return new Response($boolean, $this);
} }

View File

@@ -32,7 +32,7 @@ class UUID extends AbstractChecker
*/ */
public function check(EntityManager $em, File $file) public function check(EntityManager $em, File $file)
{ {
$boolean = ! count($file->getCollection()->get_databox()->getRecordRepository()->findByUuid($file->getUUID())); $boolean = empty($file->getCollection()->get_databox()->getRecordRepository()->findByUuid($file->getUUID()));
return new Response($boolean, $this); return new Response($boolean, $this);
} }

View File

@@ -66,7 +66,7 @@ class File
$this->media = $media; $this->media = $media;
$this->collection = $collection; $this->collection = $collection;
$this->attributes = []; $this->attributes = [];
$this->originalName = $originalName ? : pathinfo($this->media->getFile()->getPathname(), PATHINFO_BASENAME); $this->originalName = $originalName ?: pathinfo($this->media->getFile()->getPathname(), PATHINFO_BASENAME);
} }
/** /**
@@ -92,7 +92,7 @@ class File
*/ */
public function getUUID($generate = false, $write = false) public function getUUID($generate = false, $write = false)
{ {
if ($this->uuid && ! $write) { if ($this->uuid && !$write) {
return $this->uuid; return $this->uuid;
} }
@@ -104,7 +104,7 @@ class File
'Canon:ImageUniqueID', 'Canon:ImageUniqueID',
]; ];
if (! $this->uuid) { if (!$this->uuid) {
$metadatas = $this->media->getMetadatas(); $metadatas = $this->media->getMetadatas();
$uuid = null; $uuid = null;
@@ -119,7 +119,7 @@ class File
} }
} }
if (! $uuid && $generate) { if (!$uuid && $generate) {
$uuid = Uuid::uuid4(); $uuid = Uuid::uuid4();
} }
@@ -152,7 +152,8 @@ class File
*/ */
public function getType() public function getType()
{ {
switch ($this->media->getType()) { switch ($this->media->getType())
{
case MediaInterface::TYPE_AUDIO: case MediaInterface::TYPE_AUDIO:
return new Audio(); return new Audio();
break; break;
@@ -180,7 +181,7 @@ class File
*/ */
public function getSha256() public function getSha256()
{ {
if (! $this->sha256) { if (!$this->sha256) {
$this->sha256 = $this->media->getHash('sha256'); $this->sha256 = $this->media->getHash('sha256');
} }
@@ -194,7 +195,7 @@ class File
*/ */
public function getMD5() public function getMD5()
{ {
if (! $this->md5) { if (!$this->md5) {
$this->md5 = $this->media->getHash('md5'); $this->md5 = $this->media->getHash('md5');
} }

View File

@@ -77,7 +77,7 @@ class Visa
{ {
foreach ($this->responses as $response) { foreach ($this->responses as $response) {
if ( ! $response->isOk()) { if (!$response->isOk()) {
return false; return false;
} }
} }

View File

@@ -45,7 +45,7 @@ class ArrayCache extends DoctrineArray implements Cache
*/ */
public function get($id) public function get($id)
{ {
if ( ! $this->contains($id)) { if (!$this->contains($id)) {
throw new Exception(sprintf('Unable to find key %s', $id)); throw new Exception(sprintf('Unable to find key %s', $id));
} }

View File

@@ -82,7 +82,7 @@ class Manager
if (isset($options['namespace']) && is_string($options['namespace'])) { if (isset($options['namespace']) && is_string($options['namespace'])) {
$cache->setNamespace($options['namespace']); $cache->setNamespace($options['namespace']);
} else { } else {
$cache->setNamespace(md5(gethostname().'-'.__DIR__)); $cache->setNamespace(md5(gethostname() . '-' . __DIR__));
} }
$this->drivers[$label] = $cache; $this->drivers[$label] = $cache;
@@ -95,17 +95,28 @@ class Manager
return $cache; return $cache;
} }
/**
* @param string $name
* @param string $label
*/
private function register($name, $label) private function register($name, $label)
{ {
$this->registry[$label] = $name; $this->registry[$label] = $name;
$this->save(); $this->save();
} }
/**
* @param string $name
* @param string $label
*/
private function isAlreadyRegistered($name, $label) private function isAlreadyRegistered($name, $label)
{ {
return isset($this->registry[$label]) && $name === $this->registry[$label]; return isset($this->registry[$label]) && $name === $this->registry[$label];
} }
/**
* @param string $label
*/
private function isAlreadyLoaded($label) private function isAlreadyLoaded($label)
{ {
return isset($this->drivers[$label]); return isset($this->drivers[$label]);
@@ -115,7 +126,7 @@ class Manager
{ {
$date = new \DateTime(); $date = new \DateTime();
$data = $this->compiler->compile($this->registry) $data = $this->compiler->compile($this->registry)
. "\n// Last Update on ".$date->format(DATE_ISO8601)." \n"; . "\n// Last Update on " . $date->format(DATE_ISO8601) . " \n";
file_put_contents($this->file, $data); file_put_contents($this->file, $data);
} }

View File

@@ -86,8 +86,8 @@ class DbalCollectionRepository implements CollectionRepository
} }
$query = self::$selectQuery . ' WHERE coll_id IN (:collectionIds)'; $query = self::$selectQuery . ' WHERE coll_id IN (:collectionIds)';
$parameters = [ 'collectionIds' => $parameters ]; $parameters = ['collectionIds' => $parameters];
$parameterTypes = [ 'collectionIds' => Connection::PARAM_INT_ARRAY ]; $parameterTypes = ['collectionIds' => Connection::PARAM_INT_ARRAY];
$rows = $this->databoxConnection->fetchAll($query, $parameters, $parameterTypes); $rows = $this->databoxConnection->fetchAll($query, $parameters, $parameterTypes);
@@ -107,7 +107,7 @@ class DbalCollectionRepository implements CollectionRepository
} }
$query = self::$selectQuery . ' WHERE coll_id = :collectionId'; $query = self::$selectQuery . ' WHERE coll_id = :collectionId';
$row = $this->databoxConnection->fetchAssoc($query, [ ':collectionId' => $reference->getCollectionId() ]); $row = $this->databoxConnection->fetchAssoc($query, [':collectionId' => $reference->getCollectionId()]);
if ($row !== false) { if ($row !== false) {
return $this->collectionFactory->create($this->databoxId, $reference, $row); return $this->collectionFactory->create($this->databoxId, $reference, $row);
@@ -130,7 +130,7 @@ class DbalCollectionRepository implements CollectionRepository
} }
$query = self::$selectQuery . ' WHERE coll_id = :collectionId'; $query = self::$selectQuery . ' WHERE coll_id = :collectionId';
$row = $this->databoxConnection->fetchAssoc($query, [ ':collectionId' => $reference->getCollectionId() ]); $row = $this->databoxConnection->fetchAssoc($query, [':collectionId' => $reference->getCollectionId()]);
if ($row !== false) { if ($row !== false) {
return $this->collectionFactory->create($this->databoxId, $reference, $row); return $this->collectionFactory->create($this->databoxId, $reference, $row);

View File

@@ -59,8 +59,8 @@ class BuildMissingSubdefs extends Command
$subdefGenerator->generateSubdefs($record, $wanted_subdefs); $subdefGenerator->generateSubdefs($record, $wanted_subdefs);
foreach ($wanted_subdefs as $subdef) { foreach ($wanted_subdefs as $subdef) {
$this->container['monolog']->addInfo("generate " .$subdef . " for record " . $record->getRecordId()); $this->container['monolog']->addInfo("generate " . $subdef . " for record " . $record->getRecordId());
$n ++; $n++;
} }
} }

View File

@@ -52,7 +52,7 @@ class CreateCollection extends Command
foreach ($results as $user) { foreach ($results as $user) {
$this->container->getAclForUser($user)->duplicate_right_from_bas($input->getOption('base_id_rights'), $new_collection->get_base_id()); $this->container->getAclForUser($user)->duplicate_right_from_bas($input->getOption('base_id_rights'), $new_collection->get_base_id());
} }
$n+=40; $n += 40;
} }
} }

View File

@@ -146,7 +146,7 @@ class Firewall
public function requireOrdersAdmin() public function requireOrdersAdmin()
{ {
if (false === !!count($this->app->getAclForUser($this->app->getAuthenticatedUser())->get_granted_base(['order_master']))) { if (empty($this->app->getAclForUser($this->app->getAuthenticatedUser())->get_granted_base(['order_master']))) {
$this->app->abort(403, 'You are not an order admin'); $this->app->abort(403, 'You are not an order admin');
} }

View File

@@ -43,7 +43,7 @@ class eventsmanager_notify_uploadquarantine extends eventsmanager_notifyAbstract
$text = $this->app->trans('The document %name% has been quarantined', ['%name%' => $filename]); $text = $this->app->trans('The document %name% has been quarantined', ['%name%' => $filename]);
if ( ! ! count($reasons)) { if ($reasons) {
$text .= ' ' . $this->app->trans('for the following reasons : %reasons%', ['%reasons%' => implode(', ', $reasons)]); $text .= ' ' . $this->app->trans('for the following reasons : %reasons%', ['%reasons%' => implode(', ', $reasons)]);
} }

View File

@@ -6,6 +6,7 @@ use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Authentication\ACLProvider; use Alchemy\Phrasea\Authentication\ACLProvider;
use Alchemy\Phrasea\Border\File; use Alchemy\Phrasea\Border\File;
use Ramsey\Uuid\Uuid; use Ramsey\Uuid\Uuid;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Client; use Symfony\Component\HttpKernel\Client;
/** /**
@@ -49,7 +50,7 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
parent::tearDown(); parent::tearDown();
} }
public function getJson($response) public function getJson(Response $response)
{ {
$this->assertTrue($response->isOk()); $this->assertTrue($response->isOk());
$this->assertEquals('application/json', $response->headers->get('Content-Type')); $this->assertEquals('application/json', $response->headers->get('Content-Type'));
@@ -134,8 +135,8 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
{ {
$this->setAdmin(false); $this->setAdmin(false);
$this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/suggested-values/'); $response = $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/suggested-values/');
$this->assertXMLHTTPBadJsonResponse(self::$DI['client']->getResponse()); $this->assertXMLHTTPBadJsonResponse($response);
} }
/** /**
@@ -147,11 +148,11 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
$prefs = '<?xml version="1.0" encoding="UTF-8"?> <baseprefs> <status>0</status> <sugestedValues> <Object> <value>my_new_value</value> </Object> </sugestedValues> </baseprefs>'; $prefs = '<?xml version="1.0" encoding="UTF-8"?> <baseprefs> <status>0</status> <sugestedValues> <Object> <value>my_new_value</value> </Object> </sugestedValues> </baseprefs>';
$this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/suggested-values/', [ $response = $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/suggested-values/', [
'str' => $prefs 'str' => $prefs
]); ]);
$json = $this->getJson(self::$DI['client']->getResponse()); $json = $this->getJson($response);
$this->assertTrue($json->success); $this->assertTrue($json->success);
$collection = $collection = \collection::getByBaseId(self::$DI['app'], self::$DI['collection']->get_base_id()); $collection = $collection = \collection::getByBaseId(self::$DI['app'], self::$DI['collection']->get_base_id());
@@ -168,11 +169,11 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
$prefs = '<?xml version="1.0" encoding="UTF-alues> </baseprefs>'; $prefs = '<?xml version="1.0" encoding="UTF-alues> </baseprefs>';
$this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/suggested-values/', [ $response = $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/suggested-values/', [
'str' => $prefs 'str' => $prefs
]); ]);
$json = $this->getJson(self::$DI['client']->getResponse()); $json = $this->getJson($response);
$this->assertFalse($json->success); $this->assertFalse($json->success);
} }
@@ -207,9 +208,9 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
{ {
$this->setAdmin(true); $this->setAdmin(true);
$this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/enable/'); $response = $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/enable/');
$json = $this->getJson(self::$DI['client']->getResponse()); $json = $this->getJson($response);
$this->assertTrue($json->success); $this->assertTrue($json->success);
$collection = \collection::getByBaseId(self::$DI['app'], self::$DI['collection']->get_base_id()); $collection = \collection::getByBaseId(self::$DI['app'], self::$DI['collection']->get_base_id());
@@ -248,9 +249,9 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
{ {
$this->setAdmin(true); $this->setAdmin(true);
$this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/disabled/'); $response = $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/disabled/');
$json = $this->getJson(self::$DI['client']->getResponse()); $json = $this->getJson($response);
$this->assertTrue($json->success); $this->assertTrue($json->success);
$collection = \collection::getByBaseId(self::$DI['app'], self::$DI['collection']->get_base_id()); $collection = \collection::getByBaseId(self::$DI['app'], self::$DI['collection']->get_base_id());
$this->assertFalse($collection->is_active()); $this->assertFalse($collection->is_active());
@@ -318,8 +319,8 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
{ {
$this->setAdmin(true); $this->setAdmin(true);
$this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/publication/display/'); $response = $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/publication/display/');
$this->assertXMLHTTPBadJsonResponse(self::$DI['client']->getResponse()); $this->assertXMLHTTPBadJsonResponse($response);
} }
/** /**
@@ -329,11 +330,11 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
{ {
$this->setAdmin(true); $this->setAdmin(true);
$this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/publication/display/', [ $response = $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/publication/display/', [
'pub_wm' => 'wm', 'pub_wm' => 'wm',
]); ]);
$json = $this->getJson(self::$DI['client']->getResponse()); $json = $this->getJson($response);
$this->assertTrue($json->success); $this->assertTrue($json->success);
$collection = \collection::getByBaseId(self::$DI['app'], self::$DI['collection']->get_base_id()); $collection = \collection::getByBaseId(self::$DI['app'], self::$DI['collection']->get_base_id());
$this->assertNotNull($collection->get_pub_wm()); $this->assertNotNull($collection->get_pub_wm());
@@ -409,8 +410,8 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
{ {
$this->setAdmin(true); $this->setAdmin(true);
$this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/rename/'); $response = $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/rename/');
$this->assertXMLHTTPBadJsonResponse(self::$DI['client']->getResponse()); $this->assertXMLHTTPBadJsonResponse($response);
} }
/** /**
@@ -420,8 +421,8 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
{ {
$this->setAdmin(true); $this->setAdmin(true);
$this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/labels/'); $response = $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/labels/');
$this->assertXMLHTTPBadJsonResponse(self::$DI['client']->getResponse()); $this->assertXMLHTTPBadJsonResponse($response);
} }
/** /**
@@ -433,11 +434,11 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
$collection = $this->createOneCollection(); $collection = $this->createOneCollection();
$this->XMLHTTPRequest('POST', '/admin/collection/' . $collection->get_base_id() . '/rename/', [ $response = $this->XMLHTTPRequest('POST', '/admin/collection/' . $collection->get_base_id() . '/rename/', [
'name' => 'test_rename_coll' 'name' => 'test_rename_coll'
]); ]);
$json = $this->getJson(self::$DI['client']->getResponse()); $json = $this->getJson($response);
$this->assertTrue($json->success); $this->assertTrue($json->success);
// Collection has to be reloaded since it was modified outside of the current process // Collection has to be reloaded since it was modified outside of the current process
@@ -459,7 +460,7 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
$collection = $this->createOneCollection(); $collection = $this->createOneCollection();
$this->XMLHTTPRequest('POST', '/admin/collection/' . $collection->get_base_id() . '/labels/', [ $response = $this->XMLHTTPRequest('POST', '/admin/collection/' . $collection->get_base_id() . '/labels/', [
'labels' => [ 'labels' => [
'nl' => 'netherlands label', 'nl' => 'netherlands label',
'de' => 'german label', 'de' => 'german label',
@@ -469,7 +470,7 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
] ]
]); ]);
$json = $this->getJson(self::$DI['client']->getResponse()); $json = $this->getJson($response);
$this->assertTrue($json->success); $this->assertTrue($json->success);
$databox = $this->getApplication()->findDataboxById($collection->get_sbas_id()); $databox = $this->getApplication()->findDataboxById($collection->get_sbas_id());
@@ -504,8 +505,8 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
{ {
$this->setAdmin(false); $this->setAdmin(false);
$this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/empty/'); $response = $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/empty/');
$this->assertXMLHTTPBadJsonResponse(self::$DI['client']->getResponse()); $this->assertXMLHTTPBadJsonResponse($response);
} }
/** /**
@@ -524,9 +525,9 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
$this->markTestSkipped('No record were added'); $this->markTestSkipped('No record were added');
} }
$this->XMLHTTPRequest('POST', '/admin/collection/' . $collection->get_base_id() . '/empty/'); $response = $this->XMLHTTPRequest('POST', '/admin/collection/' . $collection->get_base_id() . '/empty/');
$json = $this->getJson(self::$DI['client']->getResponse()); $json = $this->getJson($response);
$this->assertTrue($json->success); $this->assertTrue($json->success);
$this->assertEquals(0, $collection->get_record_amount()); $this->assertEquals(0, $collection->get_record_amount());
} }
@@ -573,9 +574,9 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
$this->markTestSkipped('No enough records added'); $this->markTestSkipped('No enough records added');
} }
$this->XMLHTTPRequest('POST', '/admin/collection/' . $collection->get_base_id() . '/empty/'); $response = $this->XMLHTTPRequest('POST', '/admin/collection/' . $collection->get_base_id() . '/empty/');
$json = $this->getJson(self::$DI['client']->getResponse()); $json = $this->getJson($response);
$this->assertTrue($json->success); $this->assertTrue($json->success);
if (count(self::$DI['app']['orm.em']->getRepository('Phraseanet:Task')->findAll()) === 0) { if (count(self::$DI['app']['orm.em']->getRepository('Phraseanet:Task')->findAll()) === 0) {
@@ -662,8 +663,8 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
$this->setAdmin(true); $this->setAdmin(true);
$this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/picture/mini-logo/delete/'); $response = $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/picture/mini-logo/delete/');
$json = $this->getJson(self::$DI['client']->getResponse()); $json = $this->getJson($response);
$this->assertTrue($json->success); $this->assertTrue($json->success);
} }
@@ -712,9 +713,9 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
} }
$this->setAdmin(true); $this->setAdmin(true);
$this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/picture/watermark/delete/'); $response = $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/picture/watermark/delete/');
$json = $this->getJson(self::$DI['client']->getResponse()); $json = $this->getJson($response);
$this->assertTrue($json->success); $this->assertTrue($json->success);
} }
@@ -760,9 +761,9 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
$this->setAdmin(true); $this->setAdmin(true);
$this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/picture/stamp-logo/delete/'); $response = $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/picture/stamp-logo/delete/');
$json = $this->getJson(self::$DI['client']->getResponse()); $json = $this->getJson($response);
$this->assertTrue($json->success); $this->assertTrue($json->success);
} }
@@ -837,9 +838,9 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
$collection = $this->createOneCollection(); $collection = $this->createOneCollection();
$this->XMLHTTPRequest('POST', '/admin/collection/' . $collection->get_base_id() . '/delete/'); $response = $this->XMLHTTPRequest('POST', '/admin/collection/' . $collection->get_base_id() . '/delete/');
$json = $this->getJson(self::$DI['client']->getResponse()); $json = $this->getJson($response);
$this->assertTrue($json->success); $this->assertTrue($json->success);
try { try {
\collection::getByBaseId(self::$DI['app'], $collection->get_base_id()); \collection::getByBaseId(self::$DI['app'], $collection->get_base_id());
@@ -865,9 +866,9 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
$this->markTestSkipped('No record were added'); $this->markTestSkipped('No record were added');
} }
$this->XMLHTTPRequest('POST', '/admin/collection/' . $collection->get_base_id() . '/delete/'); $response = $this->XMLHTTPRequest('POST', '/admin/collection/' . $collection->get_base_id() . '/delete/');
$json = $this->getJson(self::$DI['client']->getResponse()); $json = $this->getJson($response);
$this->assertFalse($json->success); $this->assertFalse($json->success);
$collection->empty_collection(); $collection->empty_collection();
} }
@@ -893,8 +894,8 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
{ {
$this->setAdmin(false); $this->setAdmin(false);
$this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/unmount/'); $response = $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/unmount/');
$this->assertXMLHTTPBadJsonResponse(self::$DI['client']->getResponse()); $this->assertXMLHTTPBadJsonResponse($response);
} }
/** /**
@@ -906,9 +907,9 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
$collection = $this->createOneCollection(); $collection = $this->createOneCollection();
$this->XMLHTTPRequest('POST', '/admin/collection/' . $collection->get_base_id() . '/unmount/'); $response = $this->XMLHTTPRequest('POST', '/admin/collection/' . $collection->get_base_id() . '/unmount/');
$json = $this->getJson(self::$DI['client']->getResponse()); $json = $this->getJson($response);
$this->assertTrue($json->success); $this->assertTrue($json->success);
try { try {

View File

@@ -114,12 +114,13 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase
$app = $this->getApplication(); $app = $this->getApplication();
$collection = \collection::create($app, $databox, $app['phraseanet.appbox'], 'TESTTODELETE'); $collection = \collection::create($app, $databox, $app['phraseanet.appbox'], 'TESTTODELETE');
$this->XMLHTTPRequest('POST', '/admin/databox/' . $databox->get_sbas_id() . '/collections/order/', [ $response = $this->XMLHTTPRequest('POST', '/admin/databox/' . $databox->get_sbas_id() . '/collections/order/', [
'order' => [ 'order' => [
2 => $collection->get_base_id() 2 => $collection->get_base_id()
]]); ]
]);
$this->assertTrue(self::$DI['client']->getResponse()->isOk()); $this->assertTrue($response->isOk());
$databox->unmount_databox(); $databox->unmount_databox();
$databox->delete(); $databox->delete();
@@ -197,11 +198,11 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase
$cgusUpdate = 'Test update CGUS'; $cgusUpdate = 'Test update CGUS';
$this->XMLHTTPRequest('POST', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/cgus/', [ $response = $this->XMLHTTPRequest('POST', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/cgus/', [
'TOU' => ['fr' => $cgusUpdate] 'TOU' => ['fr' => $cgusUpdate]
]); ]);
$this->checkRedirection(self::$DI['client']->getResponse(), '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/cgus/?success=1'); $this->checkRedirection($response, '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/cgus/?success=1');
$databox = self::$DI['app']->findDataboxById(self::$DI['collection']->get_sbas_id()); $databox = self::$DI['app']->findDataboxById(self::$DI['collection']->get_sbas_id());
$cgus = $databox->get_cgus(); $cgus = $databox->get_cgus();
@@ -228,9 +229,9 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase
{ {
$this->setAdmin(true); $this->setAdmin(true);
$this->XMLHTTPRequest('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/informations/documents/'); $response = $this->XMLHTTPRequest('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/informations/documents/');
$json = $this->getJson(self::$DI['client']->getResponse()); $json = $this->getJson($response);
$this->assertTrue($json->success); $this->assertTrue($json->success);
$this->assertObjectHasAttribute('sbas_id', $json); $this->assertObjectHasAttribute('sbas_id', $json);
$this->assertObjectHasAttribute('indexable', $json); $this->assertObjectHasAttribute('indexable', $json);
@@ -305,8 +306,8 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase
{ {
$this->setAdmin(false); $this->setAdmin(false);
$this->XMLHTTPRequest('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/informations/documents/'); $response = $this->XMLHTTPRequest('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/informations/documents/');
$this->assertXMLHTTPBadJsonResponse(self::$DI['client']->getResponse()); $this->assertXMLHTTPBadJsonResponse($response);
} }
/** /**
@@ -352,8 +353,7 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase
{ {
$this->setAdmin(true); $this->setAdmin(true);
$this->XMLHTTPRequest('POST', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/reindex/'); $response = $this->XMLHTTPRequest('POST', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/reindex/');
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOk()); $this->assertTrue($response->isOk());
$this->assertEquals('application/json', $response->headers->get('Content-Type')); $this->assertEquals('application/json', $response->headers->get('Content-Type'));
$content = json_decode($response->getContent()); $content = json_decode($response->getContent());
@@ -382,11 +382,10 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase
{ {
$this->setAdmin(true); $this->setAdmin(true);
$this->XMLHTTPRequest('POST', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/indexable/', [ $response = $this->XMLHTTPRequest('POST', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/indexable/', [
'indexable' => 1 'indexable' => 1
]); ]);
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOk()); $this->assertTrue($response->isOk());
$this->assertEquals('application/json', $response->headers->get('Content-Type')); $this->assertEquals('application/json', $response->headers->get('Content-Type'));
$content = json_decode($response->getContent()); $content = json_decode($response->getContent());
@@ -418,9 +417,8 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase
{ {
$this->setAdmin(true); $this->setAdmin(true);
$this->XMLHTTPRequest('POST', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/clear-logs/'); $response = $this->XMLHTTPRequest('POST', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/clear-logs/');
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOk()); $this->assertTrue($response->isOk());
$this->assertEquals('application/json', $response->headers->get('Content-Type')); $this->assertEquals('application/json', $response->headers->get('Content-Type'));
$content = json_decode($response->getContent()); $content = json_decode($response->getContent());
@@ -451,8 +449,8 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase
{ {
$this->setAdmin(true); $this->setAdmin(true);
$this->XMLHTTPRequest('POST', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/view-name/'); $response = $this->XMLHTTPRequest('POST', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/view-name/');
$this->assertXMLHTTPBadJsonResponse(self::$DI['client']->getResponse()); $this->assertXMLHTTPBadJsonResponse($response);
} }
/** /**
@@ -467,11 +465,10 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase
$this->assertEquals('old_databox_name', $databox->get_viewname()); $this->assertEquals('old_databox_name', $databox->get_viewname());
$this->XMLHTTPRequest('POST', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/view-name/', [ $response = $this->XMLHTTPRequest('POST', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/view-name/', [
'viewname' => 'new_databox_name' 'viewname' => 'new_databox_name'
]); ]);
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOk()); $this->assertTrue($response->isOk());
$this->assertEquals('application/json', $response->headers->get('Content-Type')); $this->assertEquals('application/json', $response->headers->get('Content-Type'));
$content = json_decode($response->getContent()); $content = json_decode($response->getContent());
@@ -491,9 +488,9 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase
$base = $this->createDatabox(); $base = $this->createDatabox();
$this->XMLHTTPRequest('POST', '/admin/databox/' . $base->get_sbas_id() . '/delete/'); $response = $this->XMLHTTPRequest('POST', '/admin/databox/' . $base->get_sbas_id() . '/delete/');
$json = $this->getJson(self::$DI['client']->getResponse()); $json = $this->getJson($response);
$this->assertTrue($json->success); $this->assertTrue($json->success);
$this->assertObjectHasAttribute('sbas_id', $json); $this->assertObjectHasAttribute('sbas_id', $json);
@@ -557,9 +554,9 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase
$this->markTestSkipped('No logo setted'); $this->markTestSkipped('No logo setted');
} }
$this->XMLHTTPRequest('POST', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/logo/delete/'); $response = $this->XMLHTTPRequest('POST', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/logo/delete/');
$json = $this->getJson(self::$DI['client']->getResponse()); $json = $this->getJson($response);
$this->assertTrue($json->success); $this->assertTrue($json->success);
$this->assertEmpty(\databox::getPrintLogo(self::$DI['collection']->get_sbas_id())); $this->assertEmpty(\databox::getPrintLogo(self::$DI['collection']->get_sbas_id()));
} }
@@ -573,9 +570,9 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase
$base = $this->createDatabox(); $base = $this->createDatabox();
$this->XMLHTTPRequest('POST', '/admin/databox/' . $base->get_sbas_id() . '/unmount/'); $response = $this->XMLHTTPRequest('POST', '/admin/databox/' . $base->get_sbas_id() . '/unmount/');
$json = $this->getJson(self::$DI['client']->getResponse()); $json = $this->getJson($response);
$this->assertTrue($json->success); $this->assertTrue($json->success);
$this->assertObjectHasAttribute('sbas_id', $json); $this->assertObjectHasAttribute('sbas_id', $json);
@@ -607,9 +604,9 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase
$this->markTestSkipped('No record were added'); $this->markTestSkipped('No record were added');
} }
$this->XMLHTTPRequest('POST', '/admin/databox/' . $base->get_sbas_id() . '/empty/'); $response = $this->XMLHTTPRequest('POST', '/admin/databox/' . $base->get_sbas_id() . '/empty/');
$json = $this->getJson(self::$DI['client']->getResponse()); $json = $this->getJson($response);
$this->assertTrue($json->success); $this->assertTrue($json->success);
$this->assertEquals(0, $collection->get_record_amount()); $this->assertEquals(0, $collection->get_record_amount());
@@ -630,7 +627,7 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase
{ {
$this->setAdmin(true); $this->setAdmin(true);
$base = self::$DI['record_1']->get_databox(); $base = self::$DI['record_1']->get_databox();
$this->XMLHTTPRequest('POST', '/admin/databox/' . $base->get_sbas_id() . '/labels/', [ $response = $this->XMLHTTPRequest('POST', '/admin/databox/' . $base->get_sbas_id() . '/labels/', [
'labels' => [ 'labels' => [
'fr' => 'frenchy label', 'fr' => 'frenchy label',
'en' => '', 'en' => '',
@@ -639,10 +636,10 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase
] ]
]); ]);
$this->assertEquals(200, self::$DI['client']->getResponse()->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('application/json', self::$DI['client']->getResponse()->headers->get('content-type')); $this->assertEquals('application/json', $response->headers->get('content-type'));
$data = json_decode(self::$DI['client']->getResponse()->getContent(), true); $data = json_decode($response->getContent(), true);
$this->assertTrue($data['success']); $this->assertTrue($data['success']);
$base = $this->getApplication()->findDataboxById($base->get_sbas_id()); $base = $this->getApplication()->findDataboxById($base->get_sbas_id());
@@ -693,9 +690,9 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase
$this->markTestSkipped('No enough records added'); $this->markTestSkipped('No enough records added');
} }
$this->XMLHTTPRequest('POST', '/admin/databox/' . $base->get_sbas_id() . '/empty/'); $response = $this->XMLHTTPRequest('POST', '/admin/databox/' . $base->get_sbas_id() . '/empty/');
$json = $this->getJson(self::$DI['client']->getResponse()); $json = $this->getJson($response);
$this->assertTrue($json->success); $this->assertTrue($json->success);
if (count(self::$DI['app']['orm.em']->getRepository('Phraseanet:Task')->findAll()) === 0) { if (count(self::$DI['app']['orm.em']->getRepository('Phraseanet:Task')->findAll()) === 0) {

View File

@@ -431,14 +431,9 @@ class ApiJsonTest extends ApiTestCase
public function testGetMonitorTaskById() public function testGetMonitorTaskById()
{ {
$tasks = self::$DI['app']['repo.tasks']->findAll(); $idTask = $this->getTestTaskId();
if (!count($tasks)) {
$this->markTestSkipped('no tasks created for the current instance');
}
$this->setToken($this->adminAccessToken); $this->setToken($this->adminAccessToken);
$idTask = $tasks[0]->getId();
$route = '/api/v1/monitor/task/' . $idTask . '/'; $route = '/api/v1/monitor/task/' . $idTask . '/';
$this->evaluateMethodNotAllowedRoute($route, ['PUT', 'DELETE']); $this->evaluateMethodNotAllowedRoute($route, ['PUT', 'DELETE']);
@@ -454,14 +449,9 @@ class ApiJsonTest extends ApiTestCase
public function testPostMonitorTaskById() public function testPostMonitorTaskById()
{ {
$tasks = self::$DI['app']['repo.tasks']->findAll(); $idTask = $this->getTestTaskId();
if (!count($tasks)) {
$this->markTestSkipped('no tasks created for the current instance');
}
$this->setToken($this->adminAccessToken); $this->setToken($this->adminAccessToken);
$idTask = $tasks[0]->getId();
$route = '/api/v1/monitor/task/' . $idTask . '/'; $route = '/api/v1/monitor/task/' . $idTask . '/';
$this->evaluateMethodNotAllowedRoute($route, ['PUT', 'DELETE']); $this->evaluateMethodNotAllowedRoute($route, ['PUT', 'DELETE']);
@@ -492,14 +482,9 @@ class ApiJsonTest extends ApiTestCase
public function testPostMonitorStartTask() public function testPostMonitorStartTask()
{ {
$tasks = self::$DI['app']['repo.tasks']->findAll(); $idTask = $this->getTestTaskId();
if (!count($tasks)) {
$this->markTestSkipped('no tasks created for the current instance');
}
$this->setToken($this->adminAccessToken); $this->setToken($this->adminAccessToken);
$idTask = $tasks[0]->getId();
$route = '/api/v1/monitor/task/' . $idTask . '/start/'; $route = '/api/v1/monitor/task/' . $idTask . '/start/';
$this->evaluateMethodNotAllowedRoute($route, ['GET', 'PUT', 'DELETE']); $this->evaluateMethodNotAllowedRoute($route, ['GET', 'PUT', 'DELETE']);
@@ -518,14 +503,9 @@ class ApiJsonTest extends ApiTestCase
public function testPostMonitorStopTask() public function testPostMonitorStopTask()
{ {
$tasks = self::$DI['app']['repo.tasks']->findAll(); $idTask = $this->getTestTaskId();
if (!count($tasks)) {
$this->markTestSkipped('no tasks created for the current instance');
}
$this->setToken($this->adminAccessToken); $this->setToken($this->adminAccessToken);
$idTask = $tasks[0]->getId();
$route = '/api/v1/monitor/task/' . $idTask . '/stop/'; $route = '/api/v1/monitor/task/' . $idTask . '/stop/';
$this->evaluateMethodNotAllowedRoute($route, ['GET', 'PUT', 'DELETE']); $this->evaluateMethodNotAllowedRoute($route, ['GET', 'PUT', 'DELETE']);
@@ -1965,4 +1945,22 @@ class ApiJsonTest extends ApiTestCase
$this->assertTrue(is_array($response['results'])); $this->assertTrue(is_array($response['results']));
$this->assertTrue(is_string($response['query'])); $this->assertTrue(is_string($response['query']));
} }
/**
* @return int
*/
private function getTestTaskId()
{
$app = $this->getApplication();
$tasks = $app['repo.tasks']->findAll();
if (empty($tasks)) {
$this->markTestSkipped('no tasks created for the current instance');
}
/** @var Task $task */
$task = array_shift($tasks);
return $task->getId();
}
} }

View File

@@ -48,8 +48,7 @@ class ExportTest extends \PhraseanetAuthenticatedWebTestCase
->getMock(); ->getMock();
}); });
$this->XMLHTTPRequest('POST', '/prod/export/ftp/test/', ['lst' => self::$DI['record_1']->get_serialize_key()]); $response = $this->XMLHTTPRequest('POST', '/prod/export/ftp/test/', ['lst' => self::$DI['record_1']->get_serialize_key()]);
$response = self::$DI['client']->getResponse();
$datas = (array) json_decode($response->getContent()); $datas = (array) json_decode($response->getContent());
$this->assertArrayHasKey('success', $datas); $this->assertArrayHasKey('success', $datas);
$this->assertTrue($datas['success']); $this->assertTrue($datas['success']);

View File

@@ -61,12 +61,11 @@ class OrderTest extends \PhraseanetAuthenticatedWebTestCase
$triggered = true; $triggered = true;
}); });
$this->XMLHTTPRequest('POST', '/prod/order/', [ $response = $this->XMLHTTPRequest('POST', '/prod/order/', [
'lst' => $this->getRecord1()->getId(), 'lst' => $this->getRecord1()->getId(),
'deadline' => '+10 minutes' 'deadline' => '+10 minutes'
]); ]);
$response = $this->getClient()->getResponse();
$this->assertTrue($response->isOk(), 'Invalid response from create order'); $this->assertTrue($response->isOk(), 'Invalid response from create order');
$this->assertTrue($triggered, 'Order create listener not triggered'); $this->assertTrue($triggered, 'Order create listener not triggered');
$this->assertEquals('application/json', $response->headers->get('Content-Type')); $this->assertEquals('application/json', $response->headers->get('Content-Type'));
@@ -83,14 +82,13 @@ class OrderTest extends \PhraseanetAuthenticatedWebTestCase
public function testDisplayOrders() public function testDisplayOrders()
{ {
$this->XMLHTTPRequest('POST', '/prod/order/', [ $this->XMLHTTPRequest('POST', '/prod/order/', [
'lst' => $this->getRecord1()->getId(), 'lst' => $this->getRecord1()->getId(),
'deadline' => '+10 minutes' 'deadline' => '+10 minutes'
]); ]);
$client = $this->getClient(); $response = $this->request('GET', '/prod/order/', [
$client->request('GET', '/prod/order/', [
'sort' => 'usage' 'sort' => 'usage'
]); ]);
$this->assertTrue($client->getResponse()->isOk()); $this->assertTrue($response->isOk());
} }
/** /**
@@ -140,8 +138,7 @@ class OrderTest extends \PhraseanetAuthenticatedWebTestCase
foreach ($order->getElements() as $element) { foreach ($order->getElements() as $element) {
$parameters[] = $element->getId(); $parameters[] = $element->getId();
} }
$this->XMLHTTPRequest('POST', '/prod/order/' . $order->getId() . '/send/', ['elements' => $parameters]); $response = $this->XMLHTTPRequest('POST', '/prod/order/' . $order->getId() . '/send/', ['elements' => $parameters]);
$response = $this->getClient()->getResponse();
$this->assertTrue($response->isOk()); $this->assertTrue($response->isOk());
$this->assertEquals('application/json', $response->headers->get('Content-Type')); $this->assertEquals('application/json', $response->headers->get('Content-Type'));
$content = json_decode($response->getContent()); $content = json_decode($response->getContent());
@@ -189,9 +186,7 @@ class OrderTest extends \PhraseanetAuthenticatedWebTestCase
foreach ($order->getElements() as $element) { foreach ($order->getElements() as $element) {
$parameters[] = $element->getId(); $parameters[] = $element->getId();
} }
$this->XMLHTTPRequest('POST', '/prod/order/' . $order->getId() . '/deny/', ['elements' => $parameters]); $response = $this->XMLHTTPRequest('POST', '/prod/order/' . $order->getId() . '/deny/', ['elements' => $parameters]);
$client = $this->getClient();
$response = $client->getResponse();
$this->assertTrue($response->isOk()); $this->assertTrue($response->isOk());
$this->assertEquals('application/json', $response->headers->get('Content-Type')); $this->assertEquals('application/json', $response->headers->get('Content-Type'));
$content = json_decode($response->getContent()); $content = json_decode($response->getContent());

View File

@@ -19,8 +19,13 @@ class PropertyTest extends \PhraseanetAuthenticatedWebTestCase
*/ */
public function testDisplayStatusProperty() public function testDisplayStatusProperty()
{ {
$this->XMLHTTPRequest('GET', '/prod/records/property/', ['lst' => implode(';', [self::$DI['record_no_access']->get_serialize_key(), self::$DI['record_1']->get_serialize_key(), self::$DI['record_4']->get_serialize_key()])]); $response = $this->XMLHTTPRequest('GET', '/prod/records/property/', [
$response = self::$DI['client']->getResponse(); 'lst' => implode(';', [
self::$DI['record_no_access']->get_serialize_key(),
self::$DI['record_1']->get_serialize_key(),
self::$DI['record_4']->get_serialize_key()
])
]);
$this->assertTrue($response->isOk()); $this->assertTrue($response->isOk());
unset($response); unset($response);
} }
@@ -40,10 +45,14 @@ class PropertyTest extends \PhraseanetAuthenticatedWebTestCase
*/ */
public function testDisplayTypeProperty() public function testDisplayTypeProperty()
{ {
$this->XMLHTTPRequest('GET', '/prod/records/property/type/',['lst' => implode(';', [self::$DI['record_no_access']->get_serialize_key(), self::$DI['record_1']->get_serialize_key(), self::$DI['record_4']->get_serialize_key()])]); $response = $this->XMLHTTPRequest('GET', '/prod/records/property/type/', [
$response = self::$DI['client']->getResponse(); 'lst' => implode(';', [
self::$DI['record_no_access']->get_serialize_key(),
self::$DI['record_1']->get_serialize_key(),
self::$DI['record_4']->get_serialize_key()
])
]);
$this->assertTrue($response->isOk()); $this->assertTrue($response->isOk());
unset($response);
} }
/** /**

View File

@@ -36,8 +36,7 @@ class RecordsTest extends \PhraseanetAuthenticatedWebTestCase
{ {
$file = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess(__DIR__ . '/../../../../../files/cestlafete.jpg'), self::$DI['collection']); $file = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess(__DIR__ . '/../../../../../files/cestlafete.jpg'), self::$DI['collection']);
$record = \record_adapter::createFromFile($file, self::$DI['app']); $record = \record_adapter::createFromFile($file, self::$DI['app']);
$this->XMLHTTPRequest('POST', '/prod/records/delete/', ['lst' => $record->getId()]); $response = $this->XMLHTTPRequest('POST', '/prod/records/delete/', ['lst' => $record->getId()]);
$response = self::$DI['client']->getResponse();
$datas = (array) json_decode($response->getContent()); $datas = (array) json_decode($response->getContent());
$this->assertContains($record->getId(), $datas); $this->assertContains($record->getId(), $datas);
try { try {
@@ -46,7 +45,6 @@ class RecordsTest extends \PhraseanetAuthenticatedWebTestCase
} catch (\Exception $e) { } catch (\Exception $e) {
} }
unset($response, $datas, $record);
} }
/** /**
@@ -56,12 +54,10 @@ class RecordsTest extends \PhraseanetAuthenticatedWebTestCase
{ {
$file = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess(__DIR__ . '/../../../../../files/cestlafete.jpg'), self::$DI['collection']); $file = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess(__DIR__ . '/../../../../../files/cestlafete.jpg'), self::$DI['collection']);
$record = \record_adapter::createFromFile($file, self::$DI['app']); $record = \record_adapter::createFromFile($file, self::$DI['app']);
$this->XMLHTTPRequest('POST', '/prod/records/renew-url/', ['lst' => $record->getId()]); $response = $this->XMLHTTPRequest('POST', '/prod/records/renew-url/', ['lst' => $record->getId()]);
$response = self::$DI['client']->getResponse();
$datas = (array) json_decode($response->getContent()); $datas = (array) json_decode($response->getContent());
$this->assertTrue(count($datas) > 0); $this->assertTrue(count($datas) > 0);
$record->delete(); $record->delete();
unset($response, $datas, $record);
} }
/** /**
@@ -92,13 +88,12 @@ class RecordsTest extends \PhraseanetAuthenticatedWebTestCase
self::$DI['app']['orm.em']->persist($element); self::$DI['app']['orm.em']->persist($element);
self::$DI['app']['orm.em']->flush(); self::$DI['app']['orm.em']->flush();
$this->XMLHTTPRequest('POST', '/prod/records/', [ $response = $this->XMLHTTPRequest('POST', '/prod/records/', [
'env' => 'BASK', 'env' => 'BASK',
'pos' => 0, 'pos' => 0,
'query' => '', 'query' => '',
'cont' => $basket->getId(), 'cont' => $basket->getId(),
]); ]);
$response = self::$DI['client']->getResponse();
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$data = json_decode($response->getContent(), true); $data = json_decode($response->getContent(), true);
@@ -126,14 +121,13 @@ class RecordsTest extends \PhraseanetAuthenticatedWebTestCase
$options->onCollections($acl->get_granted_base()); $options->onCollections($acl->get_granted_base());
$serializedOptions = $options->serialize(); $serializedOptions = $options->serialize();
$this->XMLHTTPRequest('POST', '/prod/records/', [ $response = $this->XMLHTTPRequest('POST', '/prod/records/', [
'env' => 'RESULT', 'env' => 'RESULT',
'options_serial' => $serializedOptions, 'options_serial' => $serializedOptions,
'pos' => 0, 'pos' => 0,
'query' => '' 'query' => ''
]); ]);
$response = self::$DI['client']->getResponse();
$data = json_decode($response->getContent(), true); $data = json_decode($response->getContent(), true);
$this->assertArrayHasKey('desc', $data); $this->assertArrayHasKey('desc', $data);
@@ -145,8 +139,6 @@ class RecordsTest extends \PhraseanetAuthenticatedWebTestCase
$this->assertArrayHasKey('tools', $data); $this->assertArrayHasKey('tools', $data);
$this->assertArrayHasKey('pos', $data); $this->assertArrayHasKey('pos', $data);
$this->assertArrayHasKey('title', $data); $this->assertArrayHasKey('title', $data);
unset($response, $data);
} }
/** /**
@@ -157,14 +149,13 @@ class RecordsTest extends \PhraseanetAuthenticatedWebTestCase
$this->authenticate(self::$DI['app']); $this->authenticate(self::$DI['app']);
self::$DI['record_story_1']; self::$DI['record_story_1'];
$this->XMLHTTPRequest('POST', '/prod/records/', [ $response = $this->XMLHTTPRequest('POST', '/prod/records/', [
'env' => 'REG', 'env' => 'REG',
'pos' => 0, 'pos' => 0,
'query' => '', 'query' => '',
'cont' => self::$DI['record_story_1']->get_serialize_key() 'cont' => self::$DI['record_story_1']->get_serialize_key()
]); ]);
$response = self::$DI['client']->getResponse();
$data = json_decode($response->getContent()); $data = json_decode($response->getContent());
$this->assertObjectHasAttribute('desc', $data); $this->assertObjectHasAttribute('desc', $data);
$this->assertObjectHasAttribute('html_preview', $data); $this->assertObjectHasAttribute('html_preview', $data);
@@ -175,8 +166,6 @@ class RecordsTest extends \PhraseanetAuthenticatedWebTestCase
$this->assertObjectHasAttribute('tools', $data); $this->assertObjectHasAttribute('tools', $data);
$this->assertObjectHasAttribute('pos', $data); $this->assertObjectHasAttribute('pos', $data);
$this->assertObjectHasAttribute('title', $data); $this->assertObjectHasAttribute('title', $data);
unset($response, $data);
} }
/** /**
@@ -187,14 +176,13 @@ class RecordsTest extends \PhraseanetAuthenticatedWebTestCase
$this->authenticate(self::$DI['app']); $this->authenticate(self::$DI['app']);
$basket = self::$DI['app']['orm.em']->find('Phraseanet:Basket', 1); $basket = self::$DI['app']['orm.em']->find('Phraseanet:Basket', 1);
$this->XMLHTTPRequest('POST', '/prod/records/', [ $response = $this->XMLHTTPRequest('POST', '/prod/records/', [
'env' => 'BASK', 'env' => 'BASK',
'pos' => 0, 'pos' => 0,
'query' => '', 'query' => '',
'cont' => $basket->getId() 'cont' => $basket->getId()
]); ]);
$response = self::$DI['client']->getResponse();
$data = json_decode($response->getContent()); $data = json_decode($response->getContent());
$this->assertObjectHasAttribute('desc', $data); $this->assertObjectHasAttribute('desc', $data);
@@ -224,14 +212,13 @@ class RecordsTest extends \PhraseanetAuthenticatedWebTestCase
$feed = self::$DI['app']['orm.em']->find('Phraseanet:Feed', 1); $feed = self::$DI['app']['orm.em']->find('Phraseanet:Feed', 1);
$feedEntry = $feed->getEntries()->first(); $feedEntry = $feed->getEntries()->first();
$this->XMLHTTPRequest('POST', '/prod/records/', [ $response = $this->XMLHTTPRequest('POST', '/prod/records/', [
'env' => 'FEED', 'env' => 'FEED',
'pos' => 0, 'pos' => 0,
'query' => '', 'query' => '',
'cont' => $feedEntry->getId() 'cont' => $feedEntry->getId()
]); ]);
$response = self::$DI['client']->getResponse();
$data = json_decode($response->getContent()); $data = json_decode($response->getContent());
$this->assertObjectHasAttribute('desc', $data); $this->assertObjectHasAttribute('desc', $data);
$this->assertObjectHasAttribute('html_preview', $data); $this->assertObjectHasAttribute('html_preview', $data);

View File

@@ -34,10 +34,8 @@ class TOUTest extends \PhraseanetAuthenticatedWebTestCase
*/ */
public function testGetTOUAJAX() public function testGetTOUAJAX()
{ {
$this->XMLHTTPRequest('GET', '/prod/TOU/'); $response = $this->XMLHTTPRequest('GET', '/prod/TOU/');
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOk()); $this->assertTrue($response->isOk());
unset($response);
} }
/** /**
@@ -48,8 +46,7 @@ class TOUTest extends \PhraseanetAuthenticatedWebTestCase
$databoxes = self::$DI['app']->getDataboxes(); $databoxes = self::$DI['app']->getDataboxes();
$databox = array_shift($databoxes); $databox = array_shift($databoxes);
self::$DI['app']['authentication']->setUser(self::$DI['user_alt2']); self::$DI['app']['authentication']->setUser(self::$DI['user_alt2']);
$this->XMLHTTPRequest('POST', '/prod/TOU/deny/'.$databox->get_sbas_id() .'/'); $response = $this->XMLHTTPRequest('POST', '/prod/TOU/deny/' . $databox->get_sbas_id() . '/');
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOk()); $this->assertTrue($response->isOk());
unset($response, $databoxes); unset($response, $databoxes);

View File

@@ -34,13 +34,11 @@ class RootTest extends \PhraseanetAuthenticatedWebTestCase
{ {
$this->authenticate(self::$DI['app']); $this->authenticate(self::$DI['app']);
$this->XMLHTTPRequest('GET', '/report/dashboard', [ $response = $this->XMLHTTPRequest('GET', '/report/dashboard', [
'dmin' => $this->dmin->format('Y-m-d'), 'dmin' => $this->dmin->format('Y-m-d'),
'dmax' => $this->dmin->format('Y-m-d'), 'dmax' => $this->dmin->format('Y-m-d'),
]); ]);
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOk()); $this->assertTrue($response->isOk());
} }

View File

@@ -115,10 +115,10 @@ class DevelopersTest extends \PhraseanetAuthenticatedWebTestCase
*/ */
public function testDeleteAppError() public function testDeleteAppError()
{ {
$this->XMLHTTPRequest('DELETE', '/developers/application/0/'); $response = $this->XMLHTTPRequest('DELETE', '/developers/application/0/');
$this->assertTrue(self::$DI['client']->getResponse()->isOk()); $this->assertTrue($response->isOk());
$content = json_decode(self::$DI['client']->getResponse()->getContent()); $content = json_decode($response->getContent());
$this->assertFalse($content->success); $this->assertFalse($content->success);
} }
@@ -134,8 +134,8 @@ class DevelopersTest extends \PhraseanetAuthenticatedWebTestCase
'http://phraseanet.com/' 'http://phraseanet.com/'
); );
$id = $oauthApp->getId(); $id = $oauthApp->getId();
$this->XMLHTTPRequest('DELETE', '/developers/application/' . $id . '/'); $response = $this->XMLHTTPRequest('DELETE', '/developers/application/' . $id . '/');
$this->assertTrue(self::$DI['client']->getResponse()->isOk()); $this->assertTrue($response->isOk());
$this->assertNull(self::$DI['app']['repo.api-applications']->find($id)); $this->assertNull(self::$DI['app']['repo.api-applications']->find($id));
} }
@@ -155,12 +155,12 @@ class DevelopersTest extends \PhraseanetAuthenticatedWebTestCase
*/ */
public function testRenewAppCallbackError() public function testRenewAppCallbackError()
{ {
$this->XMLHTTPRequest('POST', '/developers/application/0/callback/', [ $response = $this->XMLHTTPRequest('POST', '/developers/application/0/callback/', [
'callback' => 'my.callback.com' 'callback' => 'my.callback.com'
]); ]);
$this->assertTrue(self::$DI['client']->getResponse()->isOk()); $this->assertTrue($response->isOk());
$content = json_decode(self::$DI['client']->getResponse()->getContent()); $content = json_decode($response->getContent());
$this->assertFalse($content->success); $this->assertFalse($content->success);
} }
@@ -170,9 +170,9 @@ class DevelopersTest extends \PhraseanetAuthenticatedWebTestCase
public function testRenewAppCallbackError2() public function testRenewAppCallbackError2()
{ {
$oauthApp = self::$DI['oauth2-app-user']; $oauthApp = self::$DI['oauth2-app-user'];
$this->XMLHTTPRequest('POST', '/developers/application/'.$oauthApp->getId().'/callback/'); $response = $this->XMLHTTPRequest('POST', '/developers/application/' . $oauthApp->getId() . '/callback/');
$this->assertTrue(self::$DI['client']->getResponse()->isOk()); $this->assertTrue($response->isOk());
$content = json_decode(self::$DI['client']->getResponse()->getContent()); $content = json_decode($response->getContent());
$this->assertFalse($content->success); $this->assertFalse($content->success);
} }
@@ -183,12 +183,12 @@ class DevelopersTest extends \PhraseanetAuthenticatedWebTestCase
{ {
$oauthApp = self::$DI['oauth2-app-user']; $oauthApp = self::$DI['oauth2-app-user'];
$this->XMLHTTPRequest('POST', '/developers/application/' . $oauthApp->getId() . '/callback/', [ $response = $this->XMLHTTPRequest('POST', '/developers/application/' . $oauthApp->getId() . '/callback/', [
'callback' => 'http://my.callback.com' 'callback' => 'http://my.callback.com'
]); ]);
$this->assertTrue(self::$DI['client']->getResponse()->isOk()); $this->assertTrue($response->isOk());
$content = json_decode(self::$DI['client']->getResponse()->getContent()); $content = json_decode($response->getContent());
$this->assertTrue($content->success); $this->assertTrue($content->success);
$oauthApp = self::$DI['app']['repo.api-applications']->find($oauthApp->getId()); $oauthApp = self::$DI['app']['repo.api-applications']->find($oauthApp->getId());
$this->assertEquals('http://my.callback.com', $oauthApp->getRedirectUri()); $this->assertEquals('http://my.callback.com', $oauthApp->getRedirectUri());
@@ -209,12 +209,12 @@ class DevelopersTest extends \PhraseanetAuthenticatedWebTestCase
*/ */
public function testRenewAccessTokenError() public function testRenewAccessTokenError()
{ {
$this->XMLHTTPRequest('POST', '/developers/application/0/access_token/', [ $response = $this->XMLHTTPRequest('POST', '/developers/application/0/access_token/', [
'callback' => 'my.callback.com' 'callback' => 'my.callback.com'
]); ]);
$this->assertTrue(self::$DI['client']->getResponse()->isOk()); $this->assertTrue($response->isOk());
$content = json_decode(self::$DI['client']->getResponse()->getContent()); $content = json_decode($response->getContent());
$this->assertFalse($content->success); $this->assertFalse($content->success);
} }
@@ -225,10 +225,10 @@ class DevelopersTest extends \PhraseanetAuthenticatedWebTestCase
{ {
$oauthApp = self::$DI['oauth2-app-user']; $oauthApp = self::$DI['oauth2-app-user'];
$this->XMLHTTPRequest('POST', '/developers/application/' . $oauthApp->getId() . '/access_token/'); $response = $this->XMLHTTPRequest('POST', '/developers/application/' . $oauthApp->getId() . '/access_token/');
$this->assertTrue(self::$DI['client']->getResponse()->isOk()); $this->assertTrue($response->isOk());
$content = json_decode(self::$DI['client']->getResponse()->getContent()); $content = json_decode($response->getContent());
$this->assertTrue($content->success); $this->assertTrue($content->success);
$this->assertNotNull($content->token); $this->assertNotNull($content->token);
} }
@@ -248,12 +248,12 @@ class DevelopersTest extends \PhraseanetAuthenticatedWebTestCase
*/ */
public function testAuthorizeGrantpasswordError() public function testAuthorizeGrantpasswordError()
{ {
$this->XMLHTTPRequest('POST', '/developers/application/0/authorize_grant_password/', [ $response = $this->XMLHTTPRequest('POST', '/developers/application/0/authorize_grant_password/', [
'callback' => 'my.callback.com' 'callback' => 'my.callback.com'
]); ]);
$this->assertTrue(self::$DI['client']->getResponse()->isOk()); $this->assertTrue($response->isOk());
$content = json_decode(self::$DI['client']->getResponse()->getContent()); $content = json_decode($response->getContent());
$this->assertFalse($content->success); $this->assertFalse($content->success);
} }
@@ -264,12 +264,12 @@ class DevelopersTest extends \PhraseanetAuthenticatedWebTestCase
{ {
$oauthApp = self::$DI['oauth2-app-user']; $oauthApp = self::$DI['oauth2-app-user'];
$this->XMLHTTPRequest('POST', '/developers/application/' . $oauthApp->getId() . '/authorize_grant_password/', [ $response = $this->XMLHTTPRequest('POST', '/developers/application/' . $oauthApp->getId() . '/authorize_grant_password/', [
'grant' => '1' 'grant' => '1'
]); ]);
$this->assertTrue(self::$DI['client']->getResponse()->isOk()); $this->assertTrue($response->isOk());
$content = json_decode(self::$DI['client']->getResponse()->getContent()); $content = json_decode($response->getContent());
$this->assertTrue($content->success); $this->assertTrue($content->success);
$oauthApp = self::$DI['app']['repo.api-applications']->find($oauthApp->getId()); $oauthApp = self::$DI['app']['repo.api-applications']->find($oauthApp->getId());
$this->assertTrue($oauthApp->isPasswordGranted()); $this->assertTrue($oauthApp->isPasswordGranted());

View File

@@ -19,9 +19,9 @@ class SessionTest extends \PhraseanetAuthenticatedWebTestCase
public function testUpdSessionLogout() public function testUpdSessionLogout()
{ {
$this->logout(self::$DI['app']); $this->logout(self::$DI['app']);
$this->XMLHTTPRequest('POST', '/session/update/'); $response = $this->XMLHTTPRequest('POST', '/session/update/');
$this->assertTrue(self::$DI['client']->getResponse()->isOk()); $this->assertTrue($response->isOk());
$datas = json_decode(self::$DI['client']->getResponse()->getContent()); $datas = json_decode($response->getContent());
$this->checkSessionReturn($datas); $this->checkSessionReturn($datas);
$this->assertEquals('disconnected', $datas->status); $this->assertEquals('disconnected', $datas->status);
} }
@@ -31,11 +31,11 @@ class SessionTest extends \PhraseanetAuthenticatedWebTestCase
*/ */
public function testUpdSessionChangeUser() public function testUpdSessionChangeUser()
{ {
$this->XMLHTTPRequest('POST', '/session/update/', [ $response = $this->XMLHTTPRequest('POST', '/session/update/', [
'usr' => self::$DI['user_alt1']->getId() 'usr' => self::$DI['user_alt1']->getId()
]); ]);
$this->assertTrue(self::$DI['client']->getResponse()->isOk()); $this->assertTrue($response->isOk());
$datas = json_decode(self::$DI['client']->getResponse()->getContent()); $datas = json_decode($response->getContent());
$this->checkSessionReturn($datas); $this->checkSessionReturn($datas);
$this->assertEquals('disconnected', $datas->status); $this->assertEquals('disconnected', $datas->status);
} }
@@ -49,13 +49,12 @@ class SessionTest extends \PhraseanetAuthenticatedWebTestCase
/** @var User $user */ /** @var User $user */
$user = self::$DI['user']; $user = self::$DI['user'];
$this->XMLHTTPRequest('POST', '/session/update/', [ $response = $this->XMLHTTPRequest('POST', '/session/update/', [
'usr' => $user->getId(), 'usr' => $user->getId(),
'module' => 1 'module' => 1
]); ]);
$client = $this->getClient(); $this->assertTrue($response->isOk());
$this->assertTrue($client->getResponse()->isOk()); $data = json_decode($response->getContent());
$data = json_decode($client->getResponse()->getContent());
$this->checkSessionReturn($data); $this->checkSessionReturn($data);
$this->assertEquals('ok', $data->status); $this->assertEquals('ok', $data->status);
} }
@@ -67,12 +66,12 @@ class SessionTest extends \PhraseanetAuthenticatedWebTestCase
{ {
$this->authenticate(self::$DI['app']); $this->authenticate(self::$DI['app']);
$this->XMLHTTPRequest('POST', '/session/update/', [ $response = $this->XMLHTTPRequest('POST', '/session/update/', [
'usr' => self::$DI['user']->getId() 'usr' => self::$DI['user']->getId()
]); ]);
$datas = json_decode(self::$DI['client']->getResponse()->getContent()); $datas = json_decode($response->getContent());
$datas = json_decode(self::$DI['client']->getResponse()->getContent()); $datas = json_decode($response->getContent());
$this->checkSessionReturn($datas); $this->checkSessionReturn($datas);
$this->assertEquals('unknown', $datas->status); $this->assertEquals('unknown', $datas->status);
} }
@@ -118,8 +117,8 @@ class SessionTest extends \PhraseanetAuthenticatedWebTestCase
->will($this->returnValue(null)); ->will($this->returnValue(null));
self::$DI['app']['orm.em'] = $em; self::$DI['app']['orm.em'] = $em;
$this->XMLHTTPRequest('POST', '/session/delete/1'); $response = $this->XMLHTTPRequest('POST', '/session/delete/1');
$this->assertTrue(self::$DI['client']->getResponse()->isOK()); $this->assertTrue($response->isOK());
} }
public function testDeleteSessionUnauthorized() public function testDeleteSessionUnauthorized()

View File

@@ -17,10 +17,8 @@ class NotificationsTest extends \PhraseanetAuthenticatedWebTestCase
*/ */
public function testListNotifications() public function testListNotifications()
{ {
$this->XMLHTTPRequest('GET', '/user/notifications/'); $response = $this->XMLHTTPRequest('GET', '/user/notifications/');
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOk()); $this->assertTrue($response->isOk());
unset($response);
} }
/** /**
@@ -48,16 +46,14 @@ class NotificationsTest extends \PhraseanetAuthenticatedWebTestCase
*/ */
public function testSetNotificationsReaded() public function testSetNotificationsReaded()
{ {
$this->XMLHTTPRequest('POST', '/user/notifications/read/', [ $response = $this->XMLHTTPRequest('POST', '/user/notifications/read/', [
'notifications' => '' 'notifications' => ''
]); ]);
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOk()); $this->assertTrue($response->isOk());
$datas = (array) json_decode($response->getContent()); $datas = (array) json_decode($response->getContent());
$this->assertArrayHasKey('success', $datas); $this->assertArrayHasKey('success', $datas);
$this->assertTrue($datas['success'], $response->getContent()); $this->assertTrue($datas['success'], $response->getContent());
$this->assertArrayHasKey('message', $datas); $this->assertArrayHasKey('message', $datas);
unset($response);
} }
/** /**

View File

@@ -17,8 +17,7 @@ class PreferencesTest extends \PhraseanetAuthenticatedWebTestCase
*/ */
public function testSaveUserPref() public function testSaveUserPref()
{ {
$this->XMLHTTPRequest('POST', '/user/preferences/', ['prop' => 'prop_test', 'value' => 'val_test']); $response = $this->XMLHTTPRequest('POST', '/user/preferences/', ['prop' => 'prop_test', 'value' => 'val_test']);
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOk()); $this->assertTrue($response->isOk());
$this->assertTrue(json_decode($response->getContent())->success); $this->assertTrue(json_decode($response->getContent())->success);
$this->assertEquals('val_test', self::$DI['app']['settings']->getUserSetting(self::$DI['user'], 'prop_test')); $this->assertEquals('val_test', self::$DI['app']['settings']->getUserSetting(self::$DI['user'], 'prop_test'));
@@ -49,8 +48,10 @@ class PreferencesTest extends \PhraseanetAuthenticatedWebTestCase
*/ */
public function testSaveTemporaryPref() public function testSaveTemporaryPref()
{ {
$this->XMLHTTPRequest('POST', "/user/preferences/temporary/", ['prop' => 'prop_test', 'value' => 'val_test']); $response = $this->XMLHTTPRequest('POST', "/user/preferences/temporary/", [
$response = self::$DI['client']->getResponse(); 'prop' => 'prop_test',
'value' => 'val_test'
]);
$this->assertTrue($response->isOk()); $this->assertTrue($response->isOk());
$this->assertTrue(json_decode($response->getContent())->success); $this->assertTrue(json_decode($response->getContent())->success);
$this->assertEquals('val_test', self::$DI['app']['session']->get('phraseanet.prop_test')); $this->assertEquals('val_test', self::$DI['app']['session']->get('phraseanet.prop_test'));

View File

@@ -492,6 +492,24 @@ abstract class PhraseanetTestCase extends WebTestCase
}); });
} }
/**
* @param string $method
* @param string $uri
* @param array $parameters
* @param array $server
* @param string $content
*
* @return Response
*/
protected function request($method, $uri, array $parameters = [], array $server = [], $content = null)
{
$client = $this->getClient();
$client->request($method, $uri, $parameters, [], $server, $content);
return $client->getResponse();
}
/** /**
* Calls a URI as XMLHTTP request. * Calls a URI as XMLHTTP request.
* *
@@ -500,11 +518,11 @@ abstract class PhraseanetTestCase extends WebTestCase
* @param array $parameters The Request parameters * @param array $parameters The Request parameters
* @param string $httpAccept Contents of the Accept header * @param string $httpAccept Contents of the Accept header
* *
* @return Crawler * @return Response
*/ */
protected function XMLHTTPRequest($method, $uri, array $parameters = [], $httpAccept = 'application/json') protected function XMLHTTPRequest($method, $uri, array $parameters = [], $httpAccept = 'application/json')
{ {
return $this->getClient()->request($method, $uri, $parameters, [], [ return $this->request($method, $uri, $parameters, [
'HTTP_ACCEPT' => $httpAccept, 'HTTP_ACCEPT' => $httpAccept,
'HTTP_X-Requested-With' => 'XMLHttpRequest', 'HTTP_X-Requested-With' => 'XMLHttpRequest',
]); ]);