mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +02:00
Merge pull request #1263 from ss23/fix_812_oldpageredirector
MINOR Change how OldPageRedirector gets URLs to fix nested redirects
This commit is contained in:
commit
4db4db05af
@ -10,8 +10,8 @@ class OldPageRedirector extends Extension {
|
|||||||
* @throws SS_HTTPResponse_Exception
|
* @throws SS_HTTPResponse_Exception
|
||||||
*/
|
*/
|
||||||
public function onBeforeHTTPError404($request) {
|
public function onBeforeHTTPError404($request) {
|
||||||
// Build up the request parameters
|
// We need to get the URL ourselves because $request->allParams() only has a max of 4 params
|
||||||
$params = array_filter(array_values($request->allParams()), function($v) { return ($v !== NULL); });
|
$params = preg_split('|/+|', $request->getURL());
|
||||||
|
|
||||||
$getvars = $request->getVars();
|
$getvars = $request->getVars();
|
||||||
unset($getvars['url']);
|
unset($getvars['url']);
|
||||||
|
@ -115,6 +115,60 @@ class ModelAsControllerTest extends FunctionalTest {
|
|||||||
$response = $this->get('newlevel1/newlevel2/level3');
|
$response = $this->get('newlevel1/newlevel2/level3');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that the redirect works even with a lot of nested pages
|
||||||
|
* Original: /oldurl/level2/level3/level4/level5
|
||||||
|
* New: /newurl/level2/level3/level4/level5
|
||||||
|
*/
|
||||||
|
public function testHeavilyNestedRenamedRedirectedPages() {
|
||||||
|
$page = new Page();
|
||||||
|
$page->Title = 'First Level';
|
||||||
|
$page->URLSegment = 'oldurl';
|
||||||
|
$page->write();
|
||||||
|
$page->publish('Stage', 'Live');
|
||||||
|
|
||||||
|
$page->URLSegment = 'newurl';
|
||||||
|
$page->write();
|
||||||
|
$page->publish('Stage', 'Live');
|
||||||
|
|
||||||
|
$page2 = new Page();
|
||||||
|
$page2->Title = 'Second Level Page';
|
||||||
|
$page2->URLSegment = 'level2';
|
||||||
|
$page2->ParentID = $page->ID;
|
||||||
|
$page2->write();
|
||||||
|
$page2->publish('Stage', 'Live');
|
||||||
|
|
||||||
|
$page3 = new Page();
|
||||||
|
$page3->Title = 'Third Level Page';
|
||||||
|
$page3->URLSegment = 'level3';
|
||||||
|
$page3->ParentID = $page2->ID;
|
||||||
|
$page3->write();
|
||||||
|
$page3->publish('Stage', 'Live');
|
||||||
|
|
||||||
|
$page4 = new Page();
|
||||||
|
$page4->Title = 'Fourth Level Page';
|
||||||
|
$page4->URLSegment = 'level4';
|
||||||
|
$page4->ParentID = $page3->ID;
|
||||||
|
$page4->write();
|
||||||
|
$page4->publish('Stage', 'Live');
|
||||||
|
|
||||||
|
$page5 = new Page();
|
||||||
|
$page5->Title = 'Fifth Level Page';
|
||||||
|
$page5->URLSegment = 'level5';
|
||||||
|
$page5->ParentID = $page4->ID;
|
||||||
|
$page5->write();
|
||||||
|
$page5->publish('Stage', 'Live');
|
||||||
|
|
||||||
|
// Test that the redirect still works fine when trying to access the most nested page
|
||||||
|
$response = $this->get('oldurl/level2/level3/level4/level5/');
|
||||||
|
$this->assertEquals($response->getStatusCode(), 301);
|
||||||
|
$this->assertEquals(
|
||||||
|
Controller::join_links(Director::baseURL() . 'newurl/level2/level3/level4/level5/'),
|
||||||
|
$response->getHeader('Location')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testRedirectionForPreNestedurlsBookmarks(){
|
public function testRedirectionForPreNestedurlsBookmarks(){
|
||||||
$this->generateNestedPagesFixture();
|
$this->generateNestedPagesFixture();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user