From 01ec6e01be7ac7b8b855c3094b3cfce5f6e7512c Mon Sep 17 00:00:00 2001 From: llaffont <llaffont@git-test.afi-sa.fr> Date: Sat, 23 Mar 2013 09:20:25 +0000 Subject: [PATCH] =?UTF-8?q?Lorsque=20on=20cr=C3=A9e=20un=20article=20dans?= =?UTF-8?q?=20une=20cat=C3=A9gorie=20qui=20correspond=20=C3=A0=20un=20doma?= =?UTF-8?q?ine,=20ce=20domaine=20est=20s=C3=A9lectionn=C3=A9=20par=20d?= =?UTF-8?q?=C3=A9faut?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controllers/CmsController.php | 5 +- library/Class/Catalogue.php | 18 +++++ public/admin/css/global.css | 5 ++ .../admin/controllers/CmsControllerTest.php | 68 ++++++++++++------- 4 files changed, 71 insertions(+), 25 deletions(-) diff --git a/application/modules/admin/controllers/CmsController.php b/application/modules/admin/controllers/CmsController.php index 6cb045d079e..c908040f0da 100644 --- a/application/modules/admin/controllers/CmsController.php +++ b/application/modules/admin/controllers/CmsController.php @@ -168,8 +168,9 @@ class Admin_CmsController extends Zend_Controller_Action { $category->setBib($this->_bib); } - $article = Class_Article::getLoader()->newInstance() - ->setCategorie($category); + $article = Class_Article::newInstance(['categorie' => $category]); + if ($domaine = Class_Catalogue::findWithSamePathAs($category)) + $article->setDomaineIds($domaine->getId()); if ($this->_isArticleSaved($article)) { $this->_helper->notify('Article ajouté'); diff --git a/library/Class/Catalogue.php b/library/Class/Catalogue.php index 09ed3bd1aee..2de6eea203f 100644 --- a/library/Class/Catalogue.php +++ b/library/Class/Catalogue.php @@ -188,6 +188,9 @@ class CatalogueLoader extends Storm_Model_Loader { } + /** + * @return array [id => label] + */ public function allByIdLabel() { $catalogues = Class_Catalogue::findAllBy(['order' => 'libelle']); $allids=[]; @@ -198,15 +201,30 @@ class CatalogueLoader extends Storm_Model_Loader { } + /** + * @return array + */ public function findTopCatalogues() { return Class_Catalogue::findAllBy(['where' => 'parent_id is null', 'order' => 'libelle']); } + /** + * @return Class_Catalogue + */ public function getRoot() { return Class_Catalogue::newInstanceWithId(null); } + + + /** + * @param $treeNode Trait_TreeNode + * @return Class_Catalogue + */ + public function findWithSamePathAs($treeNode) { + return Class_Catalogue::getRoot()->findByPath($treeNode->getPath()); + } } diff --git a/public/admin/css/global.css b/public/admin/css/global.css index ea6a1c5bea9..788e563ee05 100644 --- a/public/admin/css/global.css +++ b/public/admin/css/global.css @@ -1007,4 +1007,9 @@ img.article_edit { .table_scroll { margin-right: 50px; overflow: auto; +} + + +#description_editor_switch { + cursor: pointer; } \ No newline at end of file diff --git a/tests/application/modules/admin/controllers/CmsControllerTest.php b/tests/application/modules/admin/controllers/CmsControllerTest.php index a1ed611a042..c3c02ad6524 100644 --- a/tests/application/modules/admin/controllers/CmsControllerTest.php +++ b/tests/application/modules/admin/controllers/CmsControllerTest.php @@ -25,12 +25,23 @@ abstract class CmsControllerTestCase extends Admin_AbstractControllerTestCase { protected $concert; protected $lieu_bonlieu, $lieu_arcadium; - protected function _loginHook($account) { $account->ROLE = "admin_bib"; $account->ROLE_LEVEL = ZendAfi_Acl_AdminControllerRoles::ADMIN_BIB; } + public function setUp() { + parent::setUp(); + + $this + ->setupLieux() + ->setupDomaines() + ->setupArticles(); + + Class_Users::getLoader()->getIdentity()->setIdSite(1); + Class_AdminVar::newInstanceWithId('LANGUES', ['valeur' => 'en;ro']); + } + public function setupLieux() { $this->lieu_bonlieu = Class_Lieu::newInstanceWithId(3, @@ -53,33 +64,44 @@ abstract class CmsControllerTestCase extends Admin_AbstractControllerTestCase { ->answers([$this->lieu_bonlieu, $this->lieu_arcadium]) ->whenCalled('save')->answers(true); + return $this; } public function setupDomaines() { - $this->domaine_histoire = Class_Catalogue::newInstanceWithId(10) - ->setLibelle('Histoire') - ->setSousDomaines([$this->domaine_art = Class_Catalogue::newInstanceWithId(11) - ->setParentId(10) - ->setLibelle('Art')]); + $this->domaine_histoire = Class_Catalogue::newInstanceWithId(10, + ['libelle' => 'Histoire', + 'sous_domaines' => [$this->domaine_art = Class_Catalogue::newInstanceWithId(11, + ['parent_id' => 10, + 'libelle' => 'Art'])]]); + + $domaine_a_la_une = Class_Catalogue::newInstanceWithId(66, + ['libelle' => 'A la Une']); Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Catalogue') ->whenCalled('findAllBy') - ->with(array('order' => 'libelle')) - ->answers([$this->domaine_art,$this->domaine_histoire]) + ->with(['order' => 'libelle']) + ->answers([$this->domaine_art, + $this->domaine_histoire]) + ->whenCalled('findAllBy') ->with(['where' => 'parent_id is null', 'order' => 'libelle']) - ->answers([$this->domaine_histoire]); - } + ->answers([$this->domaine_histoire]) + ->whenCalled('findFirstBy') + ->answers(null) - public function setUp() { - parent::setUp(); + ->whenCalled('findFirstBy') + ->with(['parent_id' => null, + 'libelle' => 'A la Une']) + ->answers($domaine_a_la_une); + + return $this; + } - $this->setupLieux(); - $this->setupDomaines(); + public function setupArticles() { $cat_a_la_une = Class_ArticleCategorie::newInstanceWithId(23, ['libelle' => 'A la Une']); $this->cat_evenements = Class_ArticleCategorie::newInstanceWithId(34, @@ -136,11 +158,7 @@ abstract class CmsControllerTestCase extends Admin_AbstractControllerTestCase { ->answers([Class_Bib::getPortail(), $this->annecy, $this->cran_gevrier]); - - - Class_Users::getLoader()->getIdentity()->setIdSite(1); - - Class_AdminVar::newInstanceWithId('LANGUES', ['valeur' => 'en;ro']); + return $this; } @@ -752,7 +770,7 @@ class CmsControllerArticleAddActionPostTest extends CmsControllerTestCase { -class CmsControllerNewsAddActionTest extends CmsControllerTestCase { +class CmsControllerNewsAddToCatALaUneActionTest extends CmsControllerTestCase { public function setUp() { parent::setUp(); $this->dispatch('admin/cms/newsadd/id_cat/23',true); @@ -799,15 +817,19 @@ class CmsControllerNewsAddActionTest extends CmsControllerTestCase { /** @test */ public function categorieSelectShouldHaveALaUneSelected() { $this->assertXPathContentContains('//select[@name="id_cat"]//option[@selected="selected"]', - 'A la Une', - $this->_response->getBody()); + 'A la Une'); } - /** @test */ public function selectIdLieuShouldContainsBonlieu() { $this->assertXPath('//select[@name="id_lieu"]//option[not(@selected)][@label="Bonlieu"][@value="3"]'); } + + + /** @test */ + public function checkBoxShouldCheckedDomaineALaUne() { + $this->assertXPath("//input[@name='domaine_ids'][@value='66']"); + } } -- GitLab