diff --git a/FEATURES/122158 b/FEATURES/122158 new file mode 100644 index 0000000000000000000000000000000000000000..0e9a92643d2455705d88c03b243e3a944fd02aad --- /dev/null +++ b/FEATURES/122158 @@ -0,0 +1,10 @@ + '122158' => + ['Label' => $this->_('Ajouter Une case à cocher dans formulaire de pré-inscription'), + 'Desc' => '[SIGB Nanook & Koha] Possibilité d'ajouter une case à cocher configurable dans le formulaire d\'inscription', + 'Image' => '', + 'Video' => '', + 'Category' => '', + 'Right' => function($feature_description, $user) {return true;}, + 'Wiki' => 'http://wiki.bokeh-library-portal.org/index.php?title=Pr%C3%A9inscription#Ajouter_une_case_.C3.A0_cocher_dans_le_formulaire', + 'Test' => '', + 'Date' => '2020-11-20'], diff --git a/VERSIONS_WIP/122158 b/VERSIONS_WIP/122158 new file mode 100644 index 0000000000000000000000000000000000000000..82195e51a0f2d865eae66cb0601d019b335df475 --- /dev/null +++ b/VERSIONS_WIP/122158 @@ -0,0 +1 @@ + - ticket #122158 : Formulaire de pré-inscription : possibilité d'ajouter une case à cocher lors de la validation du formulaire \ No newline at end of file diff --git a/library/Class/AdminVar.php b/library/Class/AdminVar.php index f7c7e831a67a9a8bacfa8335836627a09cf983a0..4e45f6442158b960b79c6a7b70ca96f97276f9bf 100644 --- a/library/Class/AdminVar.php +++ b/library/Class/AdminVar.php @@ -181,7 +181,7 @@ class Class_AdminVarLoader extends Storm_Model_Loader { 'NOTIFICATION_TEMPLATE_PREREGISTRATION' => Class_AdminVar_Meta::newEditor($this->_('Modèle utilisé pour les courriels d\'accueil d\'une préinscription.'), ['value'=> "Bonjour,<br><br><p>Votre demande d'inscription à <b>{library.libelle}</b> a bien été enregistrée.</p><p>Afin de finaliser votre inscription, merci de vous rendre dans votre médiathèque : <b>{library.adresse} {library.cp} {library.ville}</b></p>"]), - + 'PREREGISTRATION_CONDITIONS_MESSAGE' => Class_AdminVar_Meta::newEditor($this->_('Formulaire de préinscription : texte de la case à cocher permettant d\'accepter les conditions de validation.'), ['value' => '']), 'NOTIFICATION_TEMPLATE_NEW_REGISTRATION_SUBJECT' => Class_AdminVar_Meta::newDefault($this->_('Sujet des courriels d\'accueil des nouveaux utilisateurs.'), ['value'=> 'Demande d\'inscription: {profil.libelle}'])]; } diff --git a/library/Class/WebService/SIGB/PreRegistration.php b/library/Class/WebService/SIGB/PreRegistration.php index eea93eae9ca0fddb37a5e63326251158ffe15dd1..2b2fd7ceae8e875bd67186fba28803820912b9fd 100644 --- a/library/Class/WebService/SIGB/PreRegistration.php +++ b/library/Class/WebService/SIGB/PreRegistration.php @@ -21,6 +21,9 @@ class Class_WebService_SIGB_PreRegistration { + use Trait_Translator; + const REQUIRED_CHECKBOX_NAME = 'conditions_message'; + protected $_enabled, $_strategy, @@ -36,7 +39,18 @@ class Class_WebService_SIGB_PreRegistration { if (!$this->isEnabled()) return; - return $this->getStrategy()->getForm(); + $form = $this->getStrategy()->getForm(); + + if (!$validation_message = Class_AdminVar::get('PREREGISTRATION_CONDITIONS_MESSAGE')) + return $form; + + $form->addElement('requiredCheckbox', + static::REQUIRED_CHECKBOX_NAME, + ['label' => $validation_message ]); + + $form->addDisplayGroup(['conditions_message'], 'conditions', + ['legend' => $this->_('Conditions')]); + return $form; } @@ -73,6 +87,8 @@ class Class_WebService_SIGB_PreRegistration { public function send($data) { + if (isset($data[ static::REQUIRED_CHECKBOX_NAME ])) + unset($data[ static::REQUIRED_CHECKBOX_NAME ]); return $this->getStrategy()->send($data); } @@ -111,6 +127,7 @@ class Class_WebService_SIGB_PreRegistration { + class Class_WebService_SIGB_PreRegistrationAbstract { protected $_pre_registration; diff --git a/library/ZendAfi/Form/Element/RequiredCheckbox.php b/library/ZendAfi/Form/Element/RequiredCheckbox.php new file mode 100644 index 0000000000000000000000000000000000000000..66b4b719a05a5ba6dc213e6a80dfc3d57d0941ff --- /dev/null +++ b/library/ZendAfi/Form/Element/RequiredCheckbox.php @@ -0,0 +1,44 @@ +<?php +/** + * Copyright (c) 2012-2019, 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 ZendAfi_Form_Element_RequiredCheckbox extends Zend_Form_Element_Checkbox { + use Trait_Translator; + + protected + $_pick_button_label, + $_reset_button_label; + + public function init() { + $this->addValidator(new ZendAfi_Validate_Checked()); + } + + + public function __construct($spec, $options = null) { + parent::__construct($spec, array_merge($options, + ['required' =>true, + 'allowEmpty' => false + ]) + ); + + $this->getDecorator('Label')->setOption('escape', false); + } +} diff --git a/library/ZendAfi/Validate/Checked.php b/library/ZendAfi/Validate/Checked.php new file mode 100644 index 0000000000000000000000000000000000000000..61254df6b21c160d38a0b8eb31ab57f912ce8a1d --- /dev/null +++ b/library/ZendAfi/Validate/Checked.php @@ -0,0 +1,30 @@ +<?php +/** + * Copyright (c) 2012, 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 ZendAfi_Validate_Checked extends Zend_Validate_Abstract { + use Trait_Translator; + const NOT_CHECKED = 'notChecked'; + + protected $_messages = [self::NOT_CHECKED => "Cette case doit être cochée."]; + + public function isValid($value) { + return $value; + } +} diff --git a/library/ZendAfi/View/Helper/Bouton.php b/library/ZendAfi/View/Helper/Bouton.php index 02723d945a58315ddc8b9167540adbea690664a0..264cbf04f73a85e6f133dbb278609849d74cc7aa 100644 --- a/library/ZendAfi/View/Helper/Bouton.php +++ b/library/ZendAfi/View/Helper/Bouton.php @@ -74,6 +74,7 @@ class ZendAfi_View_Helper_Bouton extends ZendAfi_View_Helper_BaseHelper { $largeur="120px"; $onclick = 'var form=$(this).parents(\'form\'); if (!form.length) form=$(this).parents(\'.boutons\').prevAll(\'form\');if (!form.length) form=$(this).parents(\'.boutons\').nextAll(\'form\');'; + $onclick .= 'form.submit(); return false;'; } } diff --git a/library/ZendAfi/View/Helper/RenderForm.php b/library/ZendAfi/View/Helper/RenderForm.php index 989176dc4412e16c9463c8b674907e33b500a4b9..1168417af911b71294de16a49dec8c957641cfe8 100644 --- a/library/ZendAfi/View/Helper/RenderForm.php +++ b/library/ZendAfi/View/Helper/RenderForm.php @@ -160,11 +160,20 @@ class ZendAfi_View_Helper_RenderForm extends ZendAfi_View_Helper_BaseHelper { } + protected function _cleanOptions($decorator) { + $options = []; + if (($escape = $decorator->getOption('escape')) !== null) + $options['escape'] = $escape; + return $options; + } + + protected function _labelForTableRendering($element, $decorator, $newDecorators, $name) { $newDecorators[] = [['input_data' => 'HtmlTag'], ['tag' => 'td', 'class' => 'gauche']]; - $decorator->setOptions([]); + + $decorator->setOptions($this->_cleanOptions($decorator)); $decorator->setOption('wrap', ['tag' => 'td', 'attribs' => ['class' => 'droite']]); $newDecorators[$name] = $decorator; diff --git a/library/templates/Intonation/Template.php b/library/templates/Intonation/Template.php index ccf50abef823efcc4d670993c66a8a49e941b171..f1fc12337ae71a48ddb7c8498eeb71bdc6b1ff6f 100644 --- a/library/templates/Intonation/Template.php +++ b/library/templates/Intonation/Template.php @@ -103,6 +103,9 @@ class Intonation_Template extends Class_Template { protected function _findHydrateClasses($tag, $attrib_key, $attrib_value, $matches) { + if (is_array($attrib_value)) + $attrib_value = implode(' ',$attrib_value); + $dry_key = $tag . ' ' . $attrib_key . ' '. $attrib_value; if(isset($this->_hydrating_mapping_cache[$dry_key])) { diff --git a/library/templates/Intonation/View/RenderForm.php b/library/templates/Intonation/View/RenderForm.php index b1d21ddf7bbf72a32f0e3a0b57e4195c2c9d441e..b6322ac11b296bf93e692a06f8e8923c6be803ff 100644 --- a/library/templates/Intonation/View/RenderForm.php +++ b/library/templates/Intonation/View/RenderForm.php @@ -56,7 +56,8 @@ class Intonation_View_RenderForm extends ZendAfi_View_Helper_RenderForm { $newDecorators[] = [['input_data' => 'HtmlTag'], ['tag' => 'div', 'class' => 'col-12 col-sm']]; - $decorator->setOptions([]); + + $decorator->setOptions($this->_cleanOptions($decorator)); $newDecorators[$name] = $decorator; diff --git a/tests/application/modules/opac/controllers/AuthControllerPreRegistrationTest.php b/tests/application/modules/opac/controllers/AuthControllerPreRegistrationTest.php index 55e44d7eea24f6dc43284ebc29ced5e759f2e8cc..f5709df3af6575e5eaf11c4ea016d1f958ae4659 100644 --- a/tests/application/modules/opac/controllers/AuthControllerPreRegistrationTest.php +++ b/tests/application/modules/opac/controllers/AuthControllerPreRegistrationTest.php @@ -54,37 +54,7 @@ abstract class AuthControllerPreRegistrationKohaTestCase public function setUp() { parent::setUp(); - $this->fixture('Class_CodifAnnexe', - ['id' => 1, - 'id_bib' => 5, - 'id_origine' => 'GRA', - 'libelle' => 'Grans']); - - $this->fixture('Class_Bib', - ['id' => 5, - 'libelle' => 'Médiathèque de Grans', - 'adresse' => '1 rue proche de la mer', - 'cp' => '83756', - 'ville' => 'Juan les Pins']); - - $this->fixture('Class_IntBib', - ['id' => 1, - 'comm_params' => ['url_serveur' => 'http://catalogue.sanop318.biblibre.com/cgi-bin/koha/ilsdi.pl', - 'pre-registration' => 1], - 'comm_sigb' => Class_IntBib::COM_KOHA]); - - $this->fixture('Class_IntBib', - ['id' => 3, - 'comm_params' => ['url_serveur' => 'http://catalogue.sanop318.biblibre.com/cgi-bin/koha/ilsdi.pl', - 'pre-registration' => 1], - 'comm_sigb' => Class_IntBib::COM_KOHA]); - - Class_IntBib::find(1)->getSIGBComm()->setWebClient($this->mock_web_client); - Class_IntBib::find(3)->getSIGBComm()->setWebClient($this->mock_web_client); - - $this->mock_web_client - ->whenCalled('open_url') - ->answers(KohaFixtures::branches()); + $this->mock_web_client = KohaFixtures::mockWebClientForPreRegistration($this); } } @@ -106,62 +76,74 @@ class AuthControllerPreRegistrationKohaDispatchTest extends AuthControllerPreReg /** @test */ - public function selectBranchCodeShouldContainsOption1PipeGra() { - $this->assertXPath('//form//select[@name="branchcode"]/option[@value="1|GRA"]'); + public function selectBranchCodeShouldContainsOption41PipeGra() { + $this->assertXPath('//form//select[@name="branchcode"]/option[@value="41|GRA"]'); } /** @test */ - public function selectBranchCodeShouldContainsOption3PipeGra() { - $this->assertXPath('//form//select[@name="branchcode"]/option[@value="3|GRA"]'); + public function selectBranchCodeShouldContainsOption43PipeGra() { + $this->assertXPath('//form//select[@name="branchcode"]/option[@value="43|GRA"]'); } /** @test */ public function inputAntiSpamWebsiteForSpamBotsShouldBePresent() { - $this->assertXPath('//input[@name="website"][@data-spambots="true"][@autocomplete="off"]'); + $this->assertXPath('//input[@name="website"][@data-spambots="true"][@autocomplete="off"]'); } } -class AuthControllerPreRegistrationKohaPostDispatchTest extends AuthControllerPreRegistrationKohaTestCase { + +abstract class AuthControllerPreRegistrationKohaPostDispatchTestCase extends AuthControllerPreRegistrationKohaTestCase { + protected $_required_checkbox = false; + protected $_required_value = false; + public function setUp() { parent::setUp(); - $this->mock_web_client - ->whenCalled('postData') - ->with('http://catalogue.sanop318.biblibre.com/cgi-bin/koha/rest.pl/user', - ['data' => json_encode(['branchcode' => 'GRA', - 'surname' => 'Boulard', - 'firstname' => 'Thom', - 'dateofbirth' => '1940-09-15', - 'streetnumber' => '10', - 'address' => 'rue secret', - 'zipcode' => '01630', - 'city' => 'Gotham', - 'email' => 'thom@mail.com', - 'phone' => '0123456789'])]) - ->answers(KohaFixtures::successPreRegistration()); + $data = ['branchcode' => 'GRA', + 'surname' => 'Boulard', + 'firstname' => 'Thom', + 'dateofbirth' => '1940-09-15', + 'streetnumber' => '10', + 'address' => 'rue secret', + 'zipcode' => '01630', + 'city' => 'Gotham', + 'email' => 'thom@mail.com', + 'phone' => '0123456789']; + $this->mock_web_client = KohaFixtures::mockWebClientForPreRegistration($this,$data); + if ($this->_required_checkbox) + Class_AdminVar::set('PREREGISTRATION_CONDITIONS_MESSAGE', '<a href="#">Vous devez accepter les conditions de validation</a>'); + $values = []; + + if ($this->_required_checkbox) + $values = ['conditions_message' => $this->_required_value]; $this->postDispatch('auth/pre-registration', - ['branchcode' => '1|GRA', - 'surname' => 'Boulard', - 'firstname' => 'Thom', - 'dateofbirth' => '15-09-1940', - 'streetnumber' => '10', - 'address' => 'rue secret', - 'zipcode' => '01630', - 'city' => 'Gotham', - 'email' => 'thom@mail.com', - 'phone' => '0123456789', - 'website' => '']); + array_merge ($values, ['branchcode' => '41|GRA', + 'surname' => 'Boulard', + 'firstname' => 'Thom', + 'dateofbirth' => '15-09-1940', + 'streetnumber' => '10', + 'address' => 'rue secret', + 'zipcode' => '01630', + 'city' => 'Gotham', + 'email' => 'thom@mail.com', + 'phone' => '0123456789', + 'website' => ''])); } +} + + +class AuthControllerPreRegistrationKohaPostDispatchTest extends AuthControllerPreRegistrationKohaPostDispatchTestCase { + /** @test */ - public function responseShouldRedirectToPreRegistrationIdBibFive() { - $this->assertRedirectTo('http://localhost' . BASE_URL . '/auth/pre-registration-success/id_bib/5'); + public function responseShouldRedirectToPreRegistrationSuccessIdBibFortyFive() { + $this->assertRedirectTo('http://localhost' . BASE_URL . '/auth/pre-registration-success/id_bib/45'); } @@ -183,12 +165,39 @@ class AuthControllerPreRegistrationKohaPostDispatchTest extends AuthControllerPr +class AuthControllerPreRegistrationKohaWithRequiredCondtionChecked extends AuthControllerPreRegistrationKohaPostDispatchTestCase { + protected $_required_checkbox = true; + protected $_required_value = 1; + + /** @test */ + public function responseShouldRedirectToPreRegistrationSuccess() { + $this->assertRedirectTo('http://localhost' . BASE_URL . '/auth/pre-registration-success/id_bib/45'); + } +} + + + + +class AuthControllerPreRegistrationKohaWithRequiredCondtionNotChecked extends AuthControllerPreRegistrationKohaPostDispatchTestCase { + protected $_required_checkbox = true; + protected $_required_value = 0; + + + /** @test */ + public function formShouldContainsErrorMessageOnCheckbox() { + $this->assertXpathContentContains('//ul[@class="errors"]//li','Cette case doit être cochée'); + } +} + + + + class AuthControllerKohaPreRegistrationSpammedPostDispatchTest extends AuthControllerPreRegistrationKohaTestCase { public function setUp() { parent::setUp(); $this->postDispatch('auth/pre-registration', - ['branchcode' => '1|GRA', + ['branchcode' => '41|GRA', 'surname' => 'Boulard', 'firstname' => 'Thom', 'dateofbirth' => '15/09/1940', @@ -213,23 +222,21 @@ class AuthControllerPreRegistrationKohaPostDispatchWithErrorReturnedTest extends public function setUp() { parent::setUp(); - $this->mock_web_client - ->whenCalled('postData') - ->with('http://catalogue.sanop318.biblibre.com/cgi-bin/koha/rest.pl/user', - ['data' => json_encode(['branchcode' => 'GRA', - 'surname' => 'Boulard', - 'firstname' => 'Thom', - 'dateofbirth' => '1940-09-15', - 'streetnumber' => '10', - 'address' => 'rue secret', - 'zipcode' => '01630', - 'city' => 'Gotham', - 'email' => 'thom@mail.com', - 'phone' => '0123456789'])]) - ->answers(KohaFixtures::errorPreRegistration()); + $data = ['branchcode' => 'GRA', + 'surname' => 'Boulard', + 'firstname' => 'Thom', + 'dateofbirth' => '1940-09-15', + 'streetnumber' => '10', + 'address' => 'rue secret', + 'zipcode' => '01630', + 'city' => 'Gotham', + 'email' => 'thom@mail.com', + 'phone' => '0123456789']; + + $this->mock_web_client = KohaFixtures::mockWebClientForPreRegistration($this,null,$data); $this->postDispatch('auth/pre-registration', - ['branchcode' => '1|GRA', + ['branchcode' => '41|GRA', 'surname' => 'Boulard', 'firstname' => 'Thom', 'dateofbirth' => '15/09/1940', @@ -245,7 +252,7 @@ class AuthControllerPreRegistrationKohaPostDispatchWithErrorReturnedTest extends /** @test */ public function responseShouldRedirectToPreRegistrationErrorIdBibFive() { - $this->assertRedirectTo('http://localhost' . BASE_URL . '/auth/pre-registration/id_bib/5'); + $this->assertRedirectTo('http://localhost' . BASE_URL . '/auth/pre-registration/id_bib/45'); } } @@ -256,7 +263,7 @@ class AuthControllerPreRegistrationKohaSuccessDispatchTest extends AuthControlle public function setUp() { parent::setUp(); - $this->dispatch('/auth/pre-registration-success/id_bib/5', true); + $this->dispatch('/auth/pre-registration-success/id_bib/45', true); } @@ -301,6 +308,46 @@ abstract class AuthControllerPreRegistrationNanookTestCase + +class AuthControllerPreRegistrationNanookDispatchWithValidationTest + extends AuthControllerPreRegistrationNanookTestCase { + + public function setUp() { + parent::setUp(); + Class_AdminVar::set('PREREGISTRATION_CONDITIONS_MESSAGE', '<a href"#">Vous devez accepter les conditions de validation</a>'); + $this->postDispatch('/opac/auth/pre-registration', [],true); + + } + + + /** @test */ + public function formShouldContainsCheckboxErrorValidationMessage() { + $this->assertXpathContentContains('//ul[@class="errors"]//li','Cette case doit être cochée'); + } +} + + + + +class AuthControllerRegistrationWithConditionsTest extends AuthControllerPreRegistrationNanookTestCase { + + public function setUp() { + parent::setUp(); + Class_AdminVar::set('PREREGISTRATION_CONDITIONS_MESSAGE', '<a href="#">Vous devez accepter les conditions de validation</a>'); + $this->dispatch('/opac/auth/pre-registration'); + + } + + + /** @test */ + public function formChekBoxLabelShouldntBeEscaped() { + $this->assertXpathContentContains('//label//a[@href="#"]','Vous devez accepter les conditions de validation',$this->_response->getBody()); + } +} + + + + class AuthControllerPreRegistrationNanookDispatchTest extends AuthControllerPreRegistrationNanookTestCase { @@ -342,6 +389,7 @@ class AuthControllerPreRegistrationNanookDispatchTest + class AuthControllerPreRegistrationNanookPostDispatchTest extends AuthControllerPreRegistrationNanookTestCase { @@ -404,6 +452,7 @@ class AuthControllerPreRegistrationNanookPostDispatchTest + class AuthControllerPreRegistrationNanookPostDispatchErrorTest extends AuthControllerPreRegistrationNanookTestCase { @@ -447,6 +496,7 @@ class AuthControllerPreRegistrationNanookPostDispatchErrorTest + class AuthControllerPreRegistrationNanookPostDispatchErrorPatronPasswordNotSecureTest extends AuthControllerPreRegistrationNanookTestCase { @@ -496,6 +546,7 @@ class AuthControllerPreRegistrationNanookPostDispatchErrorPatronPasswordNotSecur + class AuthControllerPreRegistrationNanookPostDispatchSpamTest extends AuthControllerPreRegistrationNanookTestCase { @@ -525,6 +576,7 @@ class AuthControllerPreRegistrationNanookPostDispatchSpamTest + class AuthControllerPreRegistrationNanookSuccessDispatchTest extends AuthControllerPreRegistrationNanookTestCase { /** @test */ public function withSiteGivenShouldDisplayLibraryName() { @@ -547,7 +599,7 @@ class AuthControllerPreRegistrationWithNoPreRegistrationTest extends AuthControl public function setUp() { parent::setUp(); Class_IntBib::find(1)->setCommParams(['url_serveur' => 'http://super.nano.ok/ilsdi/arcadia', - 'pre-registration' => 0])->save(); + 'pre-registration' => 0])->save(); $this->dispatch('/opac/auth/pre-registration', true); } diff --git a/tests/fixtures/KohaFixtures.php b/tests/fixtures/KohaFixtures.php index ddc8a16b8d19ba98c748810b24f23f95d34ac21b..ff5aae8011f2e5af078c0b7b0c9c515139f28780 100644 --- a/tests/fixtures/KohaFixtures.php +++ b/tests/fixtures/KohaFixtures.php @@ -44,6 +44,60 @@ class KohaFixtures { } + public static function mockWebClientForPreRegistration($controller,$data_success = null, $data_error =null) { + $controller->fixture('Class_CodifAnnexe', + ['id' => 41, + 'id_bib' => 45, + 'id_origine' => 'GRA', + 'libelle' => 'Grans']); + + $controller->fixture('Class_Bib', + ['id' => 45, + 'libelle' => 'Médiathèque de Grans', + 'adresse' => '1 rue proche de la mer', + 'cp' => '83756', + 'ville' => 'Juan les Pins']); + + + Class_IntBib::newInstanceWithIdAssertSave(41, + ['comm_params' => + ['url_serveur' => 'http://catalogue.sanop318.biblibre.com/cgi-bin/koha/ilsdi.pl', + 'pre-registration' => 1], + 'comm_sigb' => Class_IntBib::COM_KOHA]); + Class_IntBib::newInstanceWithIdAssertSave(43, + ['comm_params' => + ['url_serveur' => 'http://catalogue.sanop318.biblibre.com/cgi-bin/koha/ilsdi.pl', + 'pre-registration' => 1], + 'comm_sigb' => Class_IntBib::COM_KOHA]); + + + $mock_web_client = $controller->mock(); + Class_IntBib::find(41)->getSIGBComm()->setWebClient($mock_web_client); + Class_IntBib::find(43)->getSIGBComm()->setWebClient($mock_web_client); + + $mock_web_client + ->whenCalled('open_url') + ->answers(static::branches()); + + if ($data_success) + $mock_web_client + ->whenCalled('postData') + ->with('http://catalogue.sanop318.biblibre.com/cgi-bin/koha/rest.pl/user', + ['data' => json_encode($data_success)]) + ->answers(static::successPreRegistration()); + + if ($data_error) + $mock_web_client + ->whenCalled('postData') + ->with('http://catalogue.sanop318.biblibre.com/cgi-bin/koha/rest.pl/user', + ['data' => json_encode($data_error)]) + ->answers(static::errorPreRegistration()); + + + return $mock_web_client; + } + + public static function mockTwoLoansPages($mock_web_client) { $params = ['url_serveur' => 'http://cat-aficg55.biblibre.com/cgi-bin/koha/ilsdi.pl', 'loans_per_page' => 1, diff --git a/tests/scenarios/Templates/TemplatesFormTest.php b/tests/scenarios/Templates/TemplatesFormTest.php new file mode 100644 index 0000000000000000000000000000000000000000..84ff8bfd71ba7b47d8e34d72a3d13b13c4c81c4b --- /dev/null +++ b/tests/scenarios/Templates/TemplatesFormTest.php @@ -0,0 +1,118 @@ +<?php +/** + * Copyright (c) 2012-2020, 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 + */ +require_once 'TemplatesTest.php'; +require_once 'tests/fixtures/KohaFixtures.php'; + +abstract class TemplatesFormPreRegistrationTestCase + extends TemplatesIntonationTestCase { + protected $_storm_default_to_volatile = true; + public function setUp() { + parent::setUp(); + ZendAfi_Auth::getInstance()->clearIdentity(); + $this->mock_transport = new MockMailTransport(); + Zend_Mail::setDefaultTransport($this->mock_transport); + + $this->mock_web_client = KohaFixtures::mockWebClientForPreRegistration($this); + Class_AdminVar::set('PREREGISTRATION_CONDITIONS_MESSAGE', '<a href="#">Vous devez accepter les conditions de validation</a>'); + } +} + + + + +class TemplatesFormPreRegistrationWithConditionsNotCheckedPostTest extends TemplatesFormPreRegistrationTestCase { + + public function setUp() { + parent::setUp(); + $this->postDispatch('/opac/auth/pre-registration', [],true); + } + + + /** @test */ + public function formShouldContainsErrorMessageOnCheckbox() { + $this->assertXpathContentContains('//ul[@class="errors"]//li','Cette case doit être cochée'); + } +} + + + + +class TemplatesFormPreRegistrationWithConditionsPostTest extends TemplatesFormPreRegistrationTestCase { + + public function setUp() { + parent::setUp(); + + $data = ['branchcode' => 'GRA', + 'surname' => 'Boulard', + 'firstname' => 'Thom', + 'dateofbirth' => '1940-09-15', + 'streetnumber' => '10', + 'address' => 'rue secret', + 'zipcode' => '01630', + 'city' => 'Gotham', + 'email' => 'thom@mail.com', + 'phone' => '0123456789']; + $this->mock_web_client = KohaFixtures::mockWebClientForPreRegistration($this,$data); + + $this->postDispatch('auth/pre-registration', + ['conditions_message' => 1, + 'branchcode' => '41|GRA', + 'surname' => 'Boulard', + 'firstname' => 'Thom', + 'dateofbirth' => '15-09-1940', + 'streetnumber' => '10', + 'address' => 'rue secret', + 'zipcode' => '01630', + 'city' => 'Gotham', + 'email' => 'thom@mail.com', + 'phone' => '0123456789', + 'website' => '']); + } + + + /** @test */ + public function responseShouldRedirectToPreRegistrationSuccessIdBibFive() { + $this->assertRedirectTo('http://localhost' . BASE_URL . '/auth/pre-registration-success/id_bib/45'); + } +} + + + + +class TemplatesFormPreRegistrationWithConditionsTest extends TemplatesFormPreRegistrationTestCase { + + public function setUp() { + parent::setUp(); + $this->dispatch('/opac/auth/pre-registration'); + } + + + /** @test */ + public function formPreRegistrationShouldBePresent() { + $this->assertXPath('//form//input[@name="surname"]'); + } + + + /** @test */ + public function formChekBoxLabelShouldntBeEscaped() { + $this->assertXpathContentContains('//label//a[@href="#"]','Vous devez accepter les conditions de validation',$this->_response->getBody()); + } +}