diff --git a/VERSIONS_HOTLINE/137883 b/VERSIONS_HOTLINE/137883 new file mode 100644 index 0000000000000000000000000000000000000000..82b93a38a10db0021071c050f969678a80b19c2b --- /dev/null +++ b/VERSIONS_HOTLINE/137883 @@ -0,0 +1 @@ + - ticket #137883 : SIGB Nanook : amélioration des tests sur l'ajout de cartes multiples dans le cas d'un numéro de carte partagé \ No newline at end of file diff --git a/tests/scenarios/MultiCards/MultiCardsAddCardTest.php b/tests/scenarios/MultiCards/MultiCardsAddCardTest.php new file mode 100644 index 0000000000000000000000000000000000000000..a930e1c1c6f8d0e42e99a93bfe84d670b21ed5a0 --- /dev/null +++ b/tests/scenarios/MultiCards/MultiCardsAddCardTest.php @@ -0,0 +1,337 @@ +<?php +/** + * Copyright (c) 2012-2021, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + + +class Scenario_AbonneMultiCardsAddCardActionTest extends AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + public function setUp() { + parent::setUp(); + $this->dispatch('/abonne/add-card'); + } + + + /** @test */ + public function titleShouldBeAddACard() { + $this->assertXPathContentContains('//title', 'Ajouter une carte'); + } + + + /** @test */ + public function formShouldContainsInputLogin() { + $this->assertXPath('//input[@type="text"][@name="login"]'); + } + + + /** @test */ + public function formShouldContainsInputPassword() { + $this->assertXPath('//input[@type="password"][@name="password"]'); + } + + + /** @test */ + public function formActionShouldBeAbonneAddCard() { + $this->assertXPath('//form[contains(@action, "/abonne/add-card")]'); + } + + + /** + * @test + * @see ZendAfi_View_Helper_Admin_RenderForm + */ + public function pageShouldContainsOnlyOneValidateButtons() { + $this->assertNotXPathContentContains('//script', '.clone().insertBefore("#opac-dialog'); + } +} + + + + +abstract class Scenario_AbonneMultiCardsAddCardPostTestCase extends AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + public function setUp() { + parent::setUp(); + + $death_star = $this->fixture(Class_Bib::class, + ['id' => 23, + 'libelle' => 'Death Star', + ]); + + $this->fixture(Class_Users::class, + ['id' => 1, + 'login' => 'darky', + 'password' => 'darkside', + 'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB, + 'idabon' => '12345', + 'date_fin' => '2016-12-25', + 'bib' => $death_star, + 'ordreabon' => 1, + 'id_sigb' => 1, + ]); + + $this->fixture(Class_Users::class, + ['id' => 2, + 'login' => 'luke', + 'password' => 'ilovelightsabers', + 'nom' => 'Skywalker', + 'prenom' => 'Luke', + 'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB, + 'idabon' => '6789', + 'date_fin' => '2016-11-01', + 'bib' => $death_star + ]); + } +} + + + + +class Scenario_AbonneMultiCardsAddCardLukeToDarkyTest extends Scenario_AbonneMultiCardsAddCardPostTestCase { + public function setUp() { + parent::setUp(); + ZendAfi_Auth::getInstance()->logUser(Class_Users::find(1)); + + $this->postDispatch('/abonne/add-card', + ['login' => 'luke', + 'password' => 'ilovelightsabers']); + + Class_Users::clearCache(); + } + + + /** @test */ + public function linkedCardWithIdOneShouldHaveBeenCreated() { + $this->assertNotNull($card = Class_LinkedCard::find(1)); + return $card; + } + + + /** + * @depends linkedCardWithIdOneShouldHaveBeenCreated + * @test + */ + public function linkedCardParentShouldBeDarky($card) { + $this->assertEquals('darky', $card->getParentCard()->getLogin()); + } + + + /** + * @depends linkedCardWithIdOneShouldHaveBeenCreated + * @test + */ + public function linkedCardChildShouldBeLuke($card) { + $this->assertEquals('luke', $card->getChildCard()->getLogin()); + } + + + /** @test */ + public function responseShouldRedirectToAddCard() { + $this->assertXPathContentContains('//script', 'location.reload();'); + } + + + /** @test */ + public function notificationShouldContainsCardAdded() { + $this->assertFlashMessengerContentContains('Carte de "Luke Skywalker" ajoutée'); + } + + + /** @test */ + public function darkyLinkedCardsShouldContainsLukesOne() { + $child_cards = new Storm_Collection(Class_Users::find(1)->getChildCards()); + $this->assertNotNull($child_cards->detect(function($card) + { + return 'luke' == $card->getLogin(); + })); + } + + + /** @test */ + public function lukeParentCardsShouldContainsDarkys() { + $parent_cards = new Storm_Collection(Class_Users::find(2)->getParentCards()); + $this->assertNotNull($parent_cards->detect(function($card) + { + return 'darky' == $card->getLogin(); + })); + } +} + + + + +class Scenario_AbonneMultiCardsAddCardValidationRulesTest extends Scenario_AbonneMultiCardsAddCardPostTestCase { + public function setUp() { + parent::setUp(); + ZendAfi_Auth::getInstance()->logUser(Class_Users::find(1)); + } + + + /** @test */ + public function userWithoutPasswordShouldBeWarned() { + Class_Users::getIdentity() + ->setPassword(null) + ->saveWithoutValidation(); + + $this->postDispatch('/abonne/add-card', + ['login' => 'luke', + 'password' => 'ilovelightsabers']); + + $this->assertFlashMessengerContentContains('Une erreur s\'est produite en ajoutant la carte de "Luke Skywalker" : Vous devez compléter le champ \'Mot de passe\''); + } + + + /** @test */ + public function darkyCannotAddHimself() { + $this->postDispatch('/abonne/add-card', + ['login' => 'darky', + 'password' => 'darkside']); + + $this->assertFalse(Class_Users::getIdentity()->hasChildCards()); + $this->assertFlashMessengerContentContains('Vous ne pouvez pas ajouter votre propre carte'); + } + + + /** @test */ + public function darkyShouldNotAddLukeTwice() { + Class_Users::getIdentity() + ->addChildCard(Class_Users::find(2)) + ->assertSave(); + + $this->postDispatch('/abonne/add-card', + ['login' => 'luke', + 'password' => 'ilovelightsabers']); + + $this->assertCount(1, Class_Users::getIdentity()->getChildCards()); + $this->assertFlashMessengerContentContains('Vous avez déjà ajouté la carte de "Luke Skywalker"'); + } + + + /** @test */ + public function darkyShouldNotAddLukeWithBadPassword() { + $this->postDispatch('/abonne/add-card', + ['login' => 'luke', + 'password' => 'ilovesushis']); + + $this->assertFalse(Class_Users::getIdentity()->hasChildCards()); + $this->assertFlashMessengerContentContains('Identifiant et/ou mot de passe incorrect'); + } + + + /** @test */ + public function darkyShouldNotAddAnUnknownEwok() { + $this->postDispatch('/abonne/add-card', + ['login' => 'e', + 'password' => 'wok']); + + $this->assertFalse(Class_Users::getIdentity()->hasChildCards()); + $this->assertFlashMessengerContentContains('Identifiant et/ou mot de passe incorrect'); + } + + + /** @test */ + public function withoutLoginAndPasswordPostShouldDisplayErrorsOnForm() { + $this->postDispatch('/abonne/add-card', + ['login' => '', + 'password' => '']); + $this->assertXPathCount('//li[contains(text(), "Une valeur est requise")]', 2); + } +} + + + + +class Scenario_AbonneMultiCardsAddCardFromNanookWithSameIdabonTest + extends Scenario_AbonneMultiCardsAddCardPostTestCase { + + public function setUp() { + parent::setUp(); + + $darky = Class_Users::find(1)->setLogin('12345') + ->setNom('darky') + ->setIdIntBib(23); + $darky->assertSave(); + + ZendAfi_Auth::getInstance()->logUser($darky); + + $comm_params = ['url_serveur' => 'http://localhost:8080/afi_Nanook/ilsdi/', + 'id_bib' => 23, + 'type' => Class_IntBib::COM_NANOOK]; + + $int_star = $this->fixture(Class_IntBib::class, + ['id' => 23, + 'sigb' => Class_IntBib::SIGB_NANOOK, + 'comm_params'=> $comm_params, + 'comm_sigb' => Class_IntBib::COM_NANOOK]); + + $this->fixture(Class_IntMajAuto::class, + ['id' => 1, + 'int_bib'=> $int_star, + 'profil_donnees' => $this->fixture(Class_IntProfilDonnees::class, + ['id' => 1, + 'type_fichier' => Class_IntProfilDonnees::FT_PATRONS])]); + + $nanook_service = $this->mock() + ->whenCalled('providesAuthentication')->answers(true) + ->whenCalled('hasNetworkError')->answers(false) + ->whenCalled('getServerRoot')->answers($comm_params['url_serveur']) + + ->whenCalled('getEmprunteur') + ->answers(Class_WebService_SIGB_Emprunteur::newInstance(2, 'marco') + ->setCodeBarres('12345') + ->setNom('marco') + ->setOrdre(2) + ->beValid()) + ; + + Class_WebService_SIGB_Nanook::setService($comm_params, $nanook_service); + + $this->postDispatch('/abonne/add-card', + ['login' => '12345', + 'password' => 'ilovedonuts']); + } + + + /** @test */ + public function linkedCardWithIdOneShouldHaveBeenCreated() { + $this->assertNotNull($card = Class_LinkedCard::find(1)); + return $card; + } + + + /** + * @depends linkedCardWithIdOneShouldHaveBeenCreated + * @test + */ + public function linkedCardParentShouldBeDarky($card) { + $this->assertEquals('darky', $card->getParentCard()->getNom()); + } + + + /** + * @depends linkedCardWithIdOneShouldHaveBeenCreated + * @test + */ + public function linkedCardChildShouldBeLuke($card) { + $this->assertEquals('marco', $card->getChildCard()->getNom()); + } +} diff --git a/tests/scenarios/MultiCards/MultiCardsTest.php b/tests/scenarios/MultiCards/MultiCardsTest.php index 8eaea5cd1d56dc993393c726de99956599661450..024b24b2131938ed377da513823f825e94989d19 100644 --- a/tests/scenarios/MultiCards/MultiCardsTest.php +++ b/tests/scenarios/MultiCards/MultiCardsTest.php @@ -211,49 +211,6 @@ class Scenario_AbonneMultiCardsWithCardsActionTest extends Scenario_AbonneMultiC -class Scenario_AbonneMultiCardsAddCardActionTest extends Scenario_AbonneMultiCardsTestCase { - public function setUp() { - parent::setUp(); - $this->dispatch('/abonne/add-card', true); - } - - - /** @test */ - public function titleShouldBeAddACard() { - $this->assertXPathContentContains('//title', 'Ajouter une carte'); - } - - - /** @test */ - public function formShouldContainsInputLogin() { - $this->assertXPath('//input[@type="text"][@name="login"]'); - } - - - /** @test */ - public function formShouldContainsInputPassword() { - $this->assertXPath('//input[@type="password"][@name="password"]'); - } - - - /** @test */ - public function formActionShouldBeAbonneAddCard() { - $this->assertXPath('//form[contains(@action, "/abonne/add-card")]'); - } - - - /** - * @test - * @see ZendAfi_View_Helper_Admin_RenderForm - */ - public function pageShouldContainsOnlyOneValidateButtons() { - $this->assertNotXPathContentContains('//script', '.clone().insertBefore("#opac-dialog', $this->_response->getBody()); - } -} - - - - class Scenario_AbonneMultiCardsWithCardsUnlinkActionTest extends Scenario_AbonneMultiCardsTestCase { public function setUp() { parent::setUp(); @@ -287,160 +244,6 @@ class Scenario_AbonneMultiCardsWithCardsUnlinkActionTest extends Scenario_Abonne -class Scenario_AbonneMultiCardsAddCardPostActionTest extends Scenario_AbonneMultiCardsTestCase { - public function setUp() { - parent::setUp(); - - ZendAfi_Auth::getInstance()->logUser(Class_Users::find(1)); - - $this->postDispatch('/abonne/add-card', - ['login' => 'luke', - 'password' => 'ilovelightsabers'] - ); - - Class_Users::clearCache(); - } - - - /** @test */ - public function linkedCardWithIdOneShouldHaveBeenCreated() { - $this->assertNotNull($card = Class_LinkedCard::find(1)); - return $card; - } - - - /** - * @depends linkedCardWithIdOneShouldHaveBeenCreated - * @test - */ - public function linkedCardParentShouldBeDarky($card) { - $this->assertEquals('darky', $card->getParentCard()->getLogin()); - } - - - /** - * @depends linkedCardWithIdOneShouldHaveBeenCreated - * @test - */ - public function linkedCardChildShouldBeLuke($card) { - $this->assertEquals('luke', $card->getChildCard()->getLogin()); - } - - - /** @test */ - public function responseShouldRedirectToAddCard() { - $this->assertXPathContentContains('//script', 'location.reload();'); - } - - - /** @test */ - public function notificationShouldContainsCardAdded() { - $this->assertFlashMessengerContentContains('Carte de "Luke Skywalker" ajoutée'); - } - - - /** @test */ - public function darkyLinkedCardsShouldContainsLukesOne() { - $child_cards = Class_Users::find(1)->getChildCards(); - $logins = array_map(function($card) {return $card->getLogin();}, - $child_cards); - $this->assertEquals(['luke'], - $logins); - } - - - /** @test */ - public function lukeParentCardsShouldContainsDarkys() { - $parent_cards = Class_Users::find(2)->getParentCards(); - $logins = array_map(function($card) {return $card->getLogin();}, - $parent_cards); - $this->assertEquals(['darky'], - $logins); - } -} - - - - -class Scenario_AbonneMultiCardsImpossiblePostActionTest extends Scenario_AbonneMultiCardsTestCase { - public function setUp() { - parent::setUp(); - ZendAfi_Auth::getInstance()->logUser(Class_Users::find(1)); - } - - /** @test */ - public function addWithCorruptedUserShouldReturnError() { - $user = Class_Users::getIdentity(); - $user->setPassword(null); - $user->saveWithoutValidation(); - - $this->postDispatch('/abonne/add-card', - ['login' => 'luke', - 'password' => 'ilovelightsabers']); - - $this->assertFlashMessengerContentContains('Une erreur s\'est produite en ajoutant la carte de "Luke Skywalker" : Vous devez compléter le champ \'Mot de passe\''); - } - - - /** @test */ - public function darkyShouldNotAddHimself() { - $this->postDispatch('/abonne/add-card', - ['login' => 'darky', - 'password' => 'darkside'] - ); - $this->assertCount(0, Class_Users::getIdentity()->getChildCards()); - $this->assertFlashMessengerContentContains('Vous ne pouvez pas ajouter votre propre carte'); - } - - - /** @test */ - public function darkyShouldNotAddTwoLukes() { - Class_Users::getIdentity() - ->addChildCard(Class_Users::find(2)) - ->assertSave(); - - $this->postDispatch('/abonne/add-card', - ['login' => 'luke', - 'password' => 'ilovelightsabers']); - - $this->assertCount(1, Class_Users::getIdentity()->getChildCards()); - $this->assertFlashMessengerContentContains('Vous avez déjà ajouté la carte de "Luke Skywalker"'); - } - - - /** @test */ - public function darkyShouldNotLukeWithBadPassword() { - $this->postDispatch('/abonne/add-card', - ['login' => 'luke', - 'password' => 'ilovesushis']); - - $this->assertCount(0, Class_Users::getIdentity()->getChildCards()); - $this->assertFlashMessengerContentContains('Identifiant et/ou mot de passe incorrect'); - } - - - /** @test */ - public function darkyShouldNotAddAnUnsubscribedEwok() { - $this->postDispatch('/abonne/add-card', - ['login' => 'e', - 'password' => 'wok']); - - $this->assertCount(0, Class_Users::getIdentity()->getChildCards()); - $this->assertFlashMessengerContentContains('Identifiant et/ou mot de passe incorrect'); - } - - - /** @test */ - public function withoutLoginAndPasswordPostShouldDisplayErrorsOnForm() { - $this->postDispatch('/abonne/add-card', - ['login' => '', - 'password' => '']); - $this->assertXPathCount('//li[contains(text(), "Une valeur est requise")]', 2); - } -} - - - abstract class Scenario_AbonneMultiCardsAccountOfEwokTestCase extends Scenario_AbonneMultiCardsTestCase { protected $_comm;