From 8e4b8eb484305a10e29f59e7782c5d677f34b365 Mon Sep 17 00:00:00 2001
From: llaffont <llaffont@git-test.afi-sa.fr>
Date: Thu, 17 Jan 2013 16:24:55 +0000
Subject: [PATCH] =?UTF-8?q?Suggestion=20d'achat:=20le=20num=C3=A9ro=20d'ab?=
 =?UTF-8?q?onn=C3=A9=20contient=20le=20lien=20sur=20la=20fiche=20abonn?=
 =?UTF-8?q?=C3=A9.=20Une=20action=20permet=20de=20r=C3=A9pondre=20par=20ma?=
 =?UTF-8?q?il=20si=20l'adresse=20est=20renseign=C3=A9e?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../scripts/suggestion-achat/index.phtml      | 18 ++++++++++++++-
 library/Class/SuggestionAchat.php             |  7 ++++++
 library/ZendAfi/View/Helper/BoutonIco.php     |  1 +
 .../admin/controllers/ModoControllerTest.php  | 23 +++++++++++++++----
 4 files changed, 44 insertions(+), 5 deletions(-)

diff --git a/application/modules/admin/views/scripts/suggestion-achat/index.phtml b/application/modules/admin/views/scripts/suggestion-achat/index.phtml
index c7743bbed6f..2df5f3480a7 100644
--- a/application/modules/admin/views/scripts/suggestion-achat/index.phtml
+++ b/application/modules/admin/views/scripts/suggestion-achat/index.phtml
@@ -12,7 +12,23 @@ echo $this->tagModelTable($this->suggestions,
 													['date_creation', 'titre', 'auteur', 'idabon', 'libelle_bib', 'compte'],
 
 													[ ['action' => 'suggestion-achat-edit', 'content' => $this->boutonIco('type=edit')],
+														function($model) { 
+															return ($model->hasUserMail())
+															 ? $this->boutonIco('type=MAIL', 
+																									'mailto='.$model->getUserMail().'?Subject='.rawurlencode($this->_('Suggestion d\'achat:').' '.$model->getTitre()))
+															 : '';
+														},
 														['action' => 'suggestion-achat-delete', 'content' => $this->boutonIco('type=del')] ],
 
-													'suggestions');
+													'suggestions',
+
+													null,
+
+													['idabon' => function($model) {
+															return $model->hasIdAbon()
+															  ? $this->tagAnchor(['controller' => 'users', 'action' => 'edit', 'id' => $model->getUser()->getId()],
+																									 $model->getIdAbon())
+															  : '0';
+														} 
+													]);
  } ?>
\ No newline at end of file
diff --git a/library/Class/SuggestionAchat.php b/library/Class/SuggestionAchat.php
index f6ee3828947..9e8f2831d84 100644
--- a/library/Class/SuggestionAchat.php
+++ b/library/Class/SuggestionAchat.php
@@ -118,5 +118,12 @@ class Class_SuggestionAchat extends Storm_Model_Abstract {
 		return '';
 	}
 
+
+	public function getUserMail() {
+		if (!$this->hasUser())
+			return '';
+		return $this->getUser()->getMail();
+	}
+
 }
 ?>
\ No newline at end of file
diff --git a/library/ZendAfi/View/Helper/BoutonIco.php b/library/ZendAfi/View/Helper/BoutonIco.php
index b5204e71172..8dc067871af 100644
--- a/library/ZendAfi/View/Helper/BoutonIco.php
+++ b/library/ZendAfi/View/Helper/BoutonIco.php
@@ -40,6 +40,7 @@ class ZendAfi_View_Helper_BoutonIco extends ZendAfi_View_Helper_BaseHelper
 				case "picto" : $picto=URL_ADMIN_IMG.$attrib[1]; break;
 				case "url" : $url=BASE_URL. "/". $attrib[1];
 				case "bulle" : $bulle=$this->traduire($attrib[1]);
+			  case "mailto" : $url='mailto:'.$attrib[1];
 				case "type" : // Types prédéterminés
 				$type=strtoupper($attrib[1]);
 
diff --git a/tests/application/modules/admin/controllers/ModoControllerTest.php b/tests/application/modules/admin/controllers/ModoControllerTest.php
index 0f3260d8a26..23058806b6d 100644
--- a/tests/application/modules/admin/controllers/ModoControllerTest.php
+++ b/tests/application/modules/admin/controllers/ModoControllerTest.php
@@ -84,7 +84,8 @@ abstract class ModoControllerSuggestionAchatTestCase extends Admin_AbstractContr
 													 ->setIdabon('3435')
 													 ->beAbonneSIGB()
 													 ->setPrenom('Petit')
-													 ->setNom('Poucet')),
+													 ->setNom('Poucet')
+													 ->setMail('ppoucet@gmail.com')),
 
 								 Class_SuggestionAchat::newInstanceWithId(3)
 								 ->setDateCreation('2012-03-02')
@@ -134,8 +135,9 @@ class ModoControllerSuggestionAchatActionTest extends ModoControllerSuggestionAc
 
 
 	/** @test */
-	public function firstRowTDShouldContainsIdAbon3435() {
-		$this->assertXPathContentContains('//tr[1]//td', '3435');		
+	public function firstRowTDShouldContainsIdAbon3435ThatLinksToEditUser6() {
+		$this->assertXPathContentContains('//tr[1]//td//a[contains(@href, "users/edit/id/6")]', 
+																			'3435');		
 	}
 
 
@@ -157,6 +159,12 @@ class ModoControllerSuggestionAchatActionTest extends ModoControllerSuggestionAc
 	}
 
 
+	/** @test */
+	public function firstRowActionsShouldContainsLinkToMailUser() {
+		$this->assertXPath('//tr[1]//td//a[@href="mailto:ppoucet@gmail.com?Subject=Suggestion%20d%27achat%3A%20Harry%20Potter"]');		
+	}
+
+
 	/** @test */
 	public function secondRowTDShouldContainsMillenium() {
 		$this->assertXPathContentContains('//tr[2]//td', 'Millenium');		
@@ -165,7 +173,7 @@ class ModoControllerSuggestionAchatActionTest extends ModoControllerSuggestionAc
 
 	/** @test */
 	public function thirdRowTDIdAbonShouldBeEmpty() {
-		$this->assertNotXPathContentContains('//tr[3]//td[4]', '0');		
+		$this->assertNotXPathContentContains('//tr[3]//td[4]', '0');
 	}
 
 
@@ -179,6 +187,13 @@ class ModoControllerSuggestionAchatActionTest extends ModoControllerSuggestionAc
 	public function fourthRowTDShouldContainsBibAnnecy() {
 		$this->assertXPathContentContains('//tr[3]//td[5]', 'Annecy');		
 	}
+
+
+	/** @test */
+	public function fourthRowActionsShouldNotContainsLinkToMailUser() {
+		$this->assertNotXPath('//tr[3]//td//a[contains(@href, "mailto")]');		
+	}
+
 }
 
 
-- 
GitLab