From 3e4b08de54445e033f672e91d29cc61f0aecad46 Mon Sep 17 00:00:00 2001 From: llaffont <llaffont@git-test.afi-sa.fr> Date: Tue, 9 Oct 2012 15:13:07 +0000 Subject: [PATCH] =?UTF-8?q?Editeur=20CSS:=20si=20on=20=C3=A9dite=20le=20CS?= =?UTF-8?q?S=20d'une=20page,=20enregistre=20dans=20le=20profil=20parent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitattributes | 2 +- .../admin/controllers/ProfilController.php | 7 +- ....php => ProfilControllerCssUploadTest.php} | 95 ++++++++++++++----- 3 files changed, 78 insertions(+), 26 deletions(-) rename tests/application/modules/admin/controllers/{ProfilControllerControllerCssUploadTest.php => ProfilControllerCssUploadTest.php} (53%) diff --git a/.gitattributes b/.gitattributes index 18a4013efb4..8ce292e1928 100644 --- a/.gitattributes +++ b/.gitattributes @@ -4257,7 +4257,7 @@ tests/application/modules/admin/controllers/NewsletterControllerTest.php -text tests/application/modules/admin/controllers/OaiControllerTest.php -text tests/application/modules/admin/controllers/OpdsControllerTest.php -text tests/application/modules/admin/controllers/OuverturesControllerTest.php -text -tests/application/modules/admin/controllers/ProfilControllerControllerCssUploadTest.php -text +tests/application/modules/admin/controllers/ProfilControllerCssUploadTest.php -text tests/application/modules/admin/controllers/ProfilControllerIndexTest.php -text tests/application/modules/admin/controllers/ProfilControllerPageAccueilTest.php -text tests/application/modules/admin/controllers/ProfilControllerProfilJeunesseAndAdultesWithMenusTest.php -text diff --git a/application/modules/admin/controllers/ProfilController.php b/application/modules/admin/controllers/ProfilController.php index ccbfa7f785a..71f65be600e 100644 --- a/application/modules/admin/controllers/ProfilController.php +++ b/application/modules/admin/controllers/ProfilController.php @@ -119,9 +119,14 @@ class Admin_ProfilController extends Zend_Controller_Action { public function uploadCssAction() { - $this->_profil + $profil_to_update = $this->_profil->hasParentProfil() + ? $this->_profil->getParentProfil() + : $this->_profil; + + $profil_to_update ->writeHeaderCss($this->_request->getRawBody()) ->save(); + $this->getHelper('ViewRenderer')->setNoRender(); } diff --git a/tests/application/modules/admin/controllers/ProfilControllerControllerCssUploadTest.php b/tests/application/modules/admin/controllers/ProfilControllerCssUploadTest.php similarity index 53% rename from tests/application/modules/admin/controllers/ProfilControllerControllerCssUploadTest.php rename to tests/application/modules/admin/controllers/ProfilControllerCssUploadTest.php index c0955595ccd..ee9f6d09e62 100644 --- a/tests/application/modules/admin/controllers/ProfilControllerControllerCssUploadTest.php +++ b/tests/application/modules/admin/controllers/ProfilControllerCssUploadTest.php @@ -20,16 +20,20 @@ */ require_once 'AdminAbstractControllerTestCase.php'; -class ProfilControllerCssUploadTest extends Admin_AbstractControllerTestCase { + +abstract class ProfilControllerCssTestCase extends Admin_AbstractControllerTestCase { protected $_file_writer; protected $_profil_musique; + protected $_page_jazz; public function setUp() { parent::setUp(); - $this->_profil_musique = Class_Profil::getLoader() - ->newInstanceWithId(5) - ->setLibelle('Profil musique'); + $this->_profil_musique = Class_Profil::newInstanceWithId(5) + ->setLibelle('Profil musique') + ->setSubProfils([$this->_page_jazz = Class_Profil::newInstanceWithId(15) + ->setParentId(15) + ->setLibelle('Jazz')]); $this->_file_writer = Storm_Test_ObjectWrapper::mock(); Class_Profil::setFileWriter($this->_file_writer); @@ -37,12 +41,16 @@ class ProfilControllerCssUploadTest extends Admin_AbstractControllerTestCase { Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Profil') ->whenCalled('save') ->answers(true); - } +} - /** @test */ - public function uploadShoulPutContentInCssFileWhenDefined() { + + +class ProfilControllerCssUploadWithExistingCssTest extends ProfilControllerCssTestCase { + public function setUp() { + parent::setUp(); + $this->_profil_musique->setCfgSite([ 'header_css' => USERFILESURL.'css/my.css' ] ); $this->getRequest() @@ -56,13 +64,22 @@ class ProfilControllerCssUploadTest extends Admin_AbstractControllerTestCase { ->beStrict(); $this->dispatch('/admin/profil/upload-css/id_profil/5', true); - - $this->assertTrue($this->_file_writer->methodHasBeenCalled('putContents')); } /** @test */ - public function uploadShoulPutContentInANewCssFileWhenProfilHasNoCss() { + public function fileWriterShouldHavePutContents() { + $this->assertTrue($this->_file_writer->methodHasBeenCalled('putContents')); + } +} + + + + +class ProfilControllerCssUploadWithNoCssFileTest extends ProfilControllerCssTestCase { + public function setUp() { + parent::setUp(); + $this->getRequest() ->setMethod('PUT') ->setRawBody('body {font-size: 15px}'); @@ -74,27 +91,57 @@ class ProfilControllerCssUploadTest extends Admin_AbstractControllerTestCase { ->beStrict(); $this->dispatch('/admin/profil/upload-css/id_profil/5', true); - + } + + + /** @test */ + public function fileWriterShouldHavePutContents() { $this->assertTrue($this->_file_writer->methodHasBeenCalled('putContents')); - return Class_Profil::getLoader(); + } + + + /** @test */ + public function profilMusiqueShouldHaveBeenSaved() { + $this->assertTrue(Class_Profil::methodHasBeenCalledWithParams('save', [$this->_profil_musique])); } - /** - * @depends uploadShoulPutContentInANewCssFileWhenProfilHasNoCss - * @test - */ - public function profilShouldBeSaved($profil_loader) { - $this->assertTrue($profil_loader->methodHasBeenCalled('save')); + /** @test */ + public function profilCssShouldBeProfil5Css() { + $this->assertEquals(BASE_URL.'/userfiles/css/profil_5.css', $this->_profil_musique->getHeaderCss()); } +} + + + +class ProfilControllerCssUploadOnPageJazz extends ProfilControllerCssTestCase { + public function setUp() { + parent::setUp(); - /** - * @depends uploadShoulPutContentInANewCssFileWhenProfilHasNoCss - * @test - */ - public function profilCssShouldBeProfil5Css($profil_loader) { - $this->assertEquals(BASE_URL.'/userfiles/css/profil_5.css', $profil_loader->find(5)->getHeaderCss()); + $this->getRequest() + ->setMethod('PUT') + ->setRawBody('body {font-size: 15px}'); + + $this->_file_writer + ->whenCalled('putContents') + ->with(USERFILESPATH.'/css/profil_5.css', 'body {font-size: 15px}') + ->answers(22) + ->beStrict(); + + $this->dispatch('/admin/profil/upload-css/id_profil/15', true); + } + + + /** @test */ + public function profilMusiqueShouldHaveBeenSaved() { + $this->assertTrue(Class_Profil::methodHasBeenCalledWithParams('save', [$this->_profil_musique])); + } + + + /** @test */ + public function profilCssShouldBeProfil5Css() { + $this->assertEquals(BASE_URL.'/userfiles/css/profil_5.css', $this->_profil_musique->getHeaderCss()); } } -- GitLab