From 8b5006201115ae5dd5cdfad746c90bcf3222ba20 Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Tue, 29 Oct 2013 16:53:53 +0100 Subject: [PATCH] Fix tests --- lib/Alchemy/Phrasea/Controller/Root/Login.php | 4 ++-- .../Phrasea/Controller/Root/LoginTest.php | 24 +++++++++++-------- .../Form/Login/PhraseaRegisterFormTest.php | 4 ++-- tests/classes/PhraseanetPHPUnitAbstract.php | 2 +- ...seanetWebTestCaseAuthenticatedAbstract.php | 4 ++-- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/lib/Alchemy/Phrasea/Controller/Root/Login.php b/lib/Alchemy/Phrasea/Controller/Root/Login.php index 3117abfb97..6cfccd8e30 100644 --- a/lib/Alchemy/Phrasea/Controller/Root/Login.php +++ b/lib/Alchemy/Phrasea/Controller/Root/Login.php @@ -384,8 +384,8 @@ class Login implements ControllerProviderInterface $appbox_register = new \appbox_register($app['phraseanet.appbox']); - foreach ($selected as $base_id) { - if (false === $inscOK[$base_id] || $user->ACL()->has_access_to_base($base_id)) { + foreach ($inscOK as $base_id => $autorisation) { + if (false === $autorisation || $user->ACL()->has_access_to_base($base_id)) { continue; } diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Root/LoginTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Root/LoginTest.php index 4d66aecdfc..ba7dcf0af5 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Root/LoginTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Root/LoginTest.php @@ -515,6 +515,11 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $parameters[$key] = self::$email; } } + + if (self::$DI['app']['phraseanet.registry']->get('GV_autoselectDB')) { + unset($parameters['collections']); + } + $crawler = self::$DI['client']->request('POST', '/login/register-classic/', $parameters); $this->assertFalse(self::$DI['client']->getResponse()->isRedirect()); @@ -527,7 +532,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $crawler = self::$DI['client']->request('POST', '/login/register-classic/'); $this->assertFalse(self::$DI['client']->getResponse()->isRedirect()); - $this->assertFormOrFlashError($crawler, 8); + $this->assertFormOrFlashError($crawler, self::$DI['app']['phraseanet.registry']->get('GV_autoselectDB') ? 7 : 8); } public function provideInvalidRegistrationData() @@ -613,15 +618,6 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract ), "email" => $this->generateEmail(), "collections" => null - ), array(), 1), - array(array(//no demands - "password" => array( - 'password' => 'password', - 'confirm' => 'password' - ), - "email" => $this->generateEmail(), - "accept-tou" => '1', - "collections" => array() ), array(), 1) ); } @@ -955,6 +951,10 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract } } + if ( self::$DI['app']['phraseanet.registry']->get('GV_autoselectDB')) { + unset($parameters['collections']); + } + self::$DI['client']->request('POST', '/login/register-classic/', $parameters); if (false === $userId = \User_Adapter::get_usr_id_from_email(self::$DI['app'], $parameters['email'])) { @@ -1006,6 +1006,10 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract } } + if ( self::$DI['app']['phraseanet.registry']->get('GV_autoselectDB')) { + unset($parameters['collections']); + } + self::$DI['client']->request('POST', '/login/register-classic/', $parameters); if (false === $userId = \User_Adapter::get_usr_id_from_email(self::$DI['app'], $parameters['email'])) { diff --git a/tests/Alchemy/Tests/Phrasea/Form/Login/PhraseaRegisterFormTest.php b/tests/Alchemy/Tests/Phrasea/Form/Login/PhraseaRegisterFormTest.php index 331d75da26..e7e6775d88 100644 --- a/tests/Alchemy/Tests/Phrasea/Form/Login/PhraseaRegisterFormTest.php +++ b/tests/Alchemy/Tests/Phrasea/Form/Login/PhraseaRegisterFormTest.php @@ -51,7 +51,7 @@ class PhraseaRegisterFormTest extends FormTestCase $form = new PhraseaRegisterForm(self::$DI['app'], $available, $params, new Camelizer()); - $this->assertCount(8, self::$DI['app']->form($form)->createView()->vars['form']->children); + $this->assertCount(self::$DI['app']['phraseanet.registry']->get('GV_autoselectDB') ? 7 : 8, self::$DI['app']->form($form)->createView()->vars['form']->children); } public function testFormDoesNotRegisterNonValidFields() @@ -75,6 +75,6 @@ class PhraseaRegisterFormTest extends FormTestCase $form = new PhraseaRegisterForm(self::$DI['app'], $available, $params, new Camelizer()); - $this->assertCount(7, self::$DI['app']->form($form)->createView()->vars['form']->children); + $this->assertCount(self::$DI['app']['phraseanet.registry']->get('GV_autoselectDB') ? 6 : 7, self::$DI['app']->form($form)->createView()->vars['form']->children); } } diff --git a/tests/classes/PhraseanetPHPUnitAbstract.php b/tests/classes/PhraseanetPHPUnitAbstract.php index 0499a6aab8..a9d1208203 100644 --- a/tests/classes/PhraseanetPHPUnitAbstract.php +++ b/tests/classes/PhraseanetPHPUnitAbstract.php @@ -601,7 +601,7 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase $process = new Symfony\Component\Process\Process('php ' . $command); $process->run(); } catch (Symfony\Component\Process\Exception\RuntimeException $e) { - $this->fail('Unable to validate ORM schema'); + exit('Unable to validate ORM schema'); } self::$updated = true; diff --git a/tests/classes/PhraseanetWebTestCaseAuthenticatedAbstract.php b/tests/classes/PhraseanetWebTestCaseAuthenticatedAbstract.php index bbb9b4f70b..2d0f08a936 100644 --- a/tests/classes/PhraseanetWebTestCaseAuthenticatedAbstract.php +++ b/tests/classes/PhraseanetWebTestCaseAuthenticatedAbstract.php @@ -166,7 +166,7 @@ abstract class PhraseanetWebTestCaseAuthenticatedAbstract extends PhraseanetPHPU protected function assertFormOrFlashError(Crawler $crawler, $quantity) { - $total = $crawler->filter('form div:not(div[ng-show]) > div.popover.field-error')->count(); + $total = $crawler->filter('.field-error')->count(); $total += $crawler->filter('.alert')->count(); $this->assertEquals($quantity, $total); @@ -174,7 +174,7 @@ abstract class PhraseanetWebTestCaseAuthenticatedAbstract extends PhraseanetPHPU protected function assertFormError(Crawler $crawler, $quantity) { - $this->assertEquals($quantity, $crawler->filter('form div:not(div[ng-show]) > div.popover.field-error')->count()); + $this->assertEquals($quantity, $crawler->filter('.field-error')->count()); } protected function assertFlashMessage(Crawler $crawler, $flashType, $quantity, $message = null, $offset = 0)