Commit 8458f7be authored by Ghislain Loas's avatar Ghislain Loas
Browse files

dev #48675 change mail from admin to logged user

parent 050137c2
Pipeline #646 failed with stage
in 9 minutes and 46 seconds
......@@ -1201,4 +1201,29 @@ class AbonneController extends ZendAfi_Controller_Action {
$this->view->titre = $this->_('Mes formations suivies');
$this->view->sessions = Class_SessionFormation::findAllDone($this->_user);
}
public function popupEmailAction() {
$this->view->redirect = $this->_getParam('redirect');
if(!$user = Class_Users::getIdentity())
return $this->_forward('popup-login', 'auth', 'opac', $this->view->redirect);
$this->view->form = $form = new ZendAfi_Form_User_Email();
$form->setAction($this->view->url(['controller' => 'abonne',
'action' => 'popup-email',
'redirect' => $this->view->redirect],
null,
true));
if($this->_request->isPost()
&& $form->isValid($this->_getPost()))
$user->setMail($this->_getParam('email'))->save();
if($user->hasMail())
return $this->_redirect($this->view->redirect);
$this->renderPopupResult($this->view->_('Compléter votre adresse email'),
$this->view->render('abonne/ajax-email.phtml'));
}
}
\ No newline at end of file
<?php
echo $this->renderForm($this->form);
?>
\ No newline at end of file
......@@ -23,8 +23,13 @@
class ZendAfi_Controller_Plugin_Mailer_ModelFusion extends ZendAfi_Controller_Plugin_Abstract {
public function sendMailAction() {
if(!Class_Users::getIdentity())
return $this->_forward('popup-login', 'auth', 'opac', ['redirect' => $this->_view->absoluteUrl()]);
$absolute_url = $this->_view->absoluteUrl();
if(!$user = Class_Users::getIdentity())
return $this->_forward('popup-login', 'auth', 'opac', ['redirect' => $absolute_url]);
if(!$mail = $user->getMail())
return $this->_forward('popup-email', 'abonne', null, ['redirect' => $absolute_url]);
$this->_view->titre = $this->_('Envoyer par Email');
$this->_view->form = ZendAfi_Form_SendMail::newWith(['subject' => $this->_getSubject(),
......@@ -59,8 +64,8 @@ class ZendAfi_Controller_Plugin_Mailer_ModelFusion extends ZendAfi_Controller_Pl
protected function _getSender() {
$portail = Class_Profil::find(1);
return $portail->getMailSite();
$user = Class_Users::getIdentity();
return $user->getMail();
}
......
<?php
/**
* Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class ZendAfi_Form_User_Email extends ZendAfi_Form {
public function init() {
parent::init();
$this
->setAttrib('id', 'user-email')
->addElement('email',
'email',
['label' => $this->_('Email'),
'required' => true,
'allowEmpty' => false])
->addUniqDisplayGroup('email', '');
}
}
\ No newline at end of file
......@@ -20,26 +20,36 @@
*/
class MailerSearchResultSimpleTest extends AbstractControllerTestCase {
abstract class MailerWithUserConnectedTestCase extends AbstractControllerTestCase {
protected
$_storm_default_to_volatile = true,
$_mock_transport,
$_guest;
protected $_storm_default_to_volatile = true;
public function setup() {
parent::setUp();
$guest = $this->fixture('Class_Users',
['id' => 13,
'login' => 'XIII',
'password' => 'BD'])
->beInvite();
$this->_guest = $this->fixture('Class_Users',
['id' => 13,
'login' => 'XIII',
'password' => 'BD',
'mail' => 'treize@bd.com'])
->beInvite();
ZendAfi_Auth::getInstance()->logUser($guest);
ZendAfi_Auth::getInstance()->logUser($this->_guest);
$this->fixture('Class_ModeleFusion',
['id' => 6]);
}
}
class MailerSearchResultSimpleTest extends MailerWithUserConnectedTestCase {
/** @test */
public function authLoginformShouldBePresent() {
ZendAfi_Auth::getInstance()->clearIdentity();
......@@ -54,18 +64,24 @@ class MailerSearchResultSimpleTest extends AbstractControllerTestCase {
$this->dispatch('/recherche/send-mail/expressionRecherche/il+%C3%A9tait+une+fois+dans+l%27ouest/tri/%2A/code_rebond/A26874/ids/6731%3B6877%3B6917%3B7528%3B7574%3B8648%3B11793%3B11972%3B13994%3B14010/strategy/Notice_List/modele_fusion/6/subject/il+%C3%A9tait+une+fois+dans+l%27ouest', true);
$this->assertXPath('//form//input[@type="text"][@value="PHP Unit : Documents il était une fois dans l\'ouest"]');
}
}
/** @test */
public function emailFromShouldBeDisplay() {
$this->_guest->setMail('');
$this->dispatch('/recherche/send-mail/expressionRecherche/il+%C3%A9tait+une+fois+dans+l%27ouest/tri/%2A/code_rebond/A26874/ids/6731%3B6877%3B6917%3B7528%3B7574%3B8648%3B11793%3B11972%3B13994%3B14010/strategy/Notice_List/modele_fusion/6/subject/il+%C3%A9tait+une+fois+dans+l%27ouest', true);
$this->assertContains('<input type=\"email\" name=\"email\"', $this->_response->getBody());
}
}
class MailerSearchResultPostTest extends Admin_AbstractControllerTestCase {
protected $_storm_default_to_volatile = true;
class MailerSearchResultPostTest extends MailerWithUserConnectedTestCase {
public function setup() {
parent::setUp();
Zend_Mail::setDefaultTransport(new MockMailTransport());
Zend_Mail::setDefaultTransport($this->_mock_transport = new MockMailTransport());
$this->postDispatch('/opac/recherche/send-mail',
['subject' => 'search result from libray Boutheon for "One upon a time"',
......@@ -76,7 +92,13 @@ class MailerSearchResultPostTest extends Admin_AbstractControllerTestCase {
/** @test */
public function shouldContainsScriptToRedirect() {
$this->assertXPathContentContains('//script', 'document.location.href = document.location.href;', $this->_response->getBody());
$this->assertXPathContentContains('//script', 'document.location.href = document.location.href;');
}
/** @test */
public function senderShouldBeTreizeAtBdDotCom() {
$this->assertEquals('treize@bd.com', $this->_mock_transport->getSentMails()[0]->getFrom());
}
}
......@@ -101,4 +123,30 @@ class MailerLinkInSearchResultTest extends AbstractControllerTestCase {
public function shareByMAilShouldBePresent() {
$this->assertXPath('//div//a[contains(@href,"/recherche/send-mail/expressionRecherche/seven+deadly+sins/ids/")][contains(@href,"/subject/pour+%3A+/strategy/Notice_List/modele_fusion/6")]');
}
}
class MailerPopupEmailPostTest extends MailerWithUserConnectedTestCase {
public function setup() {
parent::setUp();
$this->_guest->setMail('');
$this->postDispatch('/opac/abonne/popup-email/redirect/%2Frecherche%2Fsend-mail%2FexpressionRecherche%2Fil%2B%25C3%25A9tait%2Bune%2Bfois%2Ftri%2F%252A%2Fmultifacets%2FT2%2Fids%2F61441%2Fsubject%2Fpour%2B%253A%2Bil%2B%2526eacute%253Btait%2Bune%2Bfois%2Fstrategy%2FNotice_List%2Fmodele_fusion%2F6%2Frender%2Fpopup',
['email' => 'treize@bd.org']);
}
/** @test */
public function shouldRedirect() {
$this->assertRedirectTo('/recherche/send-mail/expressionRecherche/il+%C3%A9tait+une+fois/tri/%2A/multifacets/T2/ids/61441/subject/pour+%3A+il+%26eacute%3Btait+une+fois/strategy/Notice_List/modele_fusion/6/render/popup');
}
/** @test */
public function guestMailShouldBeTreizeAtBdDotOrg() {
$this->assertEquals('treize@bd.org', $this->_guest->getMail());
}
}
\ No newline at end of file
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