From 0b7f40076db1b14f737f8d5e545799ad24eed515 Mon Sep 17 00:00:00 2001 From: Alex Arnaud <alex.arnaud@biblibre.com> Date: Mon, 10 Feb 2025 12:24:37 +0100 Subject: [PATCH 1/2] hotline#218050 : cast posted activity quotas to integer --- VERSIONS_HOTLINE/218050 | 1 + library/Class/SessionActivityInscription.php | 8 +- ...ivityInscriptionControllerNoAdulteTest.php | 82 +++++++++++++++++++ ...ityInscriptionControllerNoChildrenTest.php | 82 +++++++++++++++++++ .../AbonneControllerWithQuotasTest.php | 4 +- 5 files changed, 171 insertions(+), 6 deletions(-) create mode 100644 VERSIONS_HOTLINE/218050 create mode 100644 tests/application/modules/admin/controllers/SessionActivityInscriptionControllerNoAdulteTest.php create mode 100644 tests/application/modules/admin/controllers/SessionActivityInscriptionControllerNoChildrenTest.php diff --git a/VERSIONS_HOTLINE/218050 b/VERSIONS_HOTLINE/218050 new file mode 100644 index 00000000000..7db72639c4e --- /dev/null +++ b/VERSIONS_HOTLINE/218050 @@ -0,0 +1 @@ + - correctif #218050 : [Activités] corrige le validateur du formulaire lorsque les quotas sont à zéro. \ No newline at end of file diff --git a/library/Class/SessionActivityInscription.php b/library/Class/SessionActivityInscription.php index d58729de0c6..039b25ce814 100644 --- a/library/Class/SessionActivityInscription.php +++ b/library/Class/SessionActivityInscription.php @@ -85,8 +85,8 @@ class Class_SessionActivityInscription extends Storm_Model_Abstract if (0 === $max_adulte) $this->checkAttribute('adults', - 0 === $this->getAdults(), - $this->_('Vous ne pouvez pas inscrire d\'adultes pour cette activitée')); + 0 === (int) $this->getAdults(), + $this->_('Vous ne pouvez pas inscrire d\'adultes pour cette activité')); return $this; } @@ -104,8 +104,8 @@ class Class_SessionActivityInscription extends Storm_Model_Abstract if (0 === $max_children) $this->checkAttribute('children', - 0 === $this->getChildren(), - $this->_('Vous ne pouvez pas inscrire d\'enfants pour cette activitée')); + 0 === (int) $this->getChildren(), + $this->_('Vous ne pouvez pas inscrire d\'enfants pour cette activité')); return $this; } diff --git a/tests/application/modules/admin/controllers/SessionActivityInscriptionControllerNoAdulteTest.php b/tests/application/modules/admin/controllers/SessionActivityInscriptionControllerNoAdulteTest.php new file mode 100644 index 00000000000..2f59ae65f60 --- /dev/null +++ b/tests/application/modules/admin/controllers/SessionActivityInscriptionControllerNoAdulteTest.php @@ -0,0 +1,82 @@ +<?php +/** + * Copyright (c) 2012-2024, 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 SessionActivityInscriptionControllerNoAdulteTest + extends Admin_AbstractControllerTestCase +{ + public function setUp(): void + { + parent::setUp(); + + Class_AdminVar::set('ACTIVITY_SESSION_QUOTAS', 1); + + $group = $this->fixture(Class_UserGroup::class, + ['id' => 12, + 'libelle' => 'Le groupe des activités', + 'rights' => [Class_UserGroup::RIGHT_SUIVRE_ACTIVITY]]); + + $this->fixture(Class_Users::class, + ['id' => 10, + 'nom' => 'Pistache', + 'prenom' => 'Amandine', + 'login' => 'Amd', + 'password' => 'fx9k', + 'mail' => 'pist@che.io', + 'user_groups' => [$group]]); + + $learn_haskell = $this->fixture(Class_Activity::class, + ['id' => 30, + 'libelle' => 'Learn Haskell', + 'description' => 'Learn useless things']); + + $this->fixture(Class_SessionActivity::class, + ['id' => 32, + 'activity' => $learn_haskell, + 'date_debut' => '2025-02-10', + 'date_fin' => '2025-03-29', + 'effectif_min' => 0, + 'effectif_max' => 0, + 'effectif_child_min' => 1, + 'effectif_child_max' => 5, + 'age_child_max' => 5, + 'effectif_inscription_max' => 0, + 'effectif_inscription_child_max' => 5, + 'duree'=> 8, + 'contenu' => 'Intro à la syntaxe', + 'horaires' => '9h - 12h, 13h - 18h', + 'date_limite_inscription'=>'2025-01-31']); + + $this->postDispatch('/admin/session-activity-inscription/subscribe/id/32/stagiaire_id/10', + ['adults' => '0', + 'children' => '2']); + + } + + /** @test */ + public function withQuotasAsStringSubscriptionShouldBeCreated() + { + $this + ->assertNotNull(Class_SessionActivityInscription::findFirstBy(['stagiaire_id' => 10, + 'session_activity_id' => 32])); + + } +} diff --git a/tests/application/modules/admin/controllers/SessionActivityInscriptionControllerNoChildrenTest.php b/tests/application/modules/admin/controllers/SessionActivityInscriptionControllerNoChildrenTest.php new file mode 100644 index 00000000000..8f75630c0ed --- /dev/null +++ b/tests/application/modules/admin/controllers/SessionActivityInscriptionControllerNoChildrenTest.php @@ -0,0 +1,82 @@ +<?php +/** + * Copyright (c) 2012-2024, 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 SessionActivityInscriptionControllerNoChildrenTest + extends Admin_AbstractControllerTestCase +{ + public function setUp(): void + { + parent::setUp(); + + Class_AdminVar::set('ACTIVITY_SESSION_QUOTAS', 1); + + $group = $this->fixture(Class_UserGroup::class, + ['id' => 12, + 'libelle' => 'Le groupe des activités', + 'rights' => [Class_UserGroup::RIGHT_SUIVRE_ACTIVITY]]); + + $this->fixture(Class_Users::class, + ['id' => 10, + 'nom' => 'Pistache', + 'prenom' => 'Amandine', + 'login' => 'Amd', + 'password' => 'fx9k', + 'mail' => 'pist@che.io', + 'user_groups' => [$group]]); + + $learn_haskell = $this->fixture(Class_Activity::class, + ['id' => 30, + 'libelle' => 'Learn Haskell', + 'description' => 'Learn useless things']); + + $this->fixture(Class_SessionActivity::class, + ['id' => 32, + 'activity' => $learn_haskell, + 'date_debut' => '2025-02-10', + 'date_fin' => '2025-03-29', + 'effectif_min' => 1, + 'effectif_max' => 5, + 'effectif_child_min' => 0, + 'effectif_child_max' => 0, + 'age_child_max' => 5, + 'effectif_inscription_max' => 5, + 'effectif_inscription_child_max' => 0, + 'duree'=> 8, + 'contenu' => 'Intro à la syntaxe', + 'horaires' => '9h - 12h, 13h - 18h', + 'date_limite_inscription'=>'2025-01-31']); + + $this->postDispatch('/admin/session-activity-inscription/subscribe/id/32/stagiaire_id/10', + ['adults' => '1', + 'children' => '0']); + + } + + /** @test */ + public function withQuotasAsStringSubscriptionShouldBeCreated() + { + $this + ->assertNotNull(Class_SessionActivityInscription::findFirstBy(['stagiaire_id' => 10, + 'session_activity_id' => 32])); + + } +} diff --git a/tests/scenarios/Activities/AbonneControllerWithQuotasTest.php b/tests/scenarios/Activities/AbonneControllerWithQuotasTest.php index 0c0c91ae8d6..5245a459e00 100644 --- a/tests/scenarios/Activities/AbonneControllerWithQuotasTest.php +++ b/tests/scenarios/Activities/AbonneControllerWithQuotasTest.php @@ -953,7 +953,7 @@ class Activities_AbonneControllerWithQuotasRegisterSessionTotalWithoutInscriptio $this->postDispatch('/abonne/inscrire-session/id/32', ['children' => 5]); - $this->assertFlashMessengerContentContains('Vous ne pouvez pas inscrire d\'enfants pour cette activitée'); + $this->assertFlashMessengerContentContains('Vous ne pouvez pas inscrire d\'enfants pour cette activité'); } @@ -997,7 +997,7 @@ class Activities_AbonneControllerWithQuotasRegisterSessionTotalWithoutInscriptio $this->postDispatch('/abonne/inscrire-session/id/32', ['adults' => 5]); - $this->assertFlashMessengerContentContains('Vous ne pouvez pas inscrire d\'adultes pour cette activitée'); + $this->assertFlashMessengerContentContains('Vous ne pouvez pas inscrire d\'adultes pour cette activité'); } } -- GitLab From 4f5f424c2f01b19530ee22f71c6e18cd408901f4 Mon Sep 17 00:00:00 2001 From: Alex Arnaud <alex.arnaud@biblibre.com> Date: Thu, 13 Feb 2025 09:00:40 +0100 Subject: [PATCH 2/2] hotline#218050 : cast session activity inscription values into setters --- VERSIONS_HOTLINE/218050 | 2 +- library/Class/SessionActivityInscription.php | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/VERSIONS_HOTLINE/218050 b/VERSIONS_HOTLINE/218050 index 7db72639c4e..8bfb6245cf5 100644 --- a/VERSIONS_HOTLINE/218050 +++ b/VERSIONS_HOTLINE/218050 @@ -1 +1 @@ - - correctif #218050 : [Activités] corrige le validateur du formulaire lorsque les quotas sont à zéro. \ No newline at end of file + - correctif #218050 : Activités : Ne pas afficher de message d'eereur si on ne renseigne pas un champ non obligatoire. \ No newline at end of file diff --git a/library/Class/SessionActivityInscription.php b/library/Class/SessionActivityInscription.php index 039b25ce814..925be0065eb 100644 --- a/library/Class/SessionActivityInscription.php +++ b/library/Class/SessionActivityInscription.php @@ -85,7 +85,7 @@ class Class_SessionActivityInscription extends Storm_Model_Abstract if (0 === $max_adulte) $this->checkAttribute('adults', - 0 === (int) $this->getAdults(), + 0 === $this->getAdults(), $this->_('Vous ne pouvez pas inscrire d\'adultes pour cette activité')); return $this; @@ -104,7 +104,7 @@ class Class_SessionActivityInscription extends Storm_Model_Abstract if (0 === $max_children) $this->checkAttribute('children', - 0 === (int) $this->getChildren(), + 0 === $this->getChildren(), $this->_('Vous ne pouvez pas inscrire d\'enfants pour cette activité')); return $this; @@ -816,6 +816,18 @@ class Class_SessionActivityInscription extends Storm_Model_Abstract } + public function setChildren($number) + { + return parent::setChildren((int) $number); + } + + + public function setAdults($number) + { + return parent::setAdults((int) $number); + } + + public function isEditable() { return Class_AdminVar::isActivitySessionQuotasEnabled() && ($session = $this->getSessionActivity()) -- GitLab