From 31716c3dcb147ed4ecba572712582f62b8e4be24 Mon Sep 17 00:00:00 2001 From: llaffont <llaffont@afi-sa.fr> Date: Mon, 30 Nov 2015 15:42:42 +0100 Subject: [PATCH] dev #31762 workflow notifications article pending mail can now contains current and next status --- .../admin/controllers/CmsController.php | 18 ++++++++++-------- library/Class/AdminVar.php | 2 +- library/Class/Article.php | 10 ++++++++++ .../admin/controllers/CmsControllerTest.php | 18 ++++++++++++++++++ 4 files changed, 39 insertions(+), 9 deletions(-) diff --git a/application/modules/admin/controllers/CmsController.php b/application/modules/admin/controllers/CmsController.php index ea60bdbe735..788b20d3574 100644 --- a/application/modules/admin/controllers/CmsController.php +++ b/application/modules/admin/controllers/CmsController.php @@ -321,15 +321,17 @@ class Admin_CmsController extends ZendAfi_Controller_Action { protected function prepareBodyMail($article, $message) { + $replacements = + ['TITRE_ARTICLE' => $article->getTitre(), + 'URL_ARTICLE' => $this->view->absoluteUrl($article->getUrl(), null, true), + 'AUTHOR_ARTICLE' => $article->getNomCompletAuteur(), + 'SAVED_BY_ARTICLE' => $this->identity->getNomComplet(), + 'NEXT_STATUS_ARTICLE' => $article->getNextWorkflowStatusLabel(), + 'STATUS_ARTICLE' => $article->getStatusLabel()]; + return - str_replace(['TITRE_ARTICLE', 'URL_ARTICLE', 'AUTHOR_ARTICLE', 'SAVED_BY_ARTICLE'], - - [ - $article->getTitre(), - $this->view->absoluteUrl($article->getUrl(), null, true), - $article->getNomCompletAuteur(), - $this->identity->getNomComplet(), - ], + str_replace(array_keys($replacements), + array_values($replacements), $message); } diff --git a/library/Class/AdminVar.php b/library/Class/AdminVar.php index befeb3d1a8d..49804fcacd6 100644 --- a/library/Class/AdminVar.php +++ b/library/Class/AdminVar.php @@ -193,7 +193,7 @@ class Class_AdminVarLoader extends Storm_Model_Loader { 'Les identifiants 1 à 5 sont réservés']), ['validate' => 'ZendAfi_Validate_WorkflowVar', 'after_save' => 'setWorkflowPermissions']), - 'WORKFLOW_TEXT_MAIL_ARTICLE_PENDING' => Class_AdminVar_Meta::newDefault($this->_('Contenu de l\'email de notification d\'article en attente de validation. Termes substitués: TITRE_ARTICLE, URL_ARTICLE, AUTHOR_ARTICLE, SAVED_BY_ARTICLE')), + 'WORKFLOW_TEXT_MAIL_ARTICLE_PENDING' => Class_AdminVar_Meta::newDefault($this->_('Contenu de l\'email de notification d\'article en attente de validation. Termes substitués: TITRE_ARTICLE, URL_ARTICLE, AUTHOR_ARTICLE, SAVED_BY_ARTICLE, STATUS_ARTICLE, NEXT_STATUS_ARTICLE')), 'WORKFLOW_TEXT_MAIL_ARTICLE_REFUSED' => Class_AdminVar_Meta::newDefault($this->_('Contenu de l\'email de notification de refus d\'un article à valider. Termes substitués: TITRE_ARTICLE, URL_ARTICLE, AUTHOR_ARTICLE, SAVED_BY_ARTICLE')), 'WORKFLOW_TEXT_MAIL_ARTICLE_VALIDATED' => Class_AdminVar_Meta::newDefault($this->_('Contenu de l\'email de notification de validation d\'un article. Termes substitués: TITRE_ARTICLE, URL_ARTICLE, AUTHOR_ARTICLE, SAVED_BY_ARTICLE')), diff --git a/library/Class/Article.php b/library/Class/Article.php index 65260057830..52c7dcc6617 100644 --- a/library/Class/Article.php +++ b/library/Class/Article.php @@ -1031,6 +1031,16 @@ class Class_Article extends Storm_Model_Abstract { } + public function getStatusLabel() { + return $this->getKnownStatus()[$this->getStatus()]; + } + + + public function getNextWorkflowStatusLabel() { + return $this->getKnownStatus()[$this->getNextWorkflowStatus()]; + } + + /** * @return bool */ diff --git a/tests/application/modules/admin/controllers/CmsControllerTest.php b/tests/application/modules/admin/controllers/CmsControllerTest.php index bcabf5d7fc0..d30f338f727 100644 --- a/tests/application/modules/admin/controllers/CmsControllerTest.php +++ b/tests/application/modules/admin/controllers/CmsControllerTest.php @@ -1796,6 +1796,11 @@ class CmsControllerNewsAddActionPostWithDynamicWorkflowTest extends CmsControll $this->fixture('Class_AdminVar', ['id' => 'WORKFLOW', 'valeur' => '[{"id":"12", "label":"A lire"}]']); + + + $this->fixture('Class_AdminVar', + ['id' => 'WORKFLOW_TEXT_MAIL_ARTICLE_PENDING', + 'valeur' => 'Un nouvel article de AUTHOR_ARTICLE est passé dans l\'état "STATUS_ARTICLE" et vous devez vérifier pour l\'état "NEXT_STATUS_ARTICLE". TITRE_ARTICLE URL_ARTICLE']); } @@ -1844,7 +1849,20 @@ class CmsControllerNewsAddActionPostWithDynamicWorkflowTest extends CmsControll $this->assertEquals(['admin@afi-sa.fr'], $this->mock_transport->getSentMails()[0]->getRecipients()); + + return quoted_printable_decode($this->mock_transport->getSentMails()[0]->getBodyText()->getContent()); + } + + + /** + * @depends newArticleSavedWithStatusPendingShouldSendMailToGroupTestingWithRights + * @test + */ + public function sentMailShouldContainsStatuses($content) { + $this->assertEquals('Un nouvel article de Mario Super est passé dans l\'état "À valider" et vous devez vérifier pour l\'état "A lire". Katsuhiro Otomo en dédicace ! http://localhost'.BASE_URL.'/cms/articleview/id/5', + $content); } + } -- GitLab