Permalink
Browse files

API SiteTree->validURLSegment() prioritizes extension votes

Tri-state, use NULL to ignore the extension result
  • Loading branch information...
1 parent 4bc942d commit 0c4b2f81576433988a3173a62c7fea8d49dc1385 @chillu chillu committed Jun 12, 2013
Showing with 31 additions and 10 deletions.
  1. +9 −9 code/model/SiteTree.php
  2. +22 −1 tests/model/SiteTreeTest.php
View
18 code/model/SiteTree.php
@@ -1588,20 +1588,20 @@ public function validURLSegment() {
}
}
- $existingPage = DataObject::get_one(
- 'SiteTree',
- "\"URLSegment\" = '$this->URLSegment' $IDFilter $parentFilter"
+ $votes = array_filter(
+ (array)$this->extend('augmentValidURLSegment'),
+ function($v) {return !is_null($v);}
);
- if ($existingPage) {
- return false;
- }
-
- $votes = $this->extend('augmentValidURLSegment');
if($votes) {
return min($votes);
}
+
+ $existingPage = DataObject::get_one(
+ 'SiteTree',
+ "\"URLSegment\" = '$this->URLSegment' $IDFilter $parentFilter"
+ );
- return true;
+ return !($existingPage);
}
/**
View
23 tests/model/SiteTreeTest.php
@@ -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 @@ public function testValidURLSegmentControllerConflicts() {
$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);
@@ -960,3 +973,11 @@ public function getStatusFlags($cached = true){
return $flags;
}
}
+
+class SiteTreeTest_Extension extends DataExtension implements TestOnly {
+
+ public function augmentValidURLSegment() {
+ return false;
+ }
+
+}

0 comments on commit 0c4b2f8

Please sign in to comment.