mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +02:00
Merge pull request #772 from chillu/pulls/sitetree-urlsegment-votes
API SiteTree->validURLSegment() prioritizes extension votes
This commit is contained in:
commit
98750a9cf1
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user