diff --git a/.travis.yml b/.travis.yml
index 5bf3208a6e..7086e55e54 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -47,19 +47,19 @@ php:
- 5.6
script:
- - bin/developer system:uninstall
- - travis_retry bin/developer dependencies:all --prefer-source
+ - bin/developer system:uninstall -v
+ - travis_retry bin/developer dependencies:all --prefer-source -v
- sh -c " if [ '$SETUP_MODE' = 'update' ]; then
- cp hudson/connexion.inc config/;
- cp hudson/_GV.php config/;
- mysql -e 'source `pwd`/hudson/fixtures.sql';
+ bin/setup system:install --email=test@phraseanet.com --password=test --db-user=root --db-template=fr --db-password= --databox=db_test --appbox=ab_test --server-name=http://127.0.0.1 -y -v;
+ bin/developer ini:reset --v3.1 -v;
bin/setup system:upgrade -y -v -f;
fi"
- sh -c " if [ '$SETUP_MODE' = 'install' ]; then
- bin/setup system:install --email=test@phraseanet.com --password=test --db-user=root --db-template=fr --db-password= --databox=db_test --appbox=ab_test --server-name=http://127.0.0.1 -y;
+ bin/setup system:install --email=test@phraseanet.com --password=test --db-user=root --db-template=fr --db-password= --databox=db_test --appbox=ab_test --server-name=http://127.0.0.1 -y -v;
+ bin/developer ini:setup-tests-dbs -v;
fi"
- php hudson/cleanupSubdefs.php
- - bin/developer assets:compile-less
- - bin/developer assets:build-javascript
+ - bin/developer assets:compile-less -v
+ - bin/developer assets:build-javascript -v
- sh tests/js/run.sh
- bin/phpunit
diff --git a/bin/developer b/bin/developer
index a31c266640..75e2337693 100755
--- a/bin/developer
+++ b/bin/developer
@@ -16,10 +16,12 @@ use Alchemy\Phrasea\Command\Developer\Behat;
use Alchemy\Phrasea\Command\Developer\BowerInstall;
use Alchemy\Phrasea\Command\Developer\ComposerInstall;
use Alchemy\Phrasea\Command\Developer\LessCompiler;
+use Alchemy\Phrasea\Command\Developer\IniReset;
use Alchemy\Phrasea\Command\Developer\InstallAll;
use Alchemy\Phrasea\Command\Developer\JavascriptBuilder;
use Alchemy\Phrasea\Command\Developer\RegenerateSqliteDb;
use Alchemy\Phrasea\Command\Developer\RoutesDumper;
+use Alchemy\Phrasea\Command\Developer\SetupTestsDbs;
use Alchemy\Phrasea\Command\Developer\Uninstaller;
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
@@ -79,6 +81,8 @@ $cli->command(new Behat());
$cli->command(new LessCompiler());
$cli->command(new JavascriptBuilder());
$cli->command(new Uninstaller());
+$cli->command(new IniReset());
+$cli->command(new SetupTestsDbs());
$cli->command(new \module_console_systemTemplateGenerator('system:generate-templates'));
$cli['console']->addCommands(array(
diff --git a/build-env.sh b/build-env.sh
deleted file mode 100755
index 7cb2c77d19..0000000000
--- a/build-env.sh
+++ /dev/null
@@ -1,11 +0,0 @@
-composer install --dev
-./bin/developer dependencies:all || exit 1
-./bin/developer system:uninstall || exit 1
-cp -f hudson/connexion.inc config/ || exit 1
-cp -f hudson/_GV.php config/ || exit 1
-sudo mysql -e 'drop database ab_test;drop database db_test; drop database ab_unitTests; drop database db_unitTests;' || exit 1
-sudo mysql -e 'create database ab_test;create database db_test; create database ab_unitTests; create database db_unitTests;' || exit 1
-sudo mysql -e "GRANT ALL PRIVILEGES ON ab_unitTests.* TO 'phraseaUnitTests'@'localhost' IDENTIFIED BY 'iWvGxPE8' WITH GRANT OPTION" || exit 1
-sudo mysql -e "GRANT ALL PRIVILEGES ON db_unitTests.* TO 'phraseaUnitTests'@'localhost' IDENTIFIED BY 'iWvGxPE8' WITH GRANT OPTION" || exit 1
-sudo mysql -e "source `pwd`/hudson/fixtures.sql" || exit 1
-sudo mysql -e 'SET @@global.sql_mode= "";' || exit 1
diff --git a/hudson/InstallDBs.yml b/hudson/InstallDBs.yml
index 751ea33862..589c2c6724 100644
--- a/hudson/InstallDBs.yml
+++ b/hudson/InstallDBs.yml
@@ -1,7 +1,7 @@
database:
host: 127.0.0.1
- port: port
- user: phraseaUnitTests
+ port: 3306
+ user: phr_user
password: iWvGxPE8
- applicationBox: ab_unitTests
- dataBox: db_unitTests
+ ab_name: ab_setup_test
+ db_name: db_setup_test
diff --git a/lib/Alchemy/Phrasea/Application.php b/lib/Alchemy/Phrasea/Application.php
index 779175e4b9..62a23628e1 100644
--- a/lib/Alchemy/Phrasea/Application.php
+++ b/lib/Alchemy/Phrasea/Application.php
@@ -228,10 +228,8 @@ class Application extends SilexApplication
}
}
- $imagineDriver = $app['phraseanet.registry']->get('GV_imagine_driver');
-
- $configuration['ffmpeg.threads'] = $app['phraseanet.registry']->get('GV_ffmpeg_threads');
- $configuration['imagine.driver'] = $imagineDriver ?: null;
+ $configuration['ffmpeg.threads'] = $app['phraseanet.registry']->get('GV_ffmpeg_threads') ?: null;
+ $configuration['imagine.driver'] = $app['phraseanet.registry']->get('GV_imagine_driver') ?: null;
return $configuration;
});
diff --git a/lib/Alchemy/Phrasea/Command/Developer/IniReset.php b/lib/Alchemy/Phrasea/Command/Developer/IniReset.php
new file mode 100644
index 0000000000..73b544ecf1
--- /dev/null
+++ b/lib/Alchemy/Phrasea/Command/Developer/IniReset.php
@@ -0,0 +1,136 @@
+setDescription('Reset environment')
+ ->addOption('name', null, InputOption::VALUE_OPTIONAL, 'Databox name to reset, in case of multiple databox are mounted', null)
+ ->addOption('dependencies', null, InputOption::VALUE_NONE, 'Fetch dependencies', null)
+ ->addOption('v3.1', null, InputOption::VALUE_NONE, 'Reset with v3.1 fixtures', null)
+ ->addOption('uninstall', null, InputOption::VALUE_NONE, 'Uninstall Phraseanet', null);
+ ;
+ }
+
+ protected function doExecute(InputInterface $input, OutputInterface $output)
+ {
+ if (!$this->container['phraseanet.configuration']->isSetup()) {
+ throw new RuntimeException(sprintf(
+ 'Phraseanet is not setup. You can run bin/setup system::install command to install Phraseanet.'
+ ));
+ }
+
+ // get dbs
+ $conf = $this->container['phraseanet.configuration']->getConfig();
+ $dbs = array('ab' => $conf['main']['database']['dbname'], 'dbs' => array(), 'setup_dbs' => array());
+ foreach($this->container['phraseanet.appbox']->get_databoxes() as $databox) {
+ $dbs['dbs'][] = $databox->get_dbname();
+ }
+
+ //uninstall
+ if ($input->getOption('uninstall')) {
+ $command = $this->getApplication()->find('system:uninstall');
+
+ $output->writeln('Uninstalling...OK');
+ $input = new ArrayInput(array(
+ 'command' => 'system:uninstall'
+ ));
+ $command->run($input, $output);
+ }
+
+ //run composer
+ //run bower
+ if ($input->getOption('dependencies')) {
+ $command = $this->getApplication()->find('dependencies:composer');
+
+ $input = new ArrayInput(array(
+ 'command' => 'dependencies:composer'
+ ));
+ $command->run($input, $output);
+
+ $command = $this->getApplication()->find('dependencies:bower');
+
+ $input = new ArrayInput(array(
+ 'command' => 'dependencies:bower'
+ ));
+ $command->run($input, $output);
+ }
+
+ if (count($dbs['dbs']) > 1) {
+ if ($input->getOption('name')) {
+ $dbName = $input->getOption('name');
+ } else {
+ $dialog = $this->getHelperSet()->get('dialog');
+ $dbName = $dialog->ask(
+ $output,
+ _('Please enter the databox name to reset')
+ );
+ }
+ } else {
+ $dbName = current($dbs['dbs']);
+ }
+
+ $schema = $this->container['EM']->getConnection()->getSchemaManager();
+ $output->writeln('Creating database "'.$dbs['ab'].'"...OK');
+ $schema->dropAndCreateDatabase($dbs['ab']);
+ $output->writeln('Creating database "'.$dbName.'"...OK');
+ $schema->dropAndCreateDatabase($dbName);
+
+ // inject v3.1 fixtures
+ if ($input->getOption('v3.1')) {
+ $this->container['filesystem']->copy($this->container['root.path'].'/hudson/connexion.inc', $this->container['root.path'].'/config/connexion.inc');
+ $this->container['filesystem']->copy($this->container['root.path'].'/hudson/_GV.php', $this->container['root.path'].'/config/_GV.php');
+
+ $command = $this->getApplication()->find('dbal:import');
+
+ $content = file_get_contents($this->container['root.path'] . '/hudson/fixtures.sql');
+ $content = str_replace('ab_test', $dbs['ab'], $content);
+ $content = str_replace('db_test', $dbName, $content);
+
+ $tmpFile = tempnam(sys_get_temp_dir(), 'fixtures-v3.1-');
+ $this->container['filesystem']->dumpFile($tmpFile, $content);
+
+ $input = new ArrayInput(array(
+ 'command' => 'dbal:import',
+ 'file' => $tmpFile
+ ));
+
+ $verbosity = $output->getVerbosity();
+ $output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
+ $command->run($input, $output);
+ $output->setVerbosity($verbosity);
+ $output->writeln('Importing Phraseanet v3.1 fixtures...OK');
+ }
+
+ // create setup dbs
+ $command = $this->getApplication()->find('ini:setup-tests-dbs');
+ $input = new ArrayInput(array(
+ 'command' => 'ini:setup-tests-dbs'
+ ));
+ $command->run($input, $output);
+
+ return 0;
+ }
+}
diff --git a/lib/Alchemy/Phrasea/Command/Developer/SetupTestsDbs.php b/lib/Alchemy/Phrasea/Command/Developer/SetupTestsDbs.php
new file mode 100644
index 0000000000..b54874c04e
--- /dev/null
+++ b/lib/Alchemy/Phrasea/Command/Developer/SetupTestsDbs.php
@@ -0,0 +1,66 @@
+setDescription('Setup dbs for tests environment');
+ }
+
+ protected function doExecute(InputInterface $input, OutputInterface $output)
+ {
+ if (!$this->container['phraseanet.configuration']->isSetup()) {
+ throw new RuntimeException(sprintf(
+ 'Phraseanet is not setup. You can run bin/setup system::install command to install Phraseanet.'
+ ));
+ }
+
+ $settings = Yaml::parse(file_get_contents(__DIR__ . '/../../../../../hudson/InstallDBs.yml'));
+
+ $dbs = array();
+
+ $dbs[] = $settings['database']['ab_name'];
+ $dbs[] = $settings['database']['db_name'];
+
+ $schema = $this->container['EM']->getConnection()->getSchemaManager();
+
+ foreach($dbs as $name) {
+ $output->writeln('Creating database "'.$name.'"...OK');
+ $schema->dropAndCreateDatabase($name);
+ }
+
+ $this->container['EM']->getConnection()->executeUpdate('
+ GRANT ALL PRIVILEGES ON '.$settings['database']['ab_name'].'.* TO \''.$settings['database']['user'].'\'@\''.$settings['database']['host'].'\' IDENTIFIED BY \''.$settings['database']['password'].'\' WITH GRANT OPTION
+ ');
+
+ $this->container['EM']->getConnection()->executeUpdate('
+ GRANT ALL PRIVILEGES ON '.$settings['database']['db_name'].'.* TO \''.$settings['database']['user'].'\'@\''.$settings['database']['host'].'\' IDENTIFIED BY \''.$settings['database']['password'].'\' WITH GRANT OPTION
+ ');
+
+ $this->container['EM']->getConnection()->executeUpdate('SET @@global.sql_mode= ""');
+
+ return 0;
+ }
+}
diff --git a/lib/Alchemy/Phrasea/Core/Provider/LocaleServiceProvider.php b/lib/Alchemy/Phrasea/Core/Provider/LocaleServiceProvider.php
index 302d735e45..7b1263c652 100644
--- a/lib/Alchemy/Phrasea/Core/Provider/LocaleServiceProvider.php
+++ b/lib/Alchemy/Phrasea/Core/Provider/LocaleServiceProvider.php
@@ -22,7 +22,6 @@ class LocaleServiceProvider implements ServiceProviderInterface
$app['locale'] = $app->share(function (Application $app) {
return $app['phraseanet.registry']->get('GV_default_lng', 'en_GB');
});
-
$app['locale.I18n'] = $app->share(function (Application $app) {
$data = explode('_', $app['locale']);
diff --git a/lib/classes/module/console/systemUpgrade.php b/lib/classes/module/console/systemUpgrade.php
index a2b8c955c0..50f09e39ac 100644
--- a/lib/classes/module/console/systemUpgrade.php
+++ b/lib/classes/module/console/systemUpgrade.php
@@ -9,14 +9,8 @@
* file that was distributed with this source code.
*/
-/**
- * @todo write tests
- *
- * @package KonsoleKomander
- * @license http://opensource.org/licenses/gpl-3.0 GPLv3
- * @link www.phraseanet.com
- */
use Alchemy\Phrasea\Command\Command;
+use Alchemy\Phrasea\Core\Version;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
@@ -65,7 +59,7 @@ class module_console_systemUpgrade extends Command
}
if ($continue == 'y') {
- $output->write('Upgrading...', true);
+ $output->write(sprintf('Upgrading... from version %s to %s', $this->container['phraseanet.appbox']->get_version(), Version::getNumber()), true);
if (count(User_Adapter::get_wrong_email_users($this->container)) > 0) {
return $output->writeln(sprintf('You have to fix your database before upgrade with the system:mailCheck command '));
diff --git a/tests/Alchemy/Tests/Phrasea/Command/Setup/XSendFileMappingGeneratorTest.php b/tests/Alchemy/Tests/Phrasea/Command/Setup/XSendFileMappingGeneratorTest.php
index fe5d2d1b2c..1bbad508c0 100644
--- a/tests/Alchemy/Tests/Phrasea/Command/Setup/XSendFileMappingGeneratorTest.php
+++ b/tests/Alchemy/Tests/Phrasea/Command/Setup/XSendFileMappingGeneratorTest.php
@@ -6,10 +6,7 @@ use Alchemy\Phrasea\Command\Setup\XSendFileMappingGenerator;
class XSendFileMappingGeneratorTest extends \PhraseanetPHPUnitAbstract
{
- /**
- * @dataProvider provideVariousOptions
- */
- public function testRunWithoutProblems($option)
+ public function testRunWithoutProblems()
{
$input = $this->getMock('Symfony\Component\Console\Input\InputInterface');
$output = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
@@ -19,26 +16,13 @@ class XSendFileMappingGeneratorTest extends \PhraseanetPHPUnitAbstract
->with('type')
->will($this->returnValue('nginx'));
- $input->expects($this->any())
- ->method('getOption')
- ->with($this->isType('string'))
- ->will($this->returnValue($option));
-
$command = new XSendFileMappingGenerator();
$phpunit = $this;
self::$DI['cli']['monolog'] = self::$DI['cli']->share(function () use ($phpunit) {
return $phpunit->getMockBuilder('Monolog\Logger')->disableOriginalConstructor()->getMock();
});
- self::$DI['cli']['phraseanet.configuration'] = $this->getMock('Alchemy\Phrasea\Core\Configuration\ConfigurationInterface');
- if ($option) {
- self::$DI['cli']['phraseanet.configuration']->expects($this->once())
- ->method('offsetSet')
- ->with('xsendfile');
- } else {
- self::$DI['cli']['phraseanet.configuration']->expects($this->never())
- ->method('offsetSet');
- }
+
$command->setContainer(self::$DI['cli']);
$this->assertEquals(0, $command->execute($input, $output));
@@ -59,12 +43,4 @@ class XSendFileMappingGeneratorTest extends \PhraseanetPHPUnitAbstract
$this->setExpectedException('Alchemy\Phrasea\Exception\InvalidArgumentException');
$command->execute($input, $output);
}
-
- public function provideVariousOptions()
- {
- return array(
- array(true),
- array(false),
- );
- }
}
diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Root/RSSFeedTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Root/RSSFeedTest.php
index d08e5dd8cb..0c6a031353 100644
--- a/tests/Alchemy/Tests/Phrasea/Controller/Root/RSSFeedTest.php
+++ b/tests/Alchemy/Tests/Phrasea/Controller/Root/RSSFeedTest.php
@@ -166,6 +166,12 @@ class RSSFeedTest extends \PhraseanetWebTestCaseAbstract
if (self::$feed instanceof \Feed_Adapter) {
self::$feed->delete();
}
+ if (self::$public_feeds instanceof \Feed_Collection) {
+ self::$public_feeds->delete_data_from_cache();
+ }
+ if (self::$private_feeds instanceof \Feed_Collection) {
+ self::$public_feeds->delete_data_from_cache();
+ }
parent::tearDown();
}
@@ -226,8 +232,8 @@ class RSSFeedTest extends \PhraseanetWebTestCaseAbstract
protected function evaluateResponse200(Response $response)
{
- $this->assertEquals(200, $response->getStatusCode(), 'Test status code ');
- $this->assertEquals('UTF-8', $response->getCharset(), 'Test charset response');
+ $this->assertEquals(200, $response->getStatusCode(), $response);
+ $this->assertEquals('UTF-8', $response->getCharset(), $response);
}
public function testPublicFeed()
@@ -321,7 +327,7 @@ class RSSFeedTest extends \PhraseanetWebTestCaseAbstract
$this->assertTrue($feed->is_public());
}
$crawler = self::$DI['client']->request("GET", "/feeds/aggregated/rss/");
- $this->assertTrue(self::$DI['client']->getResponse()->isOk());
+ $this->assertTrue(self::$DI['client']->getResponse()->isOk(), self::$DI['client']->getResponse());
$this->assertEquals("application/rss+xml", self::$DI['client']->getResponse()->headers->get("content-type"));
$xml = self::$DI['client']->getResponse()->getContent();
$this->verifyXML($xml);
diff --git a/tests/Alchemy/Tests/Phrasea/Controller/SetupTest.php b/tests/Alchemy/Tests/Phrasea/Controller/SetupTest.php
index 83ad320264..19550178bb 100644
--- a/tests/Alchemy/Tests/Phrasea/Controller/SetupTest.php
+++ b/tests/Alchemy/Tests/Phrasea/Controller/SetupTest.php
@@ -41,10 +41,10 @@ class SetupTest extends \Silex\WebTestCase
public function testRouteSlashWhenInstalled()
{
- $this->app['phraseanet.configuration-tester']->expects($this->once())
+ $this->app['phraseanet.configuration-tester']->expects($this->any())
->method('isInstalled')
->will($this->returnValue(true));
- $this->app['phraseanet.configuration-tester']->expects($this->once())
+ $this->app['phraseanet.configuration-tester']->expects($this->any())
->method('isBlank')
->will($this->returnValue(false));
@@ -57,10 +57,10 @@ class SetupTest extends \Silex\WebTestCase
public function testRouteInstructionsWhenUpgradeRequired()
{
- $this->app['phraseanet.configuration-tester']->expects($this->once())
+ $this->app['phraseanet.configuration-tester']->expects($this->any())
->method('isInstalled')
->will($this->returnValue(false));
- $this->app['phraseanet.configuration-tester']->expects($this->once())
+ $this->app['phraseanet.configuration-tester']->expects($this->any())
->method('isBlank')
->will($this->returnValue(false));
@@ -75,7 +75,7 @@ class SetupTest extends \Silex\WebTestCase
{
$client = $this->createClient();
- $this->app['phraseanet.configuration-tester']->expects($this->once())
+ $this->app['phraseanet.configuration-tester']->expects($this->any())
->method('isBlank')
->will($this->returnValue(true));
@@ -88,7 +88,7 @@ class SetupTest extends \Silex\WebTestCase
{
$client = $this->createClient();
- $this->app['phraseanet.configuration-tester']->expects($this->once())
+ $this->app['phraseanet.configuration-tester']->expects($this->any())
->method('isBlank')
->will($this->returnValue(true));
@@ -111,37 +111,32 @@ class SetupTest extends \Silex\WebTestCase
->disableOriginalConstructor()
->getMock();
- $user->expects($this->exactly(2))
- ->method('get_id')
- ->will($this->returnValue(4));
-
- $acl = $this->getMockBuilder('ACL')
- ->disableOriginalConstructor()
- ->getMock();
- $acl->expects($this->once())
- ->method('get_granted_sbas')
- ->will($this->returnValue(array()));
-
- $user->expects($this->once())
- ->method('ACL')
- ->will($this->returnValue($acl));
-
$this->app['phraseanet.installer']->expects($this->once())
->method('install')
->will($this->returnValue($user));
+ $authenticator = $this->getMockBuilder('Alchemy\Phrasea\Authentication\Authenticator')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $session = $this->getMock('Entities\Session');
+
+ $authenticator->expects($this->once())
+ ->method('openAccount')
+ ->with($this->equalTo($user))
+ ->will($this->returnValue($session));
+
+ $this->app['authentication'] = $authenticator;
+
$client = $this->createClient();
$settings = Yaml::parse(file_get_contents(__DIR__ . '/../../../../../hudson/InstallDBs.yml'));
$settings = $settings['database'];
$host = isset($settings['host']) ? $settings['host'] : 'localhost';
$port = isset($settings['port']) ? $settings['port'] : '3306';
- $MySQLuser = isset($settings['user']) ? $settings['user'] : 'root';
- $MySQLpassword = isset($settings['password']) ? $settings['password'] : '';
- $abName = isset($settings['applicationBox']) ? $settings['applicationBox'] : null;
- $dbName = isset($settings['dataBox']) ? $settings['dataBox'] : null;
-
- $dataDir = sys_get_temp_dir() . '/datainstall/';
+ $user = isset($settings['user']) ? $settings['user'] : 'root';
+ $password = isset($settings['password']) ? $settings['password'] : '';
+ $abName = isset($settings['ab_name']) ? $settings['ab_name'] : null;
+ $dbName = isset($settings['db_name']) ? $settings['db_name'] : null;
$params = array(
'email' => 'user@example.org',
@@ -158,23 +153,22 @@ class SetupTest extends \Silex\WebTestCase
'binary_composite' => '/path/to/composite',
'binary_convert' => '/path/to/convert',
'binary_php' => '/path/to/php',
- 'datapath_noweb' => $dataDir . 'noweb',
+ 'datapath_noweb' => sys_get_temp_dir() . '/datainstall/noweb',
'ab_hostname' => $host,
'ab_port' => $port,
- 'ab_user' => $MySQLuser,
- 'ab_password' => $MySQLpassword,
+ 'ab_user' => $user,
+ 'ab_password' => $password,
'ab_name' => $abName,
'db_name' => $dbName,
- 'db_template' => 'en-simple',
+ 'db_template' => 'en',
'create_task' => array(),
'binary_phraseanet_indexer' => '/path/to/phraseanet_indexer',
);
- $crawler = $client->request('POST', '/setup/installer/install/', $params);
+ $client->request('POST', '/setup/installer/install/', $params);
$response = $client->getResponse();
-
$this->assertEquals(302, $response->getStatusCode());
- $this->assertTrue(false === strpos($response->headers->get('location'), '/setup/installer/'));
+ $this->assertTrue(false === strpos($response->headers->get('location'), '/setup/installer/'), $response);
}
public function testSetupProvidesPathTest()
diff --git a/tests/Alchemy/Tests/Phrasea/Form/Login/PhraseaRegisterFormTest.php b/tests/Alchemy/Tests/Phrasea/Form/Login/PhraseaRegisterFormTest.php
index e7e6775d88..0e5cf966a5 100644
--- a/tests/Alchemy/Tests/Phrasea/Form/Login/PhraseaRegisterFormTest.php
+++ b/tests/Alchemy/Tests/Phrasea/Form/Login/PhraseaRegisterFormTest.php
@@ -29,52 +29,76 @@ class PhraseaRegisterFormTest extends FormTestCase
public function testFormDoesRegisterValidFields()
{
$available = array(
- 'parameter' => array(
+ 'extra-parameter' => array(
'type' => 'text',
- 'label' => 'Yollah !',
+ 'label' => '',
),
- 'parameter2' => array(
+ 'extra-parameter2' => array(
'type' => 'text',
- 'label' => 'Yollah !',
+ 'label' => '',
)
);
$params = array(
array(
- 'name' => 'parameter',
+ 'name' => 'extra-parameter',
'required' => true
),
array(
- 'name' => 'parameter2',
+ 'name' => 'extra-parameter2',
'required' => true
)
);
+ $expected = array('email', 'password', 'provider-id', '_token', 'extraParameter','extraParameter2');
+
+ if (self::$DI['app']->hasTermsOfUse()) {
+ $expected[] = 'accept-tou';
+ }
+
+ if (!self::$DI['app']['phraseanet.registry']->get('GV_autoselectDB')) {
+ $expected[] = 'collections';
+ }
+
$form = new PhraseaRegisterForm(self::$DI['app'], $available, $params, new Camelizer());
- $this->assertCount(self::$DI['app']['phraseanet.registry']->get('GV_autoselectDB') ? 7 : 8, self::$DI['app']->form($form)->createView()->vars['form']->children);
+ foreach (array_keys(self::$DI['app']->form($form)->createView()->vars['form']->children) as $name) {
+ $this->assertContains($name, $expected);
+ }
}
public function testFormDoesNotRegisterNonValidFields()
{
$available = array(
- 'parameter' => array(
+ 'extra-parameter' => array(
'type' => 'text',
- 'label' => 'Yollah !',
+ 'label' => '',
)
);
$params = array(
array(
- 'name' => 'parameter',
+ 'name' => 'extra-parameter',
'required' => true
),
array(
- 'name' => 'parameter2',
+ 'name' => 'extra-parameter2',
'required' => true
)
);
+ $expected = array('email', 'password', 'provider-id', '_token', 'extraParameter');
+
+ if (self::$DI['app']->hasTermsOfUse()) {
+ $expected[] = 'accept-tou';
+ }
+
+ if (!self::$DI['app']['phraseanet.registry']->get('GV_autoselectDB')) {
+ $expected[] = 'collections';
+ }
+
$form = new PhraseaRegisterForm(self::$DI['app'], $available, $params, new Camelizer());
- $this->assertCount(self::$DI['app']['phraseanet.registry']->get('GV_autoselectDB') ? 6 : 7, self::$DI['app']->form($form)->createView()->vars['form']->children);
+ foreach (array_keys(self::$DI['app']->form($form)->createView()->vars['form']->children) as $name) {
+ $this->assertContains($name, $expected);
+ }
}
}