From 99905017b4b97b3fcaf40c7f3cfc71249a663794 Mon Sep 17 00:00:00 2001
From: efalcy <efalcy@afi-sa.fr>
Date: Thu, 4 May 2017 12:16:49 +0200
Subject: [PATCH] hotline #59638: fix newsletter_dispatch creation when preview
 newsletter

---
 VERSIONS_HOTLINE/59638                                     | 1 +
 library/ZendAfi/Controller/Plugin/Manager/Newsletter.php   | 2 +-
 .../modules/admin/controllers/NewsletterControllerTest.php | 7 +++++++
 3 files changed, 9 insertions(+), 1 deletion(-)
 create mode 100644 VERSIONS_HOTLINE/59638

diff --git a/VERSIONS_HOTLINE/59638 b/VERSIONS_HOTLINE/59638
new file mode 100644
index 00000000000..21953bd86b6
--- /dev/null
+++ b/VERSIONS_HOTLINE/59638
@@ -0,0 +1 @@
+ - ticket #59638 : Newsletter envoi version antérieure
\ No newline at end of file
diff --git a/library/ZendAfi/Controller/Plugin/Manager/Newsletter.php b/library/ZendAfi/Controller/Plugin/Manager/Newsletter.php
index e755bb98021..628c2b034a7 100644
--- a/library/ZendAfi/Controller/Plugin/Manager/Newsletter.php
+++ b/library/ZendAfi/Controller/Plugin/Manager/Newsletter.php
@@ -72,7 +72,7 @@ function sendNewsletterClick(event) {
 
     $this->_addModelToView($newsletter);
 
-    $template = Class_Newsletter_Dispatch::newFrom($newsletter)->getTemplate();
+    $template = Class_Newsletter_Dispatch::newVolatileFrom($newsletter)->getTemplate();
     $mock_user = new Class_Entity();
     $mock_user->setId(0)->setMail('');
 
diff --git a/tests/application/modules/admin/controllers/NewsletterControllerTest.php b/tests/application/modules/admin/controllers/NewsletterControllerTest.php
index c194a39a9e1..cc0b03dd785 100644
--- a/tests/application/modules/admin/controllers/NewsletterControllerTest.php
+++ b/tests/application/modules/admin/controllers/NewsletterControllerTest.php
@@ -868,6 +868,7 @@ class Admin_NewsletterControllerPreviewActionTest extends Admin_NewsletterContro
     $this->assertXPath('//div//img[@src="zork.jpg"]', $this->_response->getBody());
   }
 
+
   /** @test */
   public function noticeShouldBePresent() {
     $this->assertQueryContentContains('p', 'Martine à la plage', $this->_response->getBody());
@@ -877,6 +878,12 @@ class Admin_NewsletterControllerPreviewActionTest extends Admin_NewsletterContro
   public function noticeMartineALaPlageUrlShouldBeRechercheViewNotice42() {
     $this->assertXPath('//a[@href="http://localhost' . BASE_URL . '/recherche/viewnotice/id/42"]');
   }
+
+  /** @test */
+  public function templateShouldNotCreateNewsletterDispatch() {
+    $this->assertEmpty(Class_Newsletter_Dispatch::findAll());
+  }
+
 }
 
 
-- 
GitLab