本文整理汇总了PHP中ContentController::getViewer方法的典型用法代码示例。如果您正苦于以下问题:PHP ContentController::getViewer方法的具体用法?PHP ContentController::getViewer怎么用?PHP ContentController::getViewer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ContentController
的用法示例。
在下文中一共展示了ContentController::getViewer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetViewer
/**
* Tests that {@link ContentController::getViewer()} chooses the correct templates.
*
* @covers ContentController::getViewer()
**/
public function testGetViewer()
{
$self = $this;
$this->useTestTheme(dirname(__FILE__), 'controllertest', function () use($self) {
// Test a page without a controller (ContentControllerTest_PageWithoutController.ss)
$page = new ContentControllerTestPageWithoutController();
$page->URLSegment = "test";
$page->write();
$page->publish("Stage", "Live");
$response = $self->get($page->RelativeLink());
$self->assertEquals("ContentControllerTestPageWithoutController", trim($response->getBody()));
// // This should fall over to user Page.ss
$page = new ContentControllerTestPage();
$page->URLSegment = "test";
$page->write();
$page->publish("Stage", "Live");
$response = $self->get($page->RelativeLink());
$self->assertEquals("Page", trim($response->getBody()));
// Test that the action template is rendered.
$page = new ContentControllerTestPage();
$page->URLSegment = "page-without-controller";
$page->write();
$page->publish("Stage", "Live");
$response = $self->get($page->RelativeLink("test"));
$self->assertEquals("ContentControllerTestPage_test", trim($response->getBody()));
// Test that an action without a template will default to the index template, which is
// to say the default Page.ss template
$response = $self->get($page->RelativeLink("testwithouttemplate"));
$self->assertEquals("Page", trim($response->getBody()));
// Test that an action with a template will render the both action template *and* the
// correct parent template
$controller = new ContentController($page);
$viewer = $controller->getViewer('test');
$templateList = array('ContentControllerTestPage_test', 'Page');
$expected = SS_TemplateLoader::instance()->findTemplates($templateList, 'controllertest');
$self->assertEquals($expected, $viewer->templates());
});
}