From a8da78b452ccfe40fd20b57e75d66c0504d2e27a Mon Sep 17 00:00:00 2001
From: gloas <gloas@afi-sa.fr>
Date: Fri, 20 Jan 2017 14:51:09 +0100
Subject: [PATCH] hotline #54111 add opening hours to library widget

---
 VERSIONS_HOTLINE/54111                          |  1 +
 library/ZendAfi/View/Helper/RenderLibrary.php   |  7 ++++---
 .../opac/controllers/BibControllerTest.php      | 17 ++++++++++++++++-
 3 files changed, 21 insertions(+), 4 deletions(-)
 create mode 100644 VERSIONS_HOTLINE/54111

diff --git a/VERSIONS_HOTLINE/54111 b/VERSIONS_HOTLINE/54111
new file mode 100644
index 00000000000..44120370aa9
--- /dev/null
+++ b/VERSIONS_HOTLINE/54111
@@ -0,0 +1 @@
+ - ticket #54111 : Boite bibliothèque : sélectionner le champ à afficher "horaire" affiche toutes les horaires, comme sur la fiche bibliothèque.
\ No newline at end of file
diff --git a/library/ZendAfi/View/Helper/RenderLibrary.php b/library/ZendAfi/View/Helper/RenderLibrary.php
index 80a993e248a..8ff9a635002 100644
--- a/library/ZendAfi/View/Helper/RenderLibrary.php
+++ b/library/ZendAfi/View/Helper/RenderLibrary.php
@@ -125,10 +125,11 @@ class ZendAfi_View_Helper_RenderLibrary extends ZendAfi_View_Helper_BaseHelper {
 
 
   protected function renderOpeningHours() {
-    if (!strlen($this->library->getHoraire()))
-      return '';
+    $openings = $this->library->getHoraire()
+      ? $this->library->getHoraire()
+      : $this->view->libraryOpenings($this->library);
 
-    return $this->_renderField($this->_escapeInfo($this->library->getHoraire()),
+    return $this->_renderField($this->_escapeInfo($openings),
                                'field-opening-hours');
   }
 
diff --git a/tests/application/modules/opac/controllers/BibControllerTest.php b/tests/application/modules/opac/controllers/BibControllerTest.php
index eb809290692..f6c3b788dce 100644
--- a/tests/application/modules/opac/controllers/BibControllerTest.php
+++ b/tests/application/modules/opac/controllers/BibControllerTest.php
@@ -592,7 +592,7 @@ class BibControllerBibViewAnnecyHideNewsTest extends BibControllerBibViewTestCas
 
 
 
-class BibControllerBibViewAnnecyRangeOpeningsTest extends BibControllerBibViewTestCase {
+abstract class BibControllerLibraryWithOpeningsTestCase extends BibControllerBibViewTestCase {
   public function setUp() {
     parent::setUp();
 
@@ -651,7 +651,15 @@ class BibControllerBibViewAnnecyRangeOpeningsTest extends BibControllerBibViewTe
                     'debut_apres_midi' => '00:00',
                     'fin_apres_midi' => '00:00',
                     'label' => 'Repos']);
+  }
+}
+
 
+
+
+class BibControllerBibViewAnnecyRangeOpeningsTest extends BibControllerLibraryWithOpeningsTestCase {
+  public function setUp() {
+    parent::setUp();
     $this->dispatch('bib/bibview/id/4', true);
   }
 
@@ -1261,6 +1269,7 @@ abstract class BibControllerWidgetPageTestCase extends BibControllerWithThreeBib
     $this->_preferences = ['titre' => 'Bibliotheques',
                            'libraries' => '4;1;2',
                            'nb_aff' => 3,
+                           'fields' => 'opening_hours',
                            'order' => Class_Systeme_ModulesAccueil_Library::ORDER_SELECTION,
                            'filters' => 'custom_field_7;custom_field_5;custom_field_3;opening;town;territory;search'];
 
@@ -1385,6 +1394,12 @@ class BibControllerWidgetPageSelectOpenLibrariesTest extends BibControllerWidget
   }
 
 
+  /** @test */
+  public function openingHoursShouldBePresent() {
+    $this->assertXPathContentContains('//div[@class="field-opening-hours"]//li', '10h - 12h');
+  }
+
+
   /** @test */
   public function widgetShouldRenderLibraryCran() {
     $this->assertXPathContentContains('//div[@class="boite library"]//section/h2', 'Cran');
-- 
GitLab