From 515ae4aab45e4b0d036f56a218c5912b3ba6c047 Mon Sep 17 00:00:00 2001
From: llaffont <llaffont@git-test.afi-sa.fr>
Date: Sat, 14 Dec 2013 13:28:42 +0000
Subject: [PATCH] =?UTF-8?q?Fiche=20abonne:=20affiche=20les=20liens=20prets?=
 =?UTF-8?q?=20et=20reservations=20seulement=20si=20l'utilisateur=20connect?=
 =?UTF-8?q?=C3=A9=20est=20un=20abonn=C3=A9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 library/ZendAfi/View/Helper/Abonne/Prets.php  |  3 ++
 .../View/Helper/Abonne/Reservations.php       |  3 ++
 .../controllers/AbonneControllerFicheTest.php | 50 +++++++++++++++++--
 3 files changed, 53 insertions(+), 3 deletions(-)

diff --git a/library/ZendAfi/View/Helper/Abonne/Prets.php b/library/ZendAfi/View/Helper/Abonne/Prets.php
index b84a2d70a97..37af2feb8ab 100644
--- a/library/ZendAfi/View/Helper/Abonne/Prets.php
+++ b/library/ZendAfi/View/Helper/Abonne/Prets.php
@@ -20,6 +20,9 @@
  */
 class ZendAfi_View_Helper_Abonne_Prets extends ZendAfi_View_Helper_Abonne_Abstract {
 	public function abonne_prets($user) {
+		if (!$user->isAbonne())
+			return '';
+
 		$fiche_sigb = $user->getFicheSigb();
 		if (!isset($fiche_sigb['fiche']))
 			return '';
diff --git a/library/ZendAfi/View/Helper/Abonne/Reservations.php b/library/ZendAfi/View/Helper/Abonne/Reservations.php
index 061d1738cb7..406391dbfc0 100644
--- a/library/ZendAfi/View/Helper/Abonne/Reservations.php
+++ b/library/ZendAfi/View/Helper/Abonne/Reservations.php
@@ -20,6 +20,9 @@
  */
 class ZendAfi_View_Helper_Abonne_Reservations extends ZendAfi_View_Helper_Abonne_Abstract {
 	public function abonne_reservations($user) {
+		if (!$user->isAbonne())
+			return '';
+
 		$fiche_sigb = $user->getFicheSigb();
 		if (!isset($fiche_sigb['fiche']))
 			return '';
diff --git a/tests/application/modules/opac/controllers/AbonneControllerFicheTest.php b/tests/application/modules/opac/controllers/AbonneControllerFicheTest.php
index 415a8a60f85..005b2827a48 100644
--- a/tests/application/modules/opac/controllers/AbonneControllerFicheTest.php
+++ b/tests/application/modules/opac/controllers/AbonneControllerFicheTest.php
@@ -19,22 +19,66 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA 
  */
 
-class AbstractAbonneControllerFicheTest extends AbstractControllerTestCase {
+abstract class AbstractAbonneControllerFicheTest extends AbstractControllerTestCase {
 	public function setUp() {
 		parent::setUp();
 		$this->marcus = Class_Users::newInstanceWithId(10,
 																									 ['prenom' => 'Marcus',
-																										'nom' => 'Miller'])->beAdminPortail();
+																										'nom' => 'Miller']);
 		ZendAfi_Auth::getInstance()->logUser($this->marcus);
 	}
+}
+
+
+
+class AbonneControllerFicheAsAdminTest extends AbstractAbonneControllerFicheTest {
+	public function setUp() {
+		parent::setUp();
+		$this->marcus->beAdminPortail();
+		$this->dispatch('/abonne/fiche', true);
+	}
 
 
 	/** @test */
 	public function linkShouldToSuggestionAchatShouldBePresent() {
-		$this->dispatch('/abonne/fiche', true);
 		$this->assertXPathContentContains('//a[contains(@href, "/abonne/suggestion-achat")]', 
 																			'Suggérer un achat');
 	}
+
+
+	/** @test */
+	public function linkToPretsShouldNotBePresent() {
+		$this->assertNotXPath('//a[contains(@href, "/abonne/prets")]');
+	}
+
+
+	/** @test */
+	public function linkToReservationsShouldNotBePresent() {
+		$this->assertNotXPath('//a[contains(@href, "/abonne/reservations")]');
+	}
+}
+
+
+
+
+class AbonneControllerFicheAsAbonneTest extends AbstractAbonneControllerFicheTest {
+	public function setUp() {
+		parent::setUp();
+		$this->marcus->beAbonneSIGB();
+		$this->dispatch('/abonne/fiche', true);
+	}
+
+
+	/** @test */
+	public function linkToPretsShouldBePresent() {
+		$this->assertXPath('//a[contains(@href, "/abonne/prets")]');
+	}
+
+
+	/** @test */
+	public function linkToReservationsShouldNotBePresent() {
+		$this->assertXPath('//a[contains(@href, "/abonne/reservations")]');
+	}
 }
 
 
-- 
GitLab