diff --git a/VERSIONS_HOTLINE/211010 b/VERSIONS_HOTLINE/211010 new file mode 100644 index 0000000000000000000000000000000000000000..5cb28b3936341e55b75879e8c94d556f04a35e55 --- /dev/null +++ b/VERSIONS_HOTLINE/211010 @@ -0,0 +1 @@ + - correctif #211010 : Agenda : Affiché la date la plus proche de la date courrante quand les Articles ont de multiples timings. \ No newline at end of file diff --git a/library/templates/Intonation/Library/View/Wrapper/Article.php b/library/templates/Intonation/Library/View/Wrapper/Article.php index 951577335bb370f1099c710513b2056d6108770c..8094c3f59f4cf549dd570361efe51c63f542071f 100644 --- a/library/templates/Intonation/Library/View/Wrapper/Article.php +++ b/library/templates/Intonation/Library/View/Wrapper/Article.php @@ -81,18 +81,33 @@ class Intonation_Library_View_Wrapper_Article extends Intonation_Library_View_Wr public function getDescription() { return $this->getBadges() - . $this->_view->tagArticleEvent($this->_model) + . $this->_descriptionEvent() . $this->_truncate($this->_model->getSummary()); } public function getFullDescription() { return $this->getBadges() - . $this->_view->tagArticleEvent($this->_model) + . $this->_descriptionEvent() . $this->_model->getSummaryWithCookiesConsent(); } + protected function _descriptionEvent(): string + { + $current_and_future_timings = (Class_AdminVar::isModuleEnabled('ENABLE_ARTICLES_TIMINGS') + && $this->_model->hasEventTimings()) + ? array_filter($this->_model->getEventTimings(), + fn($timing) => ! $timing->isPast()) + : []; + + return ($timing = reset($current_and_future_timings)) + ? $this->_view->article_RenderEventTiming($timing->getStart(), + $timing->getEnd()) + : $this->_view->tagArticleEvent($this->_model); + } + + public function getDescriptionTitle() { return $this->_('Résumé de l\'article "%s"', $this->_model->getTitre()); } diff --git a/tests/scenarios/ArticlesMultipleTimings/ArticlesMultipleTimingsDisabledOnAgendaViewTest.php b/tests/scenarios/ArticlesMultipleTimings/ArticlesMultipleTimingsDisabledOnAgendaViewTest.php new file mode 100644 index 0000000000000000000000000000000000000000..e4af0b8006375c4742fc27aefad4b4c3134aecec --- /dev/null +++ b/tests/scenarios/ArticlesMultipleTimings/ArticlesMultipleTimingsDisabledOnAgendaViewTest.php @@ -0,0 +1,105 @@ +<?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 ArticlesMultipleTimingsDisabledOnAgendaViewTest extends AbstractControllerTestCase +{ + + public function setUp() + { + parent::setUp(); + + Class_AdminVar::set('ENABLE_ARTICLES_TIMINGS', 0); + + $profile = $this->_buildTemplateProfil(['id' => 34, + 'template' => 'MUSCLE']); + + $profile_patcher = (new Class_Template_ProfilePatcher(null)) + ->setProfile($profile); + + $heure_du_conte = $this->fixture(Class_Article::class, + ['id' => 7, + 'titre' => 'Heure du conte', + 'contenu' => 'Pour les grands et petits', + 'description' => 'Une description.', + 'events_debut' => '2021-06-01 10:00:00', + 'events_fin' => '2021-06-15 16:00:00', + 'categorie' => $this->fixture(Class_ArticleCategorie::class, + ['id' => 3, + 'libelle' => 'Agenda'])]); + $heure_du_conte + ->addEventTiming($this->fixture(Class_Article_EventTiming::class, + ['id' => 1, + 'start' => '2021-06-05 10:00:00', + 'end' => '2021-06-05 11:00:00'])) + ->addEventTiming($this->fixture(Class_Article_EventTiming::class, + ['id' => 2, + 'start' => '2021-06-08 10:00:00', + 'end' => '2021-06-08 11:00:00'])) + ->addEventTiming($this->fixture(Class_Article_EventTiming::class, + ['id' => 3, + 'start' => '2021-06-15 10:00:00', + 'end' => '2021-06-15 11:00:00'])) + ->addEventTiming($this->fixture(Class_Article_EventTiming::class, + ['id' => 4, + 'start' => '2021-06-12 00:00:00', + 'end' => '2021-06-12 23:59:00'])) + ->addEventTiming($this->fixture(Class_Article_EventTiming::class, + ['id' => 5, + 'start' => '2021-06-13', + 'end' => '2021-06-13 23:59:00'])) + ->assertSave(); + + $this->onLoaderOfModel(Class_Article::class) + ->whenCalled('getArticlesByPreferences') + ->answers([$heure_du_conte]); + + $time_source = new TimeSourceForTest('2021-06-08 09:00:00'); + Class_Article_EventTiming::setTimeSource($time_source); + + $profile_patcher + ->addWidget(Intonation_Library_Widget_Carousel_Agenda_Definition::CODE, + Class_Profil::DIV_MAIN, + ['rendering' => 'card-description', + 'layout' => 'list', + 'size' => 1, + 'MuscleShowFooter' => 1, + 'link_to_all' => 1, + 'description_length' => 4]); + + $this->dispatch('/opac/widget/render/widget_id/1/profile_id/34'); + } + + + public function tearDown() + { + Class_Article_EventTiming::setTimeSource(null); + parent::tearDown(); + } + + + /** @test */ + public function spanCalendarEventDateShouldExistsWithEventDebut() + { + $this->assertXPathContentContains('//span[contains(@class, "calendar_event_date")]', + 'Du mardi 01 au mardi 15 juin 2021'); + } +} diff --git a/tests/scenarios/ArticlesMultipleTimings/ArticlesMultipleTimingsEnabledOnAgendaViewTest.php b/tests/scenarios/ArticlesMultipleTimings/ArticlesMultipleTimingsEnabledOnAgendaViewTest.php new file mode 100644 index 0000000000000000000000000000000000000000..c43123f4ba3afb24e4f8cf2f239a85faf55222b2 --- /dev/null +++ b/tests/scenarios/ArticlesMultipleTimings/ArticlesMultipleTimingsEnabledOnAgendaViewTest.php @@ -0,0 +1,111 @@ +<?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 ArticlesMultipleTimingsEnabledOnAgendaViewTest extends AbstractControllerTestCase +{ + + public function setUp() + { + parent::setUp(); + + Class_AdminVar::set('ENABLE_ARTICLES_TIMINGS', 1); + + $profile = $this->_buildTemplateProfil(['id' => 34, + 'template' => 'MUSCLE']); + + $profile_patcher = (new Class_Template_ProfilePatcher(null)) + ->setProfile($profile); + + $heure_du_conte = $this->fixture(Class_Article::class, + ['id' => 7, + 'titre' => 'Heure du conte', + 'contenu' => 'Pour les grands et petits', + 'description' => 'Une description.', + 'events_debut' => '2021-06-01 10:00:00', + 'events_fin' => '2021-06-15 16:00:00', + 'categorie' => $this->fixture(Class_ArticleCategorie::class, + ['id' => 3, + 'libelle' => 'Agenda'])]); + $heure_du_conte + ->addEventTiming($this->fixture(Class_Article_EventTiming::class, + ['id' => 1, + 'start' => '2021-06-05 10:00:00', + 'end' => '2021-06-05 11:00:00'])) + ->addEventTiming($this->fixture(Class_Article_EventTiming::class, + ['id' => 2, + 'start' => '2021-06-08 10:00:00', + 'end' => '2021-06-08 11:00:00'])) + ->addEventTiming($this->fixture(Class_Article_EventTiming::class, + ['id' => 3, + 'start' => '2021-06-15 10:00:00', + 'end' => '2021-06-15 11:00:00'])) + ->addEventTiming($this->fixture(Class_Article_EventTiming::class, + ['id' => 4, + 'start' => '2021-06-12 00:00:00', + 'end' => '2021-06-12 23:59:00'])) + ->addEventTiming($this->fixture(Class_Article_EventTiming::class, + ['id' => 5, + 'start' => '2021-06-13', + 'end' => '2021-06-13 23:59:00'])) + ->assertSave(); + + $this->onLoaderOfModel(Class_Article::class) + ->whenCalled('getArticlesByPreferences') + ->answers([$heure_du_conte]); + + $time_source = new TimeSourceForTest('2021-06-08 09:00:00'); + Class_Article_EventTiming::setTimeSource($time_source); + + $profile_patcher + ->addWidget(Intonation_Library_Widget_Carousel_Agenda_Definition::CODE, + Class_Profil::DIV_MAIN, + ['rendering' => 'card-description', + 'layout' => 'list', + 'size' => 1, + 'MuscleShowFooter' => 1, + 'link_to_all' => 1, + 'description_length' => 4]); + + $this->dispatch('/opac/widget/render/widget_id/1/profile_id/34'); + } + + + public function tearDown() + { + Class_Article_EventTiming::setTimeSource(null); + parent::tearDown(); + } + + + /** @test */ + public function spanCalendarEventDateShouldNotExists() + { + $this->assertNotXPath('//span[contains(@class, "calendar_event_date")]'); + } + + + /** @test */ + public function timing2021_06_08ShouldBeDisplayed() + { + $this->assertXPathContentContains('//div', 'mardi 08 juin 2021 de 10:00 à 11:00'); + } +}