From 88112352c29186adde6f680a91350b4cea219814 Mon Sep 17 00:00:00 2001
From: efalcy <efalcy@git-test.afi-sa.fr>
Date: Thu, 8 Aug 2013 13:47:32 +0000
Subject: [PATCH] rel #7067 ajout de flash messenger sur le status de l'envoie
 de mail

---
 .../admin/controllers/CmsController.php        |  4 ++--
 library/Class/Article.php                      | 16 +++++++++++++---
 .../admin/controllers/CmsControllerTest.php    | 18 ++++++++++++++++++
 3 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/application/modules/admin/controllers/CmsController.php b/application/modules/admin/controllers/CmsController.php
index 4f4383e8917..a62843b20bb 100644
--- a/application/modules/admin/controllers/CmsController.php
+++ b/application/modules/admin/controllers/CmsController.php
@@ -174,7 +174,7 @@ class Admin_CmsController extends Zend_Controller_Action {
 			$article->setDomaineIds($domaine->getId());
 
 		if ($this->_isArticleSaved($article)) {
-			$this->_helper->notify('Article ajouté');
+			$this->_helper->notify('Article ajouté '.$article->getNotifyMessage());
 			$this->_redirect(sprintf('admin/cms/newsedit/id/%d', $article->getId()));
 			return;
 		}
@@ -199,7 +199,7 @@ class Admin_CmsController extends Zend_Controller_Action {
 		}
 
 		if ($this->_isArticleSaved($article)) {
-			$this->_helper->notify('Article sauvegardé');
+			$this->_helper->notify('Article sauvegardé '.$article->getNotifyMessage());
 			$this->_redirect(sprintf('admin/cms/newsedit/id/%d', $article->getId()));
 			return;
 		}
diff --git a/library/Class/Article.php b/library/Class/Article.php
index 1ecf3b977c5..075310826e4 100644
--- a/library/Class/Article.php
+++ b/library/Class/Article.php
@@ -392,6 +392,7 @@ class Class_Article extends Storm_Model_Abstract {
 	protected $_table_name = 'cms_article';
 	protected $_table_primary = 'ID_ARTICLE';
 	protected $old_status;
+	protected $notify_message;
 	protected $_has_many = ['traductions' => ['model' => 'Class_Article',
 																						'role' => 'article_original',
 																						'dependents' => 'delete'],
@@ -535,6 +536,10 @@ class Class_Article extends Storm_Model_Abstract {
 	}
 
 
+	public function getNotifyMessage() {
+		return $this->notify_message;
+	}
+
 	/**
 	 * @return string
 	 */
@@ -703,15 +708,20 @@ class Class_Article extends Storm_Model_Abstract {
 
 
 	protected function _sendMailToAuteur() {
+		xdebug_break();
 		$mail = new ZendAfi_Mail('utf8');
-		if(!$this->getAuteur())
+		if(!$this->getAuteur()) {
+			$this->notify_message.= 'Mail non envoyé: article sans auteur.';
 			return;
-		if(!$mail_address = $this->getAuteur()->getMail())
+		}
+		if(!$mail_address = $this->getAuteur()->getMail()) {
+			$this->notify_message.= 'Mail non envoyé: '.$this->getNomCompletAuteur().' sans mail.';
 			return;
+		}
 
 		$body = $this->getRefusMessage();
 		$body = str_replace('TITRE_ARTICLE',$this->getTitre(),$body);
-		$body = str_replace('URL_ARTICLE','\n'.$this->getStaticUrl().'\n',$body);
+		$body = str_replace('URL_ARTICLE',$this->getStaticUrl(),$body);
 		
 		$mail
 			->setFrom('no-reply@no-reply-afi.fr')
diff --git a/tests/application/modules/admin/controllers/CmsControllerTest.php b/tests/application/modules/admin/controllers/CmsControllerTest.php
index 8e560e99262..19a28d397f8 100644
--- a/tests/application/modules/admin/controllers/CmsControllerTest.php
+++ b/tests/application/modules/admin/controllers/CmsControllerTest.php
@@ -1042,6 +1042,24 @@ class CmsControllerNewsAddActionPostWithWorkflowTest extends CmsControllerTestCa
 		$this->assertEquals([$this->_article->getAuteur()->getMail()],$this->mock_transport->getSentMails()[0]->getRecipients());
 	}
 
+	/** @test */
+	public function statusBrouillonUpdatedToRefuserAndAuteurNotSetShouldNotifyMessagePasDAuteur() {
+		$this->_basePostDatas['auteur']='';
+		$this->postArticleRefuser();
+		$this->_article = $this->article_wrapper->getFirstAttributeForLastCallOn('save');
+		$this->assertEquals($this->_article->getNotifyMessage(), 'Mail non envoyé: article sans auteur.');
+	}
+
+
+	/** @test */
+	public function statusBrouillonUpdatedToRefuserAndAuteurWithOutMailShouldNotifyMessagePasDeMail() {
+		$this->_basePostDatas['auteur']->setMail('')->setLogin('Russe');
+		$this->postArticleRefuser();
+		$this->_article = $this->article_wrapper->getFirstAttributeForLastCallOn('save');
+		$this->assertEquals($this->_article->getNotifyMessage(), 'Mail non envoyé: Russe sans mail.');
+	}
+
+
 
 	/** @test */
 	public function sentMailToUserWhenRefusedShouldContainsDefaultTitle() {
-- 
GitLab