Commit 72990edc authored by efalcy's avatar efalcy

hotline #59638: modify button and message for newsletter sending confirmation

parent 99905017
Pipeline #1401 failed with stage
in 5 minutes and 24 seconds
- ticket #59638 : Newsletter envoi version antérieure
\ No newline at end of file
- ticket #59638 : Bug newsletter sur l'envoi de version antérieure , modification du message de confirmation avant l'envoi
\ No newline at end of file
......@@ -103,11 +103,18 @@ class Class_Newsletter extends Storm_Model_Abstract {
->run();
}
public function getDispatchIfNotEnded() {
return (($dispatch = $this->getLastDispatch()) &&
$dispatch->isRunnable())
? $dispatch : false;
}
protected function _getOrCreateDispatchToRun() {
return ($dispatch = $this->getLastDispatch()) && $dispatch->isRunnable()
? $dispatch->resetError()
: Class_Newsletter_Dispatch::newFrom($this);
if ($dispatch = $this->getDispatchIfNotEnded())
return $dispatch->resetError();
return Class_Newsletter_Dispatch::newFrom($this);
}
......
......@@ -22,6 +22,8 @@
class ZendAfi_Controller_Plugin_Manager_Newsletter extends ZendAfi_Controller_Plugin_Manager_Manager {
public function getActions($model) {
$existing_dispatch = $model->getDispatchIfNotEnded();
return [
['url' => '/admin/newsletter/edit/id/%s',
'icon' => 'edit',
......@@ -39,12 +41,14 @@ class ZendAfi_Controller_Plugin_Manager_Newsletter extends ZendAfi_Controller_Pl
['url' => '/admin/newsletter/send/id/%s',
'icon' => 'mail',
'anchorOptions' => ['rel' => 'send'],
'caption' => function($model)
'caption' => function($model) use ($existing_dispatch)
{
Class_ScriptLoader::getInstance()->addJQueryReady("
function sendNewsletterClick(event) {
var target = $(event.target).closest('a');
var answer = confirm(\"".$this->_("Envoyer la lettre d'information ?")."\");
var answer = confirm(\"". ($existing_dispatch ?
$this->_("Reprendre l'envoi de la lettre d'information: %s ? ",$existing_dispatch->getTitle())
: $this->_("Envoyer la lettre d'information ?"))."\");
if (answer == false) {
event.preventDefault();
return;
......@@ -53,7 +57,10 @@ function sendNewsletterClick(event) {
$(\"a[rel='send']\").click(sendNewsletterClick);
");},
'label' => 'Envoyer la lettre d\'information'],
'label' => ($existing_dispatch ?
$this->_('Reprendre l\'envoi en cours')
: $this->_('Envoyez la lettre d\'information');$label_send_newsletter)
],
['url' => '/admin/newsletter/duplicate/id/%s',
'icon' => 'copy',
'label' => $this->_('Dupliquer la lettre d\'information')],
......
......@@ -503,11 +503,6 @@ class Admin_NewsletterControllerSendInProgressActionTest extends Admin_Newslette
Class_Batch_SendNewsletters::setCommand($this->_command);
Class_Newsletter_Dispatch::setTimeSource(new TimeSourceForTest('2016-07-21 11:21:38'));
$dispatch = Class_Newsletter_Dispatch::newFrom(Class_Newsletter::find(2));
$dispatch->assertSave();
$this->dispatch('/admin/newsletter/send/id/2', true);
$this->_dispatch = Class_Newsletter::find(2)->getDispatchs()[0];
}
......@@ -519,6 +514,13 @@ class Admin_NewsletterControllerSendInProgressActionTest extends Admin_Newslette
/** @test */
public function shouldHaveOnlyOneDispatch() {
$dispatch = Class_Newsletter_Dispatch::newFrom(Class_Newsletter::find(2));
$dispatch->setCollected(1);
$dispatch->assertSave();
$this->dispatch('/admin/newsletter/send/id/2', true);
$this->_dispatch = Class_Newsletter::find(2)->getDispatchs()[0];
$this->assertEquals(1, Class_Newsletter::find(2)->numberOfDispatchs());
}
}
......@@ -1470,6 +1472,12 @@ class Admin_NewsletterControllerScriptTest extends Admin_NewsletterControllerTes
}
/** @test */
public function sendMailButtonShouldBeHere() {
$this->assertXPathContentContains('//script', 'Envoyer la lettre d\'information');
}
/** @test */
public function progressBarNewsletterShouldBeDisplay() {
$this->assertXPath('//div[@id="progress_bar_newsletter_1"]');
......@@ -1515,6 +1523,8 @@ class Admin_NewsletterControllerSendProgressWithWrongNewsletterIdTest extends Ad
class Admin_NewsletterControllerSendProgressWithErrorAndNothingSentTest
extends Admin_NewsletterControllerSendProgressTestCase {
......@@ -1538,6 +1548,8 @@ class Admin_NewsletterControllerSendProgressWithErrorAndNothingSentTest
public function statusShouldContainsNothingSent() {
$this->assertContains('aucun mail envoyé', $this->_json->status);
}
}
......@@ -1572,6 +1584,16 @@ class Admin_NewsletterControllerSendProgressWithErrorAnd1Of2SentTest
public function statusShouldContains1Of2Sent() {
$this->assertContains('envoyé à 1 sur 2', $this->_json->status);
}
/** @test */
public function sendButtonShouldContainsReloadText() {
Class_Newsletter::find(1)->setTitre('Other title')->save();
$this->dispatch('admin/newsletter/index', true);
$this->assertXPathContentContains('//script', 'Reprendre l\'envoi de la lettre d\'information: Nouveautés classique ?', $this->_response->getBody());
$this->assertXPath('//img[contains(@title,"Reprendre l\'envoi en cours")]', $this->_response->getBody());
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment