diff --git a/library/Class/DriveCheckout/Notification.php b/library/Class/DriveCheckout/Notification.php index dfa2a0eadda60c17f3a39dca31305246b4876a33..b91d077dfb920baf29c39a43bf3d711d187f1fb1 100644 --- a/library/Class/DriveCheckout/Notification.php +++ b/library/Class/DriveCheckout/Notification.php @@ -72,7 +72,11 @@ class Class_DriveCheckout_Notification { ->setDataSource($data_source) ->getContenuFusionne(); + if ($library->hasMail()) + $mailer->setFrom($library->getMail()); + $mail = $mailer->prepare($recipient, $subject, $body, true); + $attachment = $mail ->createAttachment((new Class_ICal_DriveCheckout($this->_checkout))->renderCalendar(Class_Profil::getCurrentProfil()), Class_ICal_DriveCheckout::MIME_TYPE); diff --git a/library/Class/Mail.php b/library/Class/Mail.php index 9c0315f465b4ab813b272326707f28c92c636258..9e0f96e632cd06c1f188554146c6415cc1be669c 100644 --- a/library/Class/Mail.php +++ b/library/Class/Mail.php @@ -22,20 +22,30 @@ class Class_Mail { use Trait_Translator; - private $params_ok=false; // Flag de controle si un mail peut etre envoyé + private $params_ok = false; // Flag de controle si un mail peut etre envoyé private $mail_from; // Header from public function __construct() { $this->params_ok = false; - $this->mail_from = Class_Profil::getCurrentProfil()->getMailSiteOrPortail(); - if (!$this->mail_from) - $this->mail_from = Class_CosmoVar::get('mail_admin'); + if (!$mail_from = Class_Profil::getCurrentProfil()->getMailSiteOrPortail()) + $mail_from = Class_CosmoVar::get('mail_admin'); + + $this->setFrom($mail_from); + } + + + public function setFrom($mail_from) { + $this->mail_from = $mail_from; if ($this->isMailValid($this->mail_from)) { ini_set('sendmail_from', $this->mail_from); - $this->params_ok=true; + $this->params_ok = true; + return $this; } + + $this->params_ok = false; + return $this; } diff --git a/library/ZendAfi/View/Helper/RenderCsv.php b/library/ZendAfi/View/Helper/RenderCsv.php index 1f64ba5daed604d9ba56974cb2749ecbbb683870..233ea3fdfbb5a2e0247937469e44c6b8bb4e7481 100644 --- a/library/ZendAfi/View/Helper/RenderCsv.php +++ b/library/ZendAfi/View/Helper/RenderCsv.php @@ -61,8 +61,6 @@ class ZendAfi_View_Helper_RenderCsv extends ZendAfi_View_Helper_BaseHelper { protected function _renderModel($model) { - if (is_array($model)) - return $this->_renderDatas($models); fputcsv($this->_fp_csv, $this->_renderModelColumns($model), ';'); diff --git a/tests/scenarios/DriveCheckOut/DriveCheckOutBookingTest.php b/tests/scenarios/DriveCheckOut/DriveCheckOutBookingTest.php index 8528acf419118f746ba97a1d1352661956dd7bdd..1cfa23c9ffc3c27735a74c8d18272933df9cd286 100644 --- a/tests/scenarios/DriveCheckOut/DriveCheckOutBookingTest.php +++ b/tests/scenarios/DriveCheckOut/DriveCheckOutBookingTest.php @@ -101,6 +101,7 @@ abstract class DriveCheckOutBookingTestCase extends AbstractControllerTestCase { 'closed_on_holidays' => false, 'enable_drive' => 1, 'horaire' => 'Ouvert tous les lundis, mardi et mercedi', + 'mail' => 'emilie@hotel-dieu.fr', 'ouvertures' => [ Class_Ouverture::chaqueLundi('00:00', '00:00', '12:00', '18:00') ->beDrive(), @@ -118,7 +119,12 @@ abstract class DriveCheckOutBookingTestCase extends AbstractControllerTestCase { $this->fixture('Class_Bib', ['id' => 3, 'enable_drive' => 1, - 'libelle' => 'Mauricette-Rafin']); + 'libelle' => 'Mauricette-Rafin', + 'ouvertures' => [ + Class_Ouverture::chaqueMardi('00:00', '00:00', '12:00', '18:00') + ->beDrive() + ] + ]); $this->fixture('Class_Bib', ['id' => 4, @@ -733,14 +739,14 @@ class DriveCheckOutBookingPlanBibHotelDieuAt2020_05_12_09_00Test /** @test */ - public function mailSiteShouldBeInBcc() { - $this->assertContains('zemail@mabib.st', $this->_mail->getHeaders()['Bcc']); + public function mailSiteHotelDieuShouldBeInBcc() { + $this->assertEquals('<emilie@hotel-dieu.fr>', $this->_mail->getHeaders()['Bcc'][0]); } /** @test */ - public function mailFromShouldBeMailSite() { - $this->assertEquals('zemail@mabib.st', $this->_mail->getFrom()); + public function mailFromShouldBeMailSiteHotelDieu() { + $this->assertEquals('emilie@hotel-dieu.fr', $this->_mail->getFrom()); } @@ -766,6 +772,34 @@ class DriveCheckOutBookingPlanBibHotelDieuAt2020_05_12_09_00Test +class DriveCheckOutBookingPlanBibHotelDieuWithoutMailAt2020_05_12_09_00Test + extends DriveCheckOutBookingTestCase { + protected $_mail; + + public function setUp() { + parent::setUp(); + Class_Bib::find(1)->setMail('')->save(); + $this->postDispatch('/opac/drive-checkout/plan/id_bib/1/checkout_date/2020-05-12', + ['checkout_time' => '09:00']); + $this->_mail = $this->_mail_transport->sent_mail; + } + + + /** @test */ + public function mailSiteHotelDieuShouldBeInBcc() { + $this->assertEquals('<zemail@mabib.st>', $this->_mail->getHeaders()['Bcc'][0]); + } + + + /** @test */ + public function mailFromShouldBeMailSiteHotelDieu() { + $this->assertEquals('zemail@mabib.st', $this->_mail->getFrom()); + } +} + + + + class DriveCheckOutBookingPlanBibHotelDieuAt2020_05_12_05_00Test extends DriveCheckOutBookingTestCase {