From 078b5857dea49e6735ad32f5cd12f2d58b769675 Mon Sep 17 00:00:00 2001
From: llaffont <llaffont@git-test.afi-sa.fr>
Date: Mon, 18 Nov 2013 22:38:30 +0000
Subject: [PATCH] La boite panier n'affiche pas les paniers dans les domaines
 pour les utilisateurs < modo bib

---
 .../opac/controllers/AbonneController.php     |  5 +--
 .../AbonneControllerPaniersTest.php           | 34 +++++++++++++++++--
 2 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/application/modules/opac/controllers/AbonneController.php b/application/modules/opac/controllers/AbonneController.php
index e8aaa77f638..53bfdfe9c02 100644
--- a/application/modules/opac/controllers/AbonneController.php
+++ b/application/modules/opac/controllers/AbonneController.php
@@ -863,8 +863,9 @@ class AbonneController extends ZendAfi_Controller_Action {
 		$this->_helper->viewRenderer->setNoRender();
 
 		$data = [];
-		$data[] = Class_Users::getIdentity()->getPaniersJson();
-		$data[] = (new Class_Catalogue())->getDomainesJson(['removeCheckbox' => true]);
+		$data[] = $this->_user->getPaniersJson();
+		if ($this->_user->canAccessBackend())
+			$data[] = (new Class_Catalogue())->getDomainesJson(['removeCheckbox' => true]);
 		$JSON = json_encode($data);
 
 		
diff --git a/tests/application/modules/opac/controllers/AbonneControllerPaniersTest.php b/tests/application/modules/opac/controllers/AbonneControllerPaniersTest.php
index 7161099d70f..c0146551087 100644
--- a/tests/application/modules/opac/controllers/AbonneControllerPaniersTest.php
+++ b/tests/application/modules/opac/controllers/AbonneControllerPaniersTest.php
@@ -34,6 +34,9 @@ class AbonneControllerPaniersForMarcusTest extends AbstractControllerTestCase {
 			->setPrenom('James')
 			->setNom('Bond');
 
+
+		ZendAfi_Auth::getInstance()->logUser($this->marcus);
+
 		$this->panier_bd = Class_PanierNotice::newInstanceWithId(2,
 																														 ['id_panier' => 1,
 																															'libelle' => 'Mes BD',
@@ -48,13 +51,15 @@ class AbonneControllerPaniersForMarcusTest extends AbstractControllerTestCase {
 		Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Catalogue')
 			->whenCalled('findTopCatalogues')
 			->answers([]);
-
-		$this->dispatch('abonne/get-paniers.json',true);
 	}
 
 
 	/** @test **/
-	public function getPaniersShouldReturnMarcusPanierAsJSON() {
+	public function getPaniersAsAdminShouldReturnMarcusPanierAsJSON() {
+		$this->marcus->beModoBib();
+
+		$this->dispatch('abonne/get-paniers.json',true);
+
 		$this->assertJsonStringEqualsJsonString(
 			$this->_response->getBody(), 
 			json_encode([
@@ -75,6 +80,29 @@ class AbonneControllerPaniersForMarcusTest extends AbstractControllerTestCase {
 			$this->_response->getBody());
 	}
 
+
+	/** @test **/
+	public function getPaniersAsInviteShouldReturnMarcusPanierWithoutDomainesAsJSON() {
+		$this->marcus->beInvite();
+
+		$this->dispatch('abonne/get-paniers.json',true);
+
+		$this->assertJsonStringEqualsJsonString(
+			$this->_response->getBody(), 
+			json_encode([
+										["id" => "panier_for_user",
+										 "label" => "Mes paniers",
+										 "categories" => [],
+										 "items" => [
+											 ["id" => 2,
+												"label" => "Mes BD",
+												"options" => ["ico" => BASE_URL."/public/admin/images/picto/paniers_16.png"]]],
+										 "options" => ["multipleSelection" => false]]
+										]),
+			$this->_response->getBody());
+	}
+
+
 }
 
 ?>
\ No newline at end of file
-- 
GitLab