From 573ca81b7e74f41a085300a0920875c48b10673b Mon Sep 17 00:00:00 2001 From: llaffont <llaffont@git-test.afi-sa.fr> Date: Tue, 9 Oct 2012 15:31:05 +0000 Subject: [PATCH] Lorsque on ajoute un profil, bascule automatiquement sur ce profil --- .../admin/controllers/ProfilController.php | 9 +- .../controllers/ProfilControllerTest.php | 104 +++++++++++------- 2 files changed, 70 insertions(+), 43 deletions(-) diff --git a/application/modules/admin/controllers/ProfilController.php b/application/modules/admin/controllers/ProfilController.php index 71f65be600e..77588063e21 100644 --- a/application/modules/admin/controllers/ProfilController.php +++ b/application/modules/admin/controllers/ProfilController.php @@ -462,9 +462,12 @@ class Admin_ProfilController extends Zend_Controller_Action { return false; $post = ZendAfi_Filters_Post::filterStatic($this->_request->getPost()); - return $profil - ->updateAttributes($post) - ->save(); + if ($result = $profil->updateAttributes($post)->save()) { + Class_Profil::setCurrentProfil($profil); + $_SESSION['id_profil'] = $profil->getId(); + } + + return $result; } diff --git a/tests/application/modules/admin/controllers/ProfilControllerTest.php b/tests/application/modules/admin/controllers/ProfilControllerTest.php index 918f5e6f490..5db17d14589 100644 --- a/tests/application/modules/admin/controllers/ProfilControllerTest.php +++ b/tests/application/modules/admin/controllers/ProfilControllerTest.php @@ -671,12 +671,42 @@ class Admin_ProfilControllerAddProfilHistoireTest extends Admin_AbstractControll /** @test */ - public function postingValidDataShouldResultInProfilToBeValid() { - $wrapper = Storm_Test_ObjectWrapper - ::onLoaderOfModel('Class_Profil') + public function profilShouldNotBeSavedIfPostingLargeurTooLow() { + $wrapper = Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Profil'); + + $data = array( 'libelle' => "Histoire", + 'id_site' => 1, + 'largeur_site' => 100); + + $this + ->getRequest() + ->setMethod('POST') + ->setPost($data); + $this->dispatch('/admin/profil/add'); + $this->assertAction('add'); + + $this->assertFalse($wrapper->methodHasBeenCalled('save')); + $this->assertXPathContentContains('//ul[@class="errors"]//li', + 'La largeur du site doit' /*être comprise entre 800 et 2000 pixels.*/, + $this->_response->getBody()); + } + +} + + + + +class Admin_ProfilControllerProfilPostAddTest extends Admin_ProfilControllerProfilJeunesseTestCase { + protected $_new_profil; + + public function setUp() { + parent::setUp(); + $wrapper = Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Profil') ->whenCalled('save') - ->answers(true) - ->getWrapper(); + ->willDo(function($model) { + $model->setId(456); + return true; + }); $data = array( 'libelle' => "Histoire", 'id_site' => 1, @@ -694,77 +724,71 @@ class Admin_ProfilControllerAddProfilHistoireTest extends Admin_AbstractControll ->setPost($data); $this->dispatch('/admin/profil/add'); - $new_profil = $wrapper->getFirstAttributeForLastCallOn('save'); - $this->assertTrue($new_profil->isValid()); + $this->_new_profil = $wrapper->getFirstAttributeForLastCallOn('save'); + } + + + /** @test */ + public function newProfilShouldBeValid() { + $this->assertTrue($this->_new_profil->isValid()); + } - $this->assertRedirectTo('/admin/profil/edit/id_profil/'.$new_profil->getId()); // id_site=1 => par défaut - return $new_profil; + /** @test */ + public function responseShouldRedirectToEditNewProfil() { + $this->assertRedirectTo('/admin/profil/edit/id_profil/456'); } /** - * @depends postingValidDataShouldResultInProfilToBeValid * @test */ - public function getNbDivisionsShouldReturnTwo($profil) { - $this->assertEquals(2, $profil->getNbDivisions()); + public function getNbDivisionsShouldReturnTwo() { + $this->assertEquals(2, $this->_new_profil->getNbDivisions()); } /** - * @depends postingValidDataShouldResultInProfilToBeValid * @test */ - public function getLibelleShouldReturnHistoire($profil) { - $this->assertEquals("Histoire", $profil->getLibelle()); + public function getLibelleShouldReturnHistoire() { + $this->assertEquals("Histoire", $this->_new_profil->getLibelle()); } /** - * @depends postingValidDataShouldResultInProfilToBeValid * @test */ - public function getAccessLevelShouldReturnSix($profil) { - $this->assertEquals(6, $profil->getAccessLevel()); + public function getAccessLevelShouldReturnSix() { + $this->assertEquals(6, $this->_new_profil->getAccessLevel()); } /** - * @depends postingValidDataShouldResultInProfilToBeValid * @test */ - public function getLargeurSiteShouldReturnNineHundred($profil) { - $this->assertEquals(900, $profil->getLargeurSite()); + public function getLargeurSiteShouldReturnNineHundred() { + $this->assertEquals(900, $this->_new_profil->getLargeurSite()); } + /** + * @test + */ + public function currentProfilShouldBeNewProfil() { + $this->assertEquals(456, Class_Profil::getCurrentProfil()->getId()); + } + /** @test */ - public function profilShouldNotBeSavedIfPostingLargeurTooLow() { - $wrapper = Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Profil'); - - $data = array( 'libelle' => "Histoire", - 'id_site' => 1, - 'largeur_site' => 100); - - $this - ->getRequest() - ->setMethod('POST') - ->setPost($data); - $this->dispatch('/admin/profil/add'); - $this->assertAction('add'); - - $this->assertFalse($wrapper->methodHasBeenCalled('save')); - $this->assertXPathContentContains('//ul[@class="errors"]//li', - 'La largeur du site doit' /*être comprise entre 800 et 2000 pixels.*/, - $this->_response->getBody()); + public function sessionIdProfilShould456() { + $this->assertEquals(456, $_SESSION['id_profil']); } - } + abstract class Admin_ProfilControllerProfilJeunesseWithPagesTestCase extends Admin_ProfilControllerProfilJeunesseTestCase { public function setUp() { parent::setUp(); -- GitLab