本文整理匯總了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());
});
}