From 4fa0e3efbb7cd8fdaeb711d96a4835cc8b0ea832 Mon Sep 17 00:00:00 2001 From: Ghislain Loas <ghislo@sandbox.pergame.net> Date: Wed, 7 May 2014 19:01:49 +0200 Subject: [PATCH] refacto render formation and session --- .../views/scripts/abonne/_formation.phtml | 27 +--- .../opac/views/scripts/abonne/_session.phtml | 14 -- .../views/scripts/abonne/formations.phtml | 4 +- library/Class/SessionFormation.php | 27 +++- .../ZendAfi/View/Helper/RenderFormation.php | 36 +++++ .../ZendAfi/View/Helper/RenderFormations.php | 2 +- library/ZendAfi/View/Helper/RenderSession.php | 129 ++++++++++++++++-- .../ZendAfi/View/Helper/RenderSessions.php | 108 +++++++++++++++ .../Helper/TagSessionFormationInscription.php | 51 +++---- .../AbonneControllerFormationsTest.php | 43 ++++-- .../Helper/Accueil/FormationsWidgetTest.php | 90 +++++++++++- 11 files changed, 431 insertions(+), 100 deletions(-) create mode 100644 library/ZendAfi/View/Helper/RenderFormation.php create mode 100644 library/ZendAfi/View/Helper/RenderSessions.php diff --git a/application/modules/opac/views/scripts/abonne/_formation.phtml b/application/modules/opac/views/scripts/abonne/_formation.phtml index ea173daa695..4d6924ab253 100644 --- a/application/modules/opac/views/scripts/abonne/_formation.phtml +++ b/application/modules/opac/views/scripts/abonne/_formation.phtml @@ -1,24 +1,3 @@ -<div> - <h2><?php echo $this->formation->getLibelle() ?></h2> - <div><?php echo $this->formation->getDescription() ?></div> - - - <table class="lieux"> - <thead> - <tr class="soustitre"> - <td>Date</td> - <td>Lieu</td> - <td></td> - <td></td> - </tr> - </thead> - <tbody> - <?php - echo $this->partialCycle('abonne/_session.phtml', - 'session', - $this->formation->getSessions(), - array('first', 'second')); - ?> - </tbody> - </table> -</div> \ No newline at end of file +<?php +echo $this->renderFormation($this->formation); +?> diff --git a/application/modules/opac/views/scripts/abonne/_session.phtml b/application/modules/opac/views/scripts/abonne/_session.phtml index be5f4ee4198..e69de29bb2d 100644 --- a/application/modules/opac/views/scripts/abonne/_session.phtml +++ b/application/modules/opac/views/scripts/abonne/_session.phtml @@ -1,14 +0,0 @@ -<tr class="session_<?php echo $this->session->getId()?> <?php echo $this->item_class ?>"> -<?php -echo sprintf("<td>%s %s</td>", - $this->renderDateRange($this->session->getDateDebut(), $this->session->getDateFin()), - $this->session->isAnnule() ? '(Annulé)' : ''); -echo sprintf("<td>%s </td>", $this->session->getLibelleLieu()); -echo sprintf("<td>%s</td>", - $this->tagAnchor(array('action' => 'detail-session', - 'id' => $this->session->getId()), - $this->_('Détails de la session'))); -echo sprintf("<td>%s</td>", - $this->tagSessionFormationInscription($this->session)); -?> -</tr> diff --git a/application/modules/opac/views/scripts/abonne/formations.phtml b/application/modules/opac/views/scripts/abonne/formations.phtml index 8af6eaaa2fa..bc118f57ab0 100644 --- a/application/modules/opac/views/scripts/abonne/formations.phtml +++ b/application/modules/opac/views/scripts/abonne/formations.phtml @@ -10,11 +10,11 @@ foreach($this->formations_by_year as $year => $formations) { echo $this->partialCycle('abonne/_formation.phtml', 'formation', $formations, - array('first', 'second')); + ['first', 'second']); echo '</div>'; } echo $this->closeBoite(); ?> -<?php echo $this->abonne_RetourFiche(); ?> \ No newline at end of file +<?php echo $this->abonne_RetourFiche(); ?> diff --git a/library/Class/SessionFormation.php b/library/Class/SessionFormation.php index 9eeaa8b944b..ccae6f4bd76 100644 --- a/library/Class/SessionFormation.php +++ b/library/Class/SessionFormation.php @@ -75,10 +75,24 @@ class Class_SessionFormation extends Storm_Model_Abstract { if ($this->isAnnule()) return true; - return ($this->hasDateLimiteInscription() && ($this->getDateLimiteInscription() < self::getTimeSource()->dateYmd())); + if(!$this->hasDateLimiteInscription()) + return true; + + return !$this->isDateSubscriable(); + } + + + + public function isDateSubscriable() { + return !$this->isDateSubscriptionExhausted(); } + public function isDateSubscriptionExhausted() { + return strtotime($this->getDateLimiteInscription()) < strtotime(self::getTimeSource()->dateYmd()); + } + + /** * @return bool */ @@ -180,14 +194,21 @@ class Class_SessionFormation extends Storm_Model_Abstract { } + public function getDateLimiteInscriptionHumanRead() { + return Class_Date::humanDate($this->getDateLimiteInscription(), 'd MMMM yyyy'); + } + + public function isSubscriableFor($user) { + xdebug_break(); + if(!$user) return false; - if(!$user->getRoleLevel()>= ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB) + if(!$user->hasRightSuivreFormation()) return false; - if(!$this->isValid() || $this->isFull() || $this->isAnnule()) + if(!$this->isValid() || $this->isFull() || $this->isAnnule() || $this->isInscriptionClosed()) return false; return true; diff --git a/library/ZendAfi/View/Helper/RenderFormation.php b/library/ZendAfi/View/Helper/RenderFormation.php new file mode 100644 index 00000000000..ba4bb32cff9 --- /dev/null +++ b/library/ZendAfi/View/Helper/RenderFormation.php @@ -0,0 +1,36 @@ +<?php +/** + * Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 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). + * + * AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class ZendAfi_View_Helper_RenderFormation extends ZendAfi_View_Helper_BaseHelper { + + public function renderFormation($formation) { + $html = $this->view->tag('h2', + $formation->getLibelle()); + $html.= $this->view->tag('div', + $formation->getDescription()); + $html.= $this->view->renderSessions($formation->getSessions(), 'Table'); + + return $this->view->tag('div', + $html); + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/RenderFormations.php b/library/ZendAfi/View/Helper/RenderFormations.php index 176d7d0be58..7858df70ac7 100644 --- a/library/ZendAfi/View/Helper/RenderFormations.php +++ b/library/ZendAfi/View/Helper/RenderFormations.php @@ -35,7 +35,7 @@ class ZendAfi_View_Helper_RenderFormations extends ZendAfi_View_Helper_BaseHelpe protected function renderFormation($formation) { - $html = $formation->getLibelle(); + $html = $this->view->tag('h2',$formation->getLibelle()); $html.= $this->renderSessions($formation->getAvailableSessions()); diff --git a/library/ZendAfi/View/Helper/RenderSession.php b/library/ZendAfi/View/Helper/RenderSession.php index 1884e6c5798..8b8874536f8 100644 --- a/library/ZendAfi/View/Helper/RenderSession.php +++ b/library/ZendAfi/View/Helper/RenderSession.php @@ -21,9 +21,38 @@ class ZendAfi_View_Helper_RenderSession extends ZendAfi_View_Helper_BaseHelper { - public function renderSession($session) { - return - $this->definitionListFor($session). + protected $_strategy; + + public function renderSession($session, $strategy='Dl') { + $render = 'Render_Session_'.$strategy; + $this->_strategy = new $render($this->view); + return $this->_strategy->render($session); + } +} + + + +class Render_Session { + protected $view; + + public function __construct($view) { + $this->view = $view; + } + + + public function errorSpan($msg) { + return $this->view->tag('span', $msg, ['class' => 'error']); + } +} + + + + +class Render_Session_Dl extends Render_Session { + + + public function render($session) { + return $this->definitionListFor($session). $this->actionsFor($session); } @@ -37,14 +66,32 @@ class ZendAfi_View_Helper_RenderSession extends ZendAfi_View_Helper_BaseHelper { protected function definitionListFor($session) { $html = + $this->view->tag('dt', $this->view->_('Informations')). + $this->view->tag('dd', ($session->isFull() + ? $this->view->_('Complet ') + : '' ). + ($session->isDateSubscriable() + ? '' + : $this->view->_('Date de limite d\'inscription dépassée'))). + $this->view->tag('dt', $this->view->_('Lieu')). $this->view->tag('dd', $this->view->renderLieu($session->getLieu(), ['size' => '300x300'])). + + $this->view->tag('dt', $this->view->_('Date de limite d\'inscription')). + $this->view->tag('dd', $session->getDateLimiteInscriptionHumanRead()). + + $this->view->tag('dt', $this->view->_('Date de début')). + $this->view->tag('dd', $session->getDateDebutTexte()). + + $this->view->tag('dt', $this->view->_('Date de fin')). + $this->view->tag('dd', $session->getDateFinTexte()). + $this->view->tag('dt', $this->view->_('Horaires')). $this->view->tag('dd', $session->getHoraires()). - $this->view->tag('dt', $this->view->_('Etat')). - $this->view->tag('dd', $session->isFull() - ? $this->view->_('Complet') - : '' ). + + $this->view->tag('dt', $this->view->_('Durée de la session')). + $this->view->tag('dd', $session->getDuree().' h'). + $this->view->tag('dt', $this->view->_('Nombre de participants')). $this->view->tag('dd', sprintf('%s: %d, %s: %d, %s: %d', $this->view->_('minimum'), @@ -53,10 +100,10 @@ class ZendAfi_View_Helper_RenderSession extends ZendAfi_View_Helper_BaseHelper { $session->getEffectifMax(), $this->view->_('actuel'), $session->getNbStagiaires())). + $this->view->tag('dt', $this->view->_('Intervenants')). $this->view->tag('dd', $this->getIntervenantsFor($session)). - $this->view->tag('dt', $this->view->_('Durée de la session')). - $this->view->tag('dd', $session->getDuree().' h'). + $this->view->tag('dt', $this->view->_('Contenu')). $this->view->tag('dd', $session->getContenu()); @@ -73,4 +120,68 @@ class ZendAfi_View_Helper_RenderSession extends ZendAfi_View_Helper_BaseHelper { return $this->view->tag('ul', $html); } } + + + + +class Render_Session_Table extends Render_Session { + + + public function render($session) { + $html = $this->view->tag('td', $session->getDateDebutTexte(). + $this->view->_(' au '). + $session->getDateFinTexte()); + $html.= $this->view->tag('td', $session->getLibelleLieu()); + $html.= $this->view->tag('td', $this->view->tagAnchor(['controller' => 'abonne', + 'action' => 'detail-session', + 'id' => $session->getId()], + $this->view->_('Détails de la session'))); + $html.= $this->view->tag('td', $this->view->tagSessionFormationInscription($session)); + $html.= $this->view->tag('td', $this->sessionInformations($session)); + + return $this->view->tag('tr', $html, ['class' => 'session']); + } + + + protected function sessionInformations($session) { + $html = $session->isAnnule() + ? $this->errorSpan($this->view->_('Annulée')) + : ''; + $html.= $session->hasDateLimiteInscription() + ? ($this->errorSpan( + (($session->isDateSubscriptionExhausted() + ? $this->view->_('Date de limite d\'inscription dépassée: ') + : ''). + $session->getDateLimiteInscriptionHumanRead()))) + : ''; + + $html.= $session->isFull() + ? $this->errorSpan($this->view->_('Complet: maximum de personnes inscrites')) + : ''; + + return $html; + } +} + + +/* + +<tr class="session_<?php echo $this->session->getId()?> <?php echo $this->item_class ?>"> +<?php +echo sprintf("<td>%s %s</td>", + $this->renderDateRange($this->session->getDateDebut(), $this->session->getDateFin()), + $this->session->isAnnule() ? '(Annulé)' : ''); +echo sprintf("<td>%s </td>", $this->session->getLibelleLieu()); +echo sprintf("<td>%s</td>", + $this->tagAnchor(array('action' => 'detail-session', + 'id' => $this->session->getId()), + $this->_('Détails de la session'))); +echo sprintf("<td>%s</td>", + $this->tagSessionFormationInscription($this->session)); +?> +</tr> + + + + */ ?> \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/RenderSessions.php b/library/ZendAfi/View/Helper/RenderSessions.php new file mode 100644 index 00000000000..b6d9421dcde --- /dev/null +++ b/library/ZendAfi/View/Helper/RenderSessions.php @@ -0,0 +1,108 @@ +<?php +/** + * Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 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). + * + * AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class ZendAfi_View_Helper_RenderSessions extends ZendAfi_View_Helper_BaseHelper { + + protected $_strategy; + + public function renderSessions($sessions, $strategy = 'Dl') { + + $render = 'Render_Sessions_'.$strategy; + + $this->_strategy = new $render($this->view); + return $this->_strategy->render($sessions); + } +} + + + +class Render_Sessions_Dl { + public function render($session) { + return ''; + } + +} + + +class Render_Sessions { + protected $view; + + public function __construct($view) { + $this->view = $view; + } +} + + +class Render_Sessions_Table extends Render_Sessions{ + + public function render($sessions) { + $html = $this->headers(); + $html.= $this->tBody($sessions); + return $this->view->tag('table',$html,['class' => 'sessions']); + } + + + protected function headers() { + $html = $this->view->tag('th', $this->view->_('Date')); + $html.= $this->view->tag('th', $this->view->_('Lieu')); + $html.= $this->view->tag('th', $this->view->_('Détails')); + $html.= $this->view->tag('th', $this->view->_('Inscription')); + $html.= $this->view->tag('th', $this->view->_('Informations')); + $html = $this->view->tag('tr', $html); + return $this->view->tag('thead', $html); + } + + + protected function tBody($sessions) { + $html = ''; + + if(array_filter($sessions)>0) + foreach($sessions as $session) + $html.= $this->view->renderSession($session, 'Table'); + + return $this->view->tag('tbody', $html); + } + +} +/* <table class="sessions""> + <thead> + <tr class="soustitre"> + <td>Date</td> + <td>Lieu</td> + <td>Détails</td> + <td>Inscription</td> + <td>Informations</td> + </tr> + </thead> + <tbody> + <?php + echo $this->partialCycle('abonne/_session.phtml', + 'session', + $this->formation->getSessions(), + array('first', 'second')); + ?> + </tbody> + </table> +</div> +*/ + +?> \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/TagSessionFormationInscription.php b/library/ZendAfi/View/Helper/TagSessionFormationInscription.php index b5d07fff7ba..372a4805d0a 100644 --- a/library/ZendAfi/View/Helper/TagSessionFormationInscription.php +++ b/library/ZendAfi/View/Helper/TagSessionFormationInscription.php @@ -26,43 +26,26 @@ class ZendAfi_View_Helper_TagSessionFormationInscription extends Zend_View_Helpe * @return string */ public function tagSessionFormationInscription($session) { - if ($session->isInscriptionClosed()) + if(!$session) return ''; - $user = Class_Users::getLoader()->getIdentity(); - if (!$user->hasRightSuivreFormation()) + $user = Class_Users::getIdentity(); + + if(!$user) return ''; - - $content = ''; - $sessions_inscrit = $user->getSessionFormations(); - $is_inscrit = in_array($session, $sessions_inscrit); - - - if ($is_inscrit) - $content = $this->view->tagAnchor(['controller' => 'abonne', - 'action' => 'desinscrire-session', - 'id' => $session->getId()], - $this->view->_('Se désinscrire')); - - if ($session->isFull()) - return $content.sprintf('<span class="error">%s</span>', - $this->view->_('Effectif maximum atteint')); - - if ($is_inscrit) - return $content; - - $link_inscription = $this->view->tagAnchor(['controller' => 'abonne', - 'action' => 'inscrire-session', - 'id' => $session->getId()], - $this->view->_('S\'inscrire')); - - if (!$session->hasDateLimiteInscription()) - return $link_inscription; - - return sprintf('%s %s: %s', - $link_inscription, - $this->view->_('Limite'), - $this->view->humanDate($session->getDateLimiteInscription(), 'd MMMM YYYY')); + + if (in_array($session, $user->getSessionFormations())) + return $this->view->tagAnchor(['controller' => 'abonne', + 'action' => 'desinscrire-session', + 'id' => $session->getId()], + $this->view->_('Se désinscrire')); + + return $session->isSubscriableFor($user) + ? $this->view->tagAnchor(['controller' => 'abonne', + 'action' => 'inscrire-session', + 'id' => $session->getId()], + $this->view->_('S\'inscrire')) + : ''; } } diff --git a/tests/application/modules/opac/controllers/AbonneControllerFormationsTest.php b/tests/application/modules/opac/controllers/AbonneControllerFormationsTest.php index 4a8975019cf..d2a87db6d07 100644 --- a/tests/application/modules/opac/controllers/AbonneControllerFormationsTest.php +++ b/tests/application/modules/opac/controllers/AbonneControllerFormationsTest.php @@ -224,7 +224,7 @@ class AbonneControllerFormationsListTest extends AbstractAbonneControllerFormati /** @test */ function session_java_mars_ShouldNotHaveLinkForInscrireAsInscriptionClosed() { - $this->assertNotXPath('//a[contains(@href, "abonne/inscrire-session/id/32")]', $this->response->getBody()); + $this->assertNotXPath('//a[contains(@href, "abonne/inscrire-session/id/32")]'); } @@ -246,7 +246,6 @@ class AbonneControllerFormationsListTest extends AbstractAbonneControllerFormati } - /** @test */ function session_fevrier_17_ShouldBeDisplayedUnderLearnJavaInSecondPosition() { $this->assertXPathContentContains('//tbody//tr//td', '10 février 2015 au 20 février 2015'); @@ -262,18 +261,39 @@ class AbonneControllerFormationsListTest extends AbstractAbonneControllerFormati /** @test */ function session_fevrier_17_ShouldHaveLinkForInscrire() { $this->assertXPathContentContains('//tbody//tr//a[contains(@href, "abonne/inscrire-session/id/31")]', - "S'inscrire", - $this->response->getBody()); + "S'inscrire"); } /** @test */ function session_fevrier_17_ShouldDisplayDateLimite15Fevrier() { - $this->assertXPathContentContains('//tbody//tr', - "Limite: 20 janvier 2015"); + $this->assertXPathContentContains('//tbody//tr/td', + '20 janvier 2015'); + } + + + /** @test */ + function sessionShouldBeFull() { + $this->assertXPathContentContains('//tbody//tr/td/span[@class="error"]', + 'Complet', $this->_response->getBody()); + } + + + /** @test */ + function sessionShouldBeCanceld() { + $this->assertXPathContentContains('//tbody//tr/td/span[@class="error"]', + 'Annul'); + } + + + /** @test */ + function sessionShouldBeDisplaySubscribeTimeExhaust() { + $this->assertXPathContentContains('//tbody//tr/td/span[@class="error"]', + 'Date '); } + /** @test */ function session_fevrier_17_ShouldHaveLinkForDetailSessionFormation() { $this->assertXPathContentContains('//tbody//tr//a[contains(@href, "abonne/detail-session/id/31")]', @@ -297,7 +317,8 @@ class AbonneControllerFormationsListTest extends AbstractAbonneControllerFormati /** @test */ function session_python_juillet_ShouldHaveLinkForDesinscrire() { $this->assertXPathContentContains('//tr//a[contains(@href, "abonne/desinscrire-session/id/121")]', - "Se désinscrire"); + "Se désinscrire", + $this->_response->getBody()); } @@ -380,7 +401,7 @@ Class AbonneControllerFormationsFicheAbonneWithoutSufficientRigthsTest extends A class AbonneControllerFormationsListWithoutRightSuivreFormationTest extends AbstractAbonneControllerFormationsTestCase { public function setUp() { parent::setUp(); - $this->_amadou->setUserGroups(array()); + $this->_amadou->setUserGroups([]); $this->dispatch('/opac/abonne/formations'); } @@ -392,8 +413,8 @@ class AbonneControllerFormationsListWithoutRightSuivreFormationTest extends Abst /** @test */ - function linkForDesinscrireShouldNotExists() { - $this->assertNotXPath('//a[contains(@href, "abonne/desinscrire-session")]'); + function linkForDesinscrireShouldExists() { + $this->assertXPath('//a[contains(@href, "abonne/desinscrire-session")]'); } @@ -482,7 +503,7 @@ class AbonneControllerFormationsSessionJavaFevrierFullListTest extends AbonneCon /** @test */ public function sessionShouldDisplayFull() { - $this->assertXPathContentContains('//tbody//tr//span', 'Effectif maximum atteint'); + $this->assertXPathContentContains('//tbody//tr/td/span[@class="error"]', 'Complet'); } } diff --git a/tests/library/ZendAfi/View/Helper/Accueil/FormationsWidgetTest.php b/tests/library/ZendAfi/View/Helper/Accueil/FormationsWidgetTest.php index 8dd2d2a6f8c..ea641b2080e 100644 --- a/tests/library/ZendAfi/View/Helper/Accueil/FormationsWidgetTest.php +++ b/tests/library/ZendAfi/View/Helper/Accueil/FormationsWidgetTest.php @@ -21,7 +21,7 @@ -class ZendAfi_View_Helper_Accueil_FormationsWidgetTest extends ViewHelperTestCase { +class ZendAfi_View_Helper_Accueil_FormationsWidgetWithNoSessionTest extends ViewHelperTestCase { public function setup() { parent::setup(); @@ -53,7 +53,7 @@ class ZendAfi_View_Helper_Accueil_FormationsWidgetTest extends ViewHelperTestCas -class ZendAfi_View_Helper_Accueil_FormationsWidgetTestWithLoggedSIGBUser extends ViewHelperTestCase { +class ZendAfi_View_Helper_Accueil_FormationsWidgetWithLoggedSIGBUserTest extends ViewHelperTestCase { public function setup() { parent::setup(); @@ -78,6 +78,7 @@ class ZendAfi_View_Helper_Accueil_FormationsWidgetTestWithLoggedSIGBUser extends 'libelle' => 'Air Dogfight chapter 1', 'sessions' => [$this->fixture('Class_SessionFormation', ['id' => 1, + 'date_limite_inscription' => '2014-06-01', 'date_debut' => '2014-06-01', 'date_fin' => '2014-06-10'])]]), ['division' => 1, @@ -100,4 +101,89 @@ class ZendAfi_View_Helper_Accueil_FormationsWidgetTestWithLoggedSIGBUser extends $this->assertXPath($this->_html, '//div[@class="actions"]/a[contains(@href,"abonne/inscrire-session/id/1")]'); } } + + + +class ZendAfi_View_Helper_Accueil_FormationsWidgetWithDateSubscriptionPastTest extends ViewHelperTestCase { + + public function setup() { + parent::setup(); + + Class_Formation::beVolatile(); + Class_SessionFormation::beVolatile(); + Class_Users::beVolatile(); + Class_SessionFormationInscription::beVolatile(); + + Class_Formation::setTimeSource(new TimeSourceForTest('2014-05-06 14:00:00')); + $sigb_user = $this->fixture('Class_Users', + ['id' => 1, + 'login' => 'uR', + 'password' => 'pwd']) + ->beAbonneSIGB(); + + ZendAfi_Auth::getInstance()->logUser($sigb_user); + + $helper = new ZendAfi_View_Helper_Accueil_FormationsWidget( + $this->fixture('Class_Formation', + ['id' => 1, + 'libelle' => 'Air Dogfight chapter 1', + 'sessions' => [$this->fixture('Class_SessionFormation', + ['id' => 1, + 'date_debut' => '2014-06-01', + 'date_fin' => '2014-06-10', + 'date_limite_inscription' => '2014-01-01'])]]), + ['division' => 1, + 'type_module' => 'FORMATIONS_WIDGET', + 'preferences' => ['selected_formations' => '1']]); + + $helper->setView(new ZendAfi_Controller_Action_Helper_View()); + $this->_html = $helper->getBoite(); + } + + + + /** @test */ + public function subscriptionDatePastShouldBeDisplay() { + $this->assertXPathContentContains($this->_html, '//dl/dd', "Date de limite "); + } +} + + + +class ZendAfi_View_Helper_Accueil_FormationsWidgetWithNoLoggedUserTest extends ViewHelperTestCase { + + public function setup() { + parent::setup(); + + Class_Formation::beVolatile(); + Class_SessionFormation::beVolatile(); + Class_Users::beVolatile(); + Class_SessionFormationInscription::beVolatile(); + + Class_Formation::setTimeSource(new TimeSourceForTest('2014-05-06 14:00:00')); + + ZendAfi_Auth::getInstance()->clearIdentity(); + + $helper = new ZendAfi_View_Helper_Accueil_FormationsWidget( + $this->fixture('Class_Formation', + ['id' => 1, + 'libelle' => 'Air Dogfight chapter 1', + 'sessions' => [$this->fixture('Class_SessionFormation', + ['id' => 1, + 'date_debut' => '2014-06-01', + 'date_fin' => '2014-06-10'])]]), + ['division' => 1, + 'type_module' => 'FORMATIONS_WIDGET', + 'preferences' => ['selected_formations' => '1']]); + + $helper->setView(new ZendAfi_Controller_Action_Helper_View()); + $this->_html = $helper->getBoite(); + } + + + /** @test */ + public function subscriptionShouldNotBeAvailable() { + $this->assertXPathContentContains($this->_html, '//div[@class="actions"]', "Vous devez vous connecter pour pouvoir vous inscrire"); + } +} ?> \ No newline at end of file -- GitLab