Commit bc42a088 authored by Patrick Barroca's avatar Patrick Barroca 🐧

rel #46014 : fix test failures

parent 69bc1549
......@@ -108,10 +108,10 @@ class Admin_NewsletterController extends ZendAfi_Controller_Action {
$form = $this->_sendTestForm($newsletter);
if ($this->getRequest()->isPost() && $form->isValid($_POST)) {
$destinataire = $this->_request->getParam('destinataire');
if ($this->_request->isPost() && $form->isValid($this->_request->getPost())) {
$destinataire = $this->_getParam('destinataire');
try {
$batch = new Class_Batch_SendNewsletters($newsletter);
$batch = new Class_Batch_SendNewsletters(Class_Newsletter_Dispatch::newFrom($newsletter));
$batch->sendOne($destinataire);
$this->view->subview = $this->_('Lettre "%s" envoyée à %s',
......@@ -165,13 +165,13 @@ class Admin_NewsletterController extends ZendAfi_Controller_Action {
return;
}
$template = $newsletter->newTemplate();
$template = Class_Newsletter_Dispatch::newFrom($newsletter)->getTemplate();
$mock_user = new Class_Entity();
$mock_user->setId(0)->setMail('');
$this->view->subview = $this->view->partial('newsletter/preview.phtml',
['newsletter' => $newsletter,
'mail' => $newsletter->newMailFromTemplate($template,$mock_user)]);
'mail' => $template->mailFor($mock_user)]);
$this->_forward('index');
}
......
......@@ -48,7 +48,7 @@ class NewsletterController extends Zend_Controller_Action {
if ((!$this->_letter = Class_Newsletter::find((int)$this->_getParam('newsletter', 0)))
|| (!$this->_user = Class_Users::find((int)$this->_getParam('user', 0)))
|| !$this->_user->getMail()
|| ($this->_getParam('hash')!=$this->_letter->hashForUser($this->_user))) {
|| ($this->_getParam('hash') != Class_Newsletter_Template::hashForUser($this->_letter->getId(), $this->_user->getMail()))) {
$this->render('unsubscribe-not-found');
return false;
}
......
......@@ -86,6 +86,7 @@ class Class_Newsletter extends Storm_Model_Abstract {
->add(new Class_Newsletter_DedicatedGroupAssociation('dedicated_group'));
}
public function getSubscriptionsPage($page=0, $items_by_page=20) {
return Class_NewsletterSubscription::findAllBy(['newsletter_id' => $this->getId(),
'limitPage' => [$page, $items_by_page]]);
......
......@@ -45,12 +45,15 @@ class Class_Newsletter_Template extends Class_Entity {
public function fillTemplate($dispatch_user, $body) {
$body = str_replace("%user.id%", $dispatch_user->getUserId(), $body);
$body = str_replace("%hash%", $this->hashForUser($dispatch_user), $body);
$body = str_replace("%hash%",
$this->hashForUser($this->getNewsletterId(),
$dispatch_user->getMail()),
$body);
return $body;
}
public function hashForUser($dispatch_user) {
return hash('crc32b', $this->getNewsletterId() . $dispatch_user->getMail());
public static function hashForUser($newsletter_id, $mail) {
return hash('crc32b', $newsletter_id . $mail);
}
}
\ No newline at end of file
......@@ -25,7 +25,7 @@ class UserGroupLoader extends Storm_Model_Loader {
public function getUsersIdsOf($group) {
$ids = [];
$closure = function($model) use (&$ids) {
$ids[] = $users->getId();
$ids[] = $model->getId();
};
Class_UserGroup::withUsersOfDo($group, $closure);
......
......@@ -788,12 +788,7 @@ class Admin_NewsletterControllerPostSendTestActionTest extends Admin_AbstractCon
protected function _post($data) {
$this
->getRequest()
->setMethod('POST')
->setPost($data);
$this->dispatch('/admin/newsletter/sendtest/id/4');
$this->postDispatch('/admin/newsletter/sendtest/id/4', $data);
$this->assertAction('index');
}
......
......@@ -124,8 +124,9 @@ class NewsletterControllerMissingHashInUnsubscribeTest extends NewsletterControl
class NewsletterControllerValidUnsubscribeTest extends NewsletterControllerTestCase {
public function setUp() {
parent::setUp();
$this->dispatch('/opac/newsletter/unsubscribe/newsletter/34/user/23/hash/'.Class_Newsletter::find(34)->hashForUser(Class_Users::find(23)), true);
$hash = Class_Newsletter_Template::hashForUser(34, Class_Users::find(23)->getMail());
$this->dispatch('/opac/newsletter/unsubscribe/newsletter/34/user/23/hash/' . $hash,
true);
}
......@@ -149,7 +150,8 @@ class NewsletterControllerEmptyUnsubscribeConfirmTest extends NewsletterControll
class NewsletterControllerValidUnsubscribeConfirmTest extends NewsletterControllerTestCase {
public function setUp() {
parent::setUp();
$this->dispatch('/opac/newsletter/unsubscribe-confirm/newsletter/34/user/23/hash/'.Class_Newsletter::find(34)->hashForUser(Class_Users::find(23)), true);
$hash = Class_Newsletter_Template::hashForUser(34, Class_Users::find(23)->getMail());
$this->dispatch('/opac/newsletter/unsubscribe-confirm/newsletter/34/user/23/hash/'. $hash, true);
}
......
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