本文整理汇总了PHP中SiteTree::publish方法的典型用法代码示例。如果您正苦于以下问题:PHP SiteTree::publish方法的具体用法?PHP SiteTree::publish怎么用?PHP SiteTree::publish使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SiteTree
的用法示例。
在下文中一共展示了SiteTree::publish方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
/**
* Test setting pagination properties and returning the object
*/
public function setUp()
{
parent::setUp();
$page = new SiteTree(['Title' => "Test Page", 'URLSegment' => 'test']);
$page->write();
$page->publish('Stage', 'Live');
}
示例2: testExternalBackUrlRedirectionDisallowed
function testExternalBackUrlRedirectionDisallowed() {
$page = new SiteTree();
$page->URLSegment = 'testpage';
$page->Title = 'Testpage';
$page->write();
$page->publish('Stage','Live');
// Test internal relative redirect
$response = $this->doTestLoginForm('noexpiry@silverstripe.com', '1nitialPassword', 'testpage');
$this->assertEquals(302, $response->getStatusCode());
$this->assertRegExp('/testpage/', $response->getHeader('Location'),
"Internal relative BackURLs work when passed through to login form"
);
// Log the user out
$this->session()->inst_set('loggedInAs', null);
// Test internal absolute redirect
$response = $this->doTestLoginForm('noexpiry@silverstripe.com', '1nitialPassword', Director::absoluteBaseURL() . 'testpage');
// for some reason the redirect happens to a relative URL
$this->assertRegExp('/^' . preg_quote(Director::absoluteBaseURL(), '/') . 'testpage/', $response->getHeader('Location'),
"Internal absolute BackURLs work when passed through to login form"
);
// Log the user out
$this->session()->inst_set('loggedInAs', null);
// Test external redirect
$response = $this->doTestLoginForm('noexpiry@silverstripe.com', '1nitialPassword', 'http://myspoofedhost.com');
$this->assertNotRegExp('/^' . preg_quote('http://myspoofedhost.com', '/') . '/', $response->getHeader('Location'),
"Redirection to external links in login form BackURL gets prevented as a measure against spoofing attacks"
);
// Log the user out
$this->session()->inst_set('loggedInAs', null);
}
示例3: SiteTree
function testPagesInDifferentSubsitesCanShareURLSegment()
{
$subsiteMain = $this->objFromFixture('Subsite', 'main');
$subsite1 = $this->objFromFixture('Subsite', 'subsite1');
$pageMain = new SiteTree();
$pageMain->URLSegment = 'testpage';
$pageMain->write();
$pageMain->publish('Stage', 'Live');
$pageMainOther = new SiteTree();
$pageMainOther->URLSegment = 'testpage';
$pageMainOther->write();
$pageMainOther->publish('Stage', 'Live');
$this->assertNotEquals($pageMain->URLSegment, $pageMainOther->URLSegment, 'Pages in same subsite cant share the same URL');
Subsite::changeSubsite($subsite1->ID);
$pageSubsite1 = new SiteTree();
$pageSubsite1->URLSegment = 'testpage';
$pageSubsite1->write();
$pageSubsite1->publish('Stage', 'Live');
$this->assertEquals($pageMain->URLSegment, $pageSubsite1->URLSegment, 'Pages in different subsites can share the same URL');
}
示例4: testMetaOutput
/**
* Test core Meta tag values
*/
public function testMetaOutput()
{
SEO::init();
$page = new SiteTree(['MetaTitle' => 'test_title', 'MetaDescription' => 'test_description', 'Canonical' => 'test_canonical', 'Robots' => 'test_index,follow', 'OGtype' => 'test_ogtype', 'OGlocale' => 'test_locale', 'TwitterCard' => 'test_summary']);
$page->write();
$page->publish('Stage', 'Live');
SEO::setPage($page);
$tags = SEO::HeadTags();
$this->assertContains('<title>test_title</title>', $tags);
$this->assertContains('<meta property="og:title" content="test_title">', $tags);
$this->assertContains('<meta name="twitter:title" content="test_title">', $tags);
$this->assertContains('<meta name="description" content="test_description">', $tags);
$this->assertContains('<meta property="og:description" content="test_description">', $tags);
$this->assertContains('<meta name="twitter:description" content="test_description">', $tags);
$this->assertContains('<link rel="canonical" href="test_canonical">', $tags);
$this->assertContains('<meta name="robots" content="test_index,follow">', $tags);
$this->assertContains('<meta property="og:type" content="test_ogtype">', $tags);
$this->assertContains('<meta property="og:locale" content="test_locale">', $tags);
$this->assertContains('<meta name="twitter:card" content="test_summary">', $tags);
}
示例5: testPageTypeChangePropagatesToLive
public function testPageTypeChangePropagatesToLive()
{
$page = new SiteTree();
$page->MySharedNonVirtualField = 'original';
$page->write();
$page->publish('Stage', 'Live');
$virtual = new VirtualPageTest_VirtualPageSub();
$virtual->CopyContentFromID = $page->ID;
$virtual->write();
$virtual->publish('Stage', 'Live');
$page->Title = 'original';
// 'Title' is a virtual field
// Publication would causes the virtual field to copy through onBeforeWrite(),
// but we want to test that it gets copied on class name change instead
$page->write();
$nonVirtual = $virtual;
$nonVirtual->ClassName = 'VirtualPageTest_ClassA';
$nonVirtual->MySharedNonVirtualField = 'changed on new type';
$nonVirtual->write();
// not publishing the page type change here
$this->assertEquals('original', $nonVirtual->Title, 'Copies virtual fields from original draft into new instance on type change ');
$nonVirtualLive = Versioned::get_one_by_stage('SiteTree', 'Live', '"SiteTree_Live"."ID" = ' . $nonVirtual->ID);
$this->assertNotNull($nonVirtualLive);
$this->assertEquals('VirtualPageTest_ClassA', $nonVirtualLive->ClassName);
$this->assertEquals('changed on new type', $nonVirtualLive->MySharedNonVirtualField);
$page->MySharedNonVirtualField = 'changed only on original';
$page->write();
$page->publish('Stage', 'Live');
$nonVirtualLive = Versioned::get_one_by_stage('SiteTree', 'Live', '"SiteTree_Live"."ID" = ' . $nonVirtual->ID, false);
$this->assertEquals('changed on new type', $nonVirtualLive->MySharedNonVirtualField, 'No field copying from previous original after page type changed');
}
示例6: testLinkShortcodes
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');
}
示例7: testStageStates
public function testStageStates()
{
// newly created page
$createdPage = new SiteTree();
$createdPage->write();
$this->assertFalse($createdPage->IsDeletedFromStage);
$this->assertTrue($createdPage->IsAddedToStage);
$this->assertTrue($createdPage->IsModifiedOnStage);
// published page
$publishedPage = new SiteTree();
$publishedPage->write();
$publishedPage->publish('Stage', 'Live');
$this->assertFalse($publishedPage->IsDeletedFromStage);
$this->assertFalse($publishedPage->IsAddedToStage);
$this->assertFalse($publishedPage->IsModifiedOnStage);
// published page, deleted from stage
$deletedFromDraftPage = new SiteTree();
$deletedFromDraftPage->write();
$deletedFromDraftPageID = $deletedFromDraftPage->ID;
$deletedFromDraftPage->publish('Stage', 'Live');
$deletedFromDraftPage->deleteFromStage('Stage');
$this->assertTrue($deletedFromDraftPage->IsDeletedFromStage);
$this->assertFalse($deletedFromDraftPage->IsAddedToStage);
$this->assertFalse($deletedFromDraftPage->IsModifiedOnStage);
// published page, deleted from live
$deletedFromLivePage = new SiteTree();
$deletedFromLivePage->write();
$deletedFromLivePage->publish('Stage', 'Live');
$deletedFromLivePage->deleteFromStage('Stage');
$deletedFromLivePage->deleteFromStage('Live');
$this->assertTrue($deletedFromLivePage->IsDeletedFromStage);
$this->assertFalse($deletedFromLivePage->IsAddedToStage);
$this->assertFalse($deletedFromLivePage->IsModifiedOnStage);
// published page, modified
$modifiedOnDraftPage = new SiteTree();
$modifiedOnDraftPage->write();
$modifiedOnDraftPage->publish('Stage', 'Live');
$modifiedOnDraftPage->Content = 'modified';
$modifiedOnDraftPage->write();
$this->assertFalse($modifiedOnDraftPage->IsDeletedFromStage);
$this->assertFalse($modifiedOnDraftPage->IsAddedToStage);
$this->assertTrue($modifiedOnDraftPage->IsModifiedOnStage);
}
示例8: testUnpublishedPage
public function testUnpublishedPage()
{
if (!class_exists('SiteTree')) {
$this->markTestSkipped('Test skipped; CMS module required for testUnpublishedPage');
}
$orphanedPage = new SiteTree();
$orphanedPage->ParentID = 999999;
// missing parent id
$orphanedPage->write();
$orphanedPage->publish("Stage", "Live");
$rootPage = new SiteTree();
$rootPage->ParentID = 0;
$rootPage->write();
$rootPage->publish("Stage", "Live");
$oldMode = Versioned::get_reading_mode();
Versioned::reading_stage('Live');
try {
$this->assertEmpty($orphanedPage->hasPublishedParent());
$this->assertEmpty($orphanedPage->canIncludeInGoogleSitemap());
$this->assertNotEmpty($rootPage->hasPublishedParent());
$this->assertNotEmpty($rootPage->canIncludeInGoogleSitemap());
} catch (Exception $ex) {
Versioned::set_reading_mode($oldMode);
throw $ex;
}
// finally {
Versioned::set_reading_mode($oldMode);
// }
}
示例9: testGetTranslationByStage
function testGetTranslationByStage()
{
$publishedPage = new SiteTree();
$publishedPage->Locale = 'en_US';
$publishedPage->Title = 'Published';
$publishedPage->write();
$publishedPage->publish('Stage', 'Live');
$publishedPage->Title = 'Unpublished';
$publishedPage->write();
$publishedTranslatedPage = $publishedPage->createTranslation('de_DE');
$publishedTranslatedPage->Title = 'Publiziert';
$publishedTranslatedPage->write();
$publishedTranslatedPage->publish('Stage', 'Live');
$publishedTranslatedPage->Title = 'Unpubliziert';
$publishedTranslatedPage->write();
$compareStage = $publishedPage->getTranslation('de_DE', 'Stage');
$this->assertNotNull($compareStage);
$this->assertEquals($compareStage->Title, 'Unpubliziert');
$compareLive = $publishedPage->getTranslation('de_DE', 'Live');
$this->assertNotNull($compareLive);
$this->assertEquals($compareLive->Title, 'Publiziert');
}