diff --git a/application/modules/admin/controllers/CmsController.php b/application/modules/admin/controllers/CmsController.php index 7676b295eb75d2bea8fa32ce6ae5d17148281486..04ce6bfd19db8b25815f21a734995d9c68b4b53a 100644 --- a/application/modules/admin/controllers/CmsController.php +++ b/application/modules/admin/controllers/CmsController.php @@ -156,6 +156,7 @@ class Admin_CmsController extends ZendAfi_Controller_Action { public function newsaddAction() { + $category = Class_ArticleCategorie::getLoader()->find($this->_getParam('id_cat')); // pas d'article non catégorisé @@ -174,6 +175,9 @@ class Admin_CmsController extends ZendAfi_Controller_Action { $article->setDomaineIds($domaine->getId()); if ($this->_isArticleSaved($article)) { + if($id_module = $this->_getParam('id_module')) + $this->updateConfigBoiteNews($id_module,$article); + $this->_helper->notify('Article ajouté '.$article->getNotifyMessage()); $this->_redirect(sprintf('admin/cms/newsedit/id/%d', $article->getId())); return; @@ -185,6 +189,18 @@ class Admin_CmsController extends ZendAfi_Controller_Action { $this->view->combo_lieu_options = $this->comboLieuOptions(); } + protected function updateConfigBoiteNews($id_module, $article){ + xdebug_break(); + $profil = Class_Profil::getCurrentProfil(); + $module_config = $profil->getModuleAccueilConfig($id_module); + $id_items= array_filter(explode('-',$module_config['preferences']['id_items'])); + array_unshift($id_items,$article->getId()); + $module_config['preferences']['id_items'] = implode('-',$id_items); + $profil->updateModuleConfigAccueil($id_module, $module_config); + $profil->save(); + return $this; + } + public function newseditAction() { $article = Class_Article::getLoader()->find((int)$this->_getParam('id')); diff --git a/tests/application/modules/admin/controllers/CmsControllerTest.php b/tests/application/modules/admin/controllers/CmsControllerTest.php index cc672bdf27d4df81181eceb4b0cd6aa59a2f8b87..27a6d5f1e5b84960ad5e4d72fe5350b09f3205b6 100644 --- a/tests/application/modules/admin/controllers/CmsControllerTest.php +++ b/tests/application/modules/admin/controllers/CmsControllerTest.php @@ -1696,4 +1696,54 @@ class CmsControllerCategorieNotFoundTest extends CmsControllerTestCase { } +class CmsControllerNewsAddToCatALaUneInNewsModuleActionTest extends CmsControllertestCase { + + public function setup() { + parent::setup(); + + $cfg_accueil_jeunesse = ['modules' => ['10' => ['division' => '2', + 'type_module' => 'NEWS']], + + 'options' => []]; + + $this->profil_jeunesse = Class_Profil::getCurrentProfil() + ->setBrowser('opac') + ->setTitreSite(null) + ->setLibelle('Profil Jeunesse') + ->setCfgAccueil($cfg_accueil_jeunesse); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Profil') + ->whenCalled('save') + ->answers(true); + + Class_Article::whenCalled('save') + ->willDo( + function($model){ + $model->setId(4); + return true; + }); + + $this->postDispatch('/admin/cms/newsadd/id_module/10/id_cat/34', + ['titre' => 'Erik Truffaz - Ladyland quartet en concert', + 'auteur' => Class_Users::newInstanceWithId(1, ['login' => 'tom']), + 'id_cat' => 34, + 'contenu' => 'Ici: <img src="../../images/bonlieu.jpg" />', + 'description' => 'Affiche: <img src="http://localhost' . BASE_URL . '/images/concert.jpg" />']); + } + + + /** @test **/ + public function boiteNewsShouldDisplayArticleConcert() { + $this->assertEquals( 4, Class_Profil::getCurrentProfil()->getModuleAccueilPreferences(10)['id_items']); + } + + + /** @test **/ + public function profilShouldHaveBeenSaved() { + $this->assertTrue(Class_Profil::methodHasBeenCalled('save')); + } +} + + + ?> \ No newline at end of file