本文整理汇总了PHP中SiteTree::write方法的典型用法代码示例。如果您正苦于以下问题:PHP SiteTree::write方法的具体用法?PHP SiteTree::write怎么用?PHP SiteTree::write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SiteTree
的用法示例。
在下文中一共展示了SiteTree::write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: write
function write()
{
if ($this->getField("LinkedPageID")) {
$this->LinkedPage()->write();
}
parent::write();
}
示例3: 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);
}
示例4: testDataIntegrity
public function testDataIntegrity()
{
$siteTree = new SiteTree();
$siteTree->MetaTitle = 'Custom meta title';
$siteTree->write();
$siteTreeTest = SiteTree::get()->byID($siteTree->ID);
$this->assertEquals('Custom meta title', $siteTreeTest->MetaTitle);
$obj = new MetaTitleExtensionTest_DataObject();
$obj->MetaTitle = 'Custom DO meta title';
$obj->write();
$objTest = MetaTitleExtensionTest_DataObject::get()->byID($obj->ID);
$this->assertEquals('Custom DO meta title', $objTest->MetaTitle);
}
示例5: 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);
}
示例6: testFindInRate
function testFindInRate()
{
$d1 = $this->objFromFixture('DMSDocument', 'd1');
$d2 = $this->objFromFixture('DMSDocument', 'd2');
$page1 = new SiteTree();
$page1->Content = 'Condition: <a title="document test 1" href="[dms_document_link,id=' . $d1->ID . ']">';
$page1ID = $page1->write();
$page2 = new SiteTree();
$page2->Content = 'Condition: <a title="document test 2" href="[dms_document_link,id=' . $d2->ID . ']">';
$page2ID = $page2->write();
$page3 = new SiteTree();
$page3->Content = 'Condition: <a title="document test 1" href="[dms_document_link,id=' . $d1->ID . ']">';
$page3ID = $page3->write();
$finder = new ShortCodeRelationFinder();
$ids = $finder->findPageIDs('UnknownShortcode');
$this->assertEquals(0, count($ids));
$ids = $finder->findPageIDs($d1->ID);
$this->assertNotContains($page2ID, $ids);
$this->assertContains($page1ID, $ids);
$this->assertContains($page3ID, $ids);
}
示例7: SiteTree
/**
* Similar to {@link SubsitesVirtualPageTest->testSubsiteVirtualPageCanHaveSameUrlsegmentAsOtherSubsite()}.
*/
function testTwoPagesWithSameURLOnDifferentSubsites()
{
// Set up a couple of pages with the same URL on different subsites
$s1 = $this->objFromFixture('Subsite', 'domaintest1');
$s2 = $this->objFromFixture('Subsite', 'domaintest2');
$p1 = new SiteTree();
$p1->Title = $p1->URLSegment = "test-page";
$p1->SubsiteID = $s1->ID;
$p1->write();
$p2 = new SiteTree();
$p2->Title = $p1->URLSegment = "test-page";
$p2->SubsiteID = $s2->ID;
$p2->write();
// Check that the URLs weren't modified in our set-up
$this->assertEquals($p1->URLSegment, 'test-page');
$this->assertEquals($p2->URLSegment, 'test-page');
// Check that if we switch between the different subsites, we receive the correct pages
Subsite::changeSubsite($s1);
$this->assertEquals($p1->ID, SiteTree::get_by_link('test-page')->ID);
Subsite::changeSubsite($s2);
$this->assertEquals($p2->ID, SiteTree::get_by_link('test-page')->ID);
}
示例8: 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');
}
示例9: 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');
}
示例10: testMenuTitleIsUnsetWhenEqualsTitle
public function testMenuTitleIsUnsetWhenEqualsTitle()
{
$page = new SiteTree();
$page->Title = 'orig';
$page->MenuTitle = 'orig';
$page->write();
// change menu title
$page->MenuTitle = 'changed';
$page->write();
$page = SiteTree::get()->byID($page->ID);
$this->assertEquals('changed', $page->getField('MenuTitle'));
// change menu title back
$page->MenuTitle = 'orig';
$page->write();
$page = SiteTree::get()->byID($page->ID);
$this->assertEquals(null, $page->getField('MenuTitle'));
}
示例11: rebaseOrphans
protected function rebaseOrphans($orphanIDs)
{
$holder = new SiteTree();
$holder->ShowInMenus = 0;
$holder->ShowInSearch = 0;
$holder->ParentID = 0;
$holder->Title = $this->rebaseHolderTitle();
$holder->write();
$removedOrphans = array();
foreach ($orphanIDs as $id) {
$stageRecord = Versioned::get_one_by_stage($this->orphanedSearchClass, 'Stage', sprintf("\"%s\".\"ID\" = %d", ClassInfo::baseDataClass($this->orphanedSearchClass), $id));
if ($stageRecord) {
$removedOrphans[$stageRecord->ID] = sprintf('Rebased %s (#%d)', $stageRecord->Title, $stageRecord->ID);
$stageRecord->ParentID = $holder->ID;
$stageRecord->ShowInMenus = 0;
$stageRecord->ShowInSearch = 0;
$stageRecord->write();
$stageRecord->doUnpublish();
$stageRecord->destroy();
//unset($stageRecord);
}
$liveRecord = Versioned::get_one_by_stage($this->orphanedSearchClass, 'Live', sprintf("\"%s\".\"ID\" = %d", ClassInfo::baseDataClass($this->orphanedSearchClass), $id));
if ($liveRecord) {
$removedOrphans[$liveRecord->ID] = sprintf('Rebased %s (#%d)', $liveRecord->Title, $liveRecord->ID);
$liveRecord->ParentID = $holder->ID;
$liveRecord->ShowInMenus = 0;
$liveRecord->ShowInSearch = 0;
$liveRecord->write();
if (!$stageRecord) {
$liveRecord->doRestoreToStage();
}
$liveRecord->doUnpublish();
$liveRecord->destroy();
unset($liveRecord);
}
if ($stageRecord) {
unset($stageRecord);
}
}
return $removedOrphans;
}
示例12: 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);
// }
}
示例13: 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');
}
示例14: testStageStates
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);
}
示例15: publish
/**
* Simplifies publishing of an actual page instance (since migrations are run from command line).
*
* @param SiteTree $page
* @param bool $force If set to false, will not publish if the page has a draft version to prevent
* accidentally publishing a draft page.
*
* TODO: Possibly change default for $force to false, but will need to start versioning this module to help prevent issues with backward compatibility.
*
* @throws MigrationException
*/
public static function publish(SiteTree $page, $force = true)
{
try {
static::whileAdmin(function () use($page, $force) {
if ($page->isPublished() || $force) {
$page->doPublish();
} else {
$page->write();
}
});
} catch (Exception $e) {
throw new MigrationException("Cannot publish page: " . $e->getMessage(), 0, $e);
}
}