From f161cbff26306cead473848b422a0d22e6af65cc Mon Sep 17 00:00:00 2001 From: llaffont <llaffont@afi-sa.fr> Date: Fri, 24 Oct 2014 15:34:37 +0200 Subject: [PATCH] hotline #7832 profils url rewriting cannot save two pages with same url and without parents --- library/ZendAfi/Validate/ProfilRewriteUrl.php | 4 ++-- tests/library/Class/ProfilTest.php | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/library/ZendAfi/Validate/ProfilRewriteUrl.php b/library/ZendAfi/Validate/ProfilRewriteUrl.php index b6d5f371644..7055e4d7954 100644 --- a/library/ZendAfi/Validate/ProfilRewriteUrl.php +++ b/library/ZendAfi/Validate/ProfilRewriteUrl.php @@ -87,9 +87,9 @@ class ZendAfi_Validate_ProfilRewriteUrl extends Zend_Validate_Abstract { $profils = array_filter($profils, function ($model) use ($page) { return $model->hasParentProfil() - && ($model->getParent()->getRewriteUrl()) && ($model->getId() !== $page->getId()) - && ($model->getParent()->getRewriteUrl() == $page->getParent()->getRewriteUrl());}); + && ($model->getParent()->getRewriteUrl() == $page->getParent()->getRewriteUrl()); + }); if (count($profils)==0) return true; diff --git a/tests/library/Class/ProfilTest.php b/tests/library/Class/ProfilTest.php index 319930150f7..b06a658c0f6 100644 --- a/tests/library/Class/ProfilTest.php +++ b/tests/library/Class/ProfilTest.php @@ -749,6 +749,7 @@ class ProfilAdulteChatenayTest extends ProfilAdulteChatenayTestCase { implode(',', $this->profil->getErrors())); } + /** @test */ public function pageWithParentProfilWithoutRewriteUrlShouldBeValid() { $this->page_nature = Class_Profil::newInstance([ @@ -760,6 +761,28 @@ class ProfilAdulteChatenayTest extends ProfilAdulteChatenayTestCase { } + + /** @test */ + public function twoPagesWithParentProfilWithoutRewriteUrlAndSameUrlShouldNotBeValid() { + $this->fixture('Class_Profil', ['id' => 345, + 'parent_id' => null, + 'libelle' => 'one profile', + 'rewrite_url' => '']); + + $this->fixture('Class_Profil', ['id' => 543, + 'parent_id' => 1, + 'libelle' => 'Nature', + 'rewrite_url' => 'nature']); + + $page_nature = Class_Profil::newInstance([ + 'parent_id' => 1, + 'libelle' => 'Nature', + 'rewrite_url' => 'nature']); + + $this->assertFalse($page_nature->isValid()); + } + + /** @test */ public function pageWithParentProfilWithSameRewriteUrlAsAnotherProfilShouldBeValid() { $this->profil_nature = $this->fixture('Class_Profil', -- GitLab