diff --git a/library/Class/Formation.php b/library/Class/Formation.php index 37db288074b7b33b161195f2f20a8958e9381d50..20780c4e627199c7a5ada68f6c16c718f7a479c0 100644 --- a/library/Class/Formation.php +++ b/library/Class/Formation.php @@ -84,7 +84,8 @@ class Class_Formation extends Storm_Model_Abstract { public function getAvailableSessions() { return Class_SessionFormation::findAllBy(['formation_id' => $this->getId(), - 'select' => 'isAvailable']); + 'select' => 'isAvailable', + 'order' => 'date_debut']); } } ?> \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/Accueil/FormationsWidget.php b/library/ZendAfi/View/Helper/Accueil/FormationsWidget.php index 1607f343a16e9a6629b46a1631eb4dec580d9c60..140ae39c4ddba7a94a0e26d4d0595be42734dd09 100644 --- a/library/ZendAfi/View/Helper/Accueil/FormationsWidget.php +++ b/library/ZendAfi/View/Helper/Accueil/FormationsWidget.php @@ -28,7 +28,10 @@ class ZendAfi_View_Helper_Accueil_FormationsWidget extends ZendAfi_View_Helper_A foreach($selected_formations as $selected_formation) { $formations[] = Class_Formation::find($selected_formation); } - $this->contenu = $this->view->renderFormations($formations); + + $formations_by_year = Class_Formation::indexByYear($formations); + + $this->contenu = $this->view->renderFormationsByYear($formations_by_year, 'Widget'); return $this->getHtmlArray(); } } diff --git a/library/ZendAfi/View/Helper/RenderFormation.php b/library/ZendAfi/View/Helper/RenderFormation.php index ba4bb32cff9357a1d5a499a0ff1c26b6a66bdfc8..09c20d18a3b40a0f952fc7ce9908d2e1dc4e7305 100644 --- a/library/ZendAfi/View/Helper/RenderFormation.php +++ b/library/ZendAfi/View/Helper/RenderFormation.php @@ -22,15 +22,45 @@ class ZendAfi_View_Helper_RenderFormation extends ZendAfi_View_Helper_BaseHelper { - public function renderFormation($formation) { + public function renderFormation($formation, $strategy = '') { + $render = $strategy ? 'Render_Strategy_'.$strategy : 'Render_Strategy'; + $this->_strategy = new $render($this->view); + return $this->_strategy->render($formation); + } +} + + + +class Render_Strategy { + protected $view; + + + public function __construct($view) { + $this->view = $view; + } + + + public function render($formation) { $html = $this->view->tag('h2', $formation->getLibelle()); $html.= $this->view->tag('div', - $formation->getDescription()); + $formation->getDescription()); $html.= $this->view->renderSessions($formation->getSessions(), 'Table'); return $this->view->tag('div', $html); } + +} + + + +class Render_Strategy_Widget extends Render_Strategy { + public function render($formation) { + $sessions = $formation->getAvailableSessions(); + $html = $this->view->tag('h2',$formation->getLibelle()); + $html.= $this->view->renderSessions($sessions, 'Table'); + return $this->view->tag('li',$html); + } } ?> \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/RenderFormations.php b/library/ZendAfi/View/Helper/RenderFormations.php index 7858df70ac73ba537d9f43ee8eb3898e2881b1a9..32e041721fda7e581faf68c15f2076941d60253f 100644 --- a/library/ZendAfi/View/Helper/RenderFormations.php +++ b/library/ZendAfi/View/Helper/RenderFormations.php @@ -21,44 +21,16 @@ class ZendAfi_View_Helper_RenderFormations extends ZendAfi_View_Helper_BaseHelper { - public function renderFormations($formations = []) { + public function renderFormations($formations, $strategy = '') { if(!array_filter($formations)>0) return ''; $html= ''; foreach($formations as $formation) { - $html.= $this->renderFormation($formation); + $html.= $this->view->renderFormation($formation, $strategy); } return $this->view->tag('ul',$html); } - - - protected function renderFormation($formation) { - $html = $this->view->tag('h2',$formation->getLibelle()); - $html.= $this->renderSessions($formation->getAvailableSessions()); - - - return $this->view->tag('li',$html); - } - - - protected function renderSessions($sessions = []) { - if(!array_filter($sessions)) - return ''; - - $html= ''; - foreach($sessions as $session) { - $html.= $this->renderSession($session); - } - - return $this->view->tag('ul',$html); - } - - - protected function renderSession($session) { - return $this->view->tag('li', - $this->view->renderSession($session)); - } } ?> \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/RenderFormationsByYear.php b/library/ZendAfi/View/Helper/RenderFormationsByYear.php new file mode 100644 index 0000000000000000000000000000000000000000..6af8f1478c2dfdcef26d610c4102c77c66b82593 --- /dev/null +++ b/library/ZendAfi/View/Helper/RenderFormationsByYear.php @@ -0,0 +1,39 @@ +<?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_RenderFormationsByYear extends ZendAfi_View_Helper_BaseHelper { + public function renderFormationsByYear($formations_by_year, $strategy ='') { + if(!array_filter($formations_by_year)>0) + return ''; + + $html= ''; + foreach($formations_by_year as $year => $formations) { + $header = $this->view->tag('h2', $this->view->tag('span',$year)); + $html.= $this->view->tag('li', + $header. + $this->view->renderFormations($formations, $strategy)); + } + + return $this->view->tag('ul', $html); + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/RenderSession.php b/library/ZendAfi/View/Helper/RenderSession.php index 917659db8695456e9ecbc177ebb36953c5e25fb9..b9be233a0212c0c86354865dde326b1ca9a44b95 100644 --- a/library/ZendAfi/View/Helper/RenderSession.php +++ b/library/ZendAfi/View/Helper/RenderSession.php @@ -147,14 +147,13 @@ class Render_Session_Table extends Render_Session { $html = $session->isAnnule() ? $this->errorSpan($this->view->_('Annulée')) : ''; - $html.= $this->errorSpan( - $session->isDateSubscriptionExhausted() - ? $this->view->_('Date de limite d\'inscription dépassée: '). - $session->getDateLimiteInscriptionHumanRead() + $html.= $session->isDateSubscriptionExhausted() + ? $this->errorSpan( $this->view->_('Date de limite d\'inscription dépassée: '). + $session->getDateLimiteInscriptionHumanRead()) : ($session->hasDateLimiteInscription() - ? $this->view->_('Date de limite d\'inscription: '). - $session->getDateLimiteInscriptionHumanRead() - :'')); + ? $this->view->tag('span',$this->view->_('Date de limite d\'inscription: '). + $session->getDateLimiteInscriptionHumanRead()) + :''); $html.= $session->isFull() ? $this->errorSpan($this->view->_('Complet: maximum de personnes inscrites')) diff --git a/library/ZendAfi/View/Helper/RenderSessions.php b/library/ZendAfi/View/Helper/RenderSessions.php index b6d9421dcde8148cc11e11ace1832731e7285de8..f4dd492cc8b2f3e481744f4088ce906dba35ac34 100644 --- a/library/ZendAfi/View/Helper/RenderSessions.php +++ b/library/ZendAfi/View/Helper/RenderSessions.php @@ -25,9 +25,7 @@ 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); } diff --git a/tests/application/modules/opac/controllers/AbonneControllerFormationsTest.php b/tests/application/modules/opac/controllers/AbonneControllerFormationsTest.php index c4f6787ded25f36a4c3d74896251192dcbe75b4c..2fd9a93b85a4a9309333965cfe75494b8d94f1d1 100644 --- a/tests/application/modules/opac/controllers/AbonneControllerFormationsTest.php +++ b/tests/application/modules/opac/controllers/AbonneControllerFormationsTest.php @@ -104,7 +104,7 @@ abstract class AbstractAbonneControllerFormationsTestCase extends AbstractContro 'effectif_max' => 10, 'lieu' => $this->_gallice_cafe, 'stagiaires' => [], - 'date_debut' => '2014-07-10']); + 'date_debut' => '2014-07-11']); $this->_learn_smalltalk = $this->fixture('Class_Formation', ['id' => 1, @@ -247,8 +247,39 @@ class AbonneControllerFormationsListTest extends AbstractAbonneControllerFormati /** @test */ - function session_fevrier_17_ShouldBeDisplayedUnderLearnJavaInSecondPosition() { - $this->assertXPathContentContains('//tbody//tr//td', '10 février 2015 au 20 février 2015'); + function sessionJanuary2014ShouldBeFirst() { + $this->assertXPathContentContains('//tbody//tr[1]//td', '10 janvier 2014'); + } + + + + /** @test */ + function sessionMarsShouldBeFirst() { + $this->assertXPathContentContains('//tbody//tr[1]//td', '1 mars 2014'); + } + + + /** @test */ + function sessionSeptemberShouldBeSecond() { + $this->assertXPathContentContains('//tbody//tr[2]//td', ' septembre 2014'); + } + + + /** @test */ + function sessionFebruary2015ShouldBeLast() { + $this->assertXPathContentContains('//tbody//tr[3]//td', ' février 2015'); + } + + + /** @test */ + function session10Juillet2014ShouldBeFirst() { + $this->assertXPathContentContains('//tbody//tr[1]//td', '10 juillet 2014'); + } + + + /** @test */ + function session11Juillet2014ShouldSecond() { + $this->assertXPathContentContains('//tbody//tr[2]//td', '11 juillet 2014'); } @@ -281,7 +312,7 @@ class AbonneControllerFormationsListTest extends AbstractAbonneControllerFormati /** @test */ function session_mars_27_ShouldBeDisplayedUnderLearnJavaInFirstPosition() { - $this->assertXPathContentContains('//tbody//tr', '1 mars 2014'); + $this->assertXPathContentContains('//tbody//tr[1]', '1 mars 2014'); } @@ -786,7 +817,7 @@ Class AbonneControllerFormationsInformationsTest extends AbstractControllerTestC /** @test */ function sessionShouldBeFull() { $this->assertXPathContentContains('//tbody//tr/td/span[@class="error"]', - 'Complet', $this->_response->getBody()); + 'Complet'); } @@ -800,14 +831,14 @@ Class AbonneControllerFormationsInformationsTest extends AbstractControllerTestC /** @test */ function sessionShouldBeDisplaySubscribeTimeExhaust() { $this->assertXPathContentContains('//tbody//tr/td/span[@class="error"]', - 'Date de limite d\'inscription dépassée:', $this->_response->getBody()); + 'Date de limite d\'inscription dépassée:'); } /** @test */ function sessionShouldDisplaySubscribeTime() { - $this->assertXPathContentContains('//tbody//tr/td/span[@class="error"]', - 'Date de limite d\'inscription:', $this->_response->getBody()); + $this->assertXPathContentContains('//tbody//tr/td/span', + 'Date de limite d\'inscription:'); } } ?> \ No newline at end of file diff --git a/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php b/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php index fd788f3b775ef0b21ae8c55c190c8498d8ca3efd..b0f6daea7cf21db39f8cbbc7da968e67fbef9c8d 100644 --- a/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php +++ b/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php @@ -1659,7 +1659,7 @@ class ModulesAccueilControllerWithProfilJeunesseThemeVideTest extends ProfilOpti -class ProfilOptionsControllerWithFormationWidgetTest extends AbstractControllerTestCase { +class ProfilOptionsControllerWithFormationWidgetAndNoLoggedUserTest extends AbstractControllerTestCase { public function setup() { parent::setup(); @@ -1669,8 +1669,9 @@ class ProfilOptionsControllerWithFormationWidgetTest extends AbstractControllerT 'preferences' => ['selected_formations' => '1-2']]]]; Class_SessionFormation::setTimeSource(new TimeSourceForTest('2014-05-02 14:14:14')); - + Class_Users::beVolatile(); Class_SessionFormation::beVolatile(); + Class_Formation::beVolatile(); $this->fixture('Class_Formation', ['id' => 1 , @@ -1681,14 +1682,24 @@ class ProfilOptionsControllerWithFormationWidgetTest extends AbstractControllerT 'contenu' => 'dogfighting tricks', 'date_debut' => '2014-05-02', 'date_fin' => '2014-05-30', - 'date_limite_lnscription' => '2011-01-01', + 'date_limite_inscription' => '2011-01-01', 'stagiaires' => [], 'effectif_max' => 0, 'effectif_min' => 0])]]); $this->fixture('Class_Formation', ['id' => 2 , - 'libelle' => 'scythe chap 2']); + 'libelle' => 'scythe chap 2', + 'sessions' => [$this->fixture('Class_SessionFormation', + ['id' => 5, + 'formation_id' => 2, + 'contenu' => 'dogfighting aim', + 'date_debut' => '2014-05-10', + 'date_fin' => '2014-05-30', + 'date_limite_inscription' => '2014-05-08', + 'stagiaires' => [], + 'effectif_max' => 10, + 'effectif_min' => 1])]]); Class_Profil::getCurrentProfil() ->setBrowser('opac') @@ -1696,13 +1707,15 @@ class ProfilOptionsControllerWithFormationWidgetTest extends AbstractControllerT ->setLibelle('Profil Portail') ->setCfgAccueil($cfg_accueil); + ZendAfi_Auth::getInstance()->clearIdentity(); + $this->dispatch('/opac'); } /** @test */ - public function boiteCalendarShouldBeDisplay() { - $this->assertXPath('//div[contains(@class,"formations_widget")]',$this->_response->getBody()); + public function widgetFormationShouldBeDisplay() { + $this->assertXPath('//div[contains(@class,"formations_widget")]'); } @@ -1718,15 +1731,22 @@ class ProfilOptionsControllerWithFormationWidgetTest extends AbstractControllerT } + /** @test */ + public function year2014ShouldBeDisplay() { + $this->assertXpathContentContains('//div[@class="boite formations_widget"]//ul/li[1]/h2/span','2014'); + } + + + /** @test */ public function sessionDogFigthShouldBeInChap1() { - $this->assertXpathContentContains('//div[@class="boite formations_widget"]//ul/li/ul/li/dl/dd', 'dogfighting tricks', $this->_response->getBody()); + $this->assertXpathContentContains('//div[@class="boite formations_widget"]//ul/li[1]/ul/li[1]', 'scythe chap 1', $this->_response->getBody()); } /** @test */ public function isFullShouldBeDisplay() { - $this->assertXpathContentContains('//div[@class="boite formations_widget"]//ul/li/ul/li/dl/dd', 'Complet'); + $this->assertXpathContentContains('//div[@class="boite formations_widget"]//ul/li[1]/ul/li[1]', 'Complet'); } } diff --git a/tests/library/ZendAfi/View/Helper/Accueil/FormationsWidgetTest.php b/tests/library/ZendAfi/View/Helper/Accueil/FormationsWidgetTest.php index c46aa481d168a314440b7a953706d736cc407699..42950012ef344bb7645146910b4e8d7c08d2d052 100644 --- a/tests/library/ZendAfi/View/Helper/Accueil/FormationsWidgetTest.php +++ b/tests/library/ZendAfi/View/Helper/Accueil/FormationsWidgetTest.php @@ -82,10 +82,15 @@ class ZendAfi_View_Helper_Accueil_FormationsWidgetWithLoggedSIGBUserTest extends ['id' => 1, 'libelle' => 'Air Dogfight chapter 1', 'sessions' => [$this->fixture('Class_SessionFormation', + ['id' => 2, + 'date_limite_inscription' => '2014-06-01', + 'date_debut' => '2014-06-02', + 'date_fin' => '2014-06-10']), + $this->fixture('Class_SessionFormation', ['id' => 1, 'date_limite_inscription' => '2014-06-01', 'date_debut' => '2014-06-01', - 'date_fin' => '2014-06-10'])]]), + 'date_fin' => '2014-06-10'])]]), ['division' => 1, 'type_module' => 'FORMATIONS_WIDGET', 'preferences' => ['selected_formations' => '1']]); @@ -97,13 +102,19 @@ class ZendAfi_View_Helper_Accueil_FormationsWidgetWithLoggedSIGBUserTest extends /** @test */ public function session1ShouldBeDisplay() { - $this->assertXPathContentContains($this->_html,'//dl/dd', 'minimum: 1, maximum: 10'); + $this->assertXPathContentContains($this->_html,'//tr[1]/td[1]', '1 juin 2014'); + } + + + /** @test */ + public function session2ShouldBeSecond() { + $this->assertXPathContentContains($this->_html,'//tr[2]/td[1]', '2 juin 2014'); } /** @test */ public function subscriptionLinkShouldBeDisplay() { - $this->assertXPath($this->_html, '//div[@class="actions"]/a[contains(@href,"abonne/inscrire-session/id/1")]'); + $this->assertXPath($this->_html, '//tr/td/a[contains(@href,"abonne/inscrire-session/id/1")]'); } } @@ -149,7 +160,7 @@ class ZendAfi_View_Helper_Accueil_FormationsWidgetWithDateSubscriptionPastTest e /** @test */ public function subscriptionDatePastShouldBeDisplay() { - $this->assertXPathContentContains($this->_html, '//dl/dd', "Date de limite "); + $this->assertXPathContentContains($this->_html, '//tr/td/span[@class="error"]', 'Date de limite d'); } } @@ -188,7 +199,7 @@ class ZendAfi_View_Helper_Accueil_FormationsWidgetWithNoLoggedUserTest extends V /** @test */ public function subscriptionShouldNotBeAvailable() { - $this->assertNotXPathContentContains($this->_html, '//div[@class="actions"]/a', "S'inscrire"); + $this->assertNotXPathContentContains($this->_html, '//tr/td/a', "inscrire"); } } ?> \ No newline at end of file