From dbd53b11586b5fd9953619394a9bbcb59f539a56 Mon Sep 17 00:00:00 2001 From: lbrun <leo@sandbox.pergame.net> Date: Thu, 17 Mar 2016 11:58:15 +0100 Subject: [PATCH] hotline#39506: fix hours comparaison --- VERSIONS_HOTLINE/39506 | 1 + .../ZendAfi/View/Helper/Accueil/Library.php | 10 +--- .../Accueil/{Library.php => LibraryTest.php} | 48 +++++++++++++++++++ 3 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 VERSIONS_HOTLINE/39506 rename tests/library/ZendAfi/View/Helper/Accueil/{Library.php => LibraryTest.php} (84%) diff --git a/VERSIONS_HOTLINE/39506 b/VERSIONS_HOTLINE/39506 new file mode 100644 index 00000000000..148e7f3bebd --- /dev/null +++ b/VERSIONS_HOTLINE/39506 @@ -0,0 +1 @@ + - ticket #39506 : Boite bibliotheque: Erreur affichage ouverture en temps réel \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/Accueil/Library.php b/library/ZendAfi/View/Helper/Accueil/Library.php index dee04acbc70..324a3923539 100644 --- a/library/ZendAfi/View/Helper/Accueil/Library.php +++ b/library/ZendAfi/View/Helper/Accueil/Library.php @@ -64,10 +64,7 @@ class ZendAfi_View_Helper_Accueil_Library extends ZendAfi_View_Helper_Accueil_Ba $this->_('Fermé.') . $this->renderNextOuvertureForLibrary($library)); } - - - $hour = (int)date('H:i', $this->getCurrentTime()); - + $hour = date('H:i', $this->getCurrentTime()); $next_open_hour = ($hour >= $ouverture->getFinMatin()) ? $ouverture->getDebutApresMidi() @@ -76,16 +73,13 @@ class ZendAfi_View_Helper_Accueil_Library extends ZendAfi_View_Helper_Accueil_Ba if ($next_open_hour > $hour) return $this->renderClosed($this->_('Ouvrira à %s', $next_open_hour)); - $next_close_hour = ($ouverture->isJourneeContinue() || $hour >= $ouverture->getDebutApresMidi()) ? max($ouverture->getFinMatin(), $ouverture->getFinApresMidi()) : $ouverture->getFinMatin(); - if ($next_close_hour > $hour) return $this->renderOpened($this->_('Ouvert jusqu\'à %s', $next_close_hour)); - return $this->renderClosed( $this->_('Fermé depuis %s.', $next_close_hour) @@ -153,7 +147,5 @@ class ZendAfi_View_Helper_Accueil_Library extends ZendAfi_View_Helper_Accueil_Ba ? $ouverture->getDebutApresMidi() : $ouverture->getDebutMatin()); } - } - ?> \ No newline at end of file diff --git a/tests/library/ZendAfi/View/Helper/Accueil/Library.php b/tests/library/ZendAfi/View/Helper/Accueil/LibraryTest.php similarity index 84% rename from tests/library/ZendAfi/View/Helper/Accueil/Library.php rename to tests/library/ZendAfi/View/Helper/Accueil/LibraryTest.php index ddbeeaf0ca9..98a31966bc3 100644 --- a/tests/library/ZendAfi/View/Helper/Accueil/Library.php +++ b/tests/library/ZendAfi/View/Helper/Accueil/LibraryTest.php @@ -255,4 +255,52 @@ class ZendAfi_View_Helper_Accueil_LibraryOnTuesdayMorningTest extends ZendAfi_Vi utf8_encode('Ouvrira à 12:00')); } } + + + +abstract class ZendAfi_View_Helper_Accueil_LibraryWithHalfHoursTestCase extends ViewHelperTestCase { + protected + $_storm_default_to_volatile = true; + + public function setUp() { + parent::setUp(); + + $annecy = $this->fixture('Class_Bib', + ['id' => 1, + 'libelle' => 'Annecy', + 'ouvertures' => [ + Class_Ouverture::chaqueLundi('10:00', '12:30', '14:00', '18:30')]]); + + $params = ['type_module' => 'LIBRARY', + 'division' => 2, + 'preferences' => ['titre' => 'My library']]; + + $this->_helper = new ZendAfi_View_Helper_Accueil_Library(2, $params); + $this->_helper->setView(new ZendAfi_Controller_Action_Helper_View()); + } +} + + +class ZendAfi_View_Helper_Accueil_LibraryWithHalfHoursTest extends ZendAfi_View_Helper_Accueil_LibraryWithHalfHoursTestCase { + + public function setUp() { + parent::setUp(); + ZendAfi_View_Helper_Accueil_Library::setTimeSource(new TimeSourceForTest('2016-03-14 12:05:00')); + $this->html = $this->_helper->getBoite(); + } + + + /** @test */ + public function h2ShouldContainsAnnecy() { + $this->assertXPathContentContains($this->html, '//h2', 'Annecy'); + } + + + /** @test */ + public function annecyShouldContainsLibraryOpenedUntil1230() { + $this->assertXPathContentContains($this->html, + '//section[1]/p[@class="opened"]', + utf8_encode('Ouvert jusqu\'à 12:30')); + } +} ?> \ No newline at end of file -- GitLab