BUGFIX: Fixed nested URLs operation for pages more than 4 levels deep.

From: Andrew Short <andrewjshort@gmail.com> (from r95902)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@97433 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Andrew Short 2010-01-22 01:39:42 +00:00 committed by Sam Minnee
parent feabafcada
commit 46a8083e57
2 changed files with 37 additions and 14 deletions

View File

@ -386,14 +386,19 @@ class SS_HTTPRequest implements ArrayAccess {
* @return string * @return string
*/ */
public function shiftAllParams() { public function shiftAllParams() {
$keys = array_keys($this->allParams); $keys = array_keys($this->allParams);
$values = array_values($this->allParams); $values = array_values($this->allParams);
$value = array_shift($values); $value = array_shift($values);
// push additional unparsed URL parts onto the parameter stack
if(array_key_exists($this->unshiftedButParsedParts, $this->dirParts)) {
$values[] = $this->dirParts[$this->unshiftedButParsedParts];
}
foreach($keys as $position => $key) { foreach($keys as $position => $key) {
$this->allParams[$key] = isset($values[$position]) ? $values[$position] : null; $this->allParams[$key] = isset($values[$position]) ? $values[$position] : null;
} }
return $value; return $value;
} }

View File

@ -65,25 +65,43 @@ class ContentControllerTest extends FunctionalTest {
$this->assertEquals(0, $controller->ChildrenOf('/third-level/')->Count()); $this->assertEquals(0, $controller->ChildrenOf('/third-level/')->Count());
} }
public function testDeepNestedURLs() {
SiteTree::enable_nested_urls();
$page = new Page();
$page->URLSegment = 'base-page';
$page->write();
for($i = 0; $i < 10; $i++) {
$parentID = $page->ID;
$page = new ContentControllerTest_Page();
$page->Title = "Page Level $i";
$page->URLSegment = "level-$i";
$page->write();
}
$this->assertEquals($page->Title, $this->get($page->Link())->getBody());
SiteTree::disable_nested_urls();
}
} }
class ContentControllerTest_Page extends Page { class ContentControllerTest_Page extends Page { }
class ContentControllerTest_Page_Controller extends Page_Controller {
public static $allowed_actions = array ( public static $allowed_actions = array (
'second_index' 'second_index'
); );
}
class ContentControllerTest_Page_Controller extends Page_Controller {
public function index() { public function index() {
return $this->Title; return $this->Title;
} }
public function second_index() { public function second_index() {
return $this->index(); return $this->index();
} }
} }