From 773961f1c84fba6d2b5608fbed12ffc470935aee Mon Sep 17 00:00:00 2001 From: llaffont <llaffont@afi-sa.fr> Date: Sat, 11 Jul 2015 11:36:32 +0200 Subject: [PATCH] dev #24821 valence user notices test fix --- .../opac/views/scripts/auth/boite-login.phtml | 5 ---- library/Class/Users.php | 23 ++++++++++++------- .../View/Helper/RenderNotifications.php | 12 +++++++--- .../opac/controllers/AuthControllerTest.php | 6 +++-- tests/library/Class/UsersTest.php | 9 ++++++++ 5 files changed, 37 insertions(+), 18 deletions(-) diff --git a/application/modules/opac/views/scripts/auth/boite-login.phtml b/application/modules/opac/views/scripts/auth/boite-login.phtml index 4374530010f..cac186020b3 100644 --- a/application/modules/opac/views/scripts/auth/boite-login.phtml +++ b/application/modules/opac/views/scripts/auth/boite-login.phtml @@ -19,11 +19,6 @@ $html = $this->tag('div', $this->preferences['message_connecte'] . ' ' . $this->abonne_NamesOrLogin($user), ['class' => 'welcome']); -// if ($user->hasIdabon() && !$user->isAbonnementValid()) -// $html .= $this->tag('p', -// $this->_('Abonnement expiré - Merci de contacter la médiathèque'), -// ['class' => 'expired']); - $html .= $this->renderNotifications($user); $user_url = $this->url(['controller' => 'abonne', diff --git a/library/Class/Users.php b/library/Class/Users.php index 6ae2bb51906..d01ee9e5fc6 100644 --- a/library/Class/Users.php +++ b/library/Class/Users.php @@ -518,16 +518,23 @@ class Class_Users extends Storm_Model_Abstract { } + public function isILSExpirable() { + return $this->isAbonne() && $this->hasDateFin(); + } + + public function isILSExpired() { - if (!$this->isAbonne()) return false; - if (! $this->hasDateFin()) return false; - return ($this->getDateFin() < date("Y-m-d")); + return + $this->isILSExpirable() + && ($this->getDateFin() < date("Y-m-d")); } public function isILSAboutToExpire() { - return ($this->ilsExpireIn() >= 0 - && Class_AdminVar::getValueOrDefault('NDAYS_EXPIRY_NOTICE') >= $this->ilsExpireIn()); + return + $this->isILSExpirable() + && ($this->ilsExpireIn() >= 0) + && (Class_AdminVar::getValueOrDefault('NDAYS_EXPIRY_NOTICE') >= $this->ilsExpireIn()); } @@ -1542,9 +1549,9 @@ class Class_Users extends Storm_Model_Abstract { $this->_('Abonnement expiré - Merci de contacter la médiathèque')) ->_notifyOn($notifiable, $this->isILSAboutToExpire(), - $this->_plural($this->ilsExpireIn(), - 'Votre abonnement expire aujourd\'hui.', - 'Votre abonnement arrivera à expiration demain.', + $this->_plural($this->ilsExpireIn(), + 'Votre abonnement expire aujourd\'hui.', + 'Votre abonnement arrivera à expiration demain.', 'Votre abonnement arrivera à expiration dans %d jours.', $this->ilsExpireIn())) ->_notifyOn($notifiable, $this->getNbEmpruntsRetard(), diff --git a/library/ZendAfi/View/Helper/RenderNotifications.php b/library/ZendAfi/View/Helper/RenderNotifications.php index b8120e0436a..cba22ec2e37 100644 --- a/library/ZendAfi/View/Helper/RenderNotifications.php +++ b/library/ZendAfi/View/Helper/RenderNotifications.php @@ -27,9 +27,15 @@ class ZendAfi_View_Helper_RenderNotifications extends ZendAfi_View_Helper_BaseHe public function renderNotifications($user) { $user->registerNotificationsOn($this); - return $this->view->tag('p', - implode('<br>', $this->_messages), - ['class' => 'user_notifications']); + + if (!$this->_messages) + return ''; + + $html = $this->view->tag('p', + implode('<br>', $this->_messages), + ['class' => 'user_notifications']); + $this->_messages = []; + return $html; } diff --git a/tests/application/modules/opac/controllers/AuthControllerTest.php b/tests/application/modules/opac/controllers/AuthControllerTest.php index 650d0f0e7f1..5c0193f5561 100644 --- a/tests/application/modules/opac/controllers/AuthControllerTest.php +++ b/tests/application/modules/opac/controllers/AuthControllerTest.php @@ -669,13 +669,15 @@ class AuthControllerAdminIsLoggedTest extends PortailWithOneLoginModuleTestCase public function testBoiteLoginDisplaysBienvenueSysadm() { - $this->assertQueryContentContains('#boite_login .welcome', 'Bienvenue sysadm'); + $this->assertQueryContentContains('#boite_login .welcome', + 'Bienvenue sysadm'); } /** @test */ public function shouldNotDisplayExpiredSubscription() { - $this->assertNotXPath('//div[@class="boite login"]//p'); + $this->assertNotXPath('//div[@class="boite login"]//p', + $this->_response->getBody()); } diff --git a/tests/library/Class/UsersTest.php b/tests/library/Class/UsersTest.php index ea28a37f0ce..4dbc9868ce2 100644 --- a/tests/library/Class/UsersTest.php +++ b/tests/library/Class/UsersTest.php @@ -716,6 +716,15 @@ class UsersFicheAbonneTest extends ModelTestCase { } + /** @test */ + public function withoutDateFinPatrickNotificationsShouldBeEmpty() { + $this->patrick->setDateFin(''); + $this->patrick->registerNotificationsOn($this->_notifiable); + + $this->assertEmpty($this->_notifications); + } + + /** @test */ public function patrickNotificationsShouldContainsAbonnementExpireDans30Jours() { $this->patrick->setDateFin(date('Y-m-d', mktime(0, 0, 0, date('m'), date('d') + 30, date('Y')))); -- GitLab