From 1894704bcc26de53ee3a777cc6665412640e9215 Mon Sep 17 00:00:00 2001 From: efalcy <efalcy@afi-sa.fr> Date: Thu, 30 Oct 2014 12:17:43 +0100 Subject: [PATCH] dev #16803 : allow all users to see sessions --- .../opac/controllers/AbonneController.php | 21 +- .../views/scripts/abonne/formations.phtml | 20 -- library/Class/SessionFormation.php | 5 +- .../ZendAfi/View/Helper/Abonne/Formations.php | 14 +- library/ZendAfi/View/Helper/RenderSession.php | 48 +-- .../Helper/TagSessionFormationInscription.php | 13 +- .../AbonneControllerFormationsTest.php | 282 +++++++++--------- .../controllers/FormationsControllerTest.php | 161 ++++++++++ 8 files changed, 343 insertions(+), 221 deletions(-) delete mode 100644 application/modules/opac/views/scripts/abonne/formations.phtml create mode 100644 tests/application/modules/opac/controllers/FormationsControllerTest.php diff --git a/application/modules/opac/controllers/AbonneController.php b/application/modules/opac/controllers/AbonneController.php index 3c3df49d92f..7760cbbd18e 100644 --- a/application/modules/opac/controllers/AbonneController.php +++ b/application/modules/opac/controllers/AbonneController.php @@ -25,7 +25,7 @@ class AbonneController extends ZendAfi_Controller_Action { public function init() { parent::init(); - + xdebug_break(); if ('authenticate' == $this->getRequest()->getActionName()) return; @@ -48,13 +48,6 @@ class AbonneController extends ZendAfi_Controller_Action { } - public function formationsAction() { - $this->sessions_inscrit = array(); - $this->view->formations_by_year = Class_Formation::indexByYear(Class_Formation::getLoader()->findAll()); - $this->view->user = $this->_user; - } - - public function inscrireSessionAction() { if (($session = Class_SessionFormation::getLoader()->find((int)$this->_getParam('id'))) && !$session->isInscriptionClosed()) { @@ -70,14 +63,14 @@ class AbonneController extends ZendAfi_Controller_Action { $this->_helper->notify('L\'inscription à cette session est fermée'); } - $this->_redirect('/abonne/formations'); + $this->_redirect('/formations'); } public function desinscrireSessionAction() { if (!$session = Class_SessionFormation::getLoader()->find((int)$this->_getParam('id'))) { $this->_helper->notify('Session non trouvée'); - $this->_redirect('/abonne/formations'); + $this->_redirect('/formations'); return; } @@ -88,7 +81,7 @@ class AbonneController extends ZendAfi_Controller_Action { $session->getLibelleFormation())); }; - $this->_redirect('/abonne/formations'); + $this->_redirect('/formations'); } @@ -126,12 +119,6 @@ class AbonneController extends ZendAfi_Controller_Action { - public function detailSessionAction() { - if (!$session = Class_SessionFormation::getLoader()->find((int)$this->_getParam('id'))) - $this->_redirect('/abonne/formations'); - $this->view->retour_action = $this->_getParam('retour', 'formations'); - $this->view->session = $session; - } public function viewavisAction(){ diff --git a/application/modules/opac/views/scripts/abonne/formations.phtml b/application/modules/opac/views/scripts/abonne/formations.phtml deleted file mode 100644 index bc118f57ab0..00000000000 --- a/application/modules/opac/views/scripts/abonne/formations.phtml +++ /dev/null @@ -1,20 +0,0 @@ -<?php -echo $this->openBoite('Formations'); - -if (!$this->user->hasRightSuivreFormation()) - echo sprintf('<p class="error">%s</p>', - $this->_("Vous n'avez pas les droits suffisants pour vous inscrire à une formation")); - -foreach($this->formations_by_year as $year => $formations) { - echo '<div class="formations">'; - echo $this->partialCycle('abonne/_formation.phtml', - 'formation', - $formations, - ['first', 'second']); - echo '</div>'; -} - -echo $this->closeBoite(); -?> - -<?php echo $this->abonne_RetourFiche(); ?> diff --git a/library/Class/SessionFormation.php b/library/Class/SessionFormation.php index 3a648d506a8..2b874b31698 100644 --- a/library/Class/SessionFormation.php +++ b/library/Class/SessionFormation.php @@ -215,10 +215,7 @@ class Class_SessionFormation extends Storm_Model_Abstract { public function isSubscriableFor($user) { - if(!$user) - return false; - - if(!$user->hasRightSuivreFormation()) + if($user && !$user->hasRightSuivreFormation()) return false; if(!$this->isValid() || $this->isFull() || $this->isAnnule() || $this->isInscriptionClosed()) diff --git a/library/ZendAfi/View/Helper/Abonne/Formations.php b/library/ZendAfi/View/Helper/Abonne/Formations.php index 894df175ff3..90d20ad260c 100644 --- a/library/ZendAfi/View/Helper/Abonne/Formations.php +++ b/library/ZendAfi/View/Helper/Abonne/Formations.php @@ -16,28 +16,28 @@ * * 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 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class ZendAfi_View_Helper_Abonne_Formations extends ZendAfi_View_Helper_Abonne_Abstract { public function abonne_formations($user) { if (!Class_AdminVar::isFormationEnabled() || !$user->hasRightSuivreFormation()) return ''; - $action_url = $this->view->url(['controller' => 'abonne', - 'action' => 'formations'], - null, + $action_url = $this->view->url(['controller' => 'formations', + 'action' => 'index'], + null, true); $html = $this->view->tagAnchor($action_url, $this->view->_("S'inscrire à une formation")); $html .= '<ul>'; - + foreach ($user->getSessionFormations() as $session) { - $html .= sprintf('<li><a href="%s">%s, %s</li>', - $this->view->url(['controller' => 'abonne', + $html .= sprintf('<li><a href="%s">%s, %s</li>', + $this->view->url(['controller' => 'formations', 'action' => 'detail-session', 'id' => $session->getId(), 'retour' => 'fiche'], diff --git a/library/ZendAfi/View/Helper/RenderSession.php b/library/ZendAfi/View/Helper/RenderSession.php index b9be233a021..59ae04d19cc 100644 --- a/library/ZendAfi/View/Helper/RenderSession.php +++ b/library/ZendAfi/View/Helper/RenderSession.php @@ -16,7 +16,7 @@ * * 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 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -49,29 +49,29 @@ class Render_Session { class Render_Session_Dl extends Render_Session { - + public function render($session) { return $this->definitionListFor($session). $this->actionsFor($session); } - + protected function actionsFor($session) { return $this->view->tag('div', $this->view->tagSessionFormationInscription($session), ['class'=>'actions']); } - + protected function definitionListFor($session) { - $html = + $html = $this->view->tag('dt', $this->view->_('Informations')). - $this->view->tag('dd', ($session->isFull() + $this->view->tag('dd', ($session->isFull() ? $this->view->_('Complet ') : '' ). - (!$session->isDateSubscriptionExhausted() - ? '' + (!$session->isDateSubscriptionExhausted() + ? '' : $this->view->_('Date de limite d\'inscription dépassée'))). $this->view->tag('dt', $this->view->_('Lieu')). @@ -79,19 +79,19 @@ class Render_Session_Dl extends Render_Session { $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->_('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'), @@ -100,23 +100,23 @@ class Render_Session_Dl extends Render_Session { $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->_('Contenu')). $this->view->tag('dd', $session->getContenu()); return $this->view->tag('dl', $html , ['class' => 'session_formation']); } - - + + protected function getIntervenantsFor($session) { $html = ''; foreach ($session->getIntervenants() as $intervenant){ $html.= $this->view->tag('li', $intervenant->getNom().', '.$intervenant->getPrenom()); } - + return $this->view->tag('ul', $html); } } @@ -125,14 +125,14 @@ class Render_Session_Dl extends Render_Session { 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', + $html.= $this->view->tag('td', $this->view->tagAnchor(['controller' => 'formations', 'action' => 'detail-session', 'id' => $session->getId()], $this->view->_('Détails de la session'))); @@ -144,18 +144,18 @@ class Render_Session_Table extends Render_Session { protected function sessionInformations($session) { - $html = $session->isAnnule() - ? $this->errorSpan($this->view->_('Annulée')) + $html = $session->isAnnule() + ? $this->errorSpan($this->view->_('Annulée')) : ''; - $html.= $session->isDateSubscriptionExhausted() + $html.= $session->isDateSubscriptionExhausted() ? $this->errorSpan( $this->view->_('Date de limite d\'inscription dépassée: '). $session->getDateLimiteInscriptionHumanRead()) - : ($session->hasDateLimiteInscription() + : ($session->hasDateLimiteInscription() ? $this->view->tag('span',$this->view->_('Date de limite d\'inscription: '). $session->getDateLimiteInscriptionHumanRead()) :''); - $html.= $session->isFull() + $html.= $session->isFull() ? $this->errorSpan($this->view->_('Complet: maximum de personnes inscrites')) : ''; diff --git a/library/ZendAfi/View/Helper/TagSessionFormationInscription.php b/library/ZendAfi/View/Helper/TagSessionFormationInscription.php index 372a4805d0a..08ea9018b6e 100644 --- a/library/ZendAfi/View/Helper/TagSessionFormationInscription.php +++ b/library/ZendAfi/View/Helper/TagSessionFormationInscription.php @@ -16,7 +16,7 @@ * * 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 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class ZendAfi_View_Helper_TagSessionFormationInscription extends Zend_View_Helper_HtmlElement { /** @@ -30,17 +30,14 @@ class ZendAfi_View_Helper_TagSessionFormationInscription extends Zend_View_Helpe return ''; $user = Class_Users::getIdentity(); - - if(!$user) - return ''; - - if (in_array($session, $user->getSessionFormations())) + + if ($user && 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) + + return $session->isSubscriableFor($user) ? $this->view->tagAnchor(['controller' => 'abonne', 'action' => 'inscrire-session', 'id' => $session->getId()], diff --git a/tests/application/modules/opac/controllers/AbonneControllerFormationsTest.php b/tests/application/modules/opac/controllers/AbonneControllerFormationsTest.php index e9c725be764..2f2e3977a27 100644 --- a/tests/application/modules/opac/controllers/AbonneControllerFormationsTest.php +++ b/tests/application/modules/opac/controllers/AbonneControllerFormationsTest.php @@ -16,7 +16,7 @@ * * 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 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ require_once 'AbstractControllerTestCase.php'; @@ -51,7 +51,7 @@ abstract class AbstractAbonneControllerFormationsTestCase extends AbstractContro Class_SessionFormation::beVolatile(); Class_SessionFormationInscription::beVolatile(); Class_Formation::beVolatile(); - + Class_Formation::setTimeSource($test_time); Class_SessionFormation::setTimeSource($test_time); @@ -69,13 +69,13 @@ abstract class AbstractAbonneControllerFormationsTestCase extends AbstractContro ->setUserGroups([$this->fixture('Class_UserGroup',['id' => 23])->addRightSuivreFormation()]); ZendAfi_Auth::getInstance()->logUser($this->_amadou); - + $this->_gallice_cafe = $this->fixture('Class_Lieu', ['id' => 98, 'libelle' => 'Galice']); - - $this->_bib_romains = $this->fixture('Class_Lieu', + + $this->_bib_romains = $this->fixture('Class_Lieu', ['id' => '99', 'libelle' => 'Bibliothèque des romains']); @@ -96,7 +96,7 @@ abstract class AbstractAbonneControllerFormationsTestCase extends AbstractContro 'effectif_max' => 10, 'lieu' => $this->_gallice_cafe, 'date_debut' => '2014-01-10']); - + $this->_session_smalltalk_juillet = $this->fixture('Class_SessionFormation', ['id' => 12, 'formation_id' => 1, @@ -105,7 +105,7 @@ abstract class AbstractAbonneControllerFormationsTestCase extends AbstractContro 'lieu' => $this->_gallice_cafe, 'stagiaires' => [], 'date_debut' => '2014-07-11']); - + $this->_learn_smalltalk = $this->fixture('Class_Formation', ['id' => 1, 'libelle' => 'Learn Smalltalk', @@ -132,7 +132,7 @@ abstract class AbstractAbonneControllerFormationsTestCase extends AbstractContro 'date_debut' => '2014-03-01', 'stagiaires' => [], 'date_limite_inscription' => '2014-03-01']); - + $this->_session_java_septembre = $this->fixture('Class_SessionFormation', ['id' => 30, 'formation_id' => 3, @@ -184,7 +184,7 @@ abstract class AbstractAbonneControllerFormationsTestCase extends AbstractContro ['id' => 1, 'stagiaire' => $this->_amadou, 'session_formation' => $this->_session_python_juillet]); - + $this->_amadou->setSessionFormationInscriptions([$inscription_amadou_python]); } } @@ -201,8 +201,8 @@ class AbonneControllerFormationsListTest extends AbstractAbonneControllerFormati Class_Profil::newInstanceWithId(42, ['cfg_modules' => ['abonne' => ['formations' => ['barre_nav' => 'Les formations']]]])); - $this->dispatch('/opac/abonne/formations', true); - } + $this->dispatch('/opac/formations', true); + } /** @test */ function aH2ShouldContainsLearnJava() { @@ -258,7 +258,7 @@ class AbonneControllerFormationsListTest extends AbstractAbonneControllerFormati $this->assertXPathContentContains('//tbody//tr[1]//td', '1 mars 2014'); } - + /** @test */ function sessionSeptemberShouldBeSecond() { $this->assertXPathContentContains('//tbody//tr[2]//td', ' septembre 2014'); @@ -270,134 +270,134 @@ class AbonneControllerFormationsListTest extends AbstractAbonneControllerFormati $this->assertXPathContentContains('//tbody//tr[3]//td', ' février 2015'); } - + /** @test */ - function session10Juillet2014ShouldBeFirst() { - $this->assertXPathContentContains('//tbody//tr[1]//td', '10 juillet 2014'); - } + function session10Juillet2014ShouldBeFirst() { + $this->assertXPathContentContains('//tbody//tr[1]//td', '10 juillet 2014'); + } - /** @test */ - function session11Juillet2014ShouldSecond() { - $this->assertXPathContentContains('//tbody//tr[2]//td', '11 juillet 2014'); - } + /** @test */ + function session11Juillet2014ShouldSecond() { + $this->assertXPathContentContains('//tbody//tr[2]//td', '11 juillet 2014'); + } - /** @test */ - function session_fevrier_17_lieuBonlieuShouldBeDisplayed() { - $this->assertXPathContentContains('//tbody//tr//td', 'Bonlieu'); - } + /** @test */ + function session_fevrier_17_lieuBonlieuShouldBeDisplayed() { + $this->assertXPathContentContains('//tbody//tr//td', 'Bonlieu'); + } - /** @test */ - function session_fevrier_17_ShouldHaveLinkForInscrire() { - $this->assertXPathContentContains('//tbody//tr//a[contains(@href, "abonne/inscrire-session/id/31")]', - "S'inscrire"); - } + /** @test */ + function session_fevrier_17_ShouldHaveLinkForInscrire() { + $this->assertXPathContentContains('//tbody//tr//a[contains(@href, "abonne/inscrire-session/id/31")]', + "S'inscrire"); + } - /** @test */ - function session_fevrier_17_ShouldDisplayDateLimite15Fevrier() { - $this->assertXPathContentContains('//tbody//tr/td', - '20 janvier 2015'); - } + /** @test */ + function session_fevrier_17_ShouldDisplayDateLimite15Fevrier() { + $this->assertXPathContentContains('//tbody//tr/td', + '20 janvier 2015'); + } - /** @test */ - function session_fevrier_17_ShouldHaveLinkForDetailSessionFormation() { - $this->assertXPathContentContains('//tbody//tr//a[contains(@href, "abonne/detail-session/id/31")]', - 'Détails de la session'); - } + /** @test */ + function session_fevrier_17_ShouldHaveLinkForDetailSessionFormation() { + $this->assertXPathContentContains('//tbody//tr//a[contains(@href, "formations/detail-session/id/31")]', + 'Détails de la session'); + } - /** @test */ - function session_mars_27_ShouldBeDisplayedUnderLearnJavaInFirstPosition() { - $this->assertXPathContentContains('//tbody//tr[1]', '1 mars 2014'); - } + /** @test */ + function session_mars_27_ShouldBeDisplayedUnderLearnJavaInFirstPosition() { + $this->assertXPathContentContains('//tbody//tr[1]', '1 mars 2014'); + } - /** @test */ - function session_septembre_java_ShouldBeAnnule() { - $this->assertXPathContentContains('//tr/td/span[@class="error"]', 'Annul'); - } + /** @test */ + function session_septembre_java_ShouldBeAnnule() { + $this->assertXPathContentContains('//tr/td/span[@class="error"]', 'Annul'); + } - /** @test */ - function session_python_juillet_ShouldHaveLinkForDesinscrire() { - $this->assertXPathContentContains('//tr//a[contains(@href, "abonne/desinscrire-session/id/121")]', - "Se désinscrire"); - } + /** @test */ + function session_python_juillet_ShouldHaveLinkForDesinscrire() { + $this->assertXPathContentContains('//tr//a[contains(@href, "abonne/desinscrire-session/id/121")]', + "Se désinscrire"); + } - /** @test */ - function boiteTitleShouldBeFormations() { - $this->assertXPathContentContains('//h1', 'Formations'); - } + /** @test */ + function boiteTitleShouldBeFormations() { + $this->assertXPathContentContains('//h1', 'Formations'); + } - /** - * @test - * @group pagetitles - */ - public function barreNavShouldContainsMonCompte() { - $this->assertXPathContentContains('//div[@class="barre_nav"]//span//a[contains(@href, "index/index?id_profil=2")]', - 'Mon compte'); - } + /** + * @test + * @group pagetitles + */ + public function barreNavShouldContainsMonCompte() { + $this->assertXPathContentContains('//div[@class="barre_nav"]//span//a[contains(@href, "index/index?id_profil=2")]', + 'Mon compte'); + } - /** @test */ - public function barreNavShouldContainsAccueilThatLinksToProfilOne() { - $this->assertXPathContentContains('//div[@class="barre_nav"]//a[contains(@href, "index/index?id_profil=1")]', - 'Accueil'); - } -} + /** @test */ + public function barreNavShouldContainsAccueilThatLinksToProfilOne() { + $this->assertXPathContentContains('//div[@class="barre_nav"]//a[contains(@href, "index/index?id_profil=1")]', + 'Accueil'); + } + } -class AbonneControllerFormationsFicheAbonneTest extends AbstractAbonneControllerFormationsTestCase { - public function setUp() { - parent::setUp(); - $this->dispatch('/opac/abonne/fiche/retour/fiche'); - } + class AbonneControllerFormationsFicheAbonneTest extends AbstractAbonneControllerFormationsTestCase { + public function setUp() { + parent::setUp(); + $this->dispatch('/opac/abonne/fiche/retour/fiche'); + } - /** @test */ - public function pageShouldContainsLinkToFormations() { - $this->assertXPathContentContains('//a[contains(@href, "abonne/formations")]', 'S\'inscrire à une formation'); - } + /** @test */ + public function pageShouldContainsLinkToFormations() { + $this->assertXPathContentContains('//a[contains(@href, "formations")]', 'S\'inscrire à une formation'); + } - /** @test */ - public function pageShouldContainsVousEtesInscritFormationPython() { - $this->assertXPathContentContains('//ul//li', 'Learn Python, 10 juillet 2014'); - } + /** @test */ + public function pageShouldContainsVousEtesInscritFormationPython() { + $this->assertXPathContentContains('//ul//li', 'Learn Python, 10 juillet 2014'); + } - /** @test */ - public function pageShouldContainsLinkToDetailSessionPyhton() { - $this->assertXPath('//li//a[contains(@href, "abonne/detail-session/id/121/retour/fiche")]'); - } -} + /** @test */ + public function pageShouldContainsLinkToDetailSessionPyhton() { + $this->assertXPath('//li//a[contains(@href, "formations/detail-session/id/121/retour/fiche")]',$this->_response->getBody()); + } + } -Class AbonneControllerFormationsFicheAbonneWithoutSufficientRigthsTest extends AbstractAbonneControllerFormationsTestCase { - /** @test */ - public function whenFormationsDisabledPageShouldNotContainsLinkToFormations() { - Class_AdminVar::getLoader() - ->newInstanceWithId('FORMATIONS') - ->setValeur('0'); - $this->dispatch('/opac/abonne/fiche'); - $this->assertNotXPath('//a[contains(@href, "abonne/formations")]'); - } + Class AbonneControllerFormationsFicheAbonneWithoutSufficientRigthsTest extends AbstractAbonneControllerFormationsTestCase { + /** @test */ + public function whenFormationsDisabledPageShouldNotContainsLinkToFormations() { + Class_AdminVar::getLoader() + ->newInstanceWithId('FORMATIONS') + ->setValeur('0'); + $this->dispatch('/opac/abonne/fiche'); + $this->assertNotXPath('//a[contains(@href, "formations")]'); + } - /** @test */ - public function whenUserNotStagiairePageShouldNotContainsLinkToFormations() { - $this->_amadou->setUserGroups(array()); - $this->dispatch('/opac/abonne/fiche'); - $this->assertNotXPath('//a[contains(@href, "abonne/formations")]'); + /** @test */ + public function whenUserNotStagiairePageShouldNotContainsLinkToFormations() { + $this->_amadou->setUserGroups(array()); + $this->dispatch('/opac/abonne/fiche'); + $this->assertNotXPath('//a[contains(@href, "formations")]'); } } @@ -407,7 +407,7 @@ class AbonneControllerFormationsListWithoutRightSuivreFormationTest extends Abst public function setUp() { parent::setUp(); $this->_amadou->setUserGroups([]); - $this->dispatch('/opac/abonne/formations'); + $this->dispatch('/opac/formations'); } @@ -422,7 +422,7 @@ class AbonneControllerFormationsListWithoutRightSuivreFormationTest extends Abst $this->assertXPath('//a[contains(@href, "abonne/desinscrire-session")]'); } - + /** @test */ public function messageVousNavezPasLesDroitsSuffisantsShouldBeVisible() { $this->assertXPathContentContains('//p', "Vous n'avez pas les droits"); @@ -436,7 +436,7 @@ class AbonneControllerFormationsAmadouInscritSessionMarsJavaClosedTest extends A public function inscrireSessionShouldNotCallSave() { $this->dispatch('/opac/abonne/inscrire-session/id/32'); $this->assertNotContains($this->_amadou, Class_SessionFormationInscription::findAllBy(['session_formation_id'=>32])); - } + } } @@ -445,7 +445,7 @@ class AbonneControllerFormationsAmadouInscritSessionFeebruaryJavaOpenTest extend public function setUp() { parent::setUp(); $this->dispatch('/opac/abonne/inscrire-session/id/31'); - } + } /** @test */ @@ -463,7 +463,7 @@ class AbonneControllerFormationsAmadouInscritSessionFeebruaryJavaOpenTest extend /** @test */ function answerShouldRedirectToFormationList() { - $this->assertRedirectTo('/abonne/formations'); + $this->assertRedirectTo('/formations'); } @@ -496,9 +496,9 @@ abstract class AbonneControllerFormationsSessionJavaFevrierFullTestCase extends class AbonneControllerFormationsSessionJavaFevrierFullListTest extends AbonneControllerFormationsSessionJavaFevrierFullTestCase { public function setUp() { parent::setUp(); - Class_AdminVar::newInstanceWithId('CHAMPS_FICHE_UTILISATEUR', + Class_AdminVar::newInstanceWithId('CHAMPS_FICHE_UTILISATEUR', ['valeur' => 'pseudo;nom;prenom;mail']); - $this->dispatch('/opac/abonne/formations'); + $this->dispatch('/opac/formations'); } @@ -521,7 +521,7 @@ class AbonneControllerFormationsSessionJavaFevrierFullAndInscritListTest extends public function pageShouldHaveLinkToDesinscrire() { $this->_session_java_fevrier->addStagiaire($this->_amadou); $this->_amadou->setSessionFormations(array($this->_session_java_fevrier)); - $this->dispatch('/opac/abonne/formations'); + $this->dispatch('/opac/formations'); $this->assertXPath('//a[contains(@href, "abonne/desinscrire-session/id/31")]'); } } @@ -576,11 +576,11 @@ class AbonneControllerFormationsAmadouDesinscritSessionJuilletPythonTest extends public function setUp() { parent::setUp(); $this->dispatch('/opac/abonne/desinscrire-session/id/121'); - } + } /** @test */ function answerShouldRedirectToFormationList() { - $this->assertRedirectTo('/abonne/formations'); + $this->assertRedirectTo('/formations'); } @@ -603,14 +603,14 @@ class AbonneControllerFormationsAmadouDesinscritSessionJuilletPythonTest extends class AbonneControllerFormationsSessionFevrierJavaTest extends AbstractAbonneControllerFormationsTestCase { public function setUp() { parent::setUp(); - $this->dispatch('/opac/abonne/detail-session/id/31', true); - } + $this->dispatch('/opac/formations/detail-session/id/31', true); + } /** @test */ public function pageShouldContainsLinkToInscrire() { - $this->assertXPathContentContains('//a[contains(@href, "abonne/inscrire-session/id/31")]', - 'S\'inscrire'); + $this->assertXPathContentContains('//a[contains(@href, "abonne/inscrire-session/id/31")]', + 'S\'inscrire'); } @@ -639,8 +639,8 @@ class AbonneControllerFormationsSessionFevrierJavaTest extends AbstractAbonneCon class AbonneControllerFormationsSessionJuilletPythonDetailTest extends AbstractAbonneControllerFormationsTestCase { public function setUp() { parent::setUp(); - $this->dispatch('/opac/abonne/detail-session/id/121'); - } + $this->dispatch('/opac/formations/detail-session/id/121'); + } /** @test */ public function actionShouldBeDetailSession() { @@ -656,14 +656,14 @@ class AbonneControllerFormationsSessionJuilletPythonDetailTest extends AbstractA /** @test */ public function pageShouldContainsAButtontoGoBackToFormations() { - $this->assertXPathContentContains('//a[contains(@href, "abonne/formations")]', 'Retour'); + $this->assertXPathContentContains('//a[contains(@href, "formations")]', 'Retour'); } /** @test */ public function pageShouldContainsLinkToDesinscrire() { - $this->assertXPathContentContains('//a[contains(@href, "abonne/desinscrire-session/id/121")]', - 'Se désinscrire'); + $this->assertXPathContentContains('//a[contains(@href, "abonne/desinscrire-session/id/121")]', + 'Se désinscrire'); } @@ -713,8 +713,8 @@ class AbonneControllerFormationsSessionJuilletPythonDetailTest extends AbstractA class AbonneControllerFormationsSessionJuilletPythonDetailRetourFicheTest extends AbstractAbonneControllerFormationsTestCase { public function setUp() { parent::setUp(); - $this->dispatch('/opac/abonne/detail-session/id/121/retour/fiche'); - } + $this->dispatch('/opac/formations/detail-session/id/121/retour/fiche'); + } /** @test */ public function pageShouldContainsAButtontoGoBackToFicheAbonne() { @@ -728,24 +728,24 @@ class AbonneControllerFormationsSessionJuilletPythonDetailRetourFicheTest extend class AbonneControllerFormationsWrongIdsTest extends AbstractAbonneControllerFormationsTestCase { /** @test */ public function onDetailSessionShouldRedirectToFormations() { - $this->dispatch('/opac/abonne/detail-session/id/9999'); - $this->assertRedirectTo('/abonne/formations'); - } + $this->dispatch('/opac/formations/detail-session/id/9999'); + $this->assertRedirectTo('/formations/index'); + } /** @test */ public function onInscrireSessionShouldRedirectToFormations() { $this->dispatch('/opac/abonne/inscrire-session/id/9999'); - $this->assertRedirectTo('/abonne/formations'); - } + $this->assertRedirectTo('/formations'); + } /** @test */ public function ondesinscrireSessionShouldRedirectToFormations() { $this->dispatch('/opac/abonne/desinscrire-session/id/9999'); - $this->assertRedirectTo('/abonne/formations'); - } - + $this->assertRedirectTo('/formations'); + } + } @@ -754,9 +754,9 @@ Class AbonneControllerFormationsInformationsTest extends AbstractControllerTestC public function setup() { parent::setup(); - + $test_time = new TimeSourceForTest('2014-05-09 14:00:00'); - + Class_Formation::setTimeSource($test_time); Class_SessionFormation::setTimeSource($test_time); @@ -768,11 +768,11 @@ Class AbonneControllerFormationsInformationsTest extends AbstractControllerTestC 'id_site' => 1, 'idabon' => '00044958', 'role_level' => 2, - 'user_groups' => [$this->fixture('Class_UserGroup',['id' => 23])->addRightSuivreFormation()] + 'user_groups' => [$this->fixture('Class_UserGroup',['id' => 23])->addRightSuivreFormation()] ]); - + ZendAfi_Auth::getInstance()->logUser($current_user); - + $session_full = $this->fixture('Class_SessionFormation', ['id' => 1, 'formation_id' => 1, @@ -806,16 +806,16 @@ Class AbonneControllerFormationsInformationsTest extends AbstractControllerTestC 'sessions' => [$session_full, $session_canceled, $session_subscription_exhausted]]); - - + + $current_user->setSessionFormationInscriptions([$this->fixture('Class_SessionFormationInscription', ['id' => 1, 'stagiaire' => $current_user, 'session_formation' => $formation])]); - $this->dispatch('/opac/abonne/formations', true); + $this->dispatch('/opac/formations', true); } - + /** @test */ function sessionShouldBeFull() { $this->assertXPathContentContains('//tbody//tr/td/span[@class="error"]', @@ -829,7 +829,7 @@ Class AbonneControllerFormationsInformationsTest extends AbstractControllerTestC 'Annul'); } - + /** @test */ function sessionShouldBeDisplaySubscribeTimeExhaust() { $this->assertXPathContentContains('//tbody//tr/td/span[@class="error"]', diff --git a/tests/application/modules/opac/controllers/FormationsControllerTest.php b/tests/application/modules/opac/controllers/FormationsControllerTest.php new file mode 100644 index 00000000000..61018ff635a --- /dev/null +++ b/tests/application/modules/opac/controllers/FormationsControllerTest.php @@ -0,0 +1,161 @@ +<?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 + */ + +abstract class AbstractFormationsControllerTestCase extends AbstractControllerTestCase { + public function setup() { + parent::setup(); + + ZendAfi_Auth::getInstance()->clearIdentity(); + $test_time = new TimeSourceForTest('2014-05-09 14:00:00'); + + Class_Formation::setTimeSource($test_time); + Class_SessionFormation::setTimeSource($test_time); + + + + $session_full = $this->fixture('Class_SessionFormation', + ['id' => 1, + 'formation_id' => 1, + 'date_debut' => '2014-07-10', + 'date_limite_inscription' => '2014-07-01', + 'effectif_min' => 1, + 'effectif_max' => 1, + 'stagiaires' => []]); + + $session_canceled = $this->fixture('Class_SessionFormation', + ['id' => 1, + 'formation_id' => 1, + 'date_debut' => '2014-07-10', + 'effectif_min' => 1, + 'effectif_max' => 10, + 'stagiaires' => []]); + $session_canceled->beAnnule(); + $_bonlieu = $this->fixture('Class_Lieu', + ['id' => 100, + 'libelle' => 'Bonlieu', + 'adresse' => "1, rue Jean-Jaures\nBP 294", + 'code_postal' => 74007, + 'ville' => 'Annecy', + 'latitude' => '45.902179', + 'longitude' => '6.128715']); + + + $_session_java_fevrier = $this->fixture('Class_SessionFormation', + ['id' => 31, + 'formation_id' => 3, + 'effectif_min' => 2, + 'effectif_max' => 5, + 'lieu' => $_bonlieu, + 'date_debut' => '2015-02-10', + 'date_fin' => '2015-02-20', + 'stagiaires' => [], + 'date_limite_inscription' => '2015-01-20']); + + $session_subscription_exhausted = $this->fixture('Class_SessionFormation', + ['id' => 1, + 'formation_id' => 1, + 'date_debut' => '2014-07-10', + 'date_limite_inscription' => '2014-01-10', + 'effectif_min' => 1, + 'effectif_max' => 10, + 'stagiaires' => []]); + + $formation = $this->fixture('Class_Formation', + ['id' => 1, + 'libelle' => 'Farming cerths', + 'sessions' => [$session_full, + $session_canceled, + $_session_java_fevrier, + $session_subscription_exhausted]]); + + } + + +} + +class FormationsControllerFormationsSessionFevrierJavaTest extends AbstractFormationsControllerTestCase { + public function setUp() { + parent::setUp(); + $this->dispatch('/opac/formations/detail-session/id/31', true); + } + + + /** @test */ + public function pageShouldContainsLinkToInscrire() { + $this->assertXPathContentContains('//a[contains(@href, "abonne/inscrire-session/id/31")]', + 'S\'inscrire', $this->_response->getBody()); + } + + + /** @test */ + public function ddShouldContainsNombreDeParticipants() { + $this->assertXPathContentContains('//dl/dd', 'minimum: 2, maximum: 5, actuel: 0'); + } + + + /** @test */ + function ddShouldContainsAdresseBonlieu() { + $this->assertXPathContentContains('//dd', 'Bonlieu'); + $this->assertXPathContentContains('//dd', '1, rue Jean-Jaures'); + $this->assertXPathContentContains('//dd', '74007 Annecy'); + } + + + /** @test */ + function ddShouldContainsGoogleMap() { + $this->assertXPath('//dd//img[@src="http://maps.googleapis.com/maps/api/staticmap?sensor=false&zoom=15&size=300x300¢er=45.902179%2C6.128715&markers=45.902179%2C6.128715"]'); + } +} + + + + +class FormationsControllerAnonymousTest extends AbstractFormationsControllerTestCase { + + public function setUp() { + parent::setUp(); + $this->dispatch('/opac/formations', true); + + } + + /** @test */ + function sessionShouldDisplaySubscribeTime() { + + $this->assertXPathContentContains('//tbody//tr/td/span', + 'Date de limite d\'inscription:'); + } + +} + +class FormationsControllerFormationsSessionJuilletPythonDetailRetourFicheTest extends AbstractFormationsControllerTestCase { + public function setUp() { + parent::setUp(); + $this->dispatch('/opac/formations/detail-session/id/31/retour/fiche'); + } + + /** @test */ + public function pageShouldContainsAButtontoGoBackToFicheAbonne() { + $this->assertXPathContentContains('//a[contains(@href, "abonne/fiche")]', 'Retour', $this->_response->getBody()); + } + +} + +?> \ No newline at end of file -- GitLab