diff --git a/.travis.yml b/.travis.yml index 81156b6436..70433f439a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,11 @@ language: php sudo: require +branches: + except: + - /^3\..*$/ + - /^scrutinizer-.*$/ + matrix: fast_finish: true include: @@ -37,8 +42,8 @@ before_install: - echo "extension=zmq.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini - yes | pecl install imagick-beta install: - - if [[ $TRAVIS_PHP_VERSION = 5.* ]];then travis_retry composer install --optimize-autoloader --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 --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 --no-progress --no-interaction; fi; - travis_retry npm install 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;' diff --git a/circle.yml b/circle.yml index 290d24058b..112204549b 100644 --- a/circle.yml +++ b/circle.yml @@ -19,13 +19,14 @@ dependencies: cache_directories: - elasticsearch-1.6.0 # relative to the build directory - node_modules + - ~/.composer pre: - yes '' | pecl install imagick - pecl install json - yes '' | pecl install zmq-beta - sed -i 's/^\(session.cache_limiter = \).*/\1""/' ~/.phpenv/versions/$(phpenv global)/etc/php.ini override: - - composer install --prefer-source --no-interaction + - composer install --no-progress --no-interaction --optimize-autoloader post: - 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 diff --git a/lib/Alchemy/Phrasea/Application/Helper/UserQueryAware.php b/lib/Alchemy/Phrasea/Application/Helper/UserQueryAware.php index dc401b693d..2e613fdbfe 100644 --- a/lib/Alchemy/Phrasea/Application/Helper/UserQueryAware.php +++ b/lib/Alchemy/Phrasea/Application/Helper/UserQueryAware.php @@ -31,7 +31,7 @@ trait UserQueryAware */ public function getUserQueryFactory() { - if (! is_callable($this->userQueryFactory)) { + if (!is_callable($this->userQueryFactory)) { throw new \LogicException('User Query factory was not set'); } @@ -44,7 +44,7 @@ trait UserQueryAware public function createUserQuery() { $userQuery = call_user_func($this->getUserQueryFactory()); - if (! $userQuery instanceof \User_Query) { + if (!$userQuery instanceof \User_Query) { throw new \LogicException(sprintf( 'User Query factory does not create %s instance, got "%s" instead', \User_Query::class, diff --git a/lib/Alchemy/Phrasea/Application/RouteLoader.php b/lib/Alchemy/Phrasea/Application/RouteLoader.php index c4e9f5ac55..6616c87cca 100644 --- a/lib/Alchemy/Phrasea/Application/RouteLoader.php +++ b/lib/Alchemy/Phrasea/Application/RouteLoader.php @@ -19,7 +19,7 @@ class RouteLoader '/admin/dashboard' => Providers\Admin\Dashboard::class, '/admin/databox' => Providers\Admin\Databox::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/plugins' => Providers\Admin\Plugins::class, '/admin/search-engine' => Providers\Admin\SearchEngine::class, @@ -125,7 +125,7 @@ class RouteLoader list($prefix, $providerKey) = $providerDefinition; } - if (! $this->isValidProviderDefinition($app, $prefix, $providerKey)) { + if (!$this->isValidProviderDefinition($app, $prefix, $providerKey)) { continue; } diff --git a/lib/Alchemy/Phrasea/Authentication/Provider/Linkedin.php b/lib/Alchemy/Phrasea/Authentication/Provider/Linkedin.php index 4564173062..1f759f36a5 100644 --- a/lib/Alchemy/Phrasea/Authentication/Provider/Linkedin.php +++ b/lib/Alchemy/Phrasea/Authentication/Provider/Linkedin.php @@ -42,7 +42,7 @@ class Linkedin extends AbstractProvider /** * @param ClientInterface $client * - * @return Github + * @return Linkedin */ public function setGuzzleClient(ClientInterface $client) { diff --git a/lib/Alchemy/Phrasea/Authentication/Provider/Token/Identity.php b/lib/Alchemy/Phrasea/Authentication/Provider/Token/Identity.php index 0e34e1ccd9..fb46ce71d7 100644 --- a/lib/Alchemy/Phrasea/Authentication/Provider/Token/Identity.php +++ b/lib/Alchemy/Phrasea/Authentication/Provider/Token/Identity.php @@ -157,7 +157,7 @@ class Identity public function get($property) { 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]; @@ -186,7 +186,7 @@ class Identity public function remove($property) { 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]; diff --git a/lib/Alchemy/Phrasea/Authentication/SuggestionFinder.php b/lib/Alchemy/Phrasea/Authentication/SuggestionFinder.php index 6bcbca9120..f4c0c22045 100644 --- a/lib/Alchemy/Phrasea/Authentication/SuggestionFinder.php +++ b/lib/Alchemy/Phrasea/Authentication/SuggestionFinder.php @@ -40,7 +40,7 @@ class SuggestionFinder $infos = $token->getIdentity(); 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; diff --git a/lib/Alchemy/Phrasea/Border/Attribute/Metadata.php b/lib/Alchemy/Phrasea/Border/Attribute/Metadata.php index 11143c7abb..59f414f586 100644 --- a/lib/Alchemy/Phrasea/Border/Attribute/Metadata.php +++ b/lib/Alchemy/Phrasea/Border/Attribute/Metadata.php @@ -75,11 +75,11 @@ class Metadata implements AttributeInterface */ public static function loadFromString(Application $app, $string) { - if ( ! $metadata = @unserialize($string)) { + if (!$metadata = @unserialize($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'); } diff --git a/lib/Alchemy/Phrasea/Border/Attribute/Story.php b/lib/Alchemy/Phrasea/Border/Attribute/Story.php index d9210fd18b..6b8e7eabcf 100644 --- a/lib/Alchemy/Phrasea/Border/Attribute/Story.php +++ b/lib/Alchemy/Phrasea/Border/Attribute/Story.php @@ -31,7 +31,7 @@ class Story implements AttributeInterface */ public function __construct(\record_adapter $story) { - if ( ! $story->isStory()) { + if (!$story->isStory()) { 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'); } - if ( ! $story->isStory()) { + if (!$story->isStory()) { throw new \InvalidArgumentException('Unable to fetch a story from string'); } diff --git a/lib/Alchemy/Phrasea/Border/Checker/AbstractChecker.php b/lib/Alchemy/Phrasea/Border/Checker/AbstractChecker.php index 8d6fe00e46..8b4de0fb58 100644 --- a/lib/Alchemy/Phrasea/Border/Checker/AbstractChecker.php +++ b/lib/Alchemy/Phrasea/Border/Checker/AbstractChecker.php @@ -58,7 +58,7 @@ abstract class AbstractChecker implements CheckerInterface $this->databoxes = []; 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'); } $this->databoxes[] = $databox; @@ -86,7 +86,7 @@ abstract class AbstractChecker implements CheckerInterface $this->collections = []; 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'); } $this->collections[] = $collection; diff --git a/lib/Alchemy/Phrasea/Border/Checker/Colorspace.php b/lib/Alchemy/Phrasea/Border/Checker/Colorspace.php index 3a55b047ff..e431f0cb61 100644 --- a/lib/Alchemy/Phrasea/Border/Checker/Colorspace.php +++ b/lib/Alchemy/Phrasea/Border/Checker/Colorspace.php @@ -26,7 +26,7 @@ class Colorspace extends AbstractChecker public function __construct(Application $app, array $options) { - if ( ! isset($options['colorspaces'])) { + if (!isset($options['colorspaces'])) { throw new \InvalidArgumentException('Missing "colorspaces" options'); } @@ -42,7 +42,8 @@ class Colorspace extends AbstractChecker $boolean = true; //bypass color if empty array } elseif (method_exists($file->getMedia(), 'getColorSpace')) { $colorspace = null; - switch ($file->getMedia()->getColorSpace()) { + switch ($file->getMedia()->getColorSpace()) + { case \MediaVorus\Media\Image::COLORSPACE_CMYK: $colorspace = self::COLORSPACE_CMYK; break; diff --git a/lib/Alchemy/Phrasea/Border/Checker/Extension.php b/lib/Alchemy/Phrasea/Border/Checker/Extension.php index 9ba8d279a8..33f4c240a0 100644 --- a/lib/Alchemy/Phrasea/Border/Checker/Extension.php +++ b/lib/Alchemy/Phrasea/Border/Checker/Extension.php @@ -22,7 +22,7 @@ class Extension extends AbstractChecker public function __construct(Application $app, array $options) { - if ( ! isset($options['extensions'])) { + if (!isset($options['extensions'])) { throw new \InvalidArgumentException('Missing "extensions" options'); } diff --git a/lib/Alchemy/Phrasea/Border/Checker/Filename.php b/lib/Alchemy/Phrasea/Border/Checker/Filename.php index 6500f0d6c9..a349348fd9 100644 --- a/lib/Alchemy/Phrasea/Border/Checker/Filename.php +++ b/lib/Alchemy/Phrasea/Border/Checker/Filename.php @@ -31,7 +31,7 @@ class Filename extends AbstractChecker */ public function __construct(Application $app, array $options = []) { - if ( ! isset($options['sensitive'])) { + if (!isset($options['sensitive'])) { $options['sensitive'] = false; } @@ -44,9 +44,9 @@ class Filename extends AbstractChecker */ public function check(EntityManager $em, File $file) { - $boolean = ! count(\record_adapter::get_records_by_originalname( - $file->getCollection()->get_databox(), $file->getOriginalName(), $this->sensitive, 0, 1 - )); + $boolean = empty(\record_adapter::get_records_by_originalname( + $file->getCollection()->get_databox(), $file->getOriginalName(), $this->sensitive, 0, 1 + )); return new Response($boolean, $this); } diff --git a/lib/Alchemy/Phrasea/Border/Checker/MediaType.php b/lib/Alchemy/Phrasea/Border/Checker/MediaType.php index e9cf44bdd5..fe041da16a 100644 --- a/lib/Alchemy/Phrasea/Border/Checker/MediaType.php +++ b/lib/Alchemy/Phrasea/Border/Checker/MediaType.php @@ -29,7 +29,7 @@ class MediaType extends AbstractChecker public function __construct(Application $app, array $options) { - if ( ! isset($options['mediatypes'])) { + if (!isset($options['mediatypes'])) { throw new \InvalidArgumentException('Missing "mediatypes" options'); } diff --git a/lib/Alchemy/Phrasea/Border/Checker/Sha256.php b/lib/Alchemy/Phrasea/Border/Checker/Sha256.php index 564421107e..2638a78002 100644 --- a/lib/Alchemy/Phrasea/Border/Checker/Sha256.php +++ b/lib/Alchemy/Phrasea/Border/Checker/Sha256.php @@ -33,7 +33,7 @@ class Sha256 extends AbstractChecker */ 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); } diff --git a/lib/Alchemy/Phrasea/Border/Checker/UUID.php b/lib/Alchemy/Phrasea/Border/Checker/UUID.php index 93803e9a42..b763d194af 100644 --- a/lib/Alchemy/Phrasea/Border/Checker/UUID.php +++ b/lib/Alchemy/Phrasea/Border/Checker/UUID.php @@ -32,7 +32,7 @@ class UUID extends AbstractChecker */ 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); } diff --git a/lib/Alchemy/Phrasea/Border/File.php b/lib/Alchemy/Phrasea/Border/File.php index 74df31a92a..be35b71e8f 100644 --- a/lib/Alchemy/Phrasea/Border/File.php +++ b/lib/Alchemy/Phrasea/Border/File.php @@ -66,7 +66,7 @@ class File $this->media = $media; $this->collection = $collection; $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) { - if ($this->uuid && ! $write) { + if ($this->uuid && !$write) { return $this->uuid; } @@ -104,7 +104,7 @@ class File 'Canon:ImageUniqueID', ]; - if (! $this->uuid) { + if (!$this->uuid) { $metadatas = $this->media->getMetadatas(); $uuid = null; @@ -119,7 +119,7 @@ class File } } - if (! $uuid && $generate) { + if (!$uuid && $generate) { $uuid = Uuid::uuid4(); } @@ -152,7 +152,8 @@ class File */ public function getType() { - switch ($this->media->getType()) { + switch ($this->media->getType()) + { case MediaInterface::TYPE_AUDIO: return new Audio(); break; @@ -180,7 +181,7 @@ class File */ public function getSha256() { - if (! $this->sha256) { + if (!$this->sha256) { $this->sha256 = $this->media->getHash('sha256'); } @@ -194,7 +195,7 @@ class File */ public function getMD5() { - if (! $this->md5) { + if (!$this->md5) { $this->md5 = $this->media->getHash('md5'); } diff --git a/lib/Alchemy/Phrasea/Border/Visa.php b/lib/Alchemy/Phrasea/Border/Visa.php index 67ab92b4db..e532f405f5 100644 --- a/lib/Alchemy/Phrasea/Border/Visa.php +++ b/lib/Alchemy/Phrasea/Border/Visa.php @@ -77,7 +77,7 @@ class Visa { foreach ($this->responses as $response) { - if ( ! $response->isOk()) { + if (!$response->isOk()) { return false; } } diff --git a/lib/Alchemy/Phrasea/Cache/ArrayCache.php b/lib/Alchemy/Phrasea/Cache/ArrayCache.php index 8f0c95b864..5bb4df0198 100644 --- a/lib/Alchemy/Phrasea/Cache/ArrayCache.php +++ b/lib/Alchemy/Phrasea/Cache/ArrayCache.php @@ -45,7 +45,7 @@ class ArrayCache extends DoctrineArray implements Cache */ public function get($id) { - if ( ! $this->contains($id)) { + if (!$this->contains($id)) { throw new Exception(sprintf('Unable to find key %s', $id)); } diff --git a/lib/Alchemy/Phrasea/Cache/Manager.php b/lib/Alchemy/Phrasea/Cache/Manager.php index aa0d382eb0..a80a1a5d1e 100644 --- a/lib/Alchemy/Phrasea/Cache/Manager.php +++ b/lib/Alchemy/Phrasea/Cache/Manager.php @@ -82,7 +82,7 @@ class Manager if (isset($options['namespace']) && is_string($options['namespace'])) { $cache->setNamespace($options['namespace']); } else { - $cache->setNamespace(md5(gethostname().'-'.__DIR__)); + $cache->setNamespace(md5(gethostname() . '-' . __DIR__)); } $this->drivers[$label] = $cache; @@ -95,17 +95,28 @@ class Manager return $cache; } + /** + * @param string $name + * @param string $label + */ private function register($name, $label) { $this->registry[$label] = $name; $this->save(); } + /** + * @param string $name + * @param string $label + */ private function isAlreadyRegistered($name, $label) { return isset($this->registry[$label]) && $name === $this->registry[$label]; } + /** + * @param string $label + */ private function isAlreadyLoaded($label) { return isset($this->drivers[$label]); @@ -115,7 +126,7 @@ class Manager { $date = new \DateTime(); $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); } diff --git a/lib/Alchemy/Phrasea/Collection/Repository/DbalCollectionRepository.php b/lib/Alchemy/Phrasea/Collection/Repository/DbalCollectionRepository.php index 73cad03892..4872a2a4ca 100644 --- a/lib/Alchemy/Phrasea/Collection/Repository/DbalCollectionRepository.php +++ b/lib/Alchemy/Phrasea/Collection/Repository/DbalCollectionRepository.php @@ -86,8 +86,8 @@ class DbalCollectionRepository implements CollectionRepository } $query = self::$selectQuery . ' WHERE coll_id IN (:collectionIds)'; - $parameters = [ 'collectionIds' => $parameters ]; - $parameterTypes = [ 'collectionIds' => Connection::PARAM_INT_ARRAY ]; + $parameters = ['collectionIds' => $parameters]; + $parameterTypes = ['collectionIds' => Connection::PARAM_INT_ARRAY]; $rows = $this->databoxConnection->fetchAll($query, $parameters, $parameterTypes); @@ -107,7 +107,7 @@ class DbalCollectionRepository implements CollectionRepository } $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) { return $this->collectionFactory->create($this->databoxId, $reference, $row); @@ -130,7 +130,7 @@ class DbalCollectionRepository implements CollectionRepository } $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) { return $this->collectionFactory->create($this->databoxId, $reference, $row); diff --git a/lib/Alchemy/Phrasea/Command/BuildMissingSubdefs.php b/lib/Alchemy/Phrasea/Command/BuildMissingSubdefs.php index 238ffa4236..32588bb2d0 100644 --- a/lib/Alchemy/Phrasea/Command/BuildMissingSubdefs.php +++ b/lib/Alchemy/Phrasea/Command/BuildMissingSubdefs.php @@ -59,8 +59,8 @@ class BuildMissingSubdefs extends Command $subdefGenerator->generateSubdefs($record, $wanted_subdefs); foreach ($wanted_subdefs as $subdef) { - $this->container['monolog']->addInfo("generate " .$subdef . " for record " . $record->getRecordId()); - $n ++; + $this->container['monolog']->addInfo("generate " . $subdef . " for record " . $record->getRecordId()); + $n++; } } diff --git a/lib/Alchemy/Phrasea/Command/CreateCollection.php b/lib/Alchemy/Phrasea/Command/CreateCollection.php index 4778b87589..163337c464 100644 --- a/lib/Alchemy/Phrasea/Command/CreateCollection.php +++ b/lib/Alchemy/Phrasea/Command/CreateCollection.php @@ -52,7 +52,7 @@ class CreateCollection extends Command foreach ($results as $user) { $this->container->getAclForUser($user)->duplicate_right_from_bas($input->getOption('base_id_rights'), $new_collection->get_base_id()); } - $n+=40; + $n += 40; } } diff --git a/lib/Alchemy/Phrasea/Security/Firewall.php b/lib/Alchemy/Phrasea/Security/Firewall.php index 38fe4ed16c..836edd1ed8 100644 --- a/lib/Alchemy/Phrasea/Security/Firewall.php +++ b/lib/Alchemy/Phrasea/Security/Firewall.php @@ -146,7 +146,7 @@ class Firewall 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'); } diff --git a/lib/classes/eventsmanager/notify/uploadquarantine.php b/lib/classes/eventsmanager/notify/uploadquarantine.php index 0f8bbd0756..4f1a82b57f 100644 --- a/lib/classes/eventsmanager/notify/uploadquarantine.php +++ b/lib/classes/eventsmanager/notify/uploadquarantine.php @@ -43,7 +43,7 @@ class eventsmanager_notify_uploadquarantine extends eventsmanager_notifyAbstract $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)]); } diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Admin/AdminCollectionTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Admin/AdminCollectionTest.php index d8d19f74cf..c1a404b294 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Admin/AdminCollectionTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Admin/AdminCollectionTest.php @@ -6,6 +6,7 @@ use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Authentication\ACLProvider; use Alchemy\Phrasea\Border\File; use Ramsey\Uuid\Uuid; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Client; /** @@ -49,7 +50,7 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase parent::tearDown(); } - public function getJson($response) + public function getJson(Response $response) { $this->assertTrue($response->isOk()); $this->assertEquals('application/json', $response->headers->get('Content-Type')); @@ -134,8 +135,8 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase { $this->setAdmin(false); - $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/suggested-values/'); - $this->assertXMLHTTPBadJsonResponse(self::$DI['client']->getResponse()); + $response = $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/suggested-values/'); + $this->assertXMLHTTPBadJsonResponse($response); } /** @@ -147,11 +148,11 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase $prefs = ' 0 my_new_value '; - $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 ]); - $json = $this->getJson(self::$DI['client']->getResponse()); + $json = $this->getJson($response); $this->assertTrue($json->success); $collection = $collection = \collection::getByBaseId(self::$DI['app'], self::$DI['collection']->get_base_id()); @@ -168,11 +169,11 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase $prefs = ' '; - $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 ]); - $json = $this->getJson(self::$DI['client']->getResponse()); + $json = $this->getJson($response); $this->assertFalse($json->success); } @@ -207,9 +208,9 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase { $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); $collection = \collection::getByBaseId(self::$DI['app'], self::$DI['collection']->get_base_id()); @@ -248,9 +249,9 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase { $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); $collection = \collection::getByBaseId(self::$DI['app'], self::$DI['collection']->get_base_id()); $this->assertFalse($collection->is_active()); @@ -318,8 +319,8 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase { $this->setAdmin(true); - $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/publication/display/'); - $this->assertXMLHTTPBadJsonResponse(self::$DI['client']->getResponse()); + $response = $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/publication/display/'); + $this->assertXMLHTTPBadJsonResponse($response); } /** @@ -329,11 +330,11 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase { $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', ]); - $json = $this->getJson(self::$DI['client']->getResponse()); + $json = $this->getJson($response); $this->assertTrue($json->success); $collection = \collection::getByBaseId(self::$DI['app'], self::$DI['collection']->get_base_id()); $this->assertNotNull($collection->get_pub_wm()); @@ -409,8 +410,8 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase { $this->setAdmin(true); - $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/rename/'); - $this->assertXMLHTTPBadJsonResponse(self::$DI['client']->getResponse()); + $response = $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/rename/'); + $this->assertXMLHTTPBadJsonResponse($response); } /** @@ -420,8 +421,8 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase { $this->setAdmin(true); - $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/labels/'); - $this->assertXMLHTTPBadJsonResponse(self::$DI['client']->getResponse()); + $response = $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/labels/'); + $this->assertXMLHTTPBadJsonResponse($response); } /** @@ -433,11 +434,11 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase $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' ]); - $json = $this->getJson(self::$DI['client']->getResponse()); + $json = $this->getJson($response); $this->assertTrue($json->success); // 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(); - $this->XMLHTTPRequest('POST', '/admin/collection/' . $collection->get_base_id() . '/labels/', [ + $response = $this->XMLHTTPRequest('POST', '/admin/collection/' . $collection->get_base_id() . '/labels/', [ 'labels' => [ 'nl' => 'netherlands 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); $databox = $this->getApplication()->findDataboxById($collection->get_sbas_id()); @@ -504,8 +505,8 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase { $this->setAdmin(false); - $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/empty/'); - $this->assertXMLHTTPBadJsonResponse(self::$DI['client']->getResponse()); + $response = $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/empty/'); + $this->assertXMLHTTPBadJsonResponse($response); } /** @@ -524,9 +525,9 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase $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->assertEquals(0, $collection->get_record_amount()); } @@ -573,9 +574,9 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase $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); if (count(self::$DI['app']['orm.em']->getRepository('Phraseanet:Task')->findAll()) === 0) { @@ -662,8 +663,8 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase $this->setAdmin(true); - $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/picture/mini-logo/delete/'); - $json = $this->getJson(self::$DI['client']->getResponse()); + $response = $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/picture/mini-logo/delete/'); + $json = $this->getJson($response); $this->assertTrue($json->success); } @@ -712,9 +713,9 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase } $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); } @@ -760,9 +761,9 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase $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); } @@ -837,9 +838,9 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase $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); try { \collection::getByBaseId(self::$DI['app'], $collection->get_base_id()); @@ -865,9 +866,9 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase $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); $collection->empty_collection(); } @@ -893,8 +894,8 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase { $this->setAdmin(false); - $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/unmount/'); - $this->assertXMLHTTPBadJsonResponse(self::$DI['client']->getResponse()); + $response = $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/unmount/'); + $this->assertXMLHTTPBadJsonResponse($response); } /** @@ -906,9 +907,9 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase $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); try { diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Admin/DataboxTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Admin/DataboxTest.php index 61dabd3af2..45630c4bc6 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Admin/DataboxTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Admin/DataboxTest.php @@ -114,12 +114,13 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase $app = $this->getApplication(); $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' => [ 2 => $collection->get_base_id() - ]]); + ] + ]); - $this->assertTrue(self::$DI['client']->getResponse()->isOk()); + $this->assertTrue($response->isOk()); $databox->unmount_databox(); $databox->delete(); @@ -197,11 +198,11 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase $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] ]); - $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()); $cgus = $databox->get_cgus(); @@ -228,9 +229,9 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase { $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->assertObjectHasAttribute('sbas_id', $json); $this->assertObjectHasAttribute('indexable', $json); @@ -305,8 +306,8 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase { $this->setAdmin(false); - $this->XMLHTTPRequest('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/informations/documents/'); - $this->assertXMLHTTPBadJsonResponse(self::$DI['client']->getResponse()); + $response = $this->XMLHTTPRequest('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/informations/documents/'); + $this->assertXMLHTTPBadJsonResponse($response); } /** @@ -352,8 +353,7 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase { $this->setAdmin(true); - $this->XMLHTTPRequest('POST', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/reindex/'); - $response = self::$DI['client']->getResponse(); + $response = $this->XMLHTTPRequest('POST', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/reindex/'); $this->assertTrue($response->isOk()); $this->assertEquals('application/json', $response->headers->get('Content-Type')); $content = json_decode($response->getContent()); @@ -382,11 +382,10 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase { $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 ]); - $response = self::$DI['client']->getResponse(); $this->assertTrue($response->isOk()); $this->assertEquals('application/json', $response->headers->get('Content-Type')); $content = json_decode($response->getContent()); @@ -418,9 +417,8 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase { $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->assertEquals('application/json', $response->headers->get('Content-Type')); $content = json_decode($response->getContent()); @@ -451,8 +449,8 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase { $this->setAdmin(true); - $this->XMLHTTPRequest('POST', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/view-name/'); - $this->assertXMLHTTPBadJsonResponse(self::$DI['client']->getResponse()); + $response = $this->XMLHTTPRequest('POST', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/view-name/'); + $this->assertXMLHTTPBadJsonResponse($response); } /** @@ -467,11 +465,10 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase $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' ]); - $response = self::$DI['client']->getResponse(); $this->assertTrue($response->isOk()); $this->assertEquals('application/json', $response->headers->get('Content-Type')); $content = json_decode($response->getContent()); @@ -491,9 +488,9 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase $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->assertObjectHasAttribute('sbas_id', $json); @@ -557,9 +554,9 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase $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->assertEmpty(\databox::getPrintLogo(self::$DI['collection']->get_sbas_id())); } @@ -573,9 +570,9 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase $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->assertObjectHasAttribute('sbas_id', $json); @@ -607,9 +604,9 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase $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->assertEquals(0, $collection->get_record_amount()); @@ -630,7 +627,7 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase { $this->setAdmin(true); $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' => [ 'fr' => 'frenchy label', 'en' => '', @@ -639,10 +636,10 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase ] ]); - $this->assertEquals(200, self::$DI['client']->getResponse()->getStatusCode()); - $this->assertEquals('application/json', self::$DI['client']->getResponse()->headers->get('content-type')); + $this->assertEquals(200, $response->getStatusCode()); + $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']); $base = $this->getApplication()->findDataboxById($base->get_sbas_id()); @@ -693,9 +690,9 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase $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); if (count(self::$DI['app']['orm.em']->getRepository('Phraseanet:Task')->findAll()) === 0) { diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Api/ApiJsonTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Api/ApiJsonTest.php index aabf8beab2..97fb95fb95 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Api/ApiJsonTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Api/ApiJsonTest.php @@ -431,14 +431,9 @@ class ApiJsonTest extends ApiTestCase public function testGetMonitorTaskById() { - $tasks = self::$DI['app']['repo.tasks']->findAll(); - - if (!count($tasks)) { - $this->markTestSkipped('no tasks created for the current instance'); - } + $idTask = $this->getTestTaskId(); $this->setToken($this->adminAccessToken); - $idTask = $tasks[0]->getId(); $route = '/api/v1/monitor/task/' . $idTask . '/'; $this->evaluateMethodNotAllowedRoute($route, ['PUT', 'DELETE']); @@ -454,14 +449,9 @@ class ApiJsonTest extends ApiTestCase public function testPostMonitorTaskById() { - $tasks = self::$DI['app']['repo.tasks']->findAll(); - - if (!count($tasks)) { - $this->markTestSkipped('no tasks created for the current instance'); - } + $idTask = $this->getTestTaskId(); $this->setToken($this->adminAccessToken); - $idTask = $tasks[0]->getId(); $route = '/api/v1/monitor/task/' . $idTask . '/'; $this->evaluateMethodNotAllowedRoute($route, ['PUT', 'DELETE']); @@ -492,14 +482,9 @@ class ApiJsonTest extends ApiTestCase public function testPostMonitorStartTask() { - $tasks = self::$DI['app']['repo.tasks']->findAll(); - - if (!count($tasks)) { - $this->markTestSkipped('no tasks created for the current instance'); - } + $idTask = $this->getTestTaskId(); $this->setToken($this->adminAccessToken); - $idTask = $tasks[0]->getId(); $route = '/api/v1/monitor/task/' . $idTask . '/start/'; $this->evaluateMethodNotAllowedRoute($route, ['GET', 'PUT', 'DELETE']); @@ -518,14 +503,9 @@ class ApiJsonTest extends ApiTestCase public function testPostMonitorStopTask() { - $tasks = self::$DI['app']['repo.tasks']->findAll(); - - if (!count($tasks)) { - $this->markTestSkipped('no tasks created for the current instance'); - } + $idTask = $this->getTestTaskId(); $this->setToken($this->adminAccessToken); - $idTask = $tasks[0]->getId(); $route = '/api/v1/monitor/task/' . $idTask . '/stop/'; $this->evaluateMethodNotAllowedRoute($route, ['GET', 'PUT', 'DELETE']); @@ -1965,4 +1945,22 @@ class ApiJsonTest extends ApiTestCase $this->assertTrue(is_array($response['results'])); $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(); + } } diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/ExportTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/ExportTest.php index c8085f437b..da278639c2 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/ExportTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/ExportTest.php @@ -48,8 +48,7 @@ class ExportTest extends \PhraseanetAuthenticatedWebTestCase ->getMock(); }); - $this->XMLHTTPRequest('POST', '/prod/export/ftp/test/', ['lst' => self::$DI['record_1']->get_serialize_key()]); - $response = self::$DI['client']->getResponse(); + $response = $this->XMLHTTPRequest('POST', '/prod/export/ftp/test/', ['lst' => self::$DI['record_1']->get_serialize_key()]); $datas = (array) json_decode($response->getContent()); $this->assertArrayHasKey('success', $datas); $this->assertTrue($datas['success']); diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/OrderTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/OrderTest.php index efbf7835a6..16b555d70e 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/OrderTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/OrderTest.php @@ -61,12 +61,11 @@ class OrderTest extends \PhraseanetAuthenticatedWebTestCase $triggered = true; }); - $this->XMLHTTPRequest('POST', '/prod/order/', [ - 'lst' => $this->getRecord1()->getId(), + $response = $this->XMLHTTPRequest('POST', '/prod/order/', [ + 'lst' => $this->getRecord1()->getId(), 'deadline' => '+10 minutes' ]); - $response = $this->getClient()->getResponse(); $this->assertTrue($response->isOk(), 'Invalid response from create order'); $this->assertTrue($triggered, 'Order create listener not triggered'); $this->assertEquals('application/json', $response->headers->get('Content-Type')); @@ -83,14 +82,13 @@ class OrderTest extends \PhraseanetAuthenticatedWebTestCase public function testDisplayOrders() { $this->XMLHTTPRequest('POST', '/prod/order/', [ - 'lst' => $this->getRecord1()->getId(), + 'lst' => $this->getRecord1()->getId(), 'deadline' => '+10 minutes' ]); - $client = $this->getClient(); - $client->request('GET', '/prod/order/', [ + $response = $this->request('GET', '/prod/order/', [ 'sort' => 'usage' ]); - $this->assertTrue($client->getResponse()->isOk()); + $this->assertTrue($response->isOk()); } /** @@ -140,8 +138,7 @@ class OrderTest extends \PhraseanetAuthenticatedWebTestCase foreach ($order->getElements() as $element) { $parameters[] = $element->getId(); } - $this->XMLHTTPRequest('POST', '/prod/order/' . $order->getId() . '/send/', ['elements' => $parameters]); - $response = $this->getClient()->getResponse(); + $response = $this->XMLHTTPRequest('POST', '/prod/order/' . $order->getId() . '/send/', ['elements' => $parameters]); $this->assertTrue($response->isOk()); $this->assertEquals('application/json', $response->headers->get('Content-Type')); $content = json_decode($response->getContent()); @@ -189,9 +186,7 @@ class OrderTest extends \PhraseanetAuthenticatedWebTestCase foreach ($order->getElements() as $element) { $parameters[] = $element->getId(); } - $this->XMLHTTPRequest('POST', '/prod/order/' . $order->getId() . '/deny/', ['elements' => $parameters]); - $client = $this->getClient(); - $response = $client->getResponse(); + $response = $this->XMLHTTPRequest('POST', '/prod/order/' . $order->getId() . '/deny/', ['elements' => $parameters]); $this->assertTrue($response->isOk()); $this->assertEquals('application/json', $response->headers->get('Content-Type')); $content = json_decode($response->getContent()); diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/PropertyTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/PropertyTest.php index e3e2b4768c..5bceadbbb7 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/PropertyTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/PropertyTest.php @@ -19,8 +19,13 @@ class PropertyTest extends \PhraseanetAuthenticatedWebTestCase */ 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 = self::$DI['client']->getResponse(); + $response = $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() + ]) + ]); $this->assertTrue($response->isOk()); unset($response); } @@ -40,10 +45,14 @@ class PropertyTest extends \PhraseanetAuthenticatedWebTestCase */ 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 = self::$DI['client']->getResponse(); + $response = $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() + ]) + ]); $this->assertTrue($response->isOk()); - unset($response); } /** diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/RecordsTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/RecordsTest.php index 6b6edc4a61..f188060e4d 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/RecordsTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/RecordsTest.php @@ -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']); $record = \record_adapter::createFromFile($file, self::$DI['app']); - $this->XMLHTTPRequest('POST', '/prod/records/delete/', ['lst' => $record->getId()]); - $response = self::$DI['client']->getResponse(); + $response = $this->XMLHTTPRequest('POST', '/prod/records/delete/', ['lst' => $record->getId()]); $datas = (array) json_decode($response->getContent()); $this->assertContains($record->getId(), $datas); try { @@ -46,7 +45,6 @@ class RecordsTest extends \PhraseanetAuthenticatedWebTestCase } 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']); $record = \record_adapter::createFromFile($file, self::$DI['app']); - $this->XMLHTTPRequest('POST', '/prod/records/renew-url/', ['lst' => $record->getId()]); - $response = self::$DI['client']->getResponse(); + $response = $this->XMLHTTPRequest('POST', '/prod/records/renew-url/', ['lst' => $record->getId()]); $datas = (array) json_decode($response->getContent()); $this->assertTrue(count($datas) > 0); $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']->flush(); - $this->XMLHTTPRequest('POST', '/prod/records/', [ - 'env' => 'BASK', - 'pos' => 0, - 'query' => '', - 'cont' => $basket->getId(), + $response = $this->XMLHTTPRequest('POST', '/prod/records/', [ + 'env' => 'BASK', + 'pos' => 0, + 'query' => '', + 'cont' => $basket->getId(), ]); - $response = self::$DI['client']->getResponse(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($response->getContent(), true); @@ -126,14 +121,13 @@ class RecordsTest extends \PhraseanetAuthenticatedWebTestCase $options->onCollections($acl->get_granted_base()); $serializedOptions = $options->serialize(); - $this->XMLHTTPRequest('POST', '/prod/records/', [ - 'env' => 'RESULT', + $response = $this->XMLHTTPRequest('POST', '/prod/records/', [ + 'env' => 'RESULT', 'options_serial' => $serializedOptions, - 'pos' => 0, - 'query' => '' + 'pos' => 0, + 'query' => '' ]); - $response = self::$DI['client']->getResponse(); $data = json_decode($response->getContent(), true); $this->assertArrayHasKey('desc', $data); @@ -145,8 +139,6 @@ class RecordsTest extends \PhraseanetAuthenticatedWebTestCase $this->assertArrayHasKey('tools', $data); $this->assertArrayHasKey('pos', $data); $this->assertArrayHasKey('title', $data); - - unset($response, $data); } /** @@ -157,14 +149,13 @@ class RecordsTest extends \PhraseanetAuthenticatedWebTestCase $this->authenticate(self::$DI['app']); self::$DI['record_story_1']; - $this->XMLHTTPRequest('POST', '/prod/records/', [ - 'env' => 'REG', - 'pos' => 0, + $response = $this->XMLHTTPRequest('POST', '/prod/records/', [ + 'env' => 'REG', + 'pos' => 0, '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()); $this->assertObjectHasAttribute('desc', $data); $this->assertObjectHasAttribute('html_preview', $data); @@ -175,8 +166,6 @@ class RecordsTest extends \PhraseanetAuthenticatedWebTestCase $this->assertObjectHasAttribute('tools', $data); $this->assertObjectHasAttribute('pos', $data); $this->assertObjectHasAttribute('title', $data); - - unset($response, $data); } /** @@ -187,14 +176,13 @@ class RecordsTest extends \PhraseanetAuthenticatedWebTestCase $this->authenticate(self::$DI['app']); $basket = self::$DI['app']['orm.em']->find('Phraseanet:Basket', 1); - $this->XMLHTTPRequest('POST', '/prod/records/', [ - 'env' => 'BASK', - 'pos' => 0, + $response = $this->XMLHTTPRequest('POST', '/prod/records/', [ + 'env' => 'BASK', + 'pos' => 0, 'query' => '', - 'cont' => $basket->getId() + 'cont' => $basket->getId() ]); - $response = self::$DI['client']->getResponse(); $data = json_decode($response->getContent()); $this->assertObjectHasAttribute('desc', $data); @@ -224,14 +212,13 @@ class RecordsTest extends \PhraseanetAuthenticatedWebTestCase $feed = self::$DI['app']['orm.em']->find('Phraseanet:Feed', 1); $feedEntry = $feed->getEntries()->first(); - $this->XMLHTTPRequest('POST', '/prod/records/', [ - 'env' => 'FEED', - 'pos' => 0, + $response = $this->XMLHTTPRequest('POST', '/prod/records/', [ + 'env' => 'FEED', + 'pos' => 0, 'query' => '', - 'cont' => $feedEntry->getId() + 'cont' => $feedEntry->getId() ]); - $response = self::$DI['client']->getResponse(); $data = json_decode($response->getContent()); $this->assertObjectHasAttribute('desc', $data); $this->assertObjectHasAttribute('html_preview', $data); diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/TOUTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/TOUTest.php index 78b38c5c8d..792b23e2a6 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/TOUTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/TOUTest.php @@ -34,10 +34,8 @@ class TOUTest extends \PhraseanetAuthenticatedWebTestCase */ public function testGetTOUAJAX() { - $this->XMLHTTPRequest('GET', '/prod/TOU/'); - $response = self::$DI['client']->getResponse(); + $response = $this->XMLHTTPRequest('GET', '/prod/TOU/'); $this->assertTrue($response->isOk()); - unset($response); } /** @@ -48,8 +46,7 @@ class TOUTest extends \PhraseanetAuthenticatedWebTestCase $databoxes = self::$DI['app']->getDataboxes(); $databox = array_shift($databoxes); self::$DI['app']['authentication']->setUser(self::$DI['user_alt2']); - $this->XMLHTTPRequest('POST', '/prod/TOU/deny/'.$databox->get_sbas_id() .'/'); - $response = self::$DI['client']->getResponse(); + $response = $this->XMLHTTPRequest('POST', '/prod/TOU/deny/' . $databox->get_sbas_id() . '/'); $this->assertTrue($response->isOk()); unset($response, $databoxes); diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Report/RootTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Report/RootTest.php index 865b29dfb0..ed4edb22b5 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Report/RootTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Report/RootTest.php @@ -34,13 +34,11 @@ class RootTest extends \PhraseanetAuthenticatedWebTestCase { $this->authenticate(self::$DI['app']); - $this->XMLHTTPRequest('GET', '/report/dashboard', [ + $response = $this->XMLHTTPRequest('GET', '/report/dashboard', [ 'dmin' => $this->dmin->format('Y-m-d'), 'dmax' => $this->dmin->format('Y-m-d'), ]); - $response = self::$DI['client']->getResponse(); - $this->assertTrue($response->isOk()); } diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Root/DevelopersTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Root/DevelopersTest.php index 7fefc9ee5f..f3fbc55fb5 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Root/DevelopersTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Root/DevelopersTest.php @@ -115,10 +115,10 @@ class DevelopersTest extends \PhraseanetAuthenticatedWebTestCase */ public function testDeleteAppError() { - $this->XMLHTTPRequest('DELETE', '/developers/application/0/'); + $response = $this->XMLHTTPRequest('DELETE', '/developers/application/0/'); - $this->assertTrue(self::$DI['client']->getResponse()->isOk()); - $content = json_decode(self::$DI['client']->getResponse()->getContent()); + $this->assertTrue($response->isOk()); + $content = json_decode($response->getContent()); $this->assertFalse($content->success); } @@ -134,8 +134,8 @@ class DevelopersTest extends \PhraseanetAuthenticatedWebTestCase 'http://phraseanet.com/' ); $id = $oauthApp->getId(); - $this->XMLHTTPRequest('DELETE', '/developers/application/' . $id . '/'); - $this->assertTrue(self::$DI['client']->getResponse()->isOk()); + $response = $this->XMLHTTPRequest('DELETE', '/developers/application/' . $id . '/'); + $this->assertTrue($response->isOk()); $this->assertNull(self::$DI['app']['repo.api-applications']->find($id)); } @@ -155,12 +155,12 @@ class DevelopersTest extends \PhraseanetAuthenticatedWebTestCase */ public function testRenewAppCallbackError() { - $this->XMLHTTPRequest('POST', '/developers/application/0/callback/', [ + $response = $this->XMLHTTPRequest('POST', '/developers/application/0/callback/', [ 'callback' => 'my.callback.com' - ]); + ]); - $this->assertTrue(self::$DI['client']->getResponse()->isOk()); - $content = json_decode(self::$DI['client']->getResponse()->getContent()); + $this->assertTrue($response->isOk()); + $content = json_decode($response->getContent()); $this->assertFalse($content->success); } @@ -170,9 +170,9 @@ class DevelopersTest extends \PhraseanetAuthenticatedWebTestCase public function testRenewAppCallbackError2() { $oauthApp = self::$DI['oauth2-app-user']; - $this->XMLHTTPRequest('POST', '/developers/application/'.$oauthApp->getId().'/callback/'); - $this->assertTrue(self::$DI['client']->getResponse()->isOk()); - $content = json_decode(self::$DI['client']->getResponse()->getContent()); + $response = $this->XMLHTTPRequest('POST', '/developers/application/' . $oauthApp->getId() . '/callback/'); + $this->assertTrue($response->isOk()); + $content = json_decode($response->getContent()); $this->assertFalse($content->success); } @@ -183,12 +183,12 @@ class DevelopersTest extends \PhraseanetAuthenticatedWebTestCase { $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' ]); - $this->assertTrue(self::$DI['client']->getResponse()->isOk()); - $content = json_decode(self::$DI['client']->getResponse()->getContent()); + $this->assertTrue($response->isOk()); + $content = json_decode($response->getContent()); $this->assertTrue($content->success); $oauthApp = self::$DI['app']['repo.api-applications']->find($oauthApp->getId()); $this->assertEquals('http://my.callback.com', $oauthApp->getRedirectUri()); @@ -209,12 +209,12 @@ class DevelopersTest extends \PhraseanetAuthenticatedWebTestCase */ public function testRenewAccessTokenError() { - $this->XMLHTTPRequest('POST', '/developers/application/0/access_token/', [ + $response = $this->XMLHTTPRequest('POST', '/developers/application/0/access_token/', [ 'callback' => 'my.callback.com' ]); - $this->assertTrue(self::$DI['client']->getResponse()->isOk()); - $content = json_decode(self::$DI['client']->getResponse()->getContent()); + $this->assertTrue($response->isOk()); + $content = json_decode($response->getContent()); $this->assertFalse($content->success); } @@ -225,10 +225,10 @@ class DevelopersTest extends \PhraseanetAuthenticatedWebTestCase { $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()); - $content = json_decode(self::$DI['client']->getResponse()->getContent()); + $this->assertTrue($response->isOk()); + $content = json_decode($response->getContent()); $this->assertTrue($content->success); $this->assertNotNull($content->token); } @@ -248,12 +248,12 @@ class DevelopersTest extends \PhraseanetAuthenticatedWebTestCase */ 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' - ]); + ]); - $this->assertTrue(self::$DI['client']->getResponse()->isOk()); - $content = json_decode(self::$DI['client']->getResponse()->getContent()); + $this->assertTrue($response->isOk()); + $content = json_decode($response->getContent()); $this->assertFalse($content->success); } @@ -264,12 +264,12 @@ class DevelopersTest extends \PhraseanetAuthenticatedWebTestCase { $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' ]); - $this->assertTrue(self::$DI['client']->getResponse()->isOk()); - $content = json_decode(self::$DI['client']->getResponse()->getContent()); + $this->assertTrue($response->isOk()); + $content = json_decode($response->getContent()); $this->assertTrue($content->success); $oauthApp = self::$DI['app']['repo.api-applications']->find($oauthApp->getId()); $this->assertTrue($oauthApp->isPasswordGranted()); diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Root/SessionTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Root/SessionTest.php index c5d176ca0c..1c0f34f26f 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Root/SessionTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Root/SessionTest.php @@ -19,9 +19,9 @@ class SessionTest extends \PhraseanetAuthenticatedWebTestCase public function testUpdSessionLogout() { $this->logout(self::$DI['app']); - $this->XMLHTTPRequest('POST', '/session/update/'); - $this->assertTrue(self::$DI['client']->getResponse()->isOk()); - $datas = json_decode(self::$DI['client']->getResponse()->getContent()); + $response = $this->XMLHTTPRequest('POST', '/session/update/'); + $this->assertTrue($response->isOk()); + $datas = json_decode($response->getContent()); $this->checkSessionReturn($datas); $this->assertEquals('disconnected', $datas->status); } @@ -31,11 +31,11 @@ class SessionTest extends \PhraseanetAuthenticatedWebTestCase */ public function testUpdSessionChangeUser() { - $this->XMLHTTPRequest('POST', '/session/update/', [ + $response = $this->XMLHTTPRequest('POST', '/session/update/', [ 'usr' => self::$DI['user_alt1']->getId() ]); - $this->assertTrue(self::$DI['client']->getResponse()->isOk()); - $datas = json_decode(self::$DI['client']->getResponse()->getContent()); + $this->assertTrue($response->isOk()); + $datas = json_decode($response->getContent()); $this->checkSessionReturn($datas); $this->assertEquals('disconnected', $datas->status); } @@ -49,13 +49,12 @@ class SessionTest extends \PhraseanetAuthenticatedWebTestCase /** @var User $user */ $user = self::$DI['user']; - $this->XMLHTTPRequest('POST', '/session/update/', [ + $response = $this->XMLHTTPRequest('POST', '/session/update/', [ 'usr' => $user->getId(), 'module' => 1 ]); - $client = $this->getClient(); - $this->assertTrue($client->getResponse()->isOk()); - $data = json_decode($client->getResponse()->getContent()); + $this->assertTrue($response->isOk()); + $data = json_decode($response->getContent()); $this->checkSessionReturn($data); $this->assertEquals('ok', $data->status); } @@ -67,12 +66,12 @@ class SessionTest extends \PhraseanetAuthenticatedWebTestCase { $this->authenticate(self::$DI['app']); - $this->XMLHTTPRequest('POST', '/session/update/', [ + $response = $this->XMLHTTPRequest('POST', '/session/update/', [ 'usr' => self::$DI['user']->getId() ]); - $datas = json_decode(self::$DI['client']->getResponse()->getContent()); - $datas = json_decode(self::$DI['client']->getResponse()->getContent()); + $datas = json_decode($response->getContent()); + $datas = json_decode($response->getContent()); $this->checkSessionReturn($datas); $this->assertEquals('unknown', $datas->status); } @@ -118,8 +117,8 @@ class SessionTest extends \PhraseanetAuthenticatedWebTestCase ->will($this->returnValue(null)); self::$DI['app']['orm.em'] = $em; - $this->XMLHTTPRequest('POST', '/session/delete/1'); - $this->assertTrue(self::$DI['client']->getResponse()->isOK()); + $response = $this->XMLHTTPRequest('POST', '/session/delete/1'); + $this->assertTrue($response->isOK()); } public function testDeleteSessionUnauthorized() diff --git a/tests/Alchemy/Tests/Phrasea/Controller/User/NotificationsTest.php b/tests/Alchemy/Tests/Phrasea/Controller/User/NotificationsTest.php index 65e1f2a182..6b67f97b60 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/User/NotificationsTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/User/NotificationsTest.php @@ -17,10 +17,8 @@ class NotificationsTest extends \PhraseanetAuthenticatedWebTestCase */ public function testListNotifications() { - $this->XMLHTTPRequest('GET', '/user/notifications/'); - $response = self::$DI['client']->getResponse(); + $response = $this->XMLHTTPRequest('GET', '/user/notifications/'); $this->assertTrue($response->isOk()); - unset($response); } /** @@ -48,16 +46,14 @@ class NotificationsTest extends \PhraseanetAuthenticatedWebTestCase */ public function testSetNotificationsReaded() { - $this->XMLHTTPRequest('POST', '/user/notifications/read/', [ + $response = $this->XMLHTTPRequest('POST', '/user/notifications/read/', [ 'notifications' => '' ]); - $response = self::$DI['client']->getResponse(); $this->assertTrue($response->isOk()); $datas = (array) json_decode($response->getContent()); $this->assertArrayHasKey('success', $datas); $this->assertTrue($datas['success'], $response->getContent()); $this->assertArrayHasKey('message', $datas); - unset($response); } /** diff --git a/tests/Alchemy/Tests/Phrasea/Controller/User/PreferencesTest.php b/tests/Alchemy/Tests/Phrasea/Controller/User/PreferencesTest.php index 2adbe080c7..2b1251e1ad 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/User/PreferencesTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/User/PreferencesTest.php @@ -17,8 +17,7 @@ class PreferencesTest extends \PhraseanetAuthenticatedWebTestCase */ public function testSaveUserPref() { - $this->XMLHTTPRequest('POST', '/user/preferences/', ['prop' => 'prop_test', 'value' => 'val_test']); - $response = self::$DI['client']->getResponse(); + $response = $this->XMLHTTPRequest('POST', '/user/preferences/', ['prop' => 'prop_test', 'value' => 'val_test']); $this->assertTrue($response->isOk()); $this->assertTrue(json_decode($response->getContent())->success); $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() { - $this->XMLHTTPRequest('POST', "/user/preferences/temporary/", ['prop' => 'prop_test', 'value' => 'val_test']); - $response = self::$DI['client']->getResponse(); + $response = $this->XMLHTTPRequest('POST', "/user/preferences/temporary/", [ + 'prop' => 'prop_test', + 'value' => 'val_test' + ]); $this->assertTrue($response->isOk()); $this->assertTrue(json_decode($response->getContent())->success); $this->assertEquals('val_test', self::$DI['app']['session']->get('phraseanet.prop_test')); diff --git a/tests/classes/PhraseanetTestCase.php b/tests/classes/PhraseanetTestCase.php index 0002f49213..003f87fda9 100644 --- a/tests/classes/PhraseanetTestCase.php +++ b/tests/classes/PhraseanetTestCase.php @@ -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. * @@ -500,11 +518,11 @@ abstract class PhraseanetTestCase extends WebTestCase * @param array $parameters The Request parameters * @param string $httpAccept Contents of the Accept header * - * @return Crawler + * @return Response */ 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_X-Requested-With' => 'XMLHttpRequest', ]);