From 616543e0d3435389f7c8f4c9c6f891b25fdc8454 Mon Sep 17 00:00:00 2001
From: Laurent Laffont <llaffont@afi-sa.fr>
Date: Mon, 1 Oct 2018 15:56:58 +0200
Subject: [PATCH] dev #59497 add select record in wall mode

---
 .../View/Helper/ListeNotices/Abstract.php     |  7 +++++
 .../ZendAfi/View/Helper/ListeNotices/Mur.php  | 28 ++++++++++++-----
 .../View/Helper/ListeNotices/Vignettes.php    |  9 +++---
 public/opac/css/global.css                    |  2 +-
 .../View/Helper/ListeNotices/MurTest.php      |  2 +-
 .../SearchSelection/SearchSelectionTest.php   | 30 +++++++++++++++++++
 6 files changed, 63 insertions(+), 15 deletions(-)

diff --git a/library/ZendAfi/View/Helper/ListeNotices/Abstract.php b/library/ZendAfi/View/Helper/ListeNotices/Abstract.php
index 6059efda377..79595eabf9c 100644
--- a/library/ZendAfi/View/Helper/ListeNotices/Abstract.php
+++ b/library/ZendAfi/View/Helper/ListeNotices/Abstract.php
@@ -20,6 +20,13 @@
  */
 abstract class ZendAfi_View_Helper_ListeNotices_Abstract extends ZendAfi_View_Helper_BaseHelper {
 
+  protected function _updatePreferences($preferences) {
+    return array_merge(['liste_codes' => 'TANE',
+                        'display_add_to_cart' => true,
+                        'display_select_record' => false],
+                       $preferences);
+  }
+
   protected function _divRecord($html, $record, $class) {
     return $this->_tag('div',
                        $html,
diff --git a/library/ZendAfi/View/Helper/ListeNotices/Mur.php b/library/ZendAfi/View/Helper/ListeNotices/Mur.php
index 77fd7869955..7f449efbc62 100644
--- a/library/ZendAfi/View/Helper/ListeNotices/Mur.php
+++ b/library/ZendAfi/View/Helper/ListeNotices/Mur.php
@@ -22,6 +22,7 @@ class ZendAfi_View_Helper_ListeNotices_Mur extends ZendAfi_View_Helper_ListeNoti
 
   public function ListeNotices_Mur($data, $preferences=[]) {
     $this->loadScript();
+    $preferences = $this->_updatePreferences($preferences);
 
     $notices = [];
     foreach($data as $notice)
@@ -35,9 +36,7 @@ class ZendAfi_View_Helper_ListeNotices_Mur extends ZendAfi_View_Helper_ListeNoti
 
 
   protected function _notice_mur($notice, $preferences=[]) {
-    $champs = isset($preferences['liste_codes'])
-      ? $preferences['liste_codes']
-      : 'TANE';
+    $champs = $preferences['liste_codes'];
 
     $datas = [$this->_tag('span',
                           $this->view->tagAnchor($this->view->urlNotice($notice, $preferences),
@@ -63,7 +62,7 @@ class ZendAfi_View_Helper_ListeNotices_Mur extends ZendAfi_View_Helper_ListeNoti
       . $this->_tag('div',
                     implode($datas),
                    ['class' => 'titre_auteur'])
-      . $this->barreDeLien($notice);
+      . $this->barreDeLien($notice, $preferences);
 
     $html = $this->_divRecord($html, $notice, 'notice');
 
@@ -73,11 +72,12 @@ class ZendAfi_View_Helper_ListeNotices_Mur extends ZendAfi_View_Helper_ListeNoti
   }
 
 
-  protected function barreDeLien($notice){
+  protected function barreDeLien($notice, $preferences){
     $html = [$this->_usersReviews($notice),
              $this->_adminsReviews($notice),
              $this->_socialNetwork($notice),
-             $this->barreDeLienPanier($notice),
+             $this->barreDeLienPanier($notice, $preferences),
+             $this->barreDeLienSelectCheckbox($notice, $preferences),
              $this->barreDeLienReserver($notice)];
 
     return implode([$this->_recordAvailability($notice),
@@ -143,7 +143,19 @@ class ZendAfi_View_Helper_ListeNotices_Mur extends ZendAfi_View_Helper_ListeNoti
   }
 
 
-  protected function barreDeLienPanier($notice) {
-    return $this->view->tag('li', $this->view->tagAddToCart($notice));
+  protected function barreDeLienPanier($notice, $preferences) {
+    return ($preferences['display_add_to_cart'])
+      ? $this->view->tag('li',
+                         $this->view->tagAddToCart($notice),
+                         ['class' => 'add_to_cart'])
+      : '';
   }
+
+
+  protected function barreDeLienSelectCheckbox($record, $preferences) {
+    return ($preferences['display_select_record'])
+      ? $this->_tag('li', $this->view->tagSelectRecord($record))
+      : '';
+	}
+
 }
\ No newline at end of file
diff --git a/library/ZendAfi/View/Helper/ListeNotices/Vignettes.php b/library/ZendAfi/View/Helper/ListeNotices/Vignettes.php
index db082fce1e4..cb9b011393a 100644
--- a/library/ZendAfi/View/Helper/ListeNotices/Vignettes.php
+++ b/library/ZendAfi/View/Helper/ListeNotices/Vignettes.php
@@ -25,10 +25,7 @@ class ZendAfi_View_Helper_ListeNotices_Vignettes extends ZendAfi_View_Helper_Lis
 
 	public function listeNotices_Vignettes($data, $preferences=[]) {
 		$this->loadScript();
-    $preferences = array_merge(['liste_codes' => 'TANE',
-                                'display_add_to_cart' => true,
-                                'display_select_record' => false],
-                               $preferences);
+    $preferences = $this->_updatePreferences($preferences);
 
 		$html = '';
 		foreach($data as $notice){
@@ -38,7 +35,9 @@ class ZendAfi_View_Helper_ListeNotices_Vignettes extends ZendAfi_View_Helper_Lis
                                     $preferences);
 		}
 
-		return $this->_tag('div', $html, ['class' => 'liste_vignettes']);
+		return $this->_tag('div',
+                       $html,
+                       ['class' => 'liste_vignettes']);
 	}
 
 
diff --git a/public/opac/css/global.css b/public/opac/css/global.css
index 1f6ff4f2bf6..9399658dc5a 100644
--- a/public/opac/css/global.css
+++ b/public/opac/css/global.css
@@ -2510,7 +2510,7 @@ button.vodeclic_link + img {
     background: url(../images/bouton/partager.png) no-repeat center  center;
 }
 
-.barre-de-lien li:first-child+li+li+li{
+.barre-de-lien li.add_to_cart {
     background: url(../../admin/images/picto/paniers_16.png) no-repeat center  center;
 }
 
diff --git a/tests/library/ZendAfi/View/Helper/ListeNotices/MurTest.php b/tests/library/ZendAfi/View/Helper/ListeNotices/MurTest.php
index 37d747b3dec..f8fb8e50367 100644
--- a/tests/library/ZendAfi/View/Helper/ListeNotices/MurTest.php
+++ b/tests/library/ZendAfi/View/Helper/ListeNotices/MurTest.php
@@ -255,7 +255,7 @@ class ZendAfi_View_Helper_ListeNotices_Mur_BarreDeLienTest extends ZendAfi_View_
 
   /** @test */
   public function barreDeLienShouldContainUrlAjoutPanier() {
-    $this->assertXPath($this->_html, '//a[contains(@href, "panier/add-record-ajax/id_notice/34")]', $this->_html);
+    $this->assertXPath($this->_html, '//li[@class="add_to_cart"]//a[contains(@href, "panier/add-record-ajax/id_notice/34")]', $this->_html);
   }
 
 
diff --git a/tests/scenarios/SearchSelection/SearchSelectionTest.php b/tests/scenarios/SearchSelection/SearchSelectionTest.php
index 74069182bed..c7f01e4d7ba 100644
--- a/tests/scenarios/SearchSelection/SearchSelectionTest.php
+++ b/tests/scenarios/SearchSelection/SearchSelectionTest.php
@@ -513,4 +513,34 @@ class SearchSelectionPostSwitchCartTest extends SearchSelectionAddToCartWithUser
   public function responseShouldBeARedirectToAddSelection() {
     $this->assertRedirectTo('/panier/add-selection');
   }
+}
+
+
+
+class SearchSelectionWithSessionViewWallModeTest extends SearchSelectionTestCase {
+  public function setUp() {
+    parent::setUp();
+
+    Class_Profil::getCurrentProfil()
+      ->setCfgModules(['recherche' =>
+                       ['resultatsimple' =>
+                        [
+                         'liste_format' => Class_Systeme_ModulesAppli::LISTE_FORMAT_MUR,
+                         'liste_codes' => "TAN9"]]]);
+
+    $this->dispatch('/recherche/simple/expressionRecherche/pomme/facettes/T3/page/1', true);
+  }
+
+
+  /** @test */
+  public function pageShouldContainsUCheckboxToSelectMilleniumRecord() {
+    $this->assertXPath('//ul[@class="barre-de-lien"]/li/input[@type="checkbox"][@value="9"][@name="select_record_9"]');
+  }
+
+
+  /** @test */
+  public function pageShouldNotIncludeLinkAddRecordAjaxOnBasket() {
+    $this->assertNotXPath('//a[contains(@href, "panier/add-record-ajax/")]');
+  }
+
 }
\ No newline at end of file
-- 
GitLab