mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #3369 from tractorcow/pulls/3.1/fix-updatetreenodes
BUG Fix issue with generating tree data for missing pages
This commit is contained in:
commit
55dca6eec6
@ -942,6 +942,7 @@ class LeftAndMain extends Controller implements PermissionProvider {
|
|||||||
if($id === "") continue; // $id may be a blank string, which is invalid and should be skipped over
|
if($id === "") continue; // $id may be a blank string, which is invalid and should be skipped over
|
||||||
|
|
||||||
$record = $this->getRecord($id);
|
$record = $this->getRecord($id);
|
||||||
|
if(!$record) continue; // In case a page is no longer available
|
||||||
$recordController = ($this->stat('tree_class') == 'SiteTree')
|
$recordController = ($this->stat('tree_class') == 'SiteTree')
|
||||||
? singleton('CMSPageEditController')
|
? singleton('CMSPageEditController')
|
||||||
: $this;
|
: $this;
|
||||||
|
@ -196,6 +196,52 @@ class LeftAndMainTest extends FunctionalTest {
|
|||||||
|
|
||||||
$this->session()->inst_set('loggedInAs', null);
|
$this->session()->inst_set('loggedInAs', null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test {@see LeftAndMain::updatetreenodes}
|
||||||
|
*/
|
||||||
|
public function testUpdateTreeNodes() {
|
||||||
|
$page1 = $this->objFromFixture('LeftAndMainTest_Object', 'page1');
|
||||||
|
$page2 = $this->objFromFixture('LeftAndMainTest_Object', 'page2');
|
||||||
|
$page3 = $this->objFromFixture('LeftAndMainTest_Object', 'page3');
|
||||||
|
$page31 = $this->objFromFixture('LeftAndMainTest_Object', 'page31');
|
||||||
|
$page32 = $this->objFromFixture('LeftAndMainTest_Object', 'page32');
|
||||||
|
$this->logInWithPermission('ADMIN');
|
||||||
|
|
||||||
|
// Check page
|
||||||
|
$result = $this->get('LeftAndMainTest_Controller/updatetreenodes?ids='.$page1->ID);
|
||||||
|
$this->assertEquals(200, $result->getStatusCode());
|
||||||
|
$this->assertEquals('text/json', $result->getHeader('Content-Type'));
|
||||||
|
$data = json_decode($result->getBody(), true);
|
||||||
|
$pageData = $data[$page1->ID];
|
||||||
|
$this->assertEquals(0, $pageData['ParentID']);
|
||||||
|
$this->assertEquals($page2->ID, $pageData['NextID']);
|
||||||
|
$this->assertEmpty($pageData['PrevID']);
|
||||||
|
|
||||||
|
// check subpage
|
||||||
|
$result = $this->get('LeftAndMainTest_Controller/updatetreenodes?ids='.$page31->ID);
|
||||||
|
$this->assertEquals(200, $result->getStatusCode());
|
||||||
|
$this->assertEquals('text/json', $result->getHeader('Content-Type'));
|
||||||
|
$data = json_decode($result->getBody(), true);
|
||||||
|
$pageData = $data[$page31->ID];
|
||||||
|
$this->assertEquals($page3->ID, $pageData['ParentID']);
|
||||||
|
$this->assertEquals($page32->ID, $pageData['NextID']);
|
||||||
|
$this->assertEmpty($pageData['PrevID']);
|
||||||
|
|
||||||
|
// Multiple pages
|
||||||
|
$result = $this->get('LeftAndMainTest_Controller/updatetreenodes?ids='.$page1->ID.','.$page2->ID);
|
||||||
|
$this->assertEquals(200, $result->getStatusCode());
|
||||||
|
$this->assertEquals('text/json', $result->getHeader('Content-Type'));
|
||||||
|
$data = json_decode($result->getBody(), true);
|
||||||
|
$this->assertEquals(2, count($data));
|
||||||
|
|
||||||
|
// Invalid IDs
|
||||||
|
$result = $this->get('LeftAndMainTest_Controller/updatetreenodes?ids=-3');
|
||||||
|
$this->assertEquals(200, $result->getStatusCode());
|
||||||
|
$this->assertEquals('text/json', $result->getHeader('Content-Type'));
|
||||||
|
$data = json_decode($result->getBody(), true);
|
||||||
|
$this->assertEquals(0, count($data));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -224,4 +270,6 @@ class LeftAndMainTest_Object extends DataObject implements TestOnly {
|
|||||||
'Hierarchy'
|
'Hierarchy'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
public function CMSTreeClasses() {}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,65 +1,94 @@
|
|||||||
LeftAndMainTest_Object:
|
LeftAndMainTest_Object:
|
||||||
page1:
|
page1:
|
||||||
Title: Page 1
|
Title: Page 1
|
||||||
|
Sort: 1
|
||||||
page2:
|
page2:
|
||||||
Title: Page 2
|
Title: Page 2
|
||||||
|
Sort: 2
|
||||||
page3:
|
page3:
|
||||||
Title: Page 3
|
Title: Page 3
|
||||||
|
Sort: 3
|
||||||
page31:
|
page31:
|
||||||
Title: Page 3.1
|
Title: Page 3.1
|
||||||
Parent: =>LeftAndMainTest_Object.page3
|
Parent: =>LeftAndMainTest_Object.page3
|
||||||
|
Sort: 1
|
||||||
page32:
|
page32:
|
||||||
Title: Page 3.2
|
Title: Page 3.2
|
||||||
Parent: =>LeftAndMainTest_Object.page3
|
Parent: =>LeftAndMainTest_Object.page3
|
||||||
|
Sort: 2
|
||||||
page4:
|
page4:
|
||||||
Title: Page 4
|
Title: Page 4
|
||||||
|
Sort: 4
|
||||||
page5:
|
page5:
|
||||||
Title: Page 5
|
Title: Page 5
|
||||||
|
Sort: 5
|
||||||
page6:
|
page6:
|
||||||
Title: Page 6
|
Title: Page 6
|
||||||
|
Sort: 6
|
||||||
page7:
|
page7:
|
||||||
Title: Page 7
|
Title: Page 7
|
||||||
|
Sort: 7
|
||||||
page8:
|
page8:
|
||||||
Title: Page 8
|
Title: Page 8
|
||||||
|
Sort: 8
|
||||||
page9:
|
page9:
|
||||||
Title: Page 9
|
Title: Page 9
|
||||||
|
Sort: 9
|
||||||
page10:
|
page10:
|
||||||
Title: Page 10
|
Title: Page 10
|
||||||
|
Sort: 10
|
||||||
page11:
|
page11:
|
||||||
Title: Page 11
|
Title: Page 11
|
||||||
|
Sort: 11
|
||||||
page12:
|
page12:
|
||||||
Title: Page 12
|
Title: Page 12
|
||||||
|
Sort: 12
|
||||||
page13:
|
page13:
|
||||||
Title: Page 13
|
Title: Page 13
|
||||||
|
Sort: 13
|
||||||
page14:
|
page14:
|
||||||
Title: Page 14
|
Title: Page 14
|
||||||
|
Sort: 14
|
||||||
page15:
|
page15:
|
||||||
Title: Page 15
|
Title: Page 15
|
||||||
|
Sort: 15
|
||||||
page16:
|
page16:
|
||||||
Title: Page 16
|
Title: Page 16
|
||||||
|
Sort: 16
|
||||||
page17:
|
page17:
|
||||||
Title: Page 17
|
Title: Page 17
|
||||||
|
Sort: 17
|
||||||
page18:
|
page18:
|
||||||
Title: Page 18
|
Title: Page 18
|
||||||
|
Sort: 18
|
||||||
page19:
|
page19:
|
||||||
Title: Page 19
|
Title: Page 19
|
||||||
|
Sort: 19
|
||||||
page20:
|
page20:
|
||||||
Title: Page 20
|
Title: Page 20
|
||||||
|
Sort: 20
|
||||||
page21:
|
page21:
|
||||||
Title: Page 21
|
Title: Page 21
|
||||||
|
Sort: 21
|
||||||
page22:
|
page22:
|
||||||
Title: Page 22
|
Title: Page 22
|
||||||
|
Sort: 22
|
||||||
page23:
|
page23:
|
||||||
Title: Page 23
|
Title: Page 23
|
||||||
|
Sort: 23
|
||||||
page24:
|
page24:
|
||||||
Title: Page 24
|
Title: Page 24
|
||||||
|
Sort: 24
|
||||||
page25:
|
page25:
|
||||||
Title: Page 25
|
Title: Page 25
|
||||||
|
Sort: 25
|
||||||
page26:
|
page26:
|
||||||
Title: Page 26
|
Title: Page 26
|
||||||
|
Sort: 26
|
||||||
home:
|
home:
|
||||||
Title: Home
|
Title: Home
|
||||||
URLSegment: home
|
URLSegment: home
|
||||||
|
Sort: 0
|
||||||
Group:
|
Group:
|
||||||
admin:
|
admin:
|
||||||
Title: Administrators
|
Title: Administrators
|
||||||
|
Loading…
Reference in New Issue
Block a user