本文整理汇总了PHP中Director::test方法的典型用法代码示例。如果您正苦于以下问题:PHP Director::test方法的具体用法?PHP Director::test怎么用?PHP Director::test使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Director
的用法示例。
在下文中一共展示了Director::test方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generatePDF
function generatePDF()
{
// tempfolder
$tmpBaseFolder = TEMP_FOLDER . '/shopsystem';
$tmpFolder = project() ? "{$tmpBaseFolder}/" . project() : "{$tmpBaseFolder}/site";
if (is_dir($tmpFolder)) {
Filesystem::removeFolder($tmpFolder);
}
if (!file_exists($tmpFolder)) {
Filesystem::makeFolder($tmpFolder);
}
$baseFolderName = basename($tmpFolder);
//Get site
Requirements::clear();
$link = Director::absoluteURL($this->pdfLink() . "/?view=1");
$response = Director::test($link);
$content = $response->getBody();
$content = utf8_decode($content);
$contentfile = "{$tmpFolder}/" . $this->PublicURL . ".html";
if (!file_exists($contentfile)) {
// Write to file
if ($fh = fopen($contentfile, 'w')) {
fwrite($fh, $content);
fclose($fh);
}
}
return $contentfile;
}
示例2: testRenderTemplatePlaceholder
public function testRenderTemplatePlaceholder()
{
// Create page object
$page = $this->objFromFixture('Page', 'page1');
$templateTitle = 'template1';
$templatePlaceHolder = '{{' . $templateTitle . '}}';
// Assert: render page
$this->assertContains($templatePlaceHolder, $page->Content());
// Create template
$template = $this->objFromFixture('ViewTemplate', $templateTitle);
$templatePlaceHolder = '{{' . $template->Title . '}}';
// Page disable template view
$page->EnableViewTemplate = false;
// Assert: render page without view template
$this->assertContains($templatePlaceHolder, $page->Content());
// Page enable template view
$page->EnableViewTemplate = true;
// Assert: render page with view template
$this->assertNotContains($templatePlaceHolder, $page->Content());
// Login admin
$this->logInWithPermission('ADMIN');
// Assert: Publish page
$published = $page->doPublish();
$this->assertTrue($published);
// Assert: page visible to public with render view template
Member::currentUser()->logOut();
$response = Director::test(Director::makeRelative($page->Link()));
$this->assertNotContains($templatePlaceHolder, $response->getBody());
$this->assertContains($template->ViewTemplate, $response->getBody());
}
示例3: testBasicView
/**
*
*/
function testBasicView()
{
// Confirm that this URL gets you the entire page, with the edit form loaded
$response = Director::test('great-show');
$this->assertTrue(strpos($response->getBody(), '<head') !== false);
$this->assertTrue(strpos($response->getBody(), 'First Episode') !== false);
}
示例4: doPublish
/**
* When an error page is published, create a static HTML page with its
* content, so the page can be shown even when SilverStripe is not
* functioning correctly before publishing this page normally.
* @param string|int $fromStage Place to copy from. Can be either a stage name or a version number.
* @param string $toStage Place to copy to. Must be a stage name.
* @param boolean $createNewVersion Set this to true to create a new version number. By default, the existing version number will be copied over.
*/
function doPublish()
{
parent::doPublish();
// Run the page (reset the theme, it might've been disabled by LeftAndMain::init())
$oldTheme = SSViewer::current_theme();
SSViewer::set_theme(SSViewer::current_custom_theme());
$response = Director::test(Director::makeRelative($this->Link()));
SSViewer::set_theme($oldTheme);
$errorContent = $response->getBody();
// Make the base tag dynamic.
// $errorContent = preg_replace('/<base[^>]+href="' . str_replace('/','\\/', Director::absoluteBaseURL()) . '"[^>]*>/i', '<base href="$BaseURL" />', $errorContent);
// Check we have an assets base directory, creating if it we don't
if (!file_exists(ASSETS_PATH)) {
mkdir(ASSETS_PATH, 02775);
}
// if the page is published in a language other than default language,
// write a specific language version of the HTML page
$filePath = self::get_filepath_for_errorcode($this->ErrorCode, $this->Locale);
if ($fh = fopen($filePath, "w")) {
fwrite($fh, $errorContent);
fclose($fh);
} else {
$fileErrorText = sprintf(_t("ErrorPage.ERRORFILEPROBLEM", "Error opening file \"%s\" for writing. Please check file permissions."), $errorFile);
FormResponse::status_message($fileErrorText, 'bad');
FormResponse::respond();
return;
}
}
示例5: makeApiRequest
/**
* Perform an api request with the given options
*
* @param string $path the request path; can consist of resource name, identifier and GET params
* @param array $options
* * string `body` the data
* * int `code` the expected response code
* * string `method` the http method
* * ApiSession `session` the test session
* @return array
* @throws SS_HTTPResponse_Exception
*/
public function makeApiRequest($path, $options = [])
{
$settings = array_merge(['session' => null, 'token' => null, 'method' => 'GET', 'body' => null, 'code' => 200], $options);
$response = Director::test(Controller::join_links($this->namespace, $path), null, $settings['session'], $settings['method'], $settings['body'], ['Authorization' => $settings['token'], 'Accept' => 'application/json']);
$this->assertEquals($settings['code'], $response->getStatusCode(), "Wrong status code: {$response->getBody()}");
return json_decode($response->getBody(), true);
}
示例6: testPublish
/**
* @todo Test the results of a publication better
*/
function testPublish()
{
$page1 = $this->objFromFixture('Page', "page1");
$page2 = $this->objFromFixture('Page', "page2");
$this->session()->inst_set('loggedInAs', $this->idFromFixture('Member', 'admin'));
$response = $this->get("admin/cms/publishall?confirm=1");
$this->assertContains(sprintf(_t('CMSMain.PUBPAGES', "Done: Published %d pages"), 30), $response->getBody());
// Some modules (e.g., cmsworkflow) will remove this action
if (isset(CMSBatchActionHandler::$batch_actions['publish'])) {
$response = Director::test("admin/cms/batchactions/publish", array('csvIDs' => implode(',', array($page1->ID, $page2->ID)), 'ajax' => 1), $this->session());
$responseData = Convert::json2array($response->getBody());
$this->assertTrue(property_exists($responseData['modified'], $page1->ID));
$this->assertTrue(property_exists($responseData['modified'], $page2->ID));
}
// Get the latest version of the redirector page
$pageID = $this->idFromFixture('RedirectorPage', 'page5');
$latestID = DB::query('select max("Version") from "RedirectorPage_versions" where "RecordID"=' . $pageID)->value();
$dsCount = DB::query('select count("Version") from "RedirectorPage_versions" where "RecordID"=' . $pageID . ' and "Version"=' . $latestID)->value();
$this->assertEquals(1, $dsCount, "Published page has no duplicate version records: it has " . $dsCount . " for version " . $latestID);
$this->session()->clear('loggedInAs');
//$this->assertRegexp('/Done: Published 4 pages/', $response->getBody())
/*
$response = Director::test("admin/publishitems", array(
'ID' => ''
'Title' => ''
'action_publish' => 'Save and publish',
), $session);
$this->assertRegexp('/Done: Published 4 pages/', $response->getBody())
*/
}
示例7: requireDefaultRecords
/**
* Create an {@link ErrorPage} for status code 503
*
* @see UnderConstruction_Extension::onBeforeInit()
* @see DataObjectDecorator::requireDefaultRecords()
* @return Void
*/
function requireDefaultRecords()
{
// Ensure that an assets path exists before we do any error page creation
if (!file_exists(ASSETS_PATH)) {
mkdir(ASSETS_PATH);
}
$pageUnderConstructionErrorPage = DataObject::get_one('ErrorPage', "\"ErrorCode\" = '503'");
$pageUnderConstructionErrorPageExists = $pageUnderConstructionErrorPage && $pageUnderConstructionErrorPage->exists() ? true : false;
$pageUnderConstructionErrorPagePath = ErrorPage::get_filepath_for_errorcode(503);
if (!($pageUnderConstructionErrorPageExists && file_exists($pageUnderConstructionErrorPagePath))) {
if (!$pageUnderConstructionErrorPageExists) {
$pageUnderConstructionErrorPage = new ErrorPage();
$pageUnderConstructionErrorPage->ErrorCode = 503;
$pageUnderConstructionErrorPage->Title = _t('UnderConstruction.TITLE', 'Under Construction');
$pageUnderConstructionErrorPage->Content = _t('UnderConstruction.CONTENT', '<p>Sorry, this site is currently under construction.</p>');
$pageUnderConstructionErrorPage->Status = 'New page';
$pageUnderConstructionErrorPage->write();
$pageUnderConstructionErrorPage->publish('Stage', 'Live');
}
// Ensure a static error page is created from latest error page content
$response = Director::test(Director::makeRelative($pageUnderConstructionErrorPage->Link()));
if ($fh = fopen($pageUnderConstructionErrorPagePath, 'w')) {
$written = fwrite($fh, $response->getBody());
fclose($fh);
}
if ($written) {
DB::alteration_message('503 error page created', 'created');
} else {
DB::alteration_message(sprintf('503 error page could not be created at %s. Please check permissions', $pageUnderConstructionErrorPagePath), 'error');
}
}
}
示例8: post
/**
* Submit a post request
* @uses Director::test()
*/
function post($url, $data, $headers = null, $session = null, $body = null, $cookies = null) {
$headers = (array) $headers;
if($this->lastUrl) $headers['Referer'] = $this->lastUrl;
$this->lastResponse = Director::test($url, $data, $session ? $session : $this->session, null, $body, $headers, $cookies);
$this->lastUrl = $url;
if(!$this->lastResponse) user_error("Director::test($url) returned null", E_USER_WARNING);
return $this->lastResponse;
}
示例9: post
/**
* Submit a post request
* @uses Director::test()
*/
function post($url, $data, $headers = null)
{
$headers = $this->lastUrl ? array('Referer' => $this->lastUrl) : null;
$this->lastResponse = Director::test($url, $data, $this->session, null, null, $headers);
$this->lastUrl = $url;
if (!$this->lastResponse) {
user_error("Director::test({$url}) returned null", E_USER_WARNING);
}
return $this->lastResponse;
}
示例10: testAllowedActions
function testAllowedActions() {
$response = Director::test("ControllerTest_SecuredController/methodaction");
$this->assertEquals(200, $response->getStatusCode());
$response = Director::test("ControllerTest_SecuredController/stringaction");
$this->assertEquals(403, $response->getStatusCode());
$response = Director::test("ControllerTest_SecuredController/adminonly");
$this->assertEquals(403, $response->getStatusCode());
}
示例11: makeApiRequest
/**
* Perform an api request with the given options
*
* @param string $path the request path; can consist of resource name, identifier and GET params
* @param array $options
* * string `body` the data
* * int `code` the expected response code
* * string `method` the http method
* * ApiSession `session` the test session
* * string `token` the auth token
* * array `postVars` the post data, eg. multi form or files
* @return array
* @throws \SS_HTTPResponse_Exception
*/
protected function makeApiRequest($path, $options = [])
{
$settings = array_merge(['session' => null, 'token' => null, 'method' => 'GET', 'body' => null, 'postVars' => null, 'code' => 200], $options);
$headers = ['Accept' => 'application/json'];
if ($settings['token']) {
$headers['Authorization'] = "Bearer {$settings['token']}";
}
$response = \Director::test(\Controller::join_links($this->namespace, $path), $settings['postVars'], $settings['session'], $settings['method'], $settings['body'], $headers);
$this->assertEquals($settings['code'], $response->getStatusCode(), "Wrong status code: {$response->getBody()}");
return json_decode($response->getBody(), true);
}
示例12: testLinksent
function testLinksent()
{
$url1 = 'unsubscribe/linksent?SendEmail=normann1@silverstripe.com';
$url2 = 'unsubscribe/linksent?SendError=normann1@silverstripe.com';
$body1 = Director::test($url1)->getBody();
$body2 = Director::test($url2)->getBody();
$message1 = sprintf(_t('Unsubscribe.LINKSENTTO', "The unsubscribe link has been sent to %s"), 'normann1@silverstripe.com');
$message2 = sprintf(_t('Unsubscribe.LINKSENDERR', "Sorry, currently we have internal error, and can't send the unsubscribe link to %s"), 'normann1@silverstripe.com');
$this->AssertContains($message1, $body1);
$this->AssertContains($message2, $body2);
}
示例13: testDeleteComment
function testDeleteComment()
{
$firstPage = $this->objFromFixture('Page', 'first');
$this->autoFollowRedirection = false;
$this->logInAs('commentadmin');
$firstComment = $this->objFromFixture('Comment', 'firstComA');
$firstCommentID = $firstComment->ID;
Director::test($firstPage->RelativeLink(), null, $this->session());
$delete = $this->get('CommentingController/delete/' . $firstComment->ID);
$this->assertFalse(DataObject::get_by_id('Comment', $firstCommentID));
}
示例14: testBasicView
/**
* Test generation of the view
*/
function testBasicView()
{
Subsite::$write_hostmap = false;
$subsite1ID = $this->objFromFixture('Subsite', 'domaintest1')->ID;
// Open the admin area logged in as admin
$response1 = Director::test('admin/subsites/', null, $this->adminLoggedInSession());
// Confirm that this URL gets you the entire page, with the edit form loaded
$response2 = Director::test("admin/subsites/Subsite/{$subsite1ID}/edit", null, $this->adminLoggedInSession());
$this->assertTrue(strpos($response2->getBody(), 'id="Form_EditForm_ID"') !== false, "Testing Form_EditForm_ID exists");
$this->assertTrue(strpos($response2->getBody(), '<head') !== false, "Testing <head> exists");
}
示例15: testAjaxRefreshing
/**
* Get that visiting the field's URL returns the content of the field.
* This capability is used by ajax
*/
function testAjaxRefreshing()
{
$controller = new TableListFieldTest_TestController();
$table = $controller->TestForm()->Fields()->First();
$ajaxResponse = Director::test($table->Link())->getBody();
// Check that the column headings have been rendered
$this->assertRegExp('/<th[^>]*>\\s*Col A\\s*<\\/th>/', $ajaxResponse);
$this->assertRegExp('/<th[^>]*>\\s*Col B\\s*<\\/th>/', $ajaxResponse);
$this->assertRegExp('/<th[^>]*>\\s*Col C\\s*<\\/th>/', $ajaxResponse);
$this->assertRegExp('/<th[^>]*>\\s*Col D\\s*<\\/th>/', $ajaxResponse);
$this->assertRegExp('/<th[^>]*>\\s*Col E\\s*<\\/th>/', $ajaxResponse);
}