Merge pull request #772 from chillu/pulls/sitetree-urlsegment-votes

API SiteTree->validURLSegment() prioritizes extension votes
This commit is contained in:
Ingo Schommer 2013-06-25 02:18:08 -07:00
commit 98750a9cf1
2 changed files with 31 additions and 10 deletions

View File

@ -1599,20 +1599,20 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
}
}
$votes = array_filter(
(array)$this->extend('augmentValidURLSegment'),
function($v) {return !is_null($v);}
);
if($votes) {
return min($votes);
}
$existingPage = DataObject::get_one(
'SiteTree',
"\"URLSegment\" = '$this->URLSegment' $IDFilter $parentFilter"
);
if ($existingPage) {
return false;
}
$votes = $this->extend('augmentValidURLSegment');
if($votes) {
return min($votes);
}
return true;
return !($existingPage);
}
/**

View File

@ -4,8 +4,9 @@
* @subpackage tests
*/
class SiteTreeTest extends SapphireTest {
protected static $fixture_file = 'SiteTreeTest.yml';
protected static $fixture_file = 'SiteTreeTest.yml';
protected $illegalExtensions = array(
'SiteTree' => array('SiteTreeSubsites')
);
@ -700,6 +701,18 @@ class SiteTreeTest extends SapphireTest {
$this->assertTrue($sitetree->validURLSegment(), 'Valid URLSegment values are allowed');
}
public function testURLSegmentPrioritizesExtensionVotes() {
$sitetree = new SiteTree();
$sitetree->URLSegment = 'unique-segment';
$this->assertTrue($sitetree->validURLSegment());
SiteTree::add_extension('SiteTreeTest_Extension');
$sitetree = new SiteTree();
$sitetree->URLSegment = 'unique-segment';
$this->assertFalse($sitetree->validURLSegment());
SiteTree::remove_extension('SiteTreeTest_Extension');
}
public function testURLSegmentMultiByte() {
$origAllow = Config::inst()->get('URLSegmentFilter', 'default_allow_multibyte');
Config::inst()->update('URLSegmentFilter', 'default_allow_multibyte', true);
@ -991,3 +1004,11 @@ class SiteTreeTest_StageStatusInherit extends SiteTree implements TestOnly {
return $flags;
}
}
class SiteTreeTest_Extension extends DataExtension implements TestOnly {
public function augmentValidURLSegment() {
return false;
}
}