From 3d39af5fdf3f1033f2129b91365f2c08e1d3bc64 Mon Sep 17 00:00:00 2001 From: Ghislain Loas <ghislo@sandbox.pergame.net> Date: Fri, 9 Oct 2015 11:18:19 +0200 Subject: [PATCH] hotline #30747 : fix cms_categories with same id and parent_id --- VERSIONS_HOTLINE/30747 | 1 + library/Class/ArticleCategorie.php | 2 ++ tests/library/Class/ArticleCategorieTest.php | 37 ++++++++++++++++---- 3 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 VERSIONS_HOTLINE/30747 diff --git a/VERSIONS_HOTLINE/30747 b/VERSIONS_HOTLINE/30747 new file mode 100644 index 00000000000..1097a362ccb --- /dev/null +++ b/VERSIONS_HOTLINE/30747 @@ -0,0 +1 @@ + - ticket #30747 : Correction de la possibilité de déclarer une catégorie d'article comme étant sa propre catégorie parente. \ No newline at end of file diff --git a/library/Class/ArticleCategorie.php b/library/Class/ArticleCategorie.php index 9e1cc7b6957..edf5dbe37d5 100644 --- a/library/Class/ArticleCategorie.php +++ b/library/Class/ArticleCategorie.php @@ -70,6 +70,8 @@ class Class_ArticleCategorie extends Storm_Model_Abstract { $filter = new Zend_Filter_StripTags(); $this->setLibelle(trim($filter->filter($this->getLibelle()))); + if($this->getId() === $this->getIdCatMere()) + $this->setIdCatMere(0); } diff --git a/tests/library/Class/ArticleCategorieTest.php b/tests/library/Class/ArticleCategorieTest.php index 8d06fbf1fed..577bc2b52af 100644 --- a/tests/library/Class/ArticleCategorieTest.php +++ b/tests/library/Class/ArticleCategorieTest.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class ArticleCategorieTest extends Storm_Test_ModelTestCase { @@ -82,7 +82,7 @@ class ArticleCategorieTest extends Storm_Test_ModelTestCase { ->answers(true) ->getWrapper(); - + $this->concert_truffaz = Class_Article::newInstanceWithId(23, ['id_cat' => 34, 'titre' => 'Concert Truffaz']); @@ -169,9 +169,9 @@ class ArticleCategorieTest extends Storm_Test_ModelTestCase { } - /** + /** * Régression vue sur Pontault - * @test + * @test */ public function annecyWithCarriageReturnToJSONShouldRemoveCR() { $this->annecy->setLibelle("Annecy\n"); @@ -317,11 +317,11 @@ JSON; /** @test */ public function findByPathAdulteConcertsJazzShouldAnswerCategorieJazz() { - $this->assertEquals($this->cat_concerts_jazz, + $this->assertEquals($this->cat_concerts_jazz, Class_ArticleCategorie::getRoot()->findByPath('/Adulte/Concerts/Jazz')); } - + /** @test **/ public function profilConcertPathAndCategorieConcertPathShouldBeEquals() { $this->assertEquals($this->cat_concerts->getPath(), $this->concert_profil->getPath()); @@ -334,4 +334,27 @@ JSON; } } -?> \ No newline at end of file + + +class ArticleCategorieParentTest extends Storm_Test_ModelTestCase { + protected $_news; + + public function setUp() { + parent::setUp(); + + $annecy = $this->fixture('Class_Bib', + ['id' => 1, + 'libelle' => 'Annecy']); + + $this->_news = $this->fixture('Class_ArticleCategorie', + ['id' => 5, + 'id_cat_mere' => 5, + 'libelle' => 'News']); + } + + + /** @test */ + public function newsParentCategorieShouldBe0() { + $this->assertEquals('0', $this->_news->getIdCatMere()); + } +} \ No newline at end of file -- GitLab