2009-10-11 02:07:07 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @package sapphire
|
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
class ContentControllerTest extends FunctionalTest {
|
|
|
|
|
|
|
|
public static $fixture_file = 'sapphire/tests/control/ContentControllerTest.yml';
|
|
|
|
|
|
|
|
public static $use_draft_site = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that nested pages, basic actions, and nested/non-nested URL switching works properly
|
|
|
|
*/
|
2010-04-13 03:42:50 +02:00
|
|
|
|
2009-10-11 02:07:07 +02:00
|
|
|
public function testNestedPages() {
|
2009-10-11 02:07:22 +02:00
|
|
|
RootURLController::reset();
|
2009-10-11 02:07:07 +02:00
|
|
|
SiteTree::enable_nested_urls();
|
2010-04-13 03:42:50 +02:00
|
|
|
|
2009-10-11 02:07:07 +02:00
|
|
|
$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());
|
2010-04-13 03:42:50 +02:00
|
|
|
|
2009-10-11 02:07:07 +02:00
|
|
|
$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());
|
2010-04-13 03:42:50 +02:00
|
|
|
|
2009-10-11 02:07:07 +02:00
|
|
|
$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());
|
2010-04-13 03:42:50 +02:00
|
|
|
|
2009-10-11 02:07:22 +02:00
|
|
|
RootURLController::reset();
|
2009-10-11 02:07:07 +02:00
|
|
|
SiteTree::disable_nested_urls();
|
2010-04-13 03:42:50 +02:00
|
|
|
|
2009-10-11 02:07:07 +02:00
|
|
|
$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());
|
2010-04-13 03:42:50 +02:00
|
|
|
|
2009-10-11 02:07:07 +02:00
|
|
|
$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());
|
2010-04-13 03:42:50 +02:00
|
|
|
|
2009-10-11 02:07:07 +02:00
|
|
|
$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());
|
|
|
|
}
|
2010-04-13 03:42:50 +02:00
|
|
|
|
2009-10-11 02:07:19 +02:00
|
|
|
/**
|
|
|
|
* Tests {@link ContentController::ChildrenOf()}
|
|
|
|
*/
|
|
|
|
public function testChildrenOf() {
|
|
|
|
$controller = new ContentController();
|
2010-04-13 03:42:50 +02:00
|
|
|
|
2009-10-11 02:07:19 +02:00
|
|
|
SiteTree::enable_nested_urls();
|
2010-04-13 03:42:50 +02:00
|
|
|
|
2009-10-11 02:07:19 +02:00
|
|
|
$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());
|
2010-04-13 03:42:50 +02:00
|
|
|
|
2009-10-11 02:07:19 +02:00
|
|
|
SiteTree::disable_nested_urls();
|
2010-04-13 03:42:50 +02:00
|
|
|
|
2009-10-11 02:07:19 +02:00
|
|
|
$this->assertEquals(1, $controller->ChildrenOf('/')->Count());
|
|
|
|
$this->assertEquals(1, $controller->ChildrenOf('/home/')->Count());
|
|
|
|
$this->assertEquals(2, $controller->ChildrenOf('/second-level/')->Count());
|
|
|
|
$this->assertEquals(0, $controller->ChildrenOf('/third-level/')->Count());
|
|
|
|
}
|
|
|
|
|
2009-12-18 06:19:28 +01:00
|
|
|
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();
|
2010-01-13 02:13:18 +01:00
|
|
|
$page->ParentID = $parentID;
|
2009-12-18 06:19:28 +01:00
|
|
|
$page->Title = "Page Level $i";
|
|
|
|
$page->URLSegment = "level-$i";
|
|
|
|
$page->write();
|
2010-01-13 02:13:18 +01:00
|
|
|
|
|
|
|
$relativeLink = Director::makeRelative($page->Link());
|
|
|
|
$this->assertEquals($page->Title, $this->get($relativeLink)->getBody());
|
2009-12-18 06:19:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SiteTree::disable_nested_urls();
|
|
|
|
}
|
|
|
|
|
2010-04-13 03:42:50 +02:00
|
|
|
public function testViewDraft(){
|
|
|
|
|
|
|
|
// test when user does not have permission, should get login form
|
2010-04-14 06:41:30 +02:00
|
|
|
$this->logInWithPermission('EDITOR');
|
2010-04-13 03:42:50 +02:00
|
|
|
$this->assertEquals('403', $this->get('/contact/?stage=Stage')->getstatusCode());
|
|
|
|
|
|
|
|
|
|
|
|
// test when user does have permission, should show page title and header ok.
|
2010-04-14 06:41:30 +02:00
|
|
|
$this->logInWithPermission('ADMIN');
|
2010-04-13 03:42:50 +02:00
|
|
|
$this->assertEquals('200', $this->get('/contact/?stage=Stage')->getstatusCode());
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2010-10-13 02:42:17 +02:00
|
|
|
|
|
|
|
public function testLinkShortcodes() {
|
|
|
|
$linkedPage = new SiteTree();
|
|
|
|
$linkedPage->URLSegment = 'linked-page';
|
|
|
|
$linkedPage->write();
|
|
|
|
$linkedPage->publish('Stage', 'Live');
|
|
|
|
|
|
|
|
$page = new SiteTree();
|
|
|
|
$page->URLSegment = 'linking-page';
|
|
|
|
$page->Content = sprintf('<a href="[sitetree_link id=%s]">Testlink</a>', $linkedPage->ID);
|
|
|
|
$page->write();
|
|
|
|
$page->publish('Stage', 'Live');
|
|
|
|
|
|
|
|
$this->assertContains(
|
|
|
|
sprintf('<a href="%s">Testlink</a>', $linkedPage->Link()),
|
|
|
|
$this->get($page->RelativeLink())->getBody(),
|
|
|
|
'"sitetree_link" shortcodes get parsed properly'
|
|
|
|
);
|
|
|
|
}
|
2010-04-13 03:42:50 +02:00
|
|
|
|
2009-10-11 02:07:07 +02:00
|
|
|
}
|
|
|
|
|
2009-12-18 06:19:28 +01:00
|
|
|
class ContentControllerTest_Page extends Page { }
|
|
|
|
|
|
|
|
class ContentControllerTest_Page_Controller extends Page_Controller {
|
|
|
|
|
2009-10-11 02:07:07 +02:00
|
|
|
public static $allowed_actions = array (
|
|
|
|
'second_index'
|
|
|
|
);
|
|
|
|
|
|
|
|
public function index() {
|
|
|
|
return $this->Title;
|
|
|
|
}
|
2009-12-18 06:19:28 +01:00
|
|
|
|
2009-10-11 02:07:07 +02:00
|
|
|
public function second_index() {
|
|
|
|
return $this->index();
|
|
|
|
}
|
2009-12-18 06:19:28 +01:00
|
|
|
|
2009-10-11 02:07:07 +02:00
|
|
|
}
|