From fd8275bca127843dc2e949dc20f65c23229a7e23 Mon Sep 17 00:00:00 2001 From: llaffont <llaffont@git-test.afi-sa.fr> Date: Thu, 26 Apr 2012 09:09:28 +0000 Subject: [PATCH] Ajout date de fin pour les session de formation --- .../admin/controllers/FormationController.php | 14 +++- library/Class/SessionFormation.php | 11 ++++ .../controllers/FormationControllerTest.php | 65 ++++++++++++++++--- 3 files changed, 77 insertions(+), 13 deletions(-) diff --git a/application/modules/admin/controllers/FormationController.php b/application/modules/admin/controllers/FormationController.php index 3e2aa487436..90455cf28b8 100644 --- a/application/modules/admin/controllers/FormationController.php +++ b/application/modules/admin/controllers/FormationController.php @@ -354,14 +354,18 @@ class Admin_FormationController extends Zend_Controller_Action { $session ->updateAttributes($post) ->setDateDebut($this->_readPostDate($this->_request->getPost('date_debut'))) + ->setDateFin($this->_readPostDate($this->_request->getPost('date_fin'))) ->setDateLimiteInscription($this->_readPostDate($this->_request->getPost('date_limite_inscription'))) ->setIntervenants($intervenants) ->validate(); if ($form->isValid($this->_request->getPost()) && $session->isValid()) { - $session->save(); - $this->_redirect('admin/formation'); - return true; + if ($session->save()) { + $this->_helper->notify(sprintf('Session du %s sauvegardée', + $this->view->humanDate($session->getDateDebut(), 'd MMMM YYYY'))); + $this->_redirect('admin/formation/session_edit/id/'.$session->getId()); + return true; + } } foreach($session->getErrors() as $attribute => $message) { @@ -399,6 +403,9 @@ class Admin_FormationController extends Zend_Controller_Action { 'size' => 10, 'required' => true, 'allowEmpty' => false )) + ->addElement('datePicker', 'date_fin', array( + 'label' => 'Date fin', + 'size' => 10 )) ->addElement('datePicker', 'date_limite_inscription', array( 'label' => 'Date limite d\'inscription *', 'size' => 10 )) @@ -446,6 +453,7 @@ class Admin_FormationController extends Zend_Controller_Action { ->addDisplayGroup( array('date_debut', + 'date_fin', 'date_limite_inscription', 'effectif_min', 'effectif_max', diff --git a/library/Class/SessionFormation.php b/library/Class/SessionFormation.php index 11dac26e338..54d8ae2cd89 100644 --- a/library/Class/SessionFormation.php +++ b/library/Class/SessionFormation.php @@ -45,6 +45,7 @@ class Class_SessionFormation extends Storm_Model_Abstract { 'cout' => 0, 'duree' => 0, 'date_debut' => '', + 'date_fin' => '', 'date_limite_inscription' => null, 'contenu' => '', 'objectif' => '', @@ -116,6 +117,12 @@ class Class_SessionFormation extends Storm_Model_Abstract { } + public function getDateFin() { + $date = parent::_get('date_fin'); + return $date ? $date : null; //pour ne pas retourner chaine vide, probleme zend_form + } + + public function getDateLimiteInscription() { $date = parent::_get('date_limite_inscription'); if ('0000-00-00' == $date) @@ -142,6 +149,10 @@ class Class_SessionFormation extends Storm_Model_Abstract { $this->checkAttribute('date_limite_inscription', Class_Date::isEndDateAfterStartDateNotEmpty($this->getDateLimiteInscription(), $this->getDateDebut()), "La date limite d'inscription doit être inférieure ou égale à la date de début"); + + $this->checkAttribute('date_fin', + Class_Date::isEndDateAfterStartDateNotEmpty($this->getDateFin(), $this->getDateDebut()), + "La date de fin doit être supérieure ou égale à la date de début"); } diff --git a/tests/application/modules/admin/controllers/FormationControllerTest.php b/tests/application/modules/admin/controllers/FormationControllerTest.php index 8ff3e153c09..8317f662f12 100644 --- a/tests/application/modules/admin/controllers/FormationControllerTest.php +++ b/tests/application/modules/admin/controllers/FormationControllerTest.php @@ -80,6 +80,7 @@ abstract class Admin_FormationControllerTestCase extends Admin_AbstractControlle ->newInstanceWithId(32) ->setFormationId(3) ->setDateDebut('2012-03-27') + ->setDateFin('2012-03-29') ->setEffectifMin(5) ->setEffectifMax(25) ->setDuree(8) @@ -95,6 +96,7 @@ abstract class Admin_FormationControllerTestCase extends Admin_AbstractControlle ->newInstanceWithId(31) ->setFormationId(3) ->setDateDebut('2012-02-17') + ->setDateFin('') ->setEffectifMax(10) ->setStagiaires(array($this->_benoit)))), @@ -514,6 +516,23 @@ class Admin_FormationControllerIndexTest extends Admin_FormationControllerTestCa +class Admin_FormationControllerEditSessionLearningJavaFevrierTest extends Admin_FormationControllerTestCase { + public function setUp() { + parent::setUp(); + $this->dispatch('/admin/formation/session_edit/id/31'); + } + + + /** @test */ + function inputDateFinShouldBeEmpty() { + $this->assertXPath('//form[@id="sessionForm"]//input[@name="date_fin"][@value=""]'); + } + +} + + + + class Admin_FormationControllerEditSessionLearningJavaMars27Test extends Admin_FormationControllerTestCase { public function setUp() { parent::setUp(); @@ -529,15 +548,19 @@ class Admin_FormationControllerEditSessionLearningJavaMars27Test extends Admin_ /** @test */ function inputDateDebutShouldContains27_03_2012() { - $this->assertXPath('//form[@id="sessionForm"][contains(@action,"formation/sessionedit")]//input[@name="date_debut"][@value="27/03/2012"]', - $this->_response->getBody()); + $this->assertXPath('//form[@id="sessionForm"][contains(@action,"formation/sessionedit")]//input[@name="date_debut"][@value="27/03/2012"]'); + } + + + /** @test */ + function inputDateFinShouldContains28_03_2012() { + $this->assertXPath('//form[@id="sessionForm"][contains(@action,"formation/sessionedit")]//input[@name="date_fin"][@value="29/03/2012"]'); } /** @test */ function inputDateLimiteInscriptionShouldContains05_03_2012() { - $this->assertXPath('//form[@id="sessionForm"][contains(@action,"formation/sessionedit")]//input[@name="date_limite_inscription"][@value="05/03/2012"]', - $this->_response->getBody()); + $this->assertXPath('//form[@id="sessionForm"][contains(@action,"formation/sessionedit")]//input[@name="date_limite_inscription"][@value="05/03/2012"]'); } @@ -678,8 +701,8 @@ class Admin_FormationControllerPostSessionLearnJavaTest extends Admin_Formation /** @test */ - function responseShouldRedirectToFormationIndex() { - $this->assertRedirectTo('/admin/formation'); + function responseShouldRedirectToSessionFormationEdit() { + $this->assertRedirectTo('/admin/formation/session_edit/id/32'); } /** @test */ @@ -722,7 +745,8 @@ class Admin_FormationControllerPostSessionLearnJavaWithInvalidDataTest extends array('date_debut' => '', 'effectif_min' => 20, 'effectif_max' => 4, - 'date_limite_inscription' => '05/01/2099')); + 'date_limite_inscription' => '05/01/2099', + 'date_fin' => '05/01/1990')); } /** @test */ @@ -746,8 +770,14 @@ class Admin_FormationControllerPostSessionLearnJavaWithInvalidDataTest extends /** @test */ public function errorsShouldContainsDateLimiteInscriptionAfterDateDebut() { $this->assertXPathContentContains('//ul[@class="errors"]//li', - "La date limite d'inscription doit être inférieure ou égale à la date de début", - $this->_response->getBody()); + "La date limite d'inscription doit être inférieure ou égale à la date de début"); + } + + + /** @test */ + public function errorsShouldContainsDateFinBeforeDateDebut() { + $this->assertXPathContentContains('//ul[@class="errors"]//li', + "La date de fin doit être supérieure ou égale à la date de début"); } } @@ -805,8 +835,17 @@ class Admin_FormationControllerPostAddSessionToFormationLearningPythonTest exten public function setUp() { parent::setUp(); + + Class_SessionFormation::getLoader() + ->whenCalled('save') + ->willDo(function($session) { + $session->setId(99); + return true; + }); + $this->postDispatch('/admin/formation/session_add/formation_id/12', array('date_debut' => '17/02/2010', + 'date_fin' => '17/02/2010', 'effectif_min' => '3', 'effectif_max' => '12', 'contenu' => 'On charme les serpents', @@ -824,9 +863,15 @@ class Admin_FormationControllerPostAddSessionToFormationLearningPythonTest exten } + /** @test */ + function newSessionDateFinShouldBe2010_02_17() { + $this->assertEquals('2010-02-17', $this->session->getDateFin()); + } + + /** @test */ function answerShouldRedirectToFormationIndex() { - $this->assertRedirectTo('/admin/formation'); + $this->assertRedirectTo('/admin/formation/session_edit/id/99'); } -- GitLab