diff --git a/application/modules/opac/controllers/AbonneController.php b/application/modules/opac/controllers/AbonneController.php index 4d299fa16c54fb81a0022d88771a9680183bcafb..782577dbfce649c6ac287203273834f66ae4a2c1 100644 --- a/application/modules/opac/controllers/AbonneController.php +++ b/application/modules/opac/controllers/AbonneController.php @@ -724,7 +724,11 @@ class AbonneController extends Zend_Controller_Action { if ($form->isValid($suggestion)) { $suggestion->save(); - $suggestion->sendMail('noreply@'.$this->_request->getHttpHost()); + try { + $suggestion->sendMail('noreply@'.$this->_request->getHttpHost()); + } catch (Zend_Mail_Exception $e) { + $this->_helper->notify($this->_('Aucun courriel envoyé: le profil n\'est pas configuré')); + } $this->_redirect('/opac/abonne/suggestion-achat/id/'.$suggestion->getId()); } } diff --git a/tests/application/modules/opac/controllers/AbonneControllerSuggestionAchatTest.php b/tests/application/modules/opac/controllers/AbonneControllerSuggestionAchatTest.php index caebcceefce91a4b7e02ad76667082ec36a860d4..b0b939217930006eb3254446accacbaf0edba6e7 100644 --- a/tests/application/modules/opac/controllers/AbonneControllerSuggestionAchatTest.php +++ b/tests/application/modules/opac/controllers/AbonneControllerSuggestionAchatTest.php @@ -176,6 +176,68 @@ class AbonneControllerSuggestionAchatPostValidDataTest extends AbstractControlle public function fromShouldBeNoReplyAtLocalhost() { $this->assertEquals('noreply@localhost', $this->_mail->getFrom()); } + + + /** @test */ + public function notificationShouldBeEmpty() { + $this->assertFalse(isset($_SESSION['FlashMessenger'])); + } + +} + + + + +class AbonneControllerSuggestionAchatPostValidDataButNoMailSentTest extends AbstractControllerTestCase { + protected $_suggestion; + protected $_mail; + + protected function _loginHook($account) { + $account->username = 'Arnaud'; + $account->ID_USER = 666; + } + + + public function setUp() { + parent::setUp(); + + Class_Users::getIdentity()->setMail(''); + Class_Profil::getPortail()->setMailSite(''); + Class_Profil::getCurrentProfil()->setMailSite(''); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_SuggestionAchat') + ->whenCalled('save') + ->willDo( + function($suggestion){ + $this->_suggestion = $suggestion->setId(66); + }); + + $mock_transport = new MockMailTransport(); + Zend_Mail::setDefaultTransport($mock_transport); + $mock_transport->onSendDo(function() {throw new Zend_Mail_Exception('Error');}); + + $this->postDispatch('/opac/abonne/suggestion-achat', + ['titre' => 'Harry Potter', + 'description_url' => '', + 'isbn' => '', + 'commentaire' => '', + 'submit' => 'Envoyer'], + true); + + $this->_mail = $mock_transport->sent_mail; + } + + + /** @test */ + public function notificationShouldContainsAucunCourrielEnvoye() { + $this->assertContains('Aucun courriel', $_SESSION['FlashMessenger']['default'][0]); + } + + + /** @test */ + public function newSuggestionShouldHaveTitreHarryPotter() { + $this->assertEquals('Harry Potter', $this->_suggestion->getTitre()); + } }