diff --git a/application/modules/admin/controllers/RssController.php b/application/modules/admin/controllers/RssController.php index f21d835db36aad19e21c2638be57034e894d14dc..a5ee48f540dfa4473063ca78e640e4cd8c912b93 100644 --- a/application/modules/admin/controllers/RssController.php +++ b/application/modules/admin/controllers/RssController.php @@ -73,7 +73,6 @@ class Admin_RssController extends Zend_Controller_Action { function cataddAction() { $this->view->titre = $this->_("Ajouter une catégorie de flux RSS"); - $class_rss = new Class_Rss(); $rss_categorie = new Class_RssCategorie(); if ($parent_categorie = Class_RssCategorie::find((int)$this->_getParam('id'))) { @@ -82,63 +81,38 @@ class Admin_RssController extends Zend_Controller_Action { ->setIdSite($parent_categorie->getIdSite()); } - if ($this->_request->isPost()) { - $filter = new Zend_Filter_StripTags(); - $libelle = trim($filter->filter($this->_request->getPost('libelle'))); - $id_cat_mere = (int)$this->_request->getPost('id_cat_mere'); - $data = array( - 'ID_CAT' => '', - 'ID_CAT_MERE' => $id_cat_mere, - 'LIBELLE' => $libelle, - 'ID_SITE' => $this->id_bib, - ); - $menu_deploy = $this->saveTreeMenu($id_cat_mere); - $class_rss = new Class_Rss(); - $errorMessage = $class_rss->addCategorie($data); - if ($errorMessage == ''){ - $this->_redirect('admin/rss?z='.$this->id_zone.'&b='.$this->id_bib); - return; - } - $this->view->message = $errorMessage; - } - else { - $menu_deploy = $this->saveTreeMenu($rss_categorie->getIdCatMere()); - } - // Action - $this->view->action = 'add'; - $this->view->sess_id_zone = $this->id_zone; - $this->view->sess_id_site = $this->id_bib; - $this->view->rss_cat = $rss_categorie; - $this->view->combo_cat = $this->view->comboParentCategorie($rss_categorie); + $this->addOrEditCategorie($rss_categorie); } function cateditAction() { $this->view->titre = $this->_("Modifier une catégorie de flux RSS"); - $id = (int)$this->_request->getParam('id', 0); + if (!$rss_categorie = Class_RssCategorie::find($id)) $this->_redirect('admin/rss?z='.$this->id_zone.'&b='.$this->id_bib); - if ($this->_request->isPost()) { - if ($rss_categorie->updateAttributes($this->_request->getPost())->save()) { - $this->_redirect('/admin/rss/index/z/'.$this->id_zone.'/b/'.$this->id_bib); - return; - } + $this->addOrEditCategorie($rss_categorie); + } - $errorMessage = implode(',', $rss_categorie->getErrors()); - } - $this->view->combo_cat = $this->view->comboParentCategorie($rss_categorie); - $this->view->action = 'edit'; + public function addOrEditCategorie($rss_categorie) { + if ($this->_request->isPost() && $rss_categorie->updateAttributes($this->_request->getPost())->save()) + $this->_redirect('admin/rss/index/z/'.$this->id_zone.'/b/'.$this->id_bib); + + $this->saveTreeMenu($rss_categorie->getIdCatMere()); + + $this->view->message = implode(',', $rss_categorie->getErrors()); + $this->view->sess_id_zone = $this->id_zone; $this->view->sess_id_site = $this->id_bib; - $this->view->id = $id; $this->view->rss_cat = $rss_categorie; + $this->view->combo_cat = $this->view->comboParentCategorie($rss_categorie); } + function catdelAction() { $class_rss = new Class_Rss(); diff --git a/application/modules/admin/views/scripts/rss/catform.phtml b/application/modules/admin/views/scripts/rss/catform.phtml index 834eadedf4c467999ab2ce2a9140385163497dc3..af362e06b872259f7e46de090003164145fd009e 100644 --- a/application/modules/admin/views/scripts/rss/catform.phtml +++ b/application/modules/admin/views/scripts/rss/catform.phtml @@ -1,9 +1,11 @@ <?php echo $this->BarreLocalisation($this->id_zone,$this->id_bib); ?> <div class="form"> - <form name="form" action="<?php echo BASE_URL ?>/admin/rss/cat<?php echo $this->action; ?>/id/<?php echo $this->id; ?>" method="post"> + <form name="form" action="<?php echo $this->url() ?>" method="post"> <fieldset> <legend><?php echo $this->traduire('Catégorie'); ?></legend> - <span id="abonne_erreur" class="abonne"><?php echo $this->message; ?></span> + <?php if ($this->message) { ?> + <div class="error"><?php echo $this->message; ?></div> + <?php } ?> <br /> <table> <tr> diff --git a/library/Class/Rss.php b/library/Class/Rss.php index d26285ba3ebf4daff74baed292f303d2feaab51d..3944a632fba0ac102c37f12c812f20ba811ae235 100644 --- a/library/Class/Rss.php +++ b/library/Class/Rss.php @@ -381,30 +381,6 @@ class Class_Rss extends Storm_Model_Abstract { ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Méthode admin ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // ajoute - public function addCategorie($data) - { - if ( $this->_rssCategorie == null ){return $this->_dataBaseError;} - $errorMessage = $this->verifCategorieData($data); - if ($errorMessage == ''){ - try{ - $this->_rssCategorie->insert($data); - }catch (Exception $e){ - logErrorMessage('Class: Class_Rss; Function: addCategorie' . NL . $e->getMessage()); - $errorMessage = $this->_dataBaseError; - } - } - return $errorMessage; - } - - - // Edit une cat - public function editCategorie($data, $id_cat) { - if ( $errorMessage = $this->verifCategorieData($data)) - return $errorMessage; - - Class_RssCategorie::find($id_cat)->updateAttributes($data)->save(); - } // Supprimer une cat @@ -426,17 +402,9 @@ class Class_Rss extends Storm_Model_Abstract { } return $errorMessage; } - // on verif les cat - public function verifCategorieData($data) - { - $errorMessage = ''; - if ( $data['LIBELLE'] == '' ){ - $errorMessage = "Vous devez compléter le champ 'Nom de la catégorie'"; - }elseif (mb_strlen($data['LIBELLE'],'UTF-8') > 50) { - $errorMessage = "Le champ 'Nom de la catégorie' doit être inférieur à 50 caractères"; - } - return $errorMessage; - } + + + /////////////////////////////////////////////// // RSS /////////////////////////////////////////////// @@ -527,6 +495,8 @@ class Class_Rss extends Storm_Model_Abstract { } return $errorMessage; } + + /* créaion d'un flux $data_array = 'titre', 'description', @@ -588,6 +558,8 @@ class Class_Rss extends Storm_Model_Abstract { } } } + + // methode a apeller de l'exterieur pour créer l'array public function rendArray($id_bib = 0, $niveau = -1, $id_cat_mere = 0) { @@ -596,11 +568,14 @@ class Class_Rss extends Storm_Model_Abstract { $this->rendArbreArray($id_bib, $niveau , $id_cat_mere); return ($this->arbre_array); } + + // methode a apeller de l'exterieur pour rendre le html, une fois l'array créer public function rendHTML() { $niveau=0; $id=0; $html= '<ul class="treeMenu">'; + xdebug_break(); if(count($this->arbre_array) > 0){ foreach($this->arbre_array as $menu) { @@ -621,20 +596,20 @@ class Class_Rss extends Storm_Model_Abstract { $ico_add_cat='<a href="'.BASE_URL.'/admin/rss/catadd/id/'.$menu["ID_CAT"].'"><img src="'.URL_ADMIN_IMG.'ico/add_cat.gif" class="ico" alt="Ajouter une sous-catégorie" title="Ajouter une sous-catégorie" style="width:22px;"/></a>'; $ico_add_news='<a href="'.BASE_URL.'/admin/rss/rssadd/id/'.$menu["ID_CAT"].'"><img src="'.URL_ADMIN_IMG.'ico/add_news.gif" class="ico" title="Ajouter un fil Rss" alt="Ajouter un fil Rss" /></a>'; $ico_edit='<a href="'.BASE_URL.'/admin/rss/catedit/id/'.$menu["ID_CAT"].'"><img src="'.URL_ADMIN_IMG.'ico/edit.gif" class="ico" title="Modifier" alt="Modifier" /></a>'; - $ico_edit_news='<a href="'.BASE_URL.'/admin/rss/rssedit/id/'.$menu["ID_RSS"].'"><img src="'.URL_ADMIN_IMG.'ico/edit.gif" class="ico" title="Modifier" alt="Modifier"/></a>'; - $ico_del_news='<a href="'.BASE_URL.'/admin/rss/rssdel/id/'.$menu["ID_RSS"].'" onclick="javascript:if(!confirm(\'Êtes vous sûr de vouloir supprimer ce fil Rss ?\')) return false;"><img src="'.URL_ADMIN_IMG.'ico/del.gif" class="ico" alt="Supprimer" title="Supprimer" /></a>'; $ico_cat='<img src="'.URL_ADMIN_IMG.'ico/cat.gif" class="ico" alt="Afficher les sous catégories" style="width:19px; height:12px;"/>'; $ico_news='<img src="'.URL_ADMIN_IMG.'ico/liste.gif" class="ico" alt="Afficher le flux" title="Afficher le flux" align="bottom"/>'; if(strlen($menu["LIBELLE"]) >= 50){$libelle_cat = substr($menu["LIBELLE"],0,50).'...'; } else $libelle_cat =$menu["LIBELLE"] ; - if(strlen($menu["TITRE"]) >= 50){$libelle_rss = substr($menu["TITRE"],0,50).'...'; } else $libelle_rss =$menu["TITRE"] ; $nb_items = count($cat_avec_rss) + count($cat_avec_subcat); - $html.= '<li style="width:100%; height:25px;padding-top:10px;border-bottom:1px solid #DEE4E8;" id="m_'.$menu["ID_CAT"].'"><div style="float:left;cursor:pointer;" onclick="show(\'sm_'.$menu["ID_CAT"].'\');">'; - if ($menu["ID_RSS"]) + + if (isset($menu["ID_RSS"])) { + $ico_edit_news='<a href="'.BASE_URL.'/admin/rss/rssedit/id/'.$menu["ID_RSS"].'"><img src="'.URL_ADMIN_IMG.'ico/edit.gif" class="ico" title="Modifier" alt="Modifier"/></a>'; + $ico_del_news='<a href="'.BASE_URL.'/admin/rss/rssdel/id/'.$menu["ID_RSS"].'" onclick="javascript:if(!confirm(\'Êtes vous sûr de vouloir supprimer ce fil Rss ?\')) return false;"><img src="'.URL_ADMIN_IMG.'ico/del.gif" class="ico" alt="Supprimer" title="Supprimer" /></a>'; + if(strlen($menu["TITRE"]) >= 50){$libelle_rss = substr($menu["TITRE"],0,50).'...'; } else $libelle_rss =$menu["TITRE"] ; $html.='<a id="rss_a_'.$menu["ID_RSS"].'" href="#" onclick="requestRss(\''.$menu["ID_RSS"].'\');show(\'sm_'.$menu["ID_CAT"].'\');">'.$ico_news.' '.$libelle_rss. '</a></div> <div style="height:20px;" align="right"> '.$ico_edit_news.$ico_del_news.'</div>'; - else + } else $html.=$ico_cat.' '.$libelle_cat. ' ('.$nb_items.')</div> <div style="height:20px;" align="right">'.$ico_add_cat.$ico_add_news.$ico_edit.$ico_del.'</div>'; $html.='</li>'; } diff --git a/library/Class/RssCategorie.php b/library/Class/RssCategorie.php index ae6b7114352886716c62a23d0423fb01a3a2c205..54a827d7939b649dcd1237b857e24904381dcde9 100644 --- a/library/Class/RssCategorie.php +++ b/library/Class/RssCategorie.php @@ -20,6 +20,8 @@ */ class Class_RssCategorie extends Storm_Model_Abstract { + use Trait_Translator; + protected $_table_name = 'rss_categorie', $_table_primary = 'ID_CAT', @@ -62,6 +64,18 @@ class Class_RssCategorie extends Storm_Model_Abstract { $all_categories = array_merge($all_categories, $categorie->getRecursiveSousCategories()); return $all_categories; } + + + public function validate() { + $this + ->checkAttribute('libelle', + trim($this->getLibelle()), + $this->_("Vous devez compléter le champ 'Nom de la catégorie'")) + ->checkAttribute('libelle', + mb_strlen($this->getLibelle()) <= 50, + $this->_("Le champ 'Nom de la catégorie' doit être inférieur à 50 caractères")); + + } } ?> diff --git a/tests/application/modules/admin/controllers/BibControllerTest.php b/tests/application/modules/admin/controllers/BibControllerTest.php index cd86f4791252be0650d64cbc9dfeceda416ada76..7d19ce781e7a14c353eb587f135f324fcdcf8d26 100644 --- a/tests/application/modules/admin/controllers/BibControllerTest.php +++ b/tests/application/modules/admin/controllers/BibControllerTest.php @@ -340,7 +340,7 @@ abstract class BibControllerDeleteCranActionTestCase extends BibControllerTestCa $this->fixture('Class_Exemplaire', ['id' => 5, 'id_bib' => 3]); $this->fixture('Class_Exemplaire', ['id' => 10, 'id_bib' => 3]); - $this->fixture('Class_RssCategorie', ['id' => 10, 'id_site' => 3]); + $this->fixture('Class_RssCategorie', ['id' => 10, 'id_site' => 3, 'libelle' => 'Infos']); $this->fixture('Class_Rss', ['id' => 23, 'id_cat' => 10]); $this->fixture('Class_Rss', ['id' => 24, 'id_cat' => 10]); $this->fixture('Class_Rss', ['id' => 25, 'id_cat' => 10]); diff --git a/tests/application/modules/admin/controllers/RssControllerTest.php b/tests/application/modules/admin/controllers/RssControllerTest.php index a787dfb8faf2c648a7979250649c964250d0cd6a..10c90def73b00a18464c5b17251f662365cdd77f 100644 --- a/tests/application/modules/admin/controllers/RssControllerTest.php +++ b/tests/application/modules/admin/controllers/RssControllerTest.php @@ -25,6 +25,7 @@ abstract class RssControllerTestCase extends Admin_AbstractControllerTestCase { parent::setUp(); $this->fixture('Class_Rss', ['id' => 3, + 'id_rss' => 3, 'titre' => 'linuxfr', 'categorie' => $this->fixture('Class_RssCategorie', ['id' => 1, @@ -81,7 +82,7 @@ class RssControllerCatEditActionTest extends RssControllerTestCase { /** @test */ public function formActionShouldBeRssCatEditIdOne() { - $this->assertXPath('//form[contains(@action, "/admin/rss/catedit/id/1")]'); + $this->assertXPath('//form[contains(@action, "/admin/rss/catedit/id/1")]', $this->_response->getBody()); } @@ -109,7 +110,7 @@ class RssControllerPostCatEditActionTest extends RssControllerTestCase { /** @test */ - public function responseShouldRedirectToIndexWithZoneAndIdBibPORTAIL() { + public function responseShouldRedirectToIndexWithZoneAllBibOne() { $this->assertRedirectTo('/admin/rss/index/z/ALL/b/1'); } } @@ -117,6 +118,35 @@ class RssControllerPostCatEditActionTest extends RssControllerTestCase { +class RssControllerPostWrongDataCatEditActionTest extends RssControllerTestCase { + /** @test */ + public function withEmptyLibelleErrorShouldBeLibelleCouldNotBeEmpty() { + $this->postDispatch('/admin/rss/catedit/id/1', ['libelle' => '']); + $this->assertXPathContentContains('//div[@class="error"]', + "Vous devez compléter le champ", + $this->_response->getBody()); + } + + + /** @test */ + public function withTooLongLibelleErrorShouldBeLibelleLessThan50Chars() { + $this->postDispatch('/admin/rss/catedit/id/1', + ['libelle' => str_repeat('a', 51)]); + $this->assertXPathContentContains('//div[@class="error"]', + "doit être inférieur à 50"); + } + + + /** @test */ + public function responseShouldNotRedirect() { + $this->postDispatch('/admin/rss/catedit/id/1', ['libelle' => '']); + $this->assertNotRedirect(); + } +} + + + + class RssControllerCatAddActionTest extends RssControllerTestCase { public function setUp() { parent::setUp(); @@ -144,4 +174,27 @@ class RssControllerCatAddActionTest extends RssControllerTestCase { } + + + +class RssControllerPostCatAddActionTest extends RssControllerTestCase { + public function setUp() { + parent::setUp(); + $this->postDispatch('/admin/rss/catadd/id/1', + ['libelle' => 'OS']); + Class_RssCategorie::clearCache(); + } + + /** @test */ + public function newCategorieShouldBeOS() { + $this->assertEquals('OS', Class_RssCategorie::find(2)->getLibelle()); + } + + + /** @test */ + public function responseShouldRedirectToIndexWithZoneAllBibOne() { + $this->assertRedirectTo('/admin/rss/index/z/ALL/b/1'); + } +} + ?> \ No newline at end of file