Merge pull request #290 from romainneutron/fix-tests

[3.8] Fix unit tests, bump to version 3.8.0 alpha 3
This commit is contained in:
Romain Neutron
2013-01-25 02:53:30 -08:00
59 changed files with 1914 additions and 948 deletions

391
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -211,5 +211,5 @@ TaskManager:
options: options:
# set the threshold for sending task logs to syslog or by mail # set the threshold for sending task logs to syslog or by mail
# values : task_abstract::[LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERROR | LOG_CRITICAL | LOG_ALERT] # values : task_abstract::[LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERROR | LOG_CRITICAL | LOG_ALERT]
syslog_level: task_abstract::LOG_ERROR #syslog_level: task_abstract::LOG_ERROR
maillog_level: task_abstract::LOG_ERROR #maillog_level: task_abstract::LOG_ERROR

View File

@@ -14,6 +14,7 @@ namespace Alchemy\Phrasea\Core;
use Alchemy\Phrasea\Core\Configuration\ApplicationSpecification; use Alchemy\Phrasea\Core\Configuration\ApplicationSpecification;
use Alchemy\Phrasea\Core\Configuration\SpecificationInterface; use Alchemy\Phrasea\Core\Configuration\SpecificationInterface;
use Alchemy\Phrasea\Exception\InvalidArgumentException; use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Alchemy\Phrasea\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
/** /**
@@ -65,7 +66,13 @@ class Configuration
if ($specifications->isSetup()) { if ($specifications->isSetup()) {
$configurations = $this->specifications->getConfigurations(); $configurations = $this->specifications->getConfigurations();
$environment = $environment ? : $configurations[self::KEYWORD_ENV]; if (!$environment) {
if (isset($configurations[self::KEYWORD_ENV])) {
$environment = $configurations[self::KEYWORD_ENV];
} else {
throw new RuntimeException('No configuration environment provided');
}
}
} else { } else {
$environment = null; $environment = null;
} }
@@ -85,6 +92,11 @@ class Configuration
return $this->configuration->has($name); return $this->configuration->has($name);
} }
public function getSpecifications()
{
return $this->specifications;
}
/** /**
* Return the current used environnement * Return the current used environnement
* *
@@ -109,7 +121,7 @@ class Configuration
$configurations = $this->specifications->getConfigurations(); $configurations = $this->specifications->getConfigurations();
if ( ! isset($configurations[$this->environment])) { if ( ! isset($configurations[$this->environment])) {
throw new \Exception('Requested environnment is not available'); throw new InvalidArgumentException('Requested environnment is not available');
} }
$this->configuration = new ParameterBag($configurations[$this->environment]); $this->configuration = new ParameterBag($configurations[$this->environment]);
@@ -201,6 +213,11 @@ class Configuration
return $this->specifications->setServices($services); return $this->specifications->setServices($services);
} }
public function resetServices($name = null)
{
return $this->specifications->resetServices($name);
}
public function setBinaries($binaries) public function setBinaries($binaries)
{ {
return $this->specifications->setBinaries($binaries); return $this->specifications->setBinaries($binaries);
@@ -231,11 +248,6 @@ class Configuration
return $this->specifications->getConnexions(); return $this->specifications->getConnexions();
} }
public function getSelectedEnvironnment()
{
return $this->selectedEnvironnment;
}
/** /**
* Return the connexion parameters as configuration parameter object * Return the connexion parameters as configuration parameter object
* *

View File

@@ -13,20 +13,15 @@ namespace Alchemy\Phrasea\Core\Configuration;
use Symfony\Component\HttpFoundation\File\File as SymfonyFile; use Symfony\Component\HttpFoundation\File\File as SymfonyFile;
use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException; use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
use Symfony\Component\Yaml\Yaml;
/**
* Precise some informations about phraseanet configuration mechanism
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class ApplicationSpecification implements SpecificationInterface class ApplicationSpecification implements SpecificationInterface
{ {
protected $parser; protected $parser;
public function __construct() public function __construct()
{ {
$this->parser = new \Symfony\Component\Yaml\Yaml(); $this->parser = new Yaml();
} }
public function setConfigurations($configurations) public function setConfigurations($configurations)
@@ -43,6 +38,29 @@ class ApplicationSpecification implements SpecificationInterface
); );
} }
public function resetServices($name = null)
{
$services = $this->getServices();
if (!$name) {
$newServices = $services;
} else {
$newServices = $services;
$legacyServices = $this->parser->parse(
file_get_contents($this->getRealRootPath() . "/conf.d/services.yml")
);
if (!isset($legacyServices[$name])) {
throw new InvalidArgumentException(sprintf('%s is not a valid service name'));
}
$newServices[$name] = $legacyServices[$name];
}
return $this->setServices($newServices);
}
public function setServices($services) public function setServices($services)
{ {
return file_put_contents( return file_put_contents(
@@ -108,17 +126,17 @@ class ApplicationSpecification implements SpecificationInterface
$this->delete(); $this->delete();
copy( copy(
$this->getRealRootPath() . "/config/connexions.sample.yml" $this->getRealRootPath() . "/lib/conf.d/connexions.yml"
, $this->getConnexionsPathFile() , $this->getConnexionsPathFile()
); );
copy( copy(
$this->getRealRootPath() . "/config/services.sample.yml" $this->getRealRootPath() . "/lib/conf.d/services.yml"
, $this->getServicesPathFile() , $this->getServicesPathFile()
); );
copy( copy(
$this->getRealRootPath() . "/config/config.sample.yml" $this->getRealRootPath() . "/lib/conf.d/config.yml"
, $this->getConfigurationsPathFile() , $this->getConfigurationsPathFile()
); );

View File

@@ -19,13 +19,14 @@ namespace Alchemy\Phrasea\Core\Configuration;
*/ */
interface SpecificationInterface interface SpecificationInterface
{ {
public function setConfigurations($configurations); public function setConfigurations($configurations);
public function setConnexions($connexions); public function setConnexions($connexions);
public function setServices($services); public function setServices($services);
public function resetServices($name = null);
public function setBinaries($binaries); public function setBinaries($binaries);
public function getConfigurations(); public function getConfigurations();

View File

@@ -31,7 +31,7 @@ class Builder
} }
try { try {
$options = $configuration->get("options"); $options = $configuration->get("options") ?: array() ;
} catch (\Exception $e) { } catch (\Exception $e) {
$options = array(); $options = array();
} }

View File

@@ -40,12 +40,12 @@ class TaskManager extends ServiceAbstract
$options = $this->getOptions(); $options = $this->getOptions();
$registry = $this->app['phraseanet.registry']; $registry = $this->app['phraseanet.registry'];
if (null !== $syslogLevel = constant($options['syslog_level'])) { if (isset($options['syslog_level']) && null !== $syslogLevel = constant($options['syslog_level'])) {
$handler = new SyslogHandler("Phraseanet-Task", "user", $syslogLevel); $handler = new SyslogHandler("Phraseanet-Task", "user", $syslogLevel);
$logger->pushHandler($handler); $logger->pushHandler($handler);
} }
if (null !== $maillogLevel = constant($options['maillog_level'])) { if (isset($options['maillog_level']) && null !== $maillogLevel = constant($options['maillog_level'])) {
if ('' === $adminMail = trim($registry->get('GV_adminMail'))) { if ('' === $adminMail = trim($registry->get('GV_adminMail'))) {
throw new RuntimeException("Admininstrator mail must be set to get log by mail."); throw new RuntimeException("Admininstrator mail must be set to get log by mail.");
} }

View File

@@ -18,7 +18,7 @@ namespace Alchemy\Phrasea\Core;
*/ */
class Version class Version
{ {
protected static $number = '3.8.0.a2'; protected static $number = '3.8.0.a3';
protected static $name = 'Carnosaurus'; protected static $name = 'Carnosaurus';
public static function getNumber() public static function getNumber()

View File

@@ -59,52 +59,60 @@ class patch_3803 implements patchInterface
*/ */
public function apply(base $appbox, Application $app) public function apply(base $appbox, Application $app)
{ {
$searchEngine = $app['phraseanet.registry']->get('GV_sphinx') ? 'sphinx-search' : 'phrasea'; $searchEngine = $app['phraseanet.registry']->get('GV_sphinx') ? 'sphinxsearch' : 'phrasea';
$app['phraseanet.registry']->set('GV_search_engine', $searchEngine, \registry::TYPE_ENUM); $confs = $app['phraseanet.configuration']->getConfigurations();
$phraseaConfiguration = null; foreach ($confs as $env => $conf) {
$phraseaConfigFile = __DIR__ . '/../../../config/phrasea-engine.json';
if (file_exists($phraseaConfigFile)) { if (in_array($env, array('environment', 'key'))) {
$phraseaConfiguration = json_decode(file_get_contents($phraseaConfigFile), true); continue;
} }
if (!is_array($phraseaConfiguration)) {
$phraseaConfiguration = array(); if (!isset($conf['search-engine'])) {
$confs[$env]['search-engine'] = $searchEngine;
}
} }
if ($app['phraseanet.registry']->get('GV_phrasea_sort')) { $app['phraseanet.configuration']->setConfigurations($confs);
$phraseaConfiguration['default_sort'] = $app['phraseanet.registry']->get('GV_phrasea_sort');
$services = $app['phraseanet.configuration']->getServices();
if (!isset($services['SearchEngine'])) {
$app['phraseanet.configuration']->resetServices('SearchEngine');
} }
file_put_contents($phraseaConfigFile, $phraseaConfiguration); if (!$app['phraseanet.registry']->get('GV_sphinx')) {
$sphinxConfiguration = null; $phraseaConfiguration = $app['phraseanet.SE']->getConfigurationPanel()->getConfiguration();
$sphinxConfigFile = __DIR__ . '/../../../config/sphinx-search.json';
if (file_exists($sphinxConfigFile)) { if ($app['phraseanet.registry']->get('GV_phrasea_sort')) {
$sphinxConfiguration = json_decode(file_get_contents($sphinxConfigFile), true); $phraseaConfiguration['default_sort'] = $app['phraseanet.registry']->get('GV_phrasea_sort');
} }
if (!is_array($sphinxConfiguration)) {
$sphinxConfiguration = array(); $app['phraseanet.SE']->getConfigurationPanel()->saveConfiguration($phraseaConfiguration);
} else {
$sphinxConfiguration = $app['phraseanet.SE']->getConfigurationPanel()->getConfiguration();
if ($app['phraseanet.registry']->get('GV_sphinx_rt_port')) {
$sphinxConfiguration['rt_port'] = $app['phraseanet.registry']->get('GV_sphinx_rt_port');
}
if ($app['phraseanet.registry']->get('GV_sphinx_rt_host')) {
$sphinxConfiguration['rt_host'] = $app['phraseanet.registry']->get('GV_sphinx_rt_host');
}
if ($app['phraseanet.registry']->get('GV_sphinx_port')) {
$sphinxConfiguration['port'] = $app['phraseanet.registry']->get('GV_sphinx_port');
}
if ($app['phraseanet.registry']->get('GV_sphinx_host')) {
$sphinxConfiguration['host'] = $app['phraseanet.registry']->get('GV_sphinx_host');
}
$app['phraseanet.SE']->getConfigurationPanel()->saveConfiguration($sphinxConfiguration);
} }
if ($app['phraseanet.registry']->get('GV_sphinx_rt_port')) { return true;
$sphinxConfiguration['rt_port'] = $app['phraseanet.registry']->get('GV_sphinx_rt_port');
}
if ($app['phraseanet.registry']->get('GV_sphinx_rt_host')) {
$sphinxConfiguration['rt_host'] = $app['phraseanet.registry']->get('GV_sphinx_rt_host');
}
if ($app['phraseanet.registry']->get('GV_sphinx_port')) {
$sphinxConfiguration['port'] = $app['phraseanet.registry']->get('GV_sphinx_port');
}
if ($app['phraseanet.registry']->get('GV_sphinx_host')) {
$sphinxConfiguration['host'] = $app['phraseanet.registry']->get('GV_sphinx_host');
}
file_put_contents($sphinxConfigFile, $sphinxConfiguration);
return;
} }
} }

View File

@@ -0,0 +1,84 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Alchemy\Phrasea\Application;
class patch_3804 implements patchInterface
{
/**
*
* @var string
*/
private $release = '3.8.0.a3';
/**
*
* @var Array
*/
private $concern = array(base::APPLICATION_BOX);
/**
*
* @return string
*/
public function get_release()
{
return $this->release;
}
public function require_all_upgrades()
{
return false;
}
/**
*
* @return Array
*/
public function concern()
{
return $this->concern;
}
/**
* @param base $appbox
*/
public function apply(base $appbox, Application $app)
{
try {
$confs = $app['phraseanet.configuration']->getConfigurations();
foreach ($confs as $env => $conf) {
if (in_array($env, array('environment', 'key'))) {
continue;
}
if (!isset($conf['task-manager'])) {
$confs[$env]['task-manager'] = 'task_manager';
}
}
$app['phraseanet.configuration']->setConfigurations($confs);
$services = $app['phraseanet.configuration']->getServices();
if (!isset($services['TaskManager'])) {
$app['phraseanet.configuration']->resetServices('TaskManager');
}
return true;
} catch (\Exception $e) {
throw $e;
}
return false;
}
}

View File

@@ -2089,7 +2089,7 @@ class task_period_archive extends task_abstract
$fields = caption_field::get_multi_values($field, $meta->get_separator()); $fields = caption_field::get_multi_values($field, $meta->get_separator());
if (!$metadataBag->containsKey($meta->get_name())) { if (!$metadataBag->containsKey($meta->get_name())) {
$values = new \PHPExiftool\Driver\Value\Multi($fields); $values = $fields;
} else { } else {
$values = array_merge($metadataBag->get($meta->get_name())->getValue(), $fields); $values = array_merge($metadataBag->get($meta->get_name())->getValue(), $fields);
} }

72
lib/conf.d/config.yml Normal file
View File

@@ -0,0 +1,72 @@
#Here's the main configuration file which is loaded when phraseanet bootstraps
#Declare which environment will be used by the application
environment : prod
key : null
#Declare all your environment configurations
#################
# DEVELOPPEMENT #
#################
dev:
#Phraseanet refers to phraseanet app specific configuration
phraseanet:
servername: 'http://sub.domain.tld/'
maintenance: false
debug: true
display_errors: true
#Assign your phraseanet application connection
#Connections are defined in connexions.yml configuration file
database: main_connexion
#Assign your template engine service & ORM service
#Services are defined in service.yml configuration file
template_engine: twig_debug
orm: doctrine_dev
cache: array_cache
opcodecache: array_cache
border-manager: border_manager
search-engine: phrasea
task-manager: task_manager
##############
# PRODUCTION #
##############
prod:
phraseanet:
servername: 'http://sub.domain.tld/'
maintenance: false
debug: false
display_errors: false
database: main_connexion
template_engine: twig
orm: doctrine_prod
cache: array_cache
opcodecache: array_cache
border-manager: border_manager
search-engine: phrasea
task-manager: task_manager
##############
# TEST #
##############
test:
phraseanet:
servername: 'http://sub.domain.tld/'
maintenance: false
debug: true
display_errors: true
database: main_connexion
template_engine: twig_debug
orm: doctrine_test
cache: array_cache
opcodecache: array_cache
border-manager: border_manager
search-engine: phrasea
task-manager: task_manager

19
lib/conf.d/connexions.yml Normal file
View File

@@ -0,0 +1,19 @@
#Here you can define many connexions configurations
#Please refer to Doctrine documentation abstraction layer for database connection configuration
#DBAL connection : http://www.doctrine-project.org/docs/dbal/2.1/en/reference/configuration.html
#Define a connexion to MYSQL database named main_connexion
main_connexion:
host: <HOSTNAME>
port: <PORT>
user: <USERNAME>
password: <PASSWORD>
dbname: <DATABASE_NAME>
driver: pdo_mysql
charset: UTF8
#Define a connexion to a SQLite database named test_connexion
test_connexion:
driver: pdo_sqlite
path: '/tmp/db.sqlite'
charset: UTF8

215
lib/conf.d/services.yml Normal file
View File

@@ -0,0 +1,215 @@
#base service file
Orm:
#Doctrine developement service options
#Service name
doctrine_dev:
type: Orm\Doctrine
options:
#Set automatically propers values for debug
#Query & result caches are setted to Array cache
#Auto-generating Proxy Classes is setted to false
debug: true
#Assign a connexion from connexions.yml to the DataBase Abstraction Layer
dbal: main_connexion
#Available cache driver [memcached, apc, array]
#Query cache : is used to cache the transformation of a DQL query to its SQL counterpart
#Result cache : is used to cache the results of your queries
#Metadata cache : is used to cache entity class metadatas
#If No cache is provided all cache are setted to default_cache which is an array cache type
cache:
query:
service: Cache\array_cache
result:
service: Cache\array_cache
metadata:
service: Cache\array_cache
# Assign a service to log doctrine queries
log:
service: Log\query_logger
# Doctrine test service options
doctrine_test:
type: Orm\Doctrine
options:
debug: true
#Doctrine use a different connection configuration base to run tests
dbal: test_connexion
cache:
query:
service: Cache\array_cache
result:
service: Cache\array_cache
metadata:
service: Cache\array_cache
log:
service: Log\query_logger
# Doctrine production service options
doctrine_prod:
type: Orm\Doctrine
options:
debug: false
dbal: main_connexion
cache:
query:
service: Cache\array_cache
result:
service: Cache\array_cache
metadata:
service: Cache\array_cache
TemplateEngine:
#Define a template engine service
#Only Twig is avalaible as a template engine service
#see http://twig.sensiolabs.org/
#Define the service name first
twig:
#Template engine type
type: TemplateEngine\Twig
options:
#When set to true, the generated templates have a __toString() method that you can use to display the generated nodes
debug: false
#The charset used by the templates
charset: utf-8
#Twig will silently ignore invalid variables (variables and or attributes/methods that do not exist)
#And replace them with a null value. When set to true, Twig throws an exception instead (default to false)
strict_variables: false
autoescape: true
#Optimize the node tree before compilation
optimizer: true
twig_debug:
type: TemplateEngine\Twig
options:
debug: true
charset: utf-8
strict_variables: true
autoescape: true
optimizer: true
Log:
# Define a Log service
# This one is defined to handle the logs of doctrine queries
# Only Monolog is available as a logger service
# Please Notice that for doctrine ONLY a echo logger service is available, see below
# Monolog logger use the PHP Monolog library to handle logs using differents handlers
query_logger:
type: Log\Doctrine\Monolog
options:
#You can precise the output format
#This option is only available when log are used to log doctrine queries
#Available output [vdump, json, yaml]
# vdump : output logs in a var_dump formatted style
# json : output logs in json
# yml : output logs yml
output: json
#Name used for the Monolog channel
channel: query-logger
#Define how the logs will be handled
#Avalaibale Handler are [rotate, stream]
#Rotate handler is used to stores logs to files that are rotated every day
#And a limited number of files are kept by defining the max_day value
#Stream handler is used to stores logs in a single local file
handler: rotate
max_day: 2
#Name of the file where logs are written
filename: doctrine-query.log
# Define a phpecho log service for Doctrine
# phpecho logger logs doctrine queries to the standard output using echo/var_dump
# Notice that phpecho logger do not have options
sql_logger:
type: Log\Doctrine\Phpecho
Cache:
#Define cache services
#There are Four different cache type available [array, xcache, apc, memcache]
#Only a memcache service can take option to define port & host for the memcache server
array_cache:
type: Cache\ArrayCache
memcache_cache:
type: Cache\MemcacheCache
options:
host: localhost
port: 11211
apc_cache:
type: Cache\ApcCache
xcache_cache:
type: Cache\XcacheCache
wincache_cache:
type: Cache\WinCacheCache
Border:
#Define Border service
#The border service handles checks validation constraints against incoming files
border_manager:
type: Border\BorderManager
options:
#Enable validation on incoming files
enabled: true
checkers:
#Check for duplicated file based on their sha256 check sum
-
type: Checker\Sha256
enabled: true
#Check for duplicated file based on their UUID
-
type: Checker\UUID
enabled: true
#Check colorspace (if applicable)
-
type: Checker\Colorspace
enabled: false
options:
colorspaces: [cmyk, grayscale, rgb]
#Check file dimension (if applicable)
-
type: Checker\Dimension
enabled: false
options:
width: 80
height: 160
#Check file extension
#set to false to enable all file extensions
-
type: Checker\Extension
enabled: false
options:
extensions: [jpg, jpeg, bmp, tif, gif, png, pdf, doc, odt, mpg, mpeg, mov, avi, xls, flv, mp3, mp2]
#Check filename
-
type: Checker\Filename
enabled: false
options:
sensitive: true
#Check media type
#Set to false to enable all mediatype
-
type: Checker\MediaType
enabled: false
options:
mediatypes: [Audio, Document, Flash, Image, Video]
SearchEngine:
phrasea:
type: SearchEngine\PhraseaEngine
sphinxsearch:
type: SearchEngine\SphinxSearch
options:
host: localhost
port: 9306
rt_host: localhost
rt_port: 9308
TaskManager:
task_manager:
type: TaskManager\TaskManager
options:
# set the threshold for sending task logs to syslog or by mail
# values : task_abstract::[LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERROR | LOG_CRITICAL | LOG_ALERT]
#syslog_level: task_abstract::LOG_ERROR
#maillog_level: task_abstract::LOG_ERROR

View File

@@ -237,8 +237,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->evaluateMeta200($content); $this->evaluateMeta200($content);
$response = $content['response']; $response = $content['response'];
$task_manager = new \task_manager(self::$DI['app']); $tasks = self::$DI['app']['task-manager']->getTasks();
$tasks = $task_manager->getTasks();
$this->assertEquals(count($tasks), count($response['tasks'])); $this->assertEquals(count($tasks), count($response['tasks']));
foreach ($response['tasks'] as $task) { foreach ($response['tasks'] as $task) {
@@ -326,8 +325,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
*/ */
public function testGetMonitorTaskById() public function testGetMonitorTaskById()
{ {
$task_manager = new \task_manager(self::$DI['app']); $tasks = self::$DI['app']['task-manager']->getTasks();
$tasks = $task_manager->getTasks();
if (null === self::$adminToken) { if (null === self::$adminToken) {
$this->markTestSkipped('there is no user with admin rights'); $this->markTestSkipped('there is no user with admin rights');
@@ -359,8 +357,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
*/ */
public function testPostMonitorTaskById() public function testPostMonitorTaskById()
{ {
$task_manager = new \task_manager(self::$DI['app']); $tasks = self::$DI['app']['task-manager']->getTasks();
$tasks = $task_manager->getTasks();
if (null === self::$adminToken) { if (null === self::$adminToken) {
$this->markTestSkipped('there is no user with admin rights'); $this->markTestSkipped('there is no user with admin rights');
@@ -415,8 +412,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->markTestSkipped('there is no user with admin rights'); $this->markTestSkipped('there is no user with admin rights');
} }
$task_manager = new \task_manager(self::$DI['app']); $tasks = self::$DI['app']['task-manager']->getTasks();
$tasks = $task_manager->getTasks();
if (!count($tasks)) { if (!count($tasks)) {
$this->markTestSkipped('no tasks created for the current instance'); $this->markTestSkipped('no tasks created for the current instance');
@@ -437,8 +433,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->assertArrayHasKey('task', $content['response']); $this->assertArrayHasKey('task', $content['response']);
$this->evaluateGoodTask($content['response']['task']); $this->evaluateGoodTask($content['response']['task']);
$task_manager->getTasks(true); $task = self::$DI['app']['task-manager']->getTask($idTask);
$task = $task_manager->getTask($idTask);
$this->assertContains($task->getState(), array(\task_abstract::STATE_TOSTART, \task_abstract::STATE_STARTED)); $this->assertContains($task->getState(), array(\task_abstract::STATE_TOSTART, \task_abstract::STATE_STARTED));
} }
@@ -448,9 +443,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
*/ */
public function testPostMonitorStopTask() public function testPostMonitorStopTask()
{ {
$task_manager = new \task_manager(self::$DI['app']); $tasks = self::$DI['app']['task-manager']->getTasks();
$tasks = $task_manager->getTasks();
if (null === self::$adminToken) { if (null === self::$adminToken) {
$this->markTestSkipped('there is no user with admin rights'); $this->markTestSkipped('there is no user with admin rights');
@@ -475,8 +468,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->assertArrayHasKey('task', $content['response']); $this->assertArrayHasKey('task', $content['response']);
$this->evaluateGoodTask($content['response']['task']); $this->evaluateGoodTask($content['response']['task']);
$task_manager->getTasks(true); $task = self::$DI['app']['task-manager']->getTask($idTask);
$task = $task_manager->getTask($idTask);
$this->assertContains($task->getState(), array(\task_abstract::STATE_TOSTOP, \task_abstract::STATE_STOPPED)); $this->assertContains($task->getState(), array(\task_abstract::STATE_TOSTOP, \task_abstract::STATE_STOPPED));
} }

View File

@@ -4,7 +4,6 @@ namespace Alchemy\Tests\Phrasea\Application;
use Alchemy\Phrasea\Border\File; use Alchemy\Phrasea\Border\File;
use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpKernel\Exception\HttpException;
class ApplicationOverviewTest extends \PhraseanetWebTestCaseAuthenticatedAbstract class ApplicationOverviewTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{ {
@@ -20,12 +19,11 @@ class ApplicationOverviewTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac
$this->assertEquals(self::$DI['record_1']->get_preview()->get_size(), $response->headers->get('content-length')); $this->assertEquals(self::$DI['record_1']->get_preview()->get_size(), $response->headers->get('content-length'));
} }
/**
* @expectedException Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
function testDatafilesNonExistentSubdef() function testDatafilesNonExistentSubdef()
{ {
$crawler = self::$DI['client']->request('GET', '/datafiles/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/asubdefthatdoesnotexists/'); self::$DI['client']->request('GET', '/datafiles/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/asubdefthatdoesnotexists/');
$this->assertNotFoundResponse(self::$DI['client']->getResponse());
} }
function testEtag() function testEtag()
@@ -58,25 +56,17 @@ class ApplicationOverviewTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac
function testDatafilesRouteNotAuthenticated() function testDatafilesRouteNotAuthenticated()
{ {
self::$DI['app']->closeAccount(); self::$DI['app']->closeAccount();
try { self::$DI['client']->request('GET', '/datafiles/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/preview/');
$crawler = self::$DI['client']->request('GET', '/datafiles/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/preview/');
$this->fail('should throw an HttpException'); $this->assertForbiddenResponse(self::$DI['client']->getResponse());
} catch (HttpException $e) {
$response = self::$DI['client']->getResponse();
$this->assertEquals(403, $e->getStatusCode());
}
} }
function testDatafilesRouteNotAuthenticatedUnknownSubdef() function testDatafilesRouteNotAuthenticatedUnknownSubdef()
{ {
self::$DI['app']->closeAccount(); self::$DI['app']->closeAccount();
try { self::$DI['client']->request('GET', '/datafiles/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/notfoundreview/');
$crawler = self::$DI['client']->request('GET', '/datafiles/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/notfoundreview/');
$this->fail('should throw an HttpException'); $this->assertForbiddenResponse(self::$DI['client']->getResponse());
} catch (HttpException $e) {
$response = self::$DI['client']->getResponse();
$this->assertEquals(403, $e->getStatusCode());
}
} }
function testPermalinkAuthenticated() function testPermalinkAuthenticated()

View File

@@ -10,12 +10,6 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
protected $client; protected $client;
public static $createdCollections = array(); public static $createdCollections = array();
public function setUp()
{
parent::setUp();
self::$DI['app.use-exception-handler'] = true;
}
public function tearDown() public function tearDown()
{ {
self::$DI['app']['phraseanet.user'] = self::$DI['user']; self::$DI['app']['phraseanet.user'] = self::$DI['user'];
@@ -192,7 +186,6 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\Admin\Bas::enable * @covers Alchemy\Phrasea\Controller\Admin\Bas::enable
*/ */
public function testPostEnableUnauthorizedException() public function testPostEnableUnauthorizedException()
@@ -200,6 +193,8 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(false); $this->setAdmin(false);
self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/enable/'); self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/enable/');
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -232,7 +227,6 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\Admin\Bas::disabled * @covers Alchemy\Phrasea\Controller\Admin\Bas::disabled
*/ */
public function testPostDisabledUnauthorizedException() public function testPostDisabledUnauthorizedException()
@@ -240,6 +234,8 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(false); $this->setAdmin(false);
self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/disabled/'); self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/disabled/');
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -259,7 +255,6 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\Admin\Bas::setOrderAdmins * @covers Alchemy\Phrasea\Controller\Admin\Bas::setOrderAdmins
*/ */
public function testPostOrderAdminsUnauthorizedException() public function testPostOrderAdminsUnauthorizedException()
@@ -267,6 +262,8 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(false); $this->setAdmin(false);
self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/order/admins/'); self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/order/admins/');
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -300,7 +297,6 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\Admin\Bas::setPublicationDisplay * @covers Alchemy\Phrasea\Controller\Admin\Bas::setPublicationDisplay
*/ */
public function testPostPublicationDisplayUnauthorizedException() public function testPostPublicationDisplayUnauthorizedException()
@@ -308,6 +304,8 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(false); $this->setAdmin(false);
self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/publication/display/'); self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/publication/display/');
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -356,7 +354,6 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\Admin\Bas::rename * @covers Alchemy\Phrasea\Controller\Admin\Bas::rename
*/ */
public function testPostNameUnauthorizedException() public function testPostNameUnauthorizedException()
@@ -364,6 +361,8 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(false); $this->setAdmin(false);
self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/rename/'); self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/rename/');
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -509,7 +508,6 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\Admin\Bas::setMiniLogo * @covers Alchemy\Phrasea\Controller\Admin\Bas::setMiniLogo
*/ */
public function testSetMiniLogoBadRequest() public function testSetMiniLogoBadRequest()
@@ -517,10 +515,11 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(true); $this->setAdmin(true);
self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/picture/mini-logo/'); self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/picture/mini-logo/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\Admin\Bas::setStamp * @covers Alchemy\Phrasea\Controller\Admin\Bas::setStamp
*/ */
public function testSetStampBadRequest() public function testSetStampBadRequest()
@@ -528,19 +527,21 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(true); $this->setAdmin(true);
self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/picture/stamp-logo/'); self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/picture/stamp-logo/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\Admin\Bas::setWatermark * @covers Alchemy\Phrasea\Controller\Admin\Bas::setWatermark
*/ */
public function testSetWatermarkBadRequest() public function testSetWatermarkBadRequest()
{ {
self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/picture/watermark/'); self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/picture/watermark/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\Admin\Bas::setBanner * @covers Alchemy\Phrasea\Controller\Admin\Bas::setBanner
*/ */
public function testSetBannerBadRequest() public function testSetBannerBadRequest()
@@ -548,6 +549,8 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(true); $this->setAdmin(true);
self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/picture/banner/'); self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/picture/banner/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -741,7 +744,6 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\Admin\Bas::getCollection * @covers Alchemy\Phrasea\Controller\Admin\Bas::getCollection
*/ */
public function testGetCollectionUnauthorizedException() public function testGetCollectionUnauthorizedException()
@@ -749,10 +751,11 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(false); $this->setAdmin(false);
self::$DI['client']->request('GET', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/'); self::$DI['client']->request('GET', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/');
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\Admin\Bas::getSuggestedValues * @covers Alchemy\Phrasea\Controller\Admin\Bas::getSuggestedValues
*/ */
public function testGetSuggestedValuesUnauthorizedException() public function testGetSuggestedValuesUnauthorizedException()
@@ -760,10 +763,11 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(false); $this->setAdmin(false);
self::$DI['client']->request('GET', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/suggested-values/'); self::$DI['client']->request('GET', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/suggested-values/');
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\Admin\Bas::getDetails * @covers Alchemy\Phrasea\Controller\Admin\Bas::getDetails
*/ */
public function testInformationsDetailsUnauthorizedException() public function testInformationsDetailsUnauthorizedException()
@@ -771,6 +775,8 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(false); $this->setAdmin(false);
self::$DI['client']->request('GET', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/informations/details/'); self::$DI['client']->request('GET', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/informations/details/');
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -788,7 +794,6 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\Admin\Bas::delete * @covers Alchemy\Phrasea\Controller\Admin\Bas::delete
*/ */
public function testDeleteCollectionUnauthorized() public function testDeleteCollectionUnauthorized()
@@ -796,6 +801,8 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(false); $this->setAdmin(false);
self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/delete/'); self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/delete/');
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
/** /**

View File

@@ -7,7 +7,6 @@ class AdminDashboardTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
protected $client; protected $client;
/** /**
* @expectedException Symfony\Component\HttpKernel\Exception\HttpException
* @covers \Alchemy\Phrasea\Controller\Admin\Dashboard::slash * @covers \Alchemy\Phrasea\Controller\Admin\Dashboard::slash
* @covers \Alchemy\Phrasea\Controller\Admin\Dashboard::connect * @covers \Alchemy\Phrasea\Controller\Admin\Dashboard::connect
* @covers \Alchemy\Phrasea\Controller\Admin\Dashboard::call * @covers \Alchemy\Phrasea\Controller\Admin\Dashboard::call
@@ -16,6 +15,8 @@ class AdminDashboardTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{ {
$this->setAdmin(false); $this->setAdmin(false);
self::$DI['client']->request('GET', '/admin/dashboard/'); self::$DI['client']->request('GET', '/admin/dashboard/');
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -62,7 +63,6 @@ class AdminDashboardTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers \Alchemy\Phrasea\Controller\Admin\Dashboard::sendMail * @covers \Alchemy\Phrasea\Controller\Admin\Dashboard::sendMail
*/ */
public function testSendMailTestBadRequest() public function testSendMailTestBadRequest()
@@ -70,6 +70,8 @@ class AdminDashboardTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(true); $this->setAdmin(true);
self::$DI['client']->request('POST', '/admin/dashboard/send-mail-test/'); self::$DI['client']->request('POST', '/admin/dashboard/send-mail-test/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**
* @covers \Alchemy\Phrasea\Controller\Admin\Dashboard::resetAdminRights * @covers \Alchemy\Phrasea\Controller\Admin\Dashboard::resetAdminRights

View File

@@ -126,7 +126,6 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
/** /**
* @covers \Alchemy\Phrasea\Controller\Admin\Database::getDatabaseCGU * @covers \Alchemy\Phrasea\Controller\Admin\Database::getDatabaseCGU
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
*/ */
public function testGetCGUHasNoRights() public function testGetCGUHasNoRights()
{ {
@@ -138,6 +137,8 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(true); $this->setAdmin(true);
self::$DI['client']->request('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/cgus/'); self::$DI['client']->request('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/cgus/');
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -199,7 +200,6 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers \Alchemy\Phrasea\Controller\Admin\Database::progressBarInfos * @covers \Alchemy\Phrasea\Controller\Admin\Database::progressBarInfos
*/ */
public function testGetInformationDocumentBadRequest() public function testGetInformationDocumentBadRequest()
@@ -207,6 +207,8 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(true); $this->setAdmin(true);
self::$DI['client']->request('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/informations/documents/'); self::$DI['client']->request('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/informations/documents/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -252,7 +254,6 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers \Alchemy\Phrasea\Controller\Admin\Database::getDatabase * @covers \Alchemy\Phrasea\Controller\Admin\Database::getDatabase
*/ */
public function testGetDataboxUnauthorizedException() public function testGetDataboxUnauthorizedException()
@@ -260,10 +261,11 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(false); $this->setAdmin(false);
self::$DI['client']->request('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/'); self::$DI['client']->request('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/');
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers \Alchemy\Phrasea\Controller\Admin\Database::getReorder * @covers \Alchemy\Phrasea\Controller\Admin\Database::getReorder
*/ */
public function testGetCollectionOrderUnauthorizedException() public function testGetCollectionOrderUnauthorizedException()
@@ -271,10 +273,11 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(false); $this->setAdmin(false);
self::$DI['client']->request('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/collections/order/'); self::$DI['client']->request('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/collections/order/');
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers \Alchemy\Phrasea\Controller\Admin\Database::getDatabaseCGU * @covers \Alchemy\Phrasea\Controller\Admin\Database::getDatabaseCGU
*/ */
public function testGetCGUUnauthorizedException() public function testGetCGUUnauthorizedException()
@@ -282,6 +285,8 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(false); $this->setAdmin(false);
self::$DI['client']->request('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/cgus/'); self::$DI['client']->request('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/cgus/');
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -297,7 +302,6 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers \Alchemy\Phrasea\Controller\Admin\Database::progressBarInfos * @covers \Alchemy\Phrasea\Controller\Admin\Database::progressBarInfos
*/ */
public function testGetInformationDetailsUnauthorizedException() public function testGetInformationDetailsUnauthorizedException()
@@ -305,10 +309,11 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(false); $this->setAdmin(false);
self::$DI['client']->request('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/informations/details/'); self::$DI['client']->request('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/informations/details/');
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers \Alchemy\Phrasea\Controller\Admin\Database::getNewCollection * @covers \Alchemy\Phrasea\Controller\Admin\Database::getNewCollection
*/ */
public function testGetNewCollectionUnauthorizedException() public function testGetNewCollectionUnauthorizedException()
@@ -316,6 +321,8 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->setAdmin(false); $this->setAdmin(false);
self::$DI['client']->request('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/collection/'); self::$DI['client']->request('GET', '/admin/databox/' . self::$DI['collection']->get_sbas_id() . '/collection/');
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
/** /**

View File

@@ -39,13 +39,14 @@ class DataboxesTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
/** /**
* @covers Alchemy\Phrasea\Controller\Admin\Databases::getDatabases * @covers Alchemy\Phrasea\Controller\Admin\Databases::getDatabases
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
*/ */
public function testGetSlashUnauthorizedException() public function testGetSlashUnauthorizedException()
{ {
$this->setAdmin(false); $this->setAdmin(false);
self::$DI['client']->request('GET', '/admin/databoxes/'); self::$DI['client']->request('GET', '/admin/databoxes/');
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
/** /**

View File

@@ -2,8 +2,6 @@
namespace Alchemy\Tests\Phrasea\Controller\Admin; namespace Alchemy\Tests\Phrasea\Controller\Admin;
use Symfony\Component\HttpKernel\Exception\HttpException;
class DescriptionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract class DescriptionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{ {
protected $client; protected $client;
@@ -186,23 +184,19 @@ class DescriptionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$field = \databox_field::create(self::$DI['app'], $databox, $name, false); $field = \databox_field::create(self::$DI['app'], $databox, $name, false);
$id = $field->get_id(); $id = $field->get_id();
try { self::$DI['client']->request("POST", "/admin/description/" . $databox->get_sbas_id() . "/", array(
self::$DI['client']->request("POST", "/admin/description/" . $databox->get_sbas_id() . "/", array( 'field_ids' => array($id)
'field_ids' => array($id) , 'name_' . $id => $name
, 'name_' . $id => $name , 'multi_' . $id => 1
, 'multi_' . $id => 1 , 'indexable_' . $id => 1
, 'indexable_' . $id => 1 , 'src_' . $id => '/rdf:RDF/rdf:Description/IPTC:SupplementalCategories'
, 'src_' . $id => '/rdf:RDF/rdf:Description/IPTC:SupplementalCategories' , 'required_' . $id => 0
, 'required_' . $id => 0 , 'readonly_' . $id => 0
, 'readonly_' . $id => 0 , 'type_' . $id => 'string'
, 'type_' . $id => 'string' , 'vocabulary_' . $id => 'User'
, 'vocabulary_' . $id => 'User' ));
));
print(self::$DI['client']->getResponse()->getContent());
$this->fail('Should throw an HttpException');
} catch (HttpException $e) {
} $this->assertForbiddenResponse(self::$DI['client']->getResponse());
$field->delete(); $field->delete();
} }
@@ -214,12 +208,9 @@ class DescriptionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$databoxes = self::$DI['app']['phraseanet.appbox']->get_databoxes(); $databoxes = self::$DI['app']['phraseanet.appbox']->get_databoxes();
$databox = array_shift($databoxes); $databox = array_shift($databoxes);
try { self::$DI['client']->request("GET", "/admin/description/" . $databox->get_sbas_id() . "/");
self::$DI['client']->request("GET", "/admin/description/" . $databox->get_sbas_id() . "/");
$this->fail('Should throw an HttpException');
} catch (HttpException $e) {
} $this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
public function testGetDescription() public function testGetDescription()

View File

@@ -8,12 +8,6 @@ class Module_Admin_Route_PublicationTest extends \PhraseanetWebTestCaseAuthentic
public static $api = null; public static $api = null;
protected $client; protected $client;
public function setUp()
{
parent::setUp();
self::$DI['app.use-exception-handler'] = true;
}
public function testList() public function testList()
{ {
$crawler = self::$DI['client']->request('GET', '/admin/publications/list/'); $crawler = self::$DI['client']->request('GET', '/admin/publications/list/');

View File

@@ -18,14 +18,14 @@ class SetupTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
/** /**
* @covers Alchemy\Phrasea\Controller\Admin\Setup::getGlobals * @covers Alchemy\Phrasea\Controller\Admin\Setup::getGlobals
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
*/ */
public function testGetSlashUnauthorizedException() public function testGetSlashUnauthorizedException()
{ {
$this->setAdmin(false); $this->setAdmin(false);
self::$DI['client']->request('GET', '/admin/setup/'); self::$DI['client']->request('GET', '/admin/setup/');
$this->assertTrue(self::$DI['client']->getResponse()->isOk());
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
/** /**

View File

@@ -46,22 +46,26 @@ class DoDownloadTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
/** /**
* @covers Alchemy\Phrasea\Controller\Prod\DoDownload::prepareDownload * @covers Alchemy\Phrasea\Controller\Prod\DoDownload::prepareDownload
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
*/ */
public function testPrepareDownloadTokenNotFound() public function testPrepareDownloadTokenNotFound()
{ {
$token = 'AzBdisusjA'; $token = 'AzBdisusjA';
self::$DI['client']->request('GET', sprintf('/download/%s/prepare/', $token)); self::$DI['client']->request('GET', sprintf('/download/%s/prepare/', $token));
$this->assertNotFoundResponse(self::$DI['client']->getResponse());
} }
/** /**
* @covers Alchemy\Phrasea\Controller\Prod\DoDownload::prepareDownload * @covers Alchemy\Phrasea\Controller\Prod\DoDownload::prepareDownload
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
*/ */
public function testPrepareDownloadInvalidData() public function testPrepareDownloadInvalidData()
{ {
$token = $this->getToken(array('bad_string' => base64_decode(serialize(array('fail'))))); $token = $this->getToken(array('bad_string' => base64_decode(serialize(array('fail')))));
self::$DI['client']->request('GET', sprintf('/download/%s/prepare/', $token)); self::$DI['client']->request('GET', sprintf('/download/%s/prepare/', $token));
$response = self::$DI['client']->getResponse();
$this->assertEquals(500, $response->getStatusCode());
$this->assertTrue(false !== stripos($response->getContent(), 'internal server error'));
} }
/** /**
@@ -185,7 +189,6 @@ class DoDownloadTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
/** /**
* @covers Alchemy\Phrasea\Controller\Prod\DoDownload::downloadDocuments * @covers Alchemy\Phrasea\Controller\Prod\DoDownload::downloadDocuments
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
*/ */
public function testDocumentsDownloadNotFound() public function testDocumentsDownloadNotFound()
{ {
@@ -215,29 +218,32 @@ class DoDownloadTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
)); ));
$url = sprintf('/download/%s/get/', $token); $url = sprintf('/download/%s/get/', $token);
self::$DI['client']->request('POST', $url); self::$DI['client']->request('POST', $url);
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOk()); $this->assertNotFoundResponse(self::$DI['client']->getResponse());
unset($response);
} }
/** /**
* @covers Alchemy\Phrasea\Controller\Prod\DoDownload::downloadDocuments * @covers Alchemy\Phrasea\Controller\Prod\DoDownload::downloadDocuments
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
*/ */
public function testDocumentsDownloadTokenNotFound() public function testDocumentsDownloadTokenNotFound()
{ {
$token = 'AzBdisusjA'; $token = 'AzBdisusjA';
self::$DI['client']->request('POST', sprintf('/download/%s/get/', $token)); self::$DI['client']->request('POST', sprintf('/download/%s/get/', $token));
$this->assertNotFoundResponse(self::$DI['client']->getResponse());
} }
/** /**
* @covers Alchemy\Phrasea\Controller\Prod\DoDownload::downloadDocuments * @covers Alchemy\Phrasea\Controller\Prod\DoDownload::downloadDocuments
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
*/ */
public function testDocumentsDownloadInvalidData() public function testDocumentsDownloadInvalidData()
{ {
$token = $this->getToken(array('bad_string' => base64_decode(serialize(array('fail'))))); $token = $this->getToken(array('bad_string' => base64_decode(serialize(array('fail')))));
self::$DI['client']->request('POST', sprintf('/download/%s/get/', $token)); self::$DI['client']->request('POST', sprintf('/download/%s/get/', $token));
$response = self::$DI['client']->getResponse();
$this->assertEquals(500, $response->getStatusCode());
$this->assertTrue(false !== stripos($response->getContent(), 'internal server error'));
} }
/** /**

View File

@@ -76,7 +76,6 @@ class ExportTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\Prod\Export::testFtpConnexion * @covers Alchemy\Phrasea\Controller\Prod\Export::testFtpConnexion
*/ */
public function testFtpConnexionNoXMLHTTPRequests() public function testFtpConnexionNoXMLHTTPRequests()
@@ -98,10 +97,8 @@ class ExportTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
self::$DI['client']->request('POST', '/prod/export/ftp/test/', array('lst' => self::$DI['record_1']->get_serialize_key())); self::$DI['client']->request('POST', '/prod/export/ftp/test/', array('lst' => self::$DI['record_1']->get_serialize_key()));
$response = self::$DI['client']->getResponse(); $response = self::$DI['client']->getResponse();
$datas = (array) json_decode($response->getContent()); $datas = (array) json_decode($response->getContent());
$this->assertArrayHasKey('success', $datas);
$this->assertFalse($datas['success']); $this->assertBadResponse(self::$DI['client']->getResponse());
$this->assertArrayHasKey('message', $datas);
unset($response, $datas);
} }
/** /**
@@ -126,13 +123,14 @@ class ExportTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\Prod\Export::exportFtp * @covers Alchemy\Phrasea\Controller\Prod\Export::exportFtp
* @dataProvider getMissingArguments * @dataProvider getMissingArguments
*/ */
public function testExportFtpBadRequest($params) public function testExportFtpBadRequest($params)
{ {
self::$DI['client']->request('POST', '/prod/export/ftp/', $params); self::$DI['client']->request('POST', '/prod/export/ftp/', $params);
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
public function getMissingArguments() public function getMissingArguments()

View File

@@ -10,26 +10,21 @@ class MustacheLoaderTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{ {
self::$DI['client']->request('GET', '/prod/MustacheLoader/'); self::$DI['client']->request('GET', '/prod/MustacheLoader/');
$response = self::$DI['client']->getResponse(); $this->assertBadResponse(self::$DI['client']->getResponse());
/* @var $response \Symfony\Component\HttpFoundation\Response */
$this->assertEquals(400, $response->getStatusCode());
} }
public function testRouteSlashWrongUrl() public function testRouteSlashWrongUrl()
{ {
self::$DI['client']->request('GET', '/prod/MustacheLoader/', array('template' => '/../../../../config/config.yml')); self::$DI['client']->request('GET', '/prod/MustacheLoader/', array('template' => '/../../../../config/config.yml'));
$response = self::$DI['client']->getResponse(); $this->assertBadResponse(self::$DI['client']->getResponse());
$this->assertEquals(400, $response->getStatusCode());
/* @var $response \Symfony\Component\HttpFoundation\Response */
} }
public function testRouteSlashWrongFile() public function testRouteSlashWrongFile()
{ {
self::$DI['client']->request('GET', '/prod/MustacheLoader/', array('template' => 'patator_lala')); self::$DI['client']->request('GET', '/prod/MustacheLoader/', array('template' => 'patator_lala'));
$response = self::$DI['client']->getResponse(); $this->assertNotFoundResponse(self::$DI['client']->getResponse());
$this->assertEquals(404, $response->getStatusCode());
} }
public function testRouteGood() public function testRouteGood()

View File

@@ -20,12 +20,13 @@ class PropertyTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\Prod\Property::displayStatusProperty * @covers Alchemy\Phrasea\Controller\Prod\Property::displayStatusProperty
*/ */
public function testDisplayStatusPropertyNotXMLHTTPRequets() public function testDisplayStatusPropertyNotXMLHTTPRequets()
{ {
self::$DI['client']->request('GET', '/prod/records/property/'); self::$DI['client']->request('GET', '/prod/records/property/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -40,12 +41,13 @@ class PropertyTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\Prod\Property::displayProperty * @covers Alchemy\Phrasea\Controller\Prod\Property::displayProperty
*/ */
public function testDisplayTypePropertyNotXMLHTTPRequets() public function testDisplayTypePropertyNotXMLHTTPRequets()
{ {
self::$DI['client']->request('GET', '/prod/records/property/type/'); self::$DI['client']->request('GET', '/prod/records/property/type/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**

View File

@@ -70,11 +70,12 @@ class RecordsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
/** /**
* @covers Alchemy\Phrasea\Controller\Prod\Records::getRecord * @covers Alchemy\Phrasea\Controller\Prod\Records::getRecord
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
*/ */
public function testGetRecordDetailNotAjax() public function testGetRecordDetailNotAjax()
{ {
self::$DI['client']->request('POST', '/prod/records/'); self::$DI['client']->request('POST', '/prod/records/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**

View File

@@ -18,25 +18,22 @@ class ControllerTooltipTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->assertTrue(self::$DI['client']->getResponse()->isOk()); $this->assertTrue(self::$DI['client']->getResponse()->isOk());
} }
/**
* @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
public function testRouteBasketFail() public function testRouteBasketFail()
{ {
$crawler = self::$DI['client']->request('POST', '/prod/tooltip/basket/notanid/'); $crawler = self::$DI['client']->request('POST', '/prod/tooltip/basket/notanid/');
$pageContent = self::$DI['client']->getResponse()->getContent(); $pageContent = self::$DI['client']->getResponse()->getContent();
$this->assertFalse(self::$DI['client']->getResponse()->isOk()); $this->assertFalse(self::$DI['client']->getResponse()->isOk());
$this->assertNotFoundResponse(self::$DI['client']->getResponse());
} }
/**
* @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
public function testRouteBasketFail2() public function testRouteBasketFail2()
{ {
$crawler = self::$DI['client']->request('POST', '/prod/tooltip/basket/-5/'); $crawler = self::$DI['client']->request('POST', '/prod/tooltip/basket/-5/');
$pageContent = self::$DI['client']->getResponse()->getContent(); $pageContent = self::$DI['client']->getResponse()->getContent();
$this->assertFalse(self::$DI['client']->getResponse()->isOk()); $this->assertFalse(self::$DI['client']->getResponse()->isOk());
$this->assertNotFoundResponse(self::$DI['client']->getResponse());
} }
public function testRoutePreview() public function testRoutePreview()

View File

@@ -20,7 +20,6 @@ class UploadTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
self::$DI['app.use-exception-handler'] = true;
$this->tmpFile = sys_get_temp_dir() . '/' . time() . mt_rand(1000, 9999) . '.jpg'; $this->tmpFile = sys_get_temp_dir() . '/' . time() . mt_rand(1000, 9999) . '.jpg';
copy(__DIR__ . '/../../../../../files/cestlafete.jpg', $this->tmpFile); copy(__DIR__ . '/../../../../../files/cestlafete.jpg', $this->tmpFile);
} }

View File

@@ -241,7 +241,7 @@ class ControllerUsrListsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$response = self::$DI['client']->getResponse(); $response = self::$DI['client']->getResponse();
$this->assertEquals(400, $response->getStatusCode()); $this->assertBadResponse($response);
$this->assertEquals('UTF-8', $response->getCharset()); $this->assertEquals('UTF-8', $response->getCharset());
@@ -251,11 +251,9 @@ class ControllerUsrListsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$response = self::$DI['client']->getResponse(); $response = self::$DI['client']->getResponse();
$this->assertEquals(400, $response->getStatusCode()); $this->assertBadResponse($response);
$this->assertEquals('UTF-8', $response->getCharset()); $this->assertEquals('UTF-8', $response->getCharset());
$route = '/prod/lists/list/' . $list->getId() . '/share/' . self::$DI['user_alt1']->get_id() . '/'; $route = '/prod/lists/list/' . $list->getId() . '/share/' . self::$DI['user_alt1']->get_id() . '/';
self::$DI['client']->request('POST', $route, array('role' => \Entities\UsrListOwner::ROLE_ADMIN)); self::$DI['client']->request('POST', $route, array('role' => \Entities\UsrListOwner::ROLE_ADMIN));

View File

@@ -28,8 +28,7 @@ class ControllerWorkZoneTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
self::$DI['client']->request('POST', $route); self::$DI['client']->request('POST', $route);
$response = self::$DI['client']->getResponse(); $response = self::$DI['client']->getResponse();
$this->assertEquals(400, $response->getStatusCode()); $this->assertBadResponse(self::$DI['client']->getResponse());
$this->assertFalse($response->isOk());
} }
public function testAttachStoryToWZ() public function testAttachStoryToWZ()
@@ -146,8 +145,7 @@ class ControllerWorkZoneTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
self::$DI['client']->request('POST', $route); self::$DI['client']->request('POST', $route);
$response = self::$DI['client']->getResponse(); $response = self::$DI['client']->getResponse();
$this->assertEquals(404, $response->getStatusCode()); $this->assertNotFoundResponse(self::$DI['client']->getResponse());
$this->assertFalse($response->isOk());
//attach //attach
$attachRoute = sprintf("/prod/WorkZone/attachStories/"); $attachRoute = sprintf("/prod/WorkZone/attachStories/");

View File

@@ -120,11 +120,12 @@ class AccountTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
/** /**
* @covers \Alchemy\Phrasea\Controller\Root\Account::resetEmail * @covers \Alchemy\Phrasea\Controller\Root\Account::resetEmail
* @expectedException Symfony\Component\HttpKernel\Exception\HttpException
*/ */
public function testPostResetMailBadRequest() public function testPostResetMailBadRequest()
{ {
self::$DI['client']->request('POST', '/account/reset-email/'); self::$DI['client']->request('POST', '/account/reset-email/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -363,12 +364,11 @@ class AccountTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->assertEquals(count($ret), count($bases)); $this->assertEquals(count($ret), count($bases));
} }
/**
* @expectedException Symfony\Component\HttpKernel\Exception\HttpException
*/
public function testAUthorizedAppGrantAccessBadRequest() public function testAUthorizedAppGrantAccessBadRequest()
{ {
self::$DI['client']->request('GET', '/account/security/application/3/grant/'); self::$DI['client']->request('GET', '/account/security/application/3/grant/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
public function testAUthorizedAppGrantAccessNotSuccessfull() public function testAUthorizedAppGrantAccessNotSuccessfull()

View File

@@ -74,11 +74,12 @@ class DevelopersTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
/** /**
* @cover \Alchemy\Phrasea\Controller\Root\Developers::getApp * @cover \Alchemy\Phrasea\Controller\Root\Developers::getApp
* @expectedException Symfony\Component\HttpKernel\Exception\HttpException
*/ */
public function testGetUnknowApp() public function testGetUnknowApp()
{ {
self::$DI['client']->request('GET', '/developers/application/0/'); self::$DI['client']->request('GET', '/developers/application/0/');
$this->assertNotFoundResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -94,11 +95,12 @@ class DevelopersTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
/** /**
* @cover \Alchemy\Phrasea\Controller\Root\Developers::deleteApp * @cover \Alchemy\Phrasea\Controller\Root\Developers::deleteApp
* @expectedException Symfony\Component\HttpKernel\Exception\HttpException
*/ */
public function testDeleteAppBadRequest() public function testDeleteAppBadRequest()
{ {
self::$DI['client']->request('DELETE', '/developers/application/1/'); self::$DI['client']->request('DELETE', '/developers/application/1/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -134,11 +136,12 @@ class DevelopersTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
/** /**
* @cover \Alchemy\Phrasea\Controller\Root\Developers::renewAppCallback * @cover \Alchemy\Phrasea\Controller\Root\Developers::renewAppCallback
* @expectedException Symfony\Component\HttpKernel\Exception\HttpException
*/ */
public function testRenewAppCallbackBadRequest() public function testRenewAppCallbackBadRequest()
{ {
self::$DI['client']->request('POST', '/developers/application/1/callback/'); self::$DI['client']->request('POST', '/developers/application/1/callback/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -189,11 +192,12 @@ class DevelopersTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
/** /**
* @cover \Alchemy\Phrasea\Controller\Root\Developers::renewAccessToken * @cover \Alchemy\Phrasea\Controller\Root\Developers::renewAccessToken
* @expectedException Symfony\Component\HttpKernel\Exception\HttpException
*/ */
public function testRenewAccessTokenbadRequest() public function testRenewAccessTokenbadRequest()
{ {
self::$DI['client']->request('POST', '/developers/application/1/access_token/'); self::$DI['client']->request('POST', '/developers/application/1/access_token/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -228,11 +232,12 @@ class DevelopersTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
/** /**
* @cover \Alchemy\Phrasea\Controller\Root\Developers::authorizeGrantpassword * @cover \Alchemy\Phrasea\Controller\Root\Developers::authorizeGrantpassword
* @expectedException Symfony\Component\HttpKernel\Exception\HttpException
*/ */
public function testAuthorizeGrantpasswordBadRequest() public function testAuthorizeGrantpasswordBadRequest()
{ {
self::$DI['client']->request('POST', '/developers/application/1/authorize_grant_password/'); self::$DI['client']->request('POST', '/developers/application/1/authorize_grant_password/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**

View File

@@ -386,12 +386,13 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
/** /**
* @covers \Alchemy\Phrasea\Controller\Root\Login::register * @covers \Alchemy\Phrasea\Controller\Root\Login::register
* @expectedException Symfony\Component\HttpKernel\Exception\HttpException
*/ */
public function testPostRegisterBadRequest() public function testPostRegisterBadRequest()
{ {
self::$DI['app']->closeAccount(); self::$DI['app']->closeAccount();
self::$DI['client']->request('POST', '/login/register/'); self::$DI['client']->request('POST', '/login/register/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -618,12 +619,13 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
/** /**
* @covers \Alchemy\Phrasea\Controller\Root\Login::sendConfirmMail * @covers \Alchemy\Phrasea\Controller\Root\Login::sendConfirmMail
* @expectedException Symfony\Component\HttpKernel\Exception\HttpException
*/ */
public function testSendConfirmMailBadRequest() public function testSendConfirmMailBadRequest()
{ {
self::$DI['app']->closeAccount(); self::$DI['app']->closeAccount();
self::$DI['client']->request('GET', '/login/send-mail-confirm/'); self::$DI['client']->request('GET', '/login/send-mail-confirm/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**

View File

@@ -74,7 +74,6 @@ class RssFeedTest extends \PhraseanetWebTestCaseAbstract
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
self::$DI['app.use-exception-handler'] = true;
self::$feed = \Feed_Adapter::create(self::$DI['app'], self::$DI['user'], 'title', 'subtitle'); self::$feed = \Feed_Adapter::create(self::$DI['app'], self::$DI['user'], 'title', 'subtitle');
self::$publisher = \Feed_Publisher_Adapter::getPublisher(self::$DI['app']['phraseanet.appbox'], self::$feed, self::$DI['user']); self::$publisher = \Feed_Publisher_Adapter::getPublisher(self::$DI['app']['phraseanet.appbox'], self::$feed, self::$DI['user']);
self::$entry = \Feed_Entry_Adapter::create(self::$DI['app'], self::$feed, self::$publisher, 'title_entry', 'subtitle', 'hello', "test@mail.com"); self::$entry = \Feed_Entry_Adapter::create(self::$DI['app'], self::$feed, self::$publisher, 'title_entry', 'subtitle', 'hello', "test@mail.com");
@@ -334,12 +333,11 @@ class RssFeedTest extends \PhraseanetWebTestCaseAbstract
$this->assertEquals(404, self::$DI['client']->getResponse()->getStatusCode()); $this->assertEquals(404, self::$DI['client']->getResponse()->getStatusCode());
} }
/**
* @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
public function testUnknowFeedId2() public function testUnknowFeedId2()
{ {
self::$DI['client']->request("GET", "/feeds/feed/titi/"); self::$DI['client']->request("GET", "/feeds/feed/titi/");
$this->assertNotFoundResponse(self::$DI['client']->getResponse());
} }
public function testGetFeedId() public function testGetFeedId()

View File

@@ -70,11 +70,12 @@ class SessionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
/** /**
* @covers \Alchemy\Phrasea\Controller\Root\Session::updateSession * @covers \Alchemy\Phrasea\Controller\Root\Session::updateSession
* @expectedException Symfony\Component\HttpKernel\Exception\HttpException
*/ */
public function testUpdSessionBadRequest() public function testUpdSessionBadRequest()
{ {
self::$DI['client']->request('POST', '/session/update/'); self::$DI['client']->request('POST', '/session/update/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
private function checkSessionReturn(\stdClass $data) private function checkSessionReturn(\stdClass $data)

View File

@@ -18,21 +18,23 @@ class NotificationsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\User\Notifications::listNotifications * @covers Alchemy\Phrasea\Controller\User\Notifications::listNotifications
*/ */
public function testListNotificationsNoXMLHTTPRequests() public function testListNotificationsNoXMLHTTPRequests()
{ {
self::$DI['client']->request('GET', '/user/notifications/'); self::$DI['client']->request('GET', '/user/notifications/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\User\Notifications::setNotificationsReaded * @covers Alchemy\Phrasea\Controller\User\Notifications::setNotificationsReaded
*/ */
public function testSetNotificationsReadedNoXMLHTTPRequests() public function testSetNotificationsReadedNoXMLHTTPRequests()
{ {
self::$DI['client']->request('POST', '/user/notifications/read/'); self::$DI['client']->request('POST', '/user/notifications/read/');
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**
@@ -53,7 +55,6 @@ class NotificationsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\User\Notifications::connect * @covers Alchemy\Phrasea\Controller\User\Notifications::connect
* @covers Alchemy\Phrasea\Controller\User\Notifications::call * @covers Alchemy\Phrasea\Controller\User\Notifications::call
*/ */
@@ -69,5 +70,7 @@ class NotificationsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
->will($this->returnValue(true)); ->will($this->returnValue(true));
self::$DI['client']->request('GET', '/user/notifications/'); self::$DI['client']->request('GET', '/user/notifications/');
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
} }
} }

View File

@@ -32,21 +32,23 @@ class PreferencesTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\User\Preferences::saveUserPref * @covers Alchemy\Phrasea\Controller\User\Preferences::saveUserPref
*/ */
public function testSaveUserPrefNoXMLHTTPRequests() public function testSaveUserPrefNoXMLHTTPRequests()
{ {
self::$DI['client']->request('POST', '/user/preferences/', array('prop' => 'prop_test', 'value' => 'val_test')); self::$DI['client']->request('POST', '/user/preferences/', array('prop' => 'prop_test', 'value' => 'val_test'));
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\User\Preferences::saveTemporaryPref * @covers Alchemy\Phrasea\Controller\User\Preferences::saveTemporaryPref
*/ */
public function testSaveTempPrefNoXMLHTTPRequests() public function testSaveTempPrefNoXMLHTTPRequests()
{ {
self::$DI['client']->request('POST', '/user/preferences/temporary/', array('prop' => 'prop_test', 'value' => 'val_test')); self::$DI['client']->request('POST', '/user/preferences/temporary/', array('prop' => 'prop_test', 'value' => 'val_test'));
$this->assertBadResponse(self::$DI['client']->getResponse());
} }
/** /**

View File

@@ -1,387 +0,0 @@
<?php
namespace Alchemy\Tests\Phrasea\Core\Configuration;
class ConfigurationTest extends \PhraseanetPHPUnitAbstract
{
/**
*
* @var \Alchemy\Phrasea\Core\Configuration
*/
protected $confProd;
/**
*
* @var \Alchemy\Phrasea\Core\Configuration
*/
protected $confDev;
/**
*
* @var \Alchemy\Phrasea\Core\Configuration
*/
protected $confTest;
/**
*
* @var \Alchemy\Phrasea\Core\Configuration
*/
protected $confNotInstalled;
/**
*
* @var \Alchemy\Phrasea\Core\Configuration
*/
protected $confExperience;
/**
*
* @var \Alchemy\Phrasea\Core\Configuration
*/
protected $object;
protected $stubNotInstalled;
protected $stubExperience;
protected $stubConfTest;
public function setUp()
{
$this->markTestSkipped('To rewrite');
parent::setUp();
$this->stubNotInstalled = $this->getMock(
'\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationsFile')
);
$this->stubNotInstalled->expects($this->any())
->method('getConfigurationsFile')
->will(
$this->throwException(new Exception)
);
$this->stubExperience = $this->getMock(
'\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationsFile')
);
$this->stubExperience->expects($this->any())
->method('getConfigurationsFile')
->will(
$this->returnValue(
new \SplFileObject(__DIR__ . '/confTestFiles/config.yml')
)
);
$handler = new Configuration\Handler($this->stubNotInstalled);
$this->confNotInstalled = new PhraseaCore\Configuration($handler);
$handler = new Configuration\Handler($this->stubExperience);
$this->object = new PhraseaCore\Configuration($handler);
touch(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
$this->stubConfTest = $this->getMock(
'\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationPathName')
);
$file = new \SplFileObject(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
$this->stubConfTest->expects($this->any())
->method('getConfigurationPathName')
->will(
$this->returnValue($file->getPathname())
);
}
public function testGetEnvironment()
{
$this->assertEquals("dev", $this->object->getEnvironnement());
$this->assertEquals(null, $this->confNotInstalled->getEnvironnement());
}
public function testSetEnvironment()
{
$this->object->setEnvironnement("test");
$this->assertEquals("test", $this->object->getEnvironnement());
$this->confNotInstalled->setEnvironnement("prod");
$this->assertEquals("prod", $this->confNotInstalled->getEnvironnement());
try {
$this->object->setEnvironnement("unknow");
$this->fail("should raise exception");
} catch (\Exception $e) {
}
}
public function testIsDebug()
{
$this->object->setEnvironnement("test");
$this->assertTrue($this->object->isDebug());
$this->object->setEnvironnement("dev");
$this->assertTrue($this->object->isDebug());
$this->object->setEnvironnement("prod");
$this->assertFalse($this->object->isDebug());
$this->object->setEnvironnement("no_debug");
$this->assertFalse($this->object->isDebug());
}
public function testIsMaintened()
{
$this->object->setEnvironnement("test");
$this->assertFalse($this->object->isMaintained());
$this->object->setEnvironnement("dev");
$this->assertFalse($this->object->isMaintained());
$this->object->setEnvironnement("prod");
$this->assertFalse($this->object->isMaintained());
$this->object->setEnvironnement("no_maintenance");
$this->assertFalse($this->object->isMaintained());
}
public function testIsDisplayingErrors()
{
$this->object->setEnvironnement("test");
$this->assertTrue($this->object->isDisplayingErrors());
$this->object->setEnvironnement("dev");
$this->assertTrue($this->object->isDisplayingErrors());
$this->object->setEnvironnement("prod");
$this->assertFalse($this->object->isDisplayingErrors());
$this->object->setEnvironnement("no_display_errors");
$this->assertFalse($this->object->isDisplayingErrors());
}
public function testGetPhraseanet()
{
$this->object->setEnvironnement("test");
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $this->object->getPhraseanet());
$this->object->setEnvironnement("dev");
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $this->object->getPhraseanet());
$this->object->setEnvironnement("prod");
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $this->object->getPhraseanet());
$this->object->setEnvironnement("missing_phraseanet");
try {
$this->object->getPhraseanet();
$this->fail("should raise an exeception");
} catch (\Exception $e) {
}
}
public function testGetConfiguration()
{
$config = $this->object->getConfiguration();
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $config);
$this->assertNotEmpty($config->all());
$config = $this->confNotInstalled->getConfiguration();
$this->assertEmpty($config->all());
}
public function testGetConnexions()
{
$connexions = $this->object->getConnexions();
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $connexions);
$this->assertGreaterThan(0, sizeof($connexions->all()));
}
public function testGetConnexion()
{
$connexion = $this->object->getConnexion();
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $connexion);
$this->assertGreaterThan(0, sizeof($connexion->all()));
}
public function testGetConnexionException()
{
try {
$this->object->getConnexion('unknow_connexion');
$this->fail('should raise an exception');
} catch (\Exception $e) {
}
}
public function testGetFile()
{
$this->assertInstanceOf("\SplFileObject", $this->object->getFile());
}
public function testGetFileExeption()
{
try {
$this->assertInstanceOf("\SplFileObject", $this->confNotInstalled->getFile());
$this->fail("should raise an excpetion");
} catch (\Exception $e) {
}
}
public function testAll()
{
$all = $this->object->all();
$this->assertTrue(is_array($all));
$this->assertArrayHasKey("test", $all);
$this->assertArrayHasKey("dev", $all);
$this->assertArrayHasKey("prod", $all);
$this->assertArrayHasKey("environment", $all);
}
public function testGetServices()
{
$services = $this->object->getServices();
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $services);
$this->assertGreaterThan(0, sizeof($services->all()));
}
public function testGetService()
{
$services = $this->object->getService('TemplateEngine\Twig');
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $services);
$this->assertGreaterThan(0, sizeof($services->all()));
}
public function testGetServiceException()
{
try {
$this->object->getService('unknow_service');
$this->fail('should raise an exception');
} catch (\Exception $e) {
}
}
public function testWrite()
{
$handler = new Configuration\Handler($this->stubConfTest);
$configuration = new PhraseaCore\Configuration($handler);
$arrayToBeWritten = array(
'hello' => 'world'
, 'key' => array(
'keyone' => 'valueone'
, 'keytwo' => 'valuetwo'
)
);
$configuration->write($arrayToBeWritten, 0, true);
$all = $configuration->all();
$this->assertArrayHasKey("hello", $all);
$this->assertArrayHasKey("key", $all);
$this->assertTrue(is_array($all["key"]));
}
public function testWriteException()
{
$handler = new Configuration\Handler($this->stubConfTest);
$configuration = new PhraseaCore\Configuration($handler);
$arrayToBeWritten = array(
'hello' => 'world'
, 'key' => array(
'keyone' => 'valueone'
, 'keytwo' => 'valuetwo'
)
);
try {
$configuration->write($arrayToBeWritten);
$this->fail("should raise an exception");
} catch (\exception $e) {
}
}
public function testDelete()
{
$handler = new Configuration\Handler($this->stubConfTest);
$configuration = new PhraseaCore\Configuration($handler);
$configuration->delete();
$this->assertFileNotExists($file->getPathname());
}
public function testDeleteException()
{
$handler = new Configuration\Handler($this->stubConfTest);
$configuration = new PhraseaCore\Configuration($handler);
try {
$configuration->delete();
$this->fail("should raise an exception");
} catch (\Exception $e) {
}
$this->assertFileExists($file->getPathname());
unlink(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
}
public function testGetTemplating()
{
try {
$templating = $this->object->getTemplating();
} catch (\Exception $e) {
$this->fail("not template_engine provided");
}
$this->assertTrue(is_string($templating));
}
public function testGetOrm()
{
try {
$orm = $this->object->getOrm();
} catch (\Exception $e) {
$this->fail("not template_engine provided");
}
$this->assertTrue(is_string($orm));
}
public function testGetServiceFile()
{
$this->assertInstanceOf("\SplFileObject", $this->object->getServiceFile());
}
public function testGetConnexionFile()
{
$this->assertInstanceOf("\SplFileObject", $this->object->getConnexionFile());
}
public function testRefresh()
{
$this->confNotInstalled->refresh();
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $this->confNotInstalled->getConfiguration());
$handler = new Configuration\Handler($this->stubConfTest);
$configuration = new PhraseaCore\Configuration($handler);
$newScope = array("prod" => array('key' => 'value', 'key2' => 'value2'));
//append new conf
$configuration->write($newScope, FILE_APPEND);
try {
$configuration->getConfiguration(); //it is not loaded
$this->fail("should raise an exception");
} catch (\Exception $e) {
}
$configuration->refresh(); //reload conf
$prod = $configuration->getConfiguration();
$this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $prod);
unlink(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
}
}

View File

@@ -1,69 +0,0 @@
environment: dev
dev:
phraseanet:
servername: 'http://dev.phrasea.net/'
maintenance: false
debug: true
display_errors: true
database: main_connexion
template_engine: twig_debug
orm: doctrine_dev
cache: array_cache
prod:
phraseanet:
servername: 'http://dev.phrasea.net/'
maintenance: false
debug: false
display_errors: false
database: main_connexion
template_engine: twig
orm: doctrine_prod
cache: apc_cache
test:
phraseanet:
servername: 'http://dev.phrasea.net/'
maintenance: false
debug: true
display_errors: true
database: main_connexion
template_engine: twig_debug
orm: doctrine_test
cache: array_cache
no_debug:
phraseanet:
servername: 'http://dev.phrasea.net/'
maintenance: false
##debug: true
display_errors: true
database: main_connexion
template_engine: twig_debug
orm: doctrine_test
cache: array_cache
no_maintenance:
phraseanet:
servername: 'http://dev.phrasea.net/'
##maintenance: false
debug: true
display_errors: true
database: main_connexion
template_engine: twig_debug
orm: doctrine_test
cache: array_cache
no_display_errors:
phraseanet:
servername: 'http://dev.phrasea.net/'
maintenance: false
debug: true
##display_errors: true
database: main_connexion
template_engine: twig_debug
orm: doctrine_test
cache: array_cache
missing_phraseanet:
template_engine: twig_debug
orm: doctrine_test
cache: array_cache

View File

@@ -1,12 +0,0 @@
{
"meta": {
"api_version": "1.0",
"request": "GET /api/v1/feeds/288/content/",
"response_time": "2011-07-27T15:52:04+02:00",
"http_code": 200,
"error_message": null,
"error_details": null,
"charset": "UTF-8"
},
"response": {}
}

View File

@@ -0,0 +1,702 @@
<?php
namespace Alchemy\Tests\Phrasea\Core;
use Alchemy\Phrasea\Core\Configuration;
use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Alchemy\Phrasea\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
class ConfigurationTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers Alchemy\Phrasea\Core\Configuration::build
*/
public function testBuild()
{
$specifications = $this->getSetupedSpecifications(array('dev' => array()));
$configuration = Configuration::build($specifications, 'dev');
$this->assertEquals('dev', $configuration->getEnvironnement());
$this->assertEquals($specifications, $configuration->getSpecifications());
}
/**
* @test
* @covers Alchemy\Phrasea\Core\Configuration::build
*/
public function buildShouldFailIfTheRequiredEnvironmentDoesNotExist()
{
$specifications = $this->getSetupedSpecifications(array('prod' => array()));
try {
Configuration::build($specifications, 'dev');
$this->fail('Should have raised an exception');
} catch (InvalidArgumentException $e) {
}
}
/**
* @test
* @covers Alchemy\Phrasea\Core\Configuration::build
*/
public function environmentShouldBeNullIsTheSpecsAreNotSetup()
{
$specifications = $this->getNotSetupedSpecifications();
$configuration = Configuration::build($specifications, 'dev');
$this->assertNull($configuration->getEnvironnement());
$this->assertEquals($specifications, $configuration->getSpecifications());
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::get
*/
public function testGet()
{
$specifications = $this->getSetupedSpecifications(array('dev' => array('pif' => 'pouf')));
$configuration = Configuration::build($specifications, 'dev');
$this->assertEquals('pouf', $configuration->get('pif'));
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::get
*/
public function testGetOnNonExistentParameterShouldFail()
{
$specifications = $this->getSetupedSpecifications(array('dev' => array('pif' => 'pouf')));
$configuration = Configuration::build($specifications, 'dev');
try {
$configuration->get('paf');
$this->fail('Should have raised an exception');
} catch (ParameterNotFoundException $e) {
}
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::has
*/
public function testHas()
{
$specifications = $this->getSetupedSpecifications(array('dev' => array('pif' => 'pouf')));
$configuration = Configuration::build($specifications, 'dev');
$this->assertTrue($configuration->has('pif'));
$this->assertFalse($configuration->has('paf'));
}
/**
* @test
* @covers Alchemy\Phrasea\Core\Configuration::build
*/
public function defaultEnvironmentShouldBeTheOneInTheEnvironmentKey()
{
$specifications = $this->getSetupedSpecifications(array('environment' => 'dave', 'dave' => array('pif' => 'pouf')));
$configuration = Configuration::build($specifications);
$this->assertEquals('dave', $configuration->getEnvironnement());
$this->assertEquals($specifications, $configuration->getSpecifications());
}
/**
* @test
* @covers Alchemy\Phrasea\Core\Configuration::build
*/
public function anErrorShouldBeThrownIfNoEnvironmentProvided()
{
$specifications = $this->getSetupedSpecifications(array('dave' => array('pif' => 'pouf')));
try {
Configuration::build($specifications);
$this->fail('Should have raised an exception');
} catch (RuntimeException $e) {
}
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::setEnvironnement
* @covers Alchemy\Phrasea\Core\Configuration::getEnvironnement
*/
public function testSetEnvironnementShouldSetTheEnvironment()
{
$specifications = $this->getSetupedSpecifications(array('dev' => array('pif' => 'pouf'), 'prod' => array('bim' => 'bame')));
$configuration = Configuration::build($specifications, 'dev');
$this->assertEquals('dev', $configuration->getEnvironnement());
$this->assertTrue($configuration->has('pif'));
$this->assertFalse($configuration->has('bim'));
$configuration->setEnvironnement('prod');
$this->assertEquals('prod', $configuration->getEnvironnement());
$this->assertFalse($configuration->has('pif'));
$this->assertTrue($configuration->has('bim'));
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::setEnvironnement
* @covers Alchemy\Phrasea\Core\Configuration::getEnvironnement
*/
public function testSetEnvironnementShouldThrowAnExceptionIfEnvironmentDoesNotExists()
{
$specifications = $this->getSetupedSpecifications(array('dev' => array('pif' => 'pouf'), 'prod' => array('bim' => 'bame')));
$configuration = Configuration::build($specifications, 'dev');
try {
$configuration->setEnvironnement('test');
$this->fail('Should have raised an exception');
} catch (InvalidArgumentException $e) {
}
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::getEnvironnement
* @covers Alchemy\Phrasea\Core\Configuration::setEnvironnement
*/
public function testSetEnvironnementWhenSetupNotReadyShouldAlwaysWork()
{
$specifications = $this->getNotSetupedSpecifications();
$configuration = Configuration::build($specifications, 'dev');
$configuration->setEnvironnement('prout');
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::isDebug
*/
public function testIsDebugIsFalseWhileSetup()
{
$specifications = $this->getNotSetupedSpecifications();
$configuration = Configuration::build($specifications);
$this->assertFalse($configuration->isDebug());
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::isDebug
*/
public function testIsDebugIsFalseByDefault()
{
$specifications = $this->getSetupedSpecifications(array('dev' => array()));
$configuration = Configuration::build($specifications, 'dev');
$this->assertFalse($configuration->isDebug());
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::isDebug
*/
public function testIsDebug()
{
$specifications = $this->getSetupedSpecifications(array('dev' => array('phraseanet' => array('debug' => true))));
$configuration = Configuration::build($specifications, 'dev');
$this->assertTrue($configuration->isDebug());
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::isMaintained
*/
public function testIsMaintainedIsFalseWhileSetup()
{
$specifications = $this->getNotSetupedSpecifications();
$configuration = Configuration::build($specifications);
$this->assertFalse($configuration->isMaintained());
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::isMaintained
*/
public function testIsMaintainedIsFalseByDefault()
{
$specifications = $this->getSetupedSpecifications(array('dev' => array()));
$configuration = Configuration::build($specifications, 'dev');
$this->assertFalse($configuration->isMaintained());
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::isMaintained
*/
public function testIsMaintained()
{
$specifications = $this->getSetupedSpecifications(array('dev' => array('phraseanet' => array('maintenance' => true))));
$configuration = Configuration::build($specifications, 'dev');
$this->assertTrue($configuration->isMaintained());
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::isDisplayingErrors
*/
public function testIsDisplayingErrorsIsFalseWhileSetup()
{
$specifications = $this->getNotSetupedSpecifications();
$configuration = Configuration::build($specifications);
$this->assertFalse($configuration->isDisplayingErrors());
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::isDisplayingErrors
*/
public function testIsDisplayingErrorsIsFalseByDefault()
{
$specifications = $this->getSetupedSpecifications(array('dev' => array()));
$configuration = Configuration::build($specifications, 'dev');
$this->assertFalse($configuration->isDisplayingErrors());
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::isDisplayingErrors
*/
public function testIsDisplayingErrors()
{
$specifications = $this->getSetupedSpecifications(array('dev' => array('phraseanet' => array('display_errors' => true))));
$configuration = Configuration::build($specifications, 'dev');
$this->assertTrue($configuration->isDisplayingErrors());
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::getPhraseanet
*/
public function testGetPhraseanet()
{
$phraseanet = array('display_errors' => true);
$specifications = $this->getSetupedSpecifications(array('dev' => array('phraseanet' => $phraseanet)));
$configuration = Configuration::build($specifications, 'dev');
$this->assertInstanceOf('Symfony\Component\DependencyInjection\ParameterBag\ParameterBag', $configuration->getPhraseanet());
$this->assertEquals($phraseanet, $configuration->getPhraseanet()->all());
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::initialize
*/
public function testInitialize()
{
$specifications = $this->getNotSetupedSpecifications();
$specifications->expects($this->once())
->method('initialize');
$configuration = Configuration::build($specifications);
$configuration->initialize();
$this->assertEquals('prod', $configuration->getEnvironnement());
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::delete
*/
public function testDelete()
{
$specifications = $this->getSetupedSpecifications(array('prod' => array()));
$specifications->expects($this->once())
->method('delete');
$configuration = Configuration::build($specifications, 'prod');
$configuration->delete();
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::setConfigurations
*/
public function testSetConfigurations()
{
$conf = array('prod' => array('bim' => 'boum'));
$specifications = $this->getSetupedSpecifications(array('prod' => array()));
$specifications->expects($this->once())
->method('setConfigurations')
->with($this->equalTo($conf));
$configuration = Configuration::build($specifications, 'prod');
$configuration->setConfigurations($conf);
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::setServices
*/
public function testSetServices()
{
$services = array('Template' => array());
$specifications = $this->getSetupedSpecifications(array('prod' => array()));
$specifications->expects($this->once())
->method('setServices')
->with($this->equalTo($services));
$configuration = Configuration::build($specifications, 'prod');
$configuration->setServices($services);
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::resetServices
*/
public function testResetAllServices()
{
$specifications = $this->getSetupedSpecifications(array('prod' => array()));
$specifications->expects($this->once())
->method('resetServices')
->with($this->equalTo(null));
$configuration = Configuration::build($specifications, 'prod');
$configuration->resetServices();
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::resetServices
*/
public function testResetByName()
{
$name = 'coool-service';
$specifications = $this->getSetupedSpecifications(array('prod' => array()));
$specifications->expects($this->once())
->method('resetServices')
->with($this->equalTo($name));
$configuration = Configuration::build($specifications, 'prod');
$configuration->resetServices($name);
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::setBinaries
*/
public function testSetBinaries()
{
$binaries = array('binarie' => array('php' => '/usr/local/bin/php'));
$specifications = $this->getSetupedSpecifications(array('prod' => array()));
$specifications->expects($this->once())
->method('setBinaries')
->with($this->equalTo($binaries));
$configuration = Configuration::build($specifications, 'prod');
$configuration->setBinaries($binaries);
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::setConnexions
*/
public function testSetConnexions()
{
$connexions = array('main' => array('path' => '/usr/local/db'));
$specifications = $this->getSetupedSpecifications(array('prod' => array()));
$specifications->expects($this->once())
->method('setConnexions')
->with($this->equalTo($connexions));
$configuration = Configuration::build($specifications, 'prod');
$configuration->setConnexions($connexions);
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::getConfigurations
*/
public function testGetConfigurations()
{
$specifications = $this->getNotSetupedSpecifications();
$specifications->expects($this->once())
->method('getConfigurations');
$configuration = Configuration::build($specifications, 'prod');
$configuration->getConfigurations();
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::getServices
*/
public function testGetServices()
{
$specifications = $this->getSetupedSpecifications(array('prod' => array()));
$specifications->expects($this->once())
->method('getServices');
$configuration = Configuration::build($specifications, 'prod');
$configuration->getServices();
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::getBinaries
*/
public function testGetBinaries()
{
$specifications = $this->getSetupedSpecifications(array('prod' => array()));
$specifications->expects($this->once())
->method('getBinaries');
$configuration = Configuration::build($specifications, 'prod');
$configuration->getBinaries();
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::getConnexions
*/
public function testGetConnexions()
{
$specifications = $this->getSetupedSpecifications(array('prod' => array()));
$specifications->expects($this->once())
->method('getConnexions');
$configuration = Configuration::build($specifications, 'prod');
$configuration->getConnexions();
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::getConnexion
*/
public function testGetConnexion()
{
$testConnexion = array('path' => '/tmp/db');
$specifications = $this->getSetupedSpecifications(array('prod' => array()));
$specifications->expects($this->once())
->method('getConnexions')
->will($this->returnValue(array('test' => $testConnexion)));
$configuration = Configuration::build($specifications, 'prod');
$conn = $configuration->getConnexion('test');
$this->assertInstanceOf('Symfony\Component\DependencyInjection\ParameterBag\ParameterBag', $conn);
$this->assertEquals($testConnexion, $conn->all());
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::getConnexion
*/
public function testGetConnexionThatDoesNotExist()
{
$testConnexion = array('path' => '/tmp/db');
$specifications = $this->getSetupedSpecifications(array('prod' => array()));
$specifications->expects($this->once())
->method('getConnexions')
->will($this->returnValue(array('test' => $testConnexion)));
$configuration = Configuration::build($specifications, 'prod');
try {
$configuration->getConnexion('not-exists');
$this->fail('Should have raised an exception');
} catch (InvalidArgumentException $e) {
}
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::getTemplating
*/
public function testGetTemplating()
{
$specifications = $this->getSetupedSpecifications(array(
'prod' => array('template_engine' => 'ObjectTwig')
));
$configuration = Configuration::build($specifications, 'prod');
$this->assertEquals('TemplateEngine\\ObjectTwig', $configuration->getTemplating());
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::getCache
*/
public function testGetCache()
{
$specifications = $this->getSetupedSpecifications(array(
'prod' => array('cache' => 'ObjectCache')
));
$configuration = Configuration::build($specifications, 'prod');
$this->assertEquals('Cache\\ObjectCache', $configuration->getCache());
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::getOpcodeCache
*/
public function testGetOpcodeCache()
{
$specifications = $this->getSetupedSpecifications(array(
'prod' => array('opcodecache' => 'ObjectOpcodeCache')
));
$configuration = Configuration::build($specifications, 'prod');
$this->assertEquals('Cache\\ObjectOpcodeCache', $configuration->getOpcodeCache());
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::getOrm
*/
public function testGetOrm()
{
$specifications = $this->getSetupedSpecifications(array(
'prod' => array('orm' => 'ObjectORM')
));
$configuration = Configuration::build($specifications, 'prod');
$this->assertEquals('Orm\\ObjectORM', $configuration->getOrm());
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::getSearchEngine
*/
public function testGetSearchEngine()
{
$specifications = $this->getSetupedSpecifications(array(
'prod' => array('search-engine' => 'ObjectPhrasea')
));
$configuration = Configuration::build($specifications, 'prod');
$this->assertEquals('SearchEngine\\ObjectPhrasea', $configuration->getSearchEngine());
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::getBorder
*/
public function testGetBorder()
{
$specifications = $this->getSetupedSpecifications(array(
'prod' => array('border-manager' => 'ObjectBorder')
));
$configuration = Configuration::build($specifications, 'prod');
$this->assertEquals('Border\\ObjectBorder', $configuration->getBorder());
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::getTaskManager
*/
public function testGetTaskManager()
{
$specifications = $this->getSetupedSpecifications(array(
'prod' => array('task-manager' => 'ObjectTask')
));
$configuration = Configuration::build($specifications, 'prod');
$this->assertEquals('TaskManager\\ObjectTask', $configuration->getTaskManager());
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::getService
* @dataProvider provideServices
*/
public function testGetService($services, $name, $expected)
{
$specifications = $this->getSetupedSpecifications(array(
'prod' => array('task-manager' => 'ObjectTask')
));
$specifications->expects($this->once())
->method('getServices')
->will($this->returnValue($services));
$configuration = Configuration::build($specifications, 'prod');
$service = $configuration->getService($name);
$this->assertInstanceOf('Symfony\Component\DependencyInjection\ParameterBag\ParameterBag', $service);
$this->assertEquals($expected, $service->all());
}
/**
* @covers Alchemy\Phrasea\Core\Configuration::getService
* @dataProvider provideFailingServiceData
*/
public function testGetServiceFail($services, $name)
{
$specifications = $this->getSetupedSpecifications(array(
'prod' => array('task-manager' => 'ObjectTask')
));
$specifications->expects($this->once())
->method('getServices')
->will($this->returnValue($services));
$configuration = Configuration::build($specifications, 'prod');
try {
$configuration->getService($name);
$this->fail('Should have raised an exception');
} catch (InvalidArgumentException $e) {
}
}
public function provideServices()
{
$services = array(
'servicetld' => array(
'sub' => array('data'),
'anothersub' => array('datalevel1' => array(
'datalevel2' => array('lowleveldata')
)),
),
'anothertop' => array('pif' => 'paf')
);
return array(
array($services, 'servicetld\\sub', array('data')),
array($services, 'servicetld\\anothersub\\datalevel1', array('datalevel2' => array('lowleveldata'))),
array($services, 'anothertop', array('pif' => 'paf')),
);
}
public function provideFailingServiceData()
{
$services = array(
'servicetld' => array(
'sub' => array('data'),
'anothersub' => array('datalevel1' => array(
'datalevel2' => array('lowleveldata')
)),
),
'anothertop' => array('pif' => 'paf')
);
return array(
array($services, 'servicetld\\sub\\data'),
array($services, 'servicetld\\data'),
array($services, 'servicetld\\anothersub\\datalevel2'),
array($services, 'anotherothertop'),
);
}
private function getNotSetupedSpecifications()
{
$specifications = $this->getMock('Alchemy\Phrasea\Core\Configuration\SpecificationInterface');
$specifications->expects($this->any())
->method('isSetup')
->will($this->returnValue(false));
return $specifications;
}
private function getSetupedSpecifications($configuration = array())
{
$specifications = $this->getMock('Alchemy\Phrasea\Core\Configuration\SpecificationInterface');
$specifications->expects($this->any())
->method('isSetup')
->will($this->returnValue(true));
if ($configuration) {
$specifications->expects($this->any())
->method('getConfigurations')
->will($this->returnValue($configuration));
}
return $specifications;
}
}

View File

@@ -2,14 +2,15 @@
namespace Alchemy\Tests\Phrasea\Core\Provider; namespace Alchemy\Tests\Phrasea\Core\Provider;
use Alchemy\Phrasea\Core\Provider\BorderManagerServiceProvider; /**
* @covers Alchemy\Phrasea\Core\Provider\BorderManagerServiceProvider
class BorderManagerServiceProvidertest extends \PhraseanetPHPUnitAbstract */
class BorderManagerServiceProvidertest extends ServiceProviderTestCase
{ {
public function testGetInstantiate() public function provideServiceDescription()
{ {
self::$DI['app']->register(new BorderManagerServiceProvider()); return array(
array('Alchemy\Phrasea\Core\Provider\BorderManagerServiceProvider', 'border-manager', 'Alchemy\\Phrasea\\Border\\Manager'),
$this->assertInstanceof('Alchemy\\Phrasea\\Border\\Manager', self::$DI['app']['border-manager']); );
} }
} }

View File

@@ -2,14 +2,15 @@
namespace Alchemy\Tests\Phrasea\Core\Provider; namespace Alchemy\Tests\Phrasea\Core\Provider;
use Alchemy\Phrasea\Core\Provider\BrowserServiceProvider; /**
* @covers Alchemy\Phrasea\Core\Provider\BrowserServiceProvider
class BrowserServiceProvidertest extends \PhraseanetPHPUnitAbstract */
class BrowserServiceProvidertest extends ServiceProviderTestCase
{ {
public function testGetInstantiate() public function provideServiceDescription()
{ {
self::$DI['app']->register(new BrowserServiceProvider()); return array(
array('Alchemy\Phrasea\Core\Provider\BrowserServiceProvider', 'browser', 'Browser'),
$this->assertInstanceof('Browser', self::$DI['app']['browser']); );
} }
} }

View File

@@ -2,16 +2,17 @@
namespace Alchemy\Tests\Phrasea\Core\Provider; namespace Alchemy\Tests\Phrasea\Core\Provider;
use Alchemy\Phrasea\Core\Provider\CacheServiceProvider; /**
* @covers Alchemy\Phrasea\Core\Provider\CacheServiceProvider
class CacheServiceProvidertest extends \PhraseanetPHPUnitAbstract */
class CacheServiceProvidertest extends ServiceProviderTestCase
{ {
public function testGetInstantiate() public function provideServiceDescription()
{ {
self::$DI['app']->register(new CacheServiceProvider()); return array(
array('Alchemy\Phrasea\Core\Provider\CacheServiceProvider', 'cache', 'Doctrine\\Common\\Cache\\Cache'),
$this->assertInstanceof('Doctrine\\Common\\Cache\\Cache', self::$DI['app']['cache']); array('Alchemy\Phrasea\Core\Provider\CacheServiceProvider', 'opcode-cache', 'Doctrine\\Common\\Cache\\Cache'),
$this->assertInstanceof('Doctrine\\Common\\Cache\\Cache', self::$DI['app']['opcode-cache']); array('Alchemy\Phrasea\Core\Provider\CacheServiceProvider', 'phraseanet.cache-service', 'Alchemy\\Phrasea\\Cache\\Manager'),
$this->assertInstanceof('Alchemy\\Phrasea\\Cache\\Manager', self::$DI['app']['phraseanet.cache-service']); );
} }
} }

View File

@@ -2,14 +2,15 @@
namespace Alchemy\Tests\Phrasea\Core\Provider; namespace Alchemy\Tests\Phrasea\Core\Provider;
use Alchemy\Phrasea\Core\Provider\ConfigurationServiceProvider; /**
* @covers Alchemy\Phrasea\Core\Provider\ConfigurationServiceProvider
class ConfigurationServiceProvidertest extends \PhraseanetPHPUnitAbstract */
class ConfigurationServiceProvidertest extends ServiceProviderTestCase
{ {
public function testGetInstantiate() public function provideServiceDescription()
{ {
self::$DI['app']->register(new ConfigurationServiceProvider()); return array(
array('Alchemy\Phrasea\Core\Provider\ConfigurationServiceProvider', 'phraseanet.configuration', 'Alchemy\\Phrasea\\Core\\Configuration'),
$this->assertInstanceof('Alchemy\\Phrasea\\Core\\Configuration', self::$DI['app']['phraseanet.configuration']); );
} }
} }

View File

@@ -2,14 +2,15 @@
namespace Alchemy\Tests\Phrasea\Core\Provider; namespace Alchemy\Tests\Phrasea\Core\Provider;
use Alchemy\Phrasea\Core\Provider\ConfigurationTesterServiceProvider; /**
* @covers Alchemy\Phrasea\Core\Provider\ConfigurationTesterServiceProvider
class ConfigurationTesterServiceProvidertest extends \PhraseanetPHPUnitAbstract */
class ConfigurationTesterServiceProvidertest extends ServiceProviderTestCase
{ {
public function testGetInstantiate() public function provideServiceDescription()
{ {
self::$DI['app']->register(new ConfigurationTesterServiceProvider()); return array(
array('Alchemy\Phrasea\Core\Provider\ConfigurationTesterServiceProvider', 'phraseanet.configuration-tester', 'Alchemy\\Phrasea\\Setup\\ConfigurationTester'),
$this->assertInstanceof('Alchemy\\Phrasea\\Setup\\ConfigurationTester', self::$DI['app']['phraseanet.configuration-tester']); );
} }
} }

View File

@@ -0,0 +1,15 @@
<?php
namespace Alchemy\Tests\Phrasea\Core\Provider;
use Alchemy\Phrasea\Core\Provider\FtpServiceProvider;
class FTPServiceProvidertest extends \PhraseanetPHPUnitAbstract
{
public function testGetInstantiate()
{
self::$DI['app']->register(new FtpServiceProvider());
$this->assertInstanceOf('Closure', self::$DI['app']['phraseanet.ftp.client']);
}
}

View File

@@ -2,14 +2,15 @@
namespace Alchemy\Tests\Phrasea\Core\Provider; namespace Alchemy\Tests\Phrasea\Core\Provider;
use Alchemy\Phrasea\Core\Provider\GeonamesServiceProvider; /**
* @covers Alchemy\Phrasea\Core\Provider\GeonamesServiceProvider
class GeonamesServiceProvidertest extends \PhraseanetPHPUnitAbstract */
class GeonamesServiceProvidertest extends ServiceProviderTestCase
{ {
public function testGetInstantiate() public function provideServiceDescription()
{ {
self::$DI['app']->register(new GeonamesServiceProvider()); return array(
array('Alchemy\Phrasea\Core\Provider\GeonamesServiceProvider', 'geonames', 'geonames'),
$this->assertInstanceof('geonames', self::$DI['app']['geonames']); );
} }
} }

View File

@@ -2,14 +2,15 @@
namespace Alchemy\Tests\Phrasea\Core\Provider; namespace Alchemy\Tests\Phrasea\Core\Provider;
use Alchemy\Phrasea\Core\Provider\ORMServiceProvider; /**
* @covers Alchemy\Phrasea\Core\Provider\ORMServiceProvider
class ORMServiceProvidertest extends \PhraseanetPHPUnitAbstract */
class ORMServiceProvidertest extends ServiceProviderTestCase
{ {
public function testGetInstantiate() public function provideServiceDescription()
{ {
self::$DI['app']->register(new ORMServiceProvider()); return array(
array('Alchemy\Phrasea\Core\Provider\ORMServiceProvider', 'EM', 'Doctrine\\ORM\\EntityManager'),
$this->assertInstanceof('Doctrine\\ORM\\EntityManager', self::$DI['app']['EM']); );
} }
} }

View File

@@ -2,17 +2,15 @@
namespace Alchemy\Tests\Phrasea\Core\Provider; namespace Alchemy\Tests\Phrasea\Core\Provider;
use Alchemy\Phrasea\Core\Provider\SearchEngineServiceProvider; /**
* @covers Alchemy\Phrasea\Core\Provider\SearchEngineServiceProvider
class SearchEngineServiceProvidertest extends \PhraseanetPHPUnitAbstract */
class SearchEngineServiceProvidertest extends ServiceProviderTestCase
{ {
/** public function provideServiceDescription()
* @covers Alchemy\Phrasea\Core\Provider\SearchEngineServiceProvider
*/
public function testGetInstantiate()
{ {
self::$DI['app']->register(new SearchEngineServiceProvider()); return array(
array('Alchemy\Phrasea\Core\Provider\SearchEngineServiceProvider', 'phraseanet.SE', 'Alchemy\Phrasea\SearchEngine\SearchEngineInterface'),
$this->assertInstanceof('Alchemy\Phrasea\SearchEngine\SearchEngineInterface', self::$DI['app']['phraseanet.SE']); );
} }
} }

View File

@@ -0,0 +1,23 @@
<?php
namespace Alchemy\Tests\Phrasea\Core\Provider;
abstract class ServiceProviderTestCase extends \PhraseanetPHPUnitAbstract
{
/**
* @test
* @dataProvider provideServiceDescription
*/
public function theSameInstanceShouldBereturnedEveryTime($service, $key, $classname)
{
self::$DI['app']->register(new $service());
$instance1 = self::$DI['app'][$key];
$instance2 = self::$DI['app'][$key];
$this->assertInstanceof($classname, $instance1);
$this->assertEquals($instance1, $instance2);
}
abstract public function provideServiceDescription();
}

View File

@@ -2,17 +2,15 @@
namespace Alchemy\Tests\Phrasea\Core\Provider; namespace Alchemy\Tests\Phrasea\Core\Provider;
use Alchemy\Phrasea\Core\Provider\TaskManagerServiceProvider; /**
* @covers Alchemy\Phrasea\Core\Provider\TaskManagerServiceProvider
class TaskManagerServiceProvidertest extends \PhraseanetPHPUnitAbstract */
class TaskManagerServiceProvidertest extends ServiceProviderTestCase
{ {
/** public function provideServiceDescription()
* @covers Alchemy\Phrasea\Core\Provider\TaskManagerServiceProvider
*/
public function testGetInstantiate()
{ {
self::$DI['app']->register(new TaskManagerServiceProvider()); return array(
array('Alchemy\Phrasea\Core\Provider\TaskManagerServiceProvider', 'task-manager', '\task_manager'),
$this->assertInstanceof('task_manager', self::$DI['app']['task-manager']); );
} }
} }

View File

@@ -2,17 +2,15 @@
namespace Alchemy\Tests\Phrasea\Core\Provider; namespace Alchemy\Tests\Phrasea\Core\Provider;
use Alchemy\Phrasea\Core\Provider\UnicodeServiceProvider; /**
* @covers Alchemy\Phrasea\Core\Provider\UnicodeServiceProvider
class UnicodeServiceProvidertest extends \PhraseanetPHPUnitAbstract */
class UnicodeServiceProvidertest extends ServiceProviderTestCase
{ {
/** public function provideServiceDescription()
* @covers Alchemy\Phrasea\Core\Provider\UnicodeServiceProvider
*/
public function testGetInstantiate()
{ {
self::$DI['app']->register(new UnicodeServiceProvider()); return array(
array('Alchemy\Phrasea\Core\Provider\UnicodeServiceProvider', 'unicode', '\unicode'),
$this->assertInstanceof('unicode', self::$DI['app']['unicode']); );
} }
} }

View File

@@ -26,6 +26,8 @@ abstract class ConfigurationPanelAbstractTest extends \PhraseanetPHPUnitAuthenti
$config = $this->getPanel()->getConfiguration(); $config = $this->getPanel()->getConfiguration();
$this->assertEquals($data, $config['test']); $this->assertEquals($data, $config['test']);
unset($config['test']);
$this->getPanel()->saveConfiguration($config);
} }
public function testGetAvailableDateFields() public function testGetAvailableDateFields()

View File

@@ -100,8 +100,6 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
parent::setUp(); parent::setUp();
self::$DI['app.use-exception-handler'] = false;
\PHPUnit_Framework_Error_Warning::$enabled = true; \PHPUnit_Framework_Error_Warning::$enabled = true;
\PHPUnit_Framework_Error_Notice::$enabled = true; \PHPUnit_Framework_Error_Notice::$enabled = true;
@@ -112,10 +110,6 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
$app['debug'] = true; $app['debug'] = true;
if (!$DI['app.use-exception-handler']) {
unset($app['exception_handler']);
}
$app['EM'] = $app->share($app->extend('EM', function($em) { $app['EM'] = $app->share($app->extend('EM', function($em) {
@unlink('/tmp/db.sqlite'); @unlink('/tmp/db.sqlite');
copy(__DIR__ . '/../db-ref.sqlite', '/tmp/db.sqlite'); copy(__DIR__ . '/../db-ref.sqlite', '/tmp/db.sqlite');
@@ -169,6 +163,25 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
set_time_limit(0); set_time_limit(0);
} }
protected function assertForbiddenResponse(Response $response)
{
$this->assertEquals(403, $response->getStatusCode());
$this->assertTrue(false !== stripos($response->getContent(), 'forbidden'));
}
protected function assertBadResponse(Response $response)
{
$this->assertEquals(400, $response->getStatusCode());
$this->assertTrue(false !== stripos($response->getContent(), 'bad request'));
}
protected function assertNotFoundResponse(Response $response)
{
$this->assertEquals(404, $response->getStatusCode());
$this->assertTrue(false !== stripos($response->getContent(), 'not found'));
}
/** /**
* Insert fixture contained in the specified fixtureLoader * Insert fixture contained in the specified fixtureLoader
* into sqlLite test temporary database * into sqlLite test temporary database

View File

@@ -0,0 +1,161 @@
<?php
class patch_3803Test extends PhraseanetPHPUnitAbstract
{
/**
* @covers patch_3803::apply
*/
public function testApplyInSphinxEnvironment()
{
$patch = new patch_3803();
$appbox = $this->getMockBuilder('appbox')
->disableOriginalConstructor()
->getMock();
$app = self::$DI['app'];
$app['phraseanet.registry'] = $this->getMock('registryInterface');
$app['phraseanet.registry']->expects($this->any())
->method('get')
->will($this->returnCallback(function ($parameter) {
switch ($parameter) {
case 'GV_sphinx':
return true;
case 'GV_sphinx_rt_port':
return 5678;
case 'GV_sphinx_rt_host':
return 'sphinx.rt_host';
case 'GV_sphinx_host':
return 'sphinx.host';
case 'GV_sphinx_port':
return 1234;
default:
throw new \InvalidArgumentException(sprintf('%s is missing, test case not ready', $parameter));
}
}));
$catchConfiguration = $catchSEConf = null;
$app['phraseanet.configuration'] = $this->getMockBuilder('Alchemy\Phrasea\Core\Configuration')
->disableOriginalConstructor()
->getMock();
$app['phraseanet.configuration']->expects($this->once())
->method('getConfigurations')
->will($this->returnValue(array('environment' => 'prod', 'prod' => array(), 'dev' => array())));
$app['phraseanet.configuration']->expects($this->once())
->method('setConfigurations')
->will($this->returnCallback(function($configuration) use (&$catchConfiguration) {
$catchConfiguration = $configuration;
}));
$panel = $this->getMock('Alchemy\Phrasea\SearchEngine\ConfigurationPanelInterface');
$panel->expects($this->once())
->method('saveConfiguration')
->will($this->returnCallback(function($json) use (&$catchSEConf){
$catchSEConf = $json;
}));
$panel->expects($this->once())
->method('getConfiguration')
->will($this->returnValue(array()));
$app['phraseanet.SE'] = $this->getMock('Alchemy\Phrasea\SearchEngine\SearchEngineInterface');
$app['phraseanet.SE']->expects($this->any())
->method('getConfigurationPanel')
->will($this->returnValue($panel));
$this->assertTrue($patch->apply($appbox, $app));
$upgrade = 0;
foreach ($catchConfiguration as $env => $conf) {
if (in_array($env, array('environment', 'key'))) {
continue;
}
$this->assertArrayHasKey('search-engine', $conf);
$upgrade++;
}
$this->assertEquals(2, $upgrade);
$this->assertArrayHasKey('port', $catchSEConf);
$this->assertArrayHasKey('host', $catchSEConf);
$this->assertArrayHasKey('rt_port', $catchSEConf);
$this->assertArrayHasKey('rt_host', $catchSEConf);
$this->assertEquals(5678, $catchSEConf['rt_port']);
$this->assertEquals('sphinx.rt_host', $catchSEConf['rt_host']);
$this->assertEquals(1234, $catchSEConf['port']);
$this->assertEquals('sphinx.host', $catchSEConf['host']);
}
/**
* @covers patch_3803::apply
*/
public function testApplyInPhraseaEnvironment()
{
$patch = new patch_3803();
$appbox = $this->getMockBuilder('appbox')
->disableOriginalConstructor()
->getMock();
$app = self::$DI['app'];
$app['phraseanet.registry'] = $this->getMock('registryInterface');
$app['phraseanet.registry']->expects($this->any())
->method('get')
->will($this->returnCallback(function ($parameter) {
switch ($parameter) {
case 'GV_sphinx':
return false;
case 'GV_phrasea_sort':
return 'custom-sort';
default:
throw new \InvalidArgumentException(sprintf('%s is missing, test case not ready', $parameter));
}
}));
$catchConfiguration = $catchPhraseaConf = null;
$app['phraseanet.configuration'] = $this->getMockBuilder('Alchemy\Phrasea\Core\Configuration')
->disableOriginalConstructor()
->getMock();
$app['phraseanet.configuration']->expects($this->once())
->method('getConfigurations')
->will($this->returnValue(array('environment' => 'prod', 'prod' => array(), 'dev' => array())));
$app['phraseanet.configuration']->expects($this->once())
->method('setConfigurations')
->will($this->returnCallback(function($configuration) use (&$catchConfiguration) {
$catchConfiguration = $configuration;
}));
$panel = $this->getMock('Alchemy\Phrasea\SearchEngine\ConfigurationPanelInterface');
$panel->expects($this->once())
->method('saveConfiguration')
->will($this->returnCallback(function($json) use (&$catchSEConf){
$catchSEConf = $json;
}));
$panel->expects($this->once())
->method('getConfiguration')
->will($this->returnValue(array()));
$app['phraseanet.SE'] = $this->getMock('Alchemy\Phrasea\SearchEngine\SearchEngineInterface');
$app['phraseanet.SE']->expects($this->any())
->method('getConfigurationPanel')
->will($this->returnValue($panel));
$this->assertTrue($patch->apply($appbox, $app));
$upgrade = 0;
foreach ($catchConfiguration as $env => $conf) {
if (in_array($env, array('environment', 'key'))) {
continue;
}
$this->assertArrayHasKey('search-engine', $conf);
$upgrade++;
}
$this->assertEquals(2, $upgrade);
$this->assertArrayHasKey('default_sort', $catchSEConf);
$this->assertEquals('custom-sort', $catchSEConf['default_sort']);
}
}

View File

@@ -0,0 +1,60 @@
<?php
class patch_3804Test extends PhraseanetPHPUnitAbstract
{
/**
* @covers patch_3804::apply
*/
public function testApply()
{
$app = self::$DI['app'];
$patch = new patch_3804();
$appbox = $this->getMockBuilder('appbox')
->disableOriginalConstructor()
->getMock();
$catchConfiguration = null;
$app['phraseanet.configuration'] = $this->getMockBuilder('Alchemy\Phrasea\Core\Configuration')
->disableOriginalConstructor()
->getMock();
$app['phraseanet.configuration']->expects($this->once())
->method('getConfigurations')
->will($this->returnValue(array(
'environment' => 'prod',
'prod' => array(),
'dev' => array()
)));
$app['phraseanet.configuration']->expects($this->once())
->method('setConfigurations')
->will($this->returnCallback(function($configuration) use (&$catchConfiguration) {
$catchConfiguration = $configuration;
}));
$app['phraseanet.configuration']->expects($this->once())
->method('getServices')
->will($this->returnValue(array(
'SearchEngine' => array(),
)));
$app['phraseanet.configuration']->expects($this->once())
->method('resetServices')
->with($this->equalTo('TaskManager'));
$this->assertTrue($patch->apply($appbox, $app));
$upgrade = 0;
foreach ($catchConfiguration as $env => $conf) {
if (in_array($env, array('environment', 'key'))) {
continue;
}
$this->assertArrayHasKey('task-manager', $conf);
$upgrade++;
}
$this->assertEquals(2, $upgrade);
}
}