diff --git a/core/control/ContentController.php b/core/control/ContentController.php index c47f781c6..832c94e37 100755 --- a/core/control/ContentController.php +++ b/core/control/ContentController.php @@ -109,9 +109,11 @@ class ContentController extends Controller { if($this->dataRecord && $this->URLSegment != 'Security' && !$this->dataRecord->can('View')) { return Security::permissionFailure($this); } - +var_dump(Versioned::current_stage()); // Draft/Archive security check - only CMS users should be able to look at stage/archived content if($this->URLSegment != 'Security' && !Session::get('unsecuredDraftSite') && (Versioned::current_archived_date() || (Versioned::current_stage() && Versioned::current_stage() != 'Live'))) { + var_dump($this->URLSegment); + var_dump($this->dataRecord->canViewStage(Versioned::current_stage())); if(!$this->dataRecord->canViewStage(Versioned::current_stage())) { $link = $this->Link(); $message = _t("ContentController.DRAFT_SITE_ACCESS_RESTRICTION", 'You must log in with your CMS password in order to view the draft or archived content. Click here to go back to the published site.'); diff --git a/tests/control/ContentControllerTest.php b/tests/control/ContentControllerTest.php index 83894c62e..aa25a9340 100755 --- a/tests/control/ContentControllerTest.php +++ b/tests/control/ContentControllerTest.php @@ -12,53 +12,54 @@ class ContentControllerTest extends FunctionalTest { /** * Test that nested pages, basic actions, and nested/non-nested URL switching works properly */ + public function testNestedPages() { RootURLController::reset(); SiteTree::enable_nested_urls(); - + $this->assertEquals('Home Page', $this->get('/')->getBody()); $this->assertEquals('Home Page', $this->get('/home/index/')->getBody()); $this->assertEquals('Home Page', $this->get('/home/second-index/')->getBody()); - + $this->assertEquals('Second Level Page', $this->get('/home/second-level/')->getBody()); $this->assertEquals('Second Level Page', $this->get('/home/second-level/index/')->getBody()); $this->assertEquals('Second Level Page', $this->get('/home/second-level/second-index/')->getBody()); - + $this->assertEquals('Third Level Page', $this->get('/home/second-level/third-level/')->getBody()); $this->assertEquals('Third Level Page', $this->get('/home/second-level/third-level/index/')->getBody()); $this->assertEquals('Third Level Page', $this->get('/home/second-level/third-level/second-index/')->getBody()); - + RootURLController::reset(); SiteTree::disable_nested_urls(); - + $this->assertEquals('Home Page', $this->get('/')->getBody()); $this->assertEquals('Home Page', $this->get('/home/')->getBody()); $this->assertEquals('Home Page', $this->get('/home/second-index/')->getBody()); - + $this->assertEquals('Second Level Page', $this->get('/second-level/')->getBody()); $this->assertEquals('Second Level Page', $this->get('/second-level/index/')->getBody()); $this->assertEquals('Second Level Page', $this->get('/second-level/second-index/')->getBody()); - + $this->assertEquals('Third Level Page', $this->get('/third-level/')->getBody()); $this->assertEquals('Third Level Page', $this->get('/third-level/index/')->getBody()); $this->assertEquals('Third Level Page', $this->get('/third-level/second-index/')->getBody()); } - + /** * Tests {@link ContentController::ChildrenOf()} */ public function testChildrenOf() { $controller = new ContentController(); - + SiteTree::enable_nested_urls(); - + $this->assertEquals(1, $controller->ChildrenOf('/')->Count()); $this->assertEquals(1, $controller->ChildrenOf('/home/')->Count()); $this->assertEquals(2, $controller->ChildrenOf('/home/second-level/')->Count()); $this->assertEquals(0, $controller->ChildrenOf('/home/second-level/third-level/')->Count()); - + SiteTree::disable_nested_urls(); - + $this->assertEquals(1, $controller->ChildrenOf('/')->Count()); $this->assertEquals(1, $controller->ChildrenOf('/home/')->Count()); $this->assertEquals(2, $controller->ChildrenOf('/second-level/')->Count()); @@ -89,6 +90,20 @@ class ContentControllerTest extends FunctionalTest { SiteTree::disable_nested_urls(); } + public function testViewDraft(){ + + // test when user does not have permission, should get login form + $this->logInWithPermssion('editor'); + $this->assertEquals('403', $this->get('/contact/?stage=Stage')->getstatusCode()); + + + // test when user does have permission, should show page title and header ok. + $this->logInWithPermssion('admin'); + $this->assertEquals('200', $this->get('/contact/?stage=Stage')->getstatusCode()); + + + } + } class ContentControllerTest_Page extends Page { }