From ae9ae8596c1644b20ffe73438b4856b80b631bec Mon Sep 17 00:00:00 2001 From: Albin Date: Thu, 25 Jul 2024 22:50:03 +0200 Subject: [PATCH] afup#1482 on valide le raccourci pour valider sans espace --- htdocs/pages/administration/site_articles.php | 10 ++++++++++ .../features/Admin/Site/AdminSiteArticles.feature | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/htdocs/pages/administration/site_articles.php b/htdocs/pages/administration/site_articles.php index 969b7206d..c576a087b 100755 --- a/htdocs/pages/administration/site_articles.php +++ b/htdocs/pages/administration/site_articles.php @@ -31,6 +31,11 @@ $forumLabelsById[$forum['id']] = $forum['titre']; } +function checkSpaceValidation($value): bool +{ + return !preg_match('/(\s)/', $value); +} + if ($action == 'lister') { $list_champs = '*'; $list_ordre = 'date'; @@ -121,6 +126,11 @@ $formulaire->addRule('titre' , 'Titre manquant' , 'required'); $formulaire->addRule('contenu' , 'Contenu manquant' , 'required'); $formulaire->addRule('raccourci' , 'Raccourci manquant' , 'required'); + $formulaire->addRule('raccourci' , 'Ne doit pas contenir d\'espace' , 'regex', '/(?!\s)/'); + + $formulaire->registerRule('checkSpace', 'callback', 'checkSpaceValidation'); + $formulaire->addRule('raccourci', 'Ne doit pas contenir d\'espace', 'checkSpace', true); + if ($formulaire->validate()) { $article->id_site_rubrique = $formulaire->exportValue('id_site_rubrique'); diff --git a/tests/behat/features/Admin/Site/AdminSiteArticles.feature b/tests/behat/features/Admin/Site/AdminSiteArticles.feature index 60fc47d75..d73b3d8f4 100644 --- a/tests/behat/features/Admin/Site/AdminSiteArticles.feature +++ b/tests/behat/features/Admin/Site/AdminSiteArticles.feature @@ -44,3 +44,12 @@ Feature: Administration - Partie Site And I follow "supprimer_2" Then I should see "Liste des articles" But the ".content table" element should not contain "Le titre de l'article modifié" + + Scenario: Le raccourci ne doit pas contenir d'espace + Given I am logged in as admin and on the Administration + And I follow "Articles" + Then I should see "Liste des articles" + When I follow "Ajouter" + And I fill in "raccourci" with "un mauvais raccourci" + And I press "Ajouter" + Then the ".negative.message" element should contain "Ne doit pas contenir d'espace"