diff --git a/.gitattributes b/.gitattributes index 08b6a80d23e0baa799a229d0190796ade6a5e67e..db17a7a50b09459f13a61fbdba544a9dda77da08 100644 --- a/.gitattributes +++ b/.gitattributes @@ -569,7 +569,6 @@ application/modules/opac/views/scripts/iframe.phtml -text application/modules/opac/views/scripts/index/embed-module.phtml -text application/modules/opac/views/scripts/index/error.phtml -text application/modules/opac/views/scripts/index/formulairecontact.phtml -text -application/modules/opac/views/scripts/index/formulairecontacterror.phtml -text application/modules/opac/views/scripts/index/formulairecontactsent.phtml -text application/modules/opac/views/scripts/index/planaccess.phtml -text application/modules/opac/views/scripts/index/sitedown.phtml -text diff --git a/application/modules/opac/controllers/IndexController.php b/application/modules/opac/controllers/IndexController.php index 3ae6da910b3b7b2a701481d23693a58f605aadf9..78edc63572291923c58bd8aa376c92abbea0187f 100644 --- a/application/modules/opac/controllers/IndexController.php +++ b/application/modules/opac/controllers/IndexController.php @@ -69,11 +69,9 @@ class IndexController extends Zend_Controller_Action { $this->_sendFormulaireContact(); $this->_redirect('index/formulairecontactsent'); } catch (Exception $e) { - $this->_helper->notify($e->getMessage()); - $this->_redirect('index/formulairecontacterror'); + $this->view->error = $e->getMessage(); } - return; - } + } $this->view->form = $form; } @@ -81,8 +79,6 @@ class IndexController extends Zend_Controller_Action { public function formulairecontactsentAction() {} - public function formulairecontacterrorAction() {} - protected function _formulaireContact() { $form = $this->view->newForm(array('id' => 'contact')) @@ -174,9 +170,9 @@ class IndexController extends Zend_Controller_Action { protected function _sendFormulaireContact() { if (!$mail_address = Class_Profil::getCurrentProfil()->getMailSiteOrPortail()) - throw new Exception($this->view->_("Erreur à l'envoi du mail: destinataire non configuré")); + throw new Exception($this->view->_("destinataire non configuré. Vérifiez les paramètres du profil, champ 'E-mail du webmestre'")); - $data = ZendAfi_Filters_Post::filterStatic($this->_request->getPost()); + $data = $this->_request->getPost(); $mail = new Zend_Mail('utf8'); $mail diff --git a/application/modules/opac/views/scripts/index/formulairecontact.phtml b/application/modules/opac/views/scripts/index/formulairecontact.phtml index 6bdf72a215d4d467f98f77565a5ce4b1881bcfb2..e1daeae50a801a9bf9190ec8398c3a352551f7e6 100644 --- a/application/modules/opac/views/scripts/index/formulairecontact.phtml +++ b/application/modules/opac/views/scripts/index/formulairecontact.phtml @@ -1,5 +1,7 @@ <?php echo $this->openBoite('Formulaire de contact'); +if ($this->error) + echo sprintf('<p class="errors">%s</p>', $this->_("Erreur d'envoi: %s", $this->error)); echo $this->renderForm($this->form); echo $this->closeBoite(); ?> \ No newline at end of file diff --git a/application/modules/opac/views/scripts/index/formulairecontacterror.phtml b/application/modules/opac/views/scripts/index/formulairecontacterror.phtml deleted file mode 100644 index 1cbfc66659f1d3c84c79d7883fbf59a7fa303fe4..0000000000000000000000000000000000000000 --- a/application/modules/opac/views/scripts/index/formulairecontacterror.phtml +++ /dev/null @@ -1,5 +0,0 @@ -<?php -echo $this->openBoite('Formulaire de contact'); -echo sprintf('<p>%s</p>', $this->_("Erreur d'envoi: problème de configuration")); -echo $this->closeBoite(); -?> \ No newline at end of file diff --git a/tests/application/modules/opac/controllers/FormulaireContactTest.php b/tests/application/modules/opac/controllers/FormulaireContactTest.php index 70f494fd5400f22d8c096b3e2b082c9fc38fe2ae..91acfc8f0dd76cc8bd0dde67065b1557b1569956 100644 --- a/tests/application/modules/opac/controllers/FormulaireContactTest.php +++ b/tests/application/modules/opac/controllers/FormulaireContactTest.php @@ -98,10 +98,14 @@ class FormulaireContactInvalidPostTest extends AbstractControllerTestCase { abstract class FormulaireContactValidPostTestCase extends AbstractControllerTestCase { protected $_mail; + public function newMailTransport() { + return new MockMailTransport(); + } + public function sendValidMail() { defineConstant('NOCAPTCHA', true); - $mock_transport = new MockMailTransport(); + $mock_transport = $this->newMailTransport(); Zend_Mail::setDefaultTransport($mock_transport); $this->postDispatch('/opac/index/formulairecontact', @@ -118,6 +122,32 @@ abstract class FormulaireContactValidPostTestCase extends AbstractControllerTest } + +class FormulaireContactValidPostThrowErrorTest extends FormulaireContactValidPostTestCase { + public function newMailTransport() { + $transport = new MockMailTransport(); + $transport->onSendDo(function() {throw new Exception('Erreur de connexion');}); + return $transport; + } + + + public function setUp() { + parent::setUp(); + + Class_Profil::getCurrentProfil()->setMailSite('laurent@afi-sa.fr'); + $this->sendValidMail(); + } + + + /** @test */ + public function pageShouldDisplayError() { + $this->assertXPathContentContains('//p[@class="errors"]', "Erreur d'envoi: Erreur de connexion"); + } +} + + + + class FormulaireContactValidPostTest extends FormulaireContactValidPostTestCase { public function setUp() { parent::setUp(); @@ -222,7 +252,7 @@ class FormulaireContactValidPostWithoutMailCurrentProfilTest extends FormulaireC $this->sendValidMail(); $this->assertNull($this->_mail); - $this->assertRedirectTo('/index/formulairecontacterror'); + $this->assertXPathContentContains('//p[@class="errors"]', "Erreur d'envoi: destinataire non configuré"); } } @@ -235,13 +265,6 @@ class FormulaireContactRelatedActionsTest extends AbstractControllerTestCase { $this->dispatch('/index/formulairecontactsent'); $this->assertXPathContentContains('//p', 'Le message a bien été envoyé'); } - - - /** @test */ - public function formulaireContectErrorShouldDisplayError() { - $this->dispatch('/index/formulairecontacterror'); - $this->assertXPathContentContains('//p', "Erreur d'envoi: problème de configuration"); - } } diff --git a/tests/library/Class/MockMailTransport.php b/tests/library/Class/MockMailTransport.php index 9a8f4d247b6c53654929d888c1594b390a11c349..f8fa22ace3f7d7f5cea842a3e2c2f467ea8598d8 100644 --- a/tests/library/Class/MockMailTransport.php +++ b/tests/library/Class/MockMailTransport.php @@ -21,9 +21,18 @@ class MockMailTransport extends Zend_Mail_Transport_Abstract { public $sent_mail = null; + protected $_send_block; public function send(Zend_Mail $mail) { $this->sent_mail = $mail; + if (isset($this->_send_block)) { + call_user_func($this->_send_block); + } + + } + + public function onSendDo($block) { + $this->_send_block = $block; } protected function _sendMail() {}