public function testCanViewStage() { // Create a new page $page = new Page(); $page->URLSegment = 'testpage'; $page->write(); $page->publish('Stage', 'Live'); // Add a stage-only version $page->Content = "Version2"; $page->write(); $response = $this->get('/testpage'); $this->assertEquals($response->getStatusCode(), 200, "Doesn't require login for implicit live stage"); $response = $this->get('/testpage/?stage=Live'); $this->assertEquals($response->getStatusCode(), 200, "Doesn't require login for explicit live stage"); try { $response = $this->get('/testpage/?stage=Stage'); } catch (SS_HTTPResponse_Exception $responseException) { $response = $responseException->getResponse(); } // should redirect to login $this->assertEquals($response->getStatusCode(), 302, 'Redirects to login page when not logged in for draft stage'); $this->assertContains(Config::inst()->get('Security', 'login_url'), $response->getHeader('Location')); $this->logInWithPermission('CMS_ACCESS_CMSMain'); $response = $this->get('/testpage/?stage=Stage'); $this->assertEquals($response->getStatusCode(), 200, 'Doesnt redirect to login, but shows page for authenticated user'); }
/** * Build page from database * @param array $data */ public static function build(array $data) { if (!isset($data['title'], $data['body'])) { return; } $content = new Page($data['title'], $data['body']); if (isset($data['stylesheets'])) { foreach ($data['stylesheets'] as $source) { $content->addStylesheet($source); } } if (isset($data['javascripts'])) { foreach ($data['javascripts'] as $source) { $content->addJavascript($source); } } $content->render('system.header'); if (isset($data['header'])) { $content->setHeader($data['header']); } $content->render('system.footer'); if (isset($data['footer'])) { $content->setFooter($data['footer']); } return $content->publish(); }
public function testFindOldPage() { $page = new Page(); $page->Title = 'Test Page'; $page->URLSegment = 'test-page'; $page->write(); $page->publish('Stage', 'Live'); $page->URLSegment = 'test'; $page->write(); $page->publish('Stage', 'Live'); $router = new ModelAsController(); $request = new HTTPRequest('GET', 'test-page/action/id/otherid'); $request->match('$URLSegment/$Action/$ID/$OtherID'); $response = $router->handleRequest($request); $this->assertEquals($response->getHeader('Location'), Controller::join_links(Director::baseURL() . 'test/action/id/otherid')); }
public function testDiffedChangesTitle() { $page = new Page(array('Title' => 'My Title')); $page->write(); $page->publish('Stage', 'Live'); $page->Title = 'My Changed Title'; $page->write(); $page->publish('Stage', 'Live'); $page->Title = 'My Unpublished Changed Title'; $page->write(); // Strip spaces from test output because they're not reliably maintained by the HTML Tidier $cleanDiffOutput = function ($val) { return str_replace(' ', '', strip_tags($val)); }; $this->assertContains(str_replace(' ', '', _t('RSSHistory.TITLECHANGED', 'Title has changed:') . 'My Changed Title'), array_map($cleanDiffOutput, $page->getDiffList()->column('DiffTitle')), 'Detects published title changes'); $this->assertNotContains(str_replace(' ', '', _t('RSSHistory.TITLECHANGED', 'Title has changed:') . 'My Unpublished Changed Title'), array_map($cleanDiffOutput, $page->getDiffList()->column('DiffTitle')), 'Ignores unpublished title changes'); }
public function setUp() { parent::setUp(); for ($i = 0; $i < 100; $i++) { $page = new Page(array('title' => "Page {$i}")); $page->write(); $page->publish('Stage', 'Live'); } $sitemap = new SiteMapPage(); $sitemap->Title = 'SiteMap'; $sitemap->write(); }
function testCustomSearchFormClassesToTest() { FulltextSearchable::enable('File'); $page = new Page(); $page->URLSegment = 'whatever'; $page->Content = 'oh really?'; $page->write(); $page->publish('Stage', 'Live'); $controller = new ContentController($page); $form = $controller->SearchForm(); if (get_class($form) == 'SearchForm') $this->assertEquals(array('File'), $form->getClassesToSearch()); }
public function setUp() { parent::setUp(); // create 2 pages for ($i = 0; $i < 2; ++$i) { $page = new Page(array('Title' => "Page {$i}")); $page->write(); $page->publish('Stage', 'Live'); } // reset configuration for the test. Config::nest(); Config::inst()->update('Foo', 'bar', 'Hello!'); }
protected function makePages($count, $depth, $prefix = "", $parentID = 0) { for ($i = 1; $i <= $count; $i++) { $page = new Page(); $page->ParentID = $parentID; $page->Title = "Test page {$prefix}{$i}"; $page->write(); $page->publish('Stage', 'Live'); echo "<li>Created '{$page->Title}'"; if ($depth > 1) { $this->makePages($count, $depth - 1, $prefix . "{$i}.", $page->ID); } } }
public function testCanViewStage() { $page = new Page(); $page->URLSegment = 'testpage'; $page->write(); $page->publish('Stage', 'Live'); $response = $this->get('/testpage'); $this->assertEquals($response->getStatusCode(), 200); $response = $this->get('/testpage/?stage=Live'); $this->assertEquals($response->getStatusCode(), 200); $response = $this->get('/testpage/?stage=Stage'); // should redirect to login $this->assertEquals($response->getStatusCode(), 302); $this->logInWithPermission('CMS_ACCESS_CMSMain'); $response = $this->get('/testpage/?stage=Stage'); $this->assertEquals($response->getStatusCode(), 200); }
public function testCanViewStage() { $page = new Page(); $page->URLSegment = 'testpage'; $page->write(); $page->publish('Stage', 'Live'); $response = $this->get('/testpage'); $this->assertEquals($response->getStatusCode(), 200, 'Doesnt require login for implicit live stage'); $response = $this->get('/testpage/?stage=Live'); $this->assertEquals($response->getStatusCode(), 200, 'Doesnt require login for explicit live stage'); $response = $this->get('/testpage/?stage=Stage'); // should redirect to login $this->assertEquals($response->getStatusCode(), 302, 'Redirects to login page when not logged in for draft stage'); $this->assertContains('Security/login', $response->getHeader('Location')); $this->logInWithPermission('CMS_ACCESS_CMSMain'); $response = $this->get('/testpage/?stage=Stage'); $this->assertEquals($response->getStatusCode(), 200, 'Doesnt redirect to login, but shows page for authenticated user'); }
public function requireDefaultRecords() { parent::requireDefaultRecords(); //clear all old records $bigFmailyPages = DB::query("SELECT \"SiteTree_Live\".\"ID\" FROM \"SiteTree_Live\" WHERE \"SiteTree_Live\".\"ClassName\" = 'BigFamilyPage'")->column(); if (count($bigFmailyPages)) { $ids = "(" . implode(",", $bigFmailyPages) . ")"; //Delete all children from all stages DB::query("DELETE FROM \"SiteTree\" WHERE \"SiteTree\".\"ParentID\" IN {$ids}"); DB::query("DELETE FROM \"SiteTree_versions\" WHERE \"SiteTree_versions\".\"ParentID\" IN {$ids}"); DB::query("DELETE FROM \"SiteTree_Live\" WHERE \"SiteTree_Live\".\"ParentID\" IN {$ids}"); //Delete themselves from all stages DB::query("DELETE FROM \"SiteTree\" WHERE \"SiteTree\".\"ID\" IN {$ids}"); DB::query("DELETE FROM \"SiteTree_versions\" WHERE \"SiteTree_versions\".\"RecordID\" IN {$ids}"); DB::query("DELETE FROM \"SiteTree_Live\" WHERE \"SiteTree_Live\".\"ID\" IN {$ids}"); } //create new records $bigFamilyPages = DataObject::get('BigFamilyPage'); foreach ($bigFamilyPages as $page) { foreach ($page->AllChildren() as $child) { $child->delete(); } $page->delete(); } $familyPage = new BigFamilyPage(); $familyPage->Title = "Big Family"; $familyPage->write(); $familyPage->publish('Stage', 'Live'); foreach (singleton('Employee')->data() as $name) { $page = new Page(); $page->Title = $name; $page->MenuTitle = $name; $page->ParentID = $familyPage->ID; $page->write(); $page->publish('Stage', 'Live'); } DB::alteration_message("Added default 'BigFamilyPage' and its children pages", "created"); }
/** * go to a page that's been published but is child of an unpublished page * * NOTE: This test requires nested_urls */ public function testChildOfDraft() { RootURLController::reset(); Config::inst()->update('SiteTree', 'nested_urls', true); $draft = new Page(); $draft->Title = 'Root Leve Draft Page'; $draft->URLSegment = 'root'; $draft->write(); $published = new Page(); $published->Title = 'Published Page Under Draft Page'; $published->URLSegment = 'sub-root'; $published->write(); $published->publish('Stage', 'Live'); $response = $this->get('root/sub-root'); $this->assertEquals($response->getStatusCode(), 404, 'The page should not be found since its parent has not been published, in this case http://<yousitename>/root/sub-root or http://<yousitename>/sub-root'); }
function testTranslationGroupNotRemovedWhenSiteTreeUnpublished() { $enPage = new Page(); $enPage->Locale = 'en_US'; $enPage->write(); $enPage->publish('Stage', 'Live'); $enTranslationGroup = $enPage->getTranslationGroup(); $frPage = $enPage->createTranslation('fr_FR'); $frPage->write(); $frPage->publish('Stage', 'Live'); $frTranslationGroup = $frPage->getTranslationGroup(); $enPage->doUnpublish(); $this->assertEquals($enPage->getTranslationGroup(), $enTranslationGroup); $frPage->doUnpublish(); $this->assertEquals($frPage->getTranslationGroup(), $frTranslationGroup); }
/** * Add default records to database. * * This function is called whenever the database is built, after the * database tables have all been created. Overload this to add default * records when the database is built, but make sure you call * parent::requireDefaultRecords(). */ function requireDefaultRecords() { parent::requireDefaultRecords(); // default pages if ($this->class == 'SiteTree' && self::$create_default_pages) { if (!SiteTree::get_by_link('home')) { $homepage = new Page(); $homepage->Title = _t('SiteTree.DEFAULTHOMETITLE', 'Home'); $homepage->Content = _t('SiteTree.DEFAULTHOMECONTENT', '<p>Welcome to SilverStripe! This is the default homepage. You can edit this page by opening <a href="admin/">the CMS</a>. You can now access the <a href="http://doc.silverstripe.org">developer documentation</a>, or begin <a href="http://doc.silverstripe.org/doku.php?id=tutorials">the tutorials.</a></p>'); $homepage->URLSegment = 'home'; $homepage->Status = 'Published'; $homepage->Sort = 1; $homepage->write(); $homepage->publish('Stage', 'Live'); $homepage->flushCache(); DB::alteration_message('Home page created', 'created'); } if (DB::query("SELECT COUNT(*) FROM \"SiteTree\"")->value() == 1) { $aboutus = new Page(); $aboutus->Title = _t('SiteTree.DEFAULTABOUTTITLE', 'About Us'); $aboutus->Content = _t('SiteTree.DEFAULTABOUTCONTENT', '<p>You can fill this page out with your own content, or delete it and create your own pages.<br /></p>'); $aboutus->Status = 'Published'; $aboutus->Sort = 2; $aboutus->write(); $aboutus->publish('Stage', 'Live'); $aboutus->flushCache(); DB::alteration_message('About Us page created', 'created'); $contactus = new Page(); $contactus->Title = _t('SiteTree.DEFAULTCONTACTTITLE', 'Contact Us'); $contactus->Content = _t('SiteTree.DEFAULTCONTACTCONTENT', '<p>You can fill this page out with your own content, or delete it and create your own pages.<br /></p>'); $contactus->Status = 'Published'; $contactus->Sort = 3; $contactus->write(); $contactus->publish('Stage', 'Live'); $contactus->flushCache(); DB::alteration_message('Contact Us page created', 'created'); } } // schema migration // @todo Move to migration task once infrastructure is implemented if ($this->class == 'SiteTree') { $conn = DB::getConn(); // only execute command if fields haven't been renamed to _obsolete_<fieldname> already by the task if (array_key_exists('Viewers', $conn->fieldList('SiteTree'))) { $task = new UpgradeSiteTreePermissionSchemaTask(); $task->run(new SS_HTTPRequest('GET', '/')); } } }
/** * This test ensures published Subsites Virtual Pages immediately reflect updates * to their published target pages. Note - this has to happen when the virtual page * is in a different subsite to the page you are editing and republishing, * otherwise the test will pass falsely due to current subsite ID being the same. */ function testPublishedSubsiteVirtualPagesUpdateIfTargetPageUpdates() { // create page $p = new Page(); $p->Content = 'Content'; $p->Title = 'Title'; $p->writeToStage('Stage'); $p->publish('Stage', 'Live'); $this->assertTrue($p->ExistsOnLive); // change to subsite $subsite = $this->objFromFixture('Subsite', 'subsite2'); Subsite::changeSubsite($subsite->ID); Subsite::$disable_subsite_filter = false; // create svp in subsite $svp = new SubsitesVirtualPage(); $svp->CopyContentFromID = $p->ID; $svp->write(); $svp->writeToStage('Stage'); $svp->publish('Stage', 'Live'); $this->assertEquals($svp->SubsiteID, $subsite->ID); $this->assertTrue($svp->ExistsOnLive); // change back to original subsite ("Main site") Subsite::changeSubsite(0); // update original page $p->Title = 'New Title'; // "save & publish" $p->writeToStage('Stage'); $p->publish('Stage', 'Live'); $this->assertNotEquals($p->SubsiteID, $subsite->ID); // reload SVP from database // can't use DO::get by id because caches. $svpdb = $svp->get()->byID($svp->ID); // ensure title changed $this->assertEquals($svpdb->Title, $p->Title); }
function testDetectsDuplicatesByParent() { $page = new Page(); $page->Title = 'MyPage'; $page->URLSegment = 'mypage'; $page->write(); $page->publish('Stage', 'Live'); // Import page with same name but a different hierarchy $data = <<<YML Parent \tMyPage YML; $this->import($data); $pages = Page::get()->filter('Title', 'MyPage')->sort('Created'); $existingPage = $pages->filter('ID', $page->ID)->First(); $this->assertNotNull($existingPage); $this->assertEquals($existingPage->Title, 'MyPage'); $this->assertEquals((int) $existingPage->ParentID, (int) $page->ParentID); $newPage = $pages->exclude('ID', $page->ID)->First(); $this->assertNotNull($newPage); $this->assertEquals($newPage->Title, 'MyPage'); $this->assertNotEquals((int) $newPage->ParentID, (int) $page->ParentID); }
/** * Add default records to database. * * This function is called whenever the database is built, after the * database tables have all been created. Overload this to add default * records when the database is built, but make sure you call * parent::requireDefaultRecords(). */ function requireDefaultRecords() { parent::requireDefaultRecords(); if ($this->class == 'SiteTree') { if (!DataObject::get_one("SiteTree", "URLSegment = 'home'")) { $homepage = new Page(); $homepage->Title = _t('SiteTree.DEFAULTHOMETITLE', 'Home'); $homepage->Content = _t('SiteTree.DEFAULTHOMECONTENT', '<p>Welcome to SilverStripe! This is the default homepage. You can edit this page by opening <a href="admin/">the CMS</a>. You can now access the <a href="http://doc.silverstripe.com">developer documentation</a>, or begin <a href="http://doc.silverstripe.com/doku.php?id=tutorials">the tutorials.</a></p>'); $homepage->URLSegment = "home"; $homepage->Status = "Published"; $homepage->write(); $homepage->publish("Stage", "Live"); $homepage->flushCache(); Database::alteration_message("Home page created", "created"); } if (DB::query("SELECT COUNT(*) FROM SiteTree")->value() == 1) { $aboutus = new Page(); $aboutus->Title = _t('SiteTree.DEFAULTABOUTTITLE', 'About Us'); $aboutus->Content = _t('SiteTree.DEFAULTABOUTCONTENT', '<p>You can fill this page out with your own content, or delete it and create your own pages.<br /></p>'); $aboutus->URLSegment = "about-us"; $aboutus->Status = "Published"; $aboutus->write(); $aboutus->publish("Stage", "Live"); Database::alteration_message("About Us created", "created"); $contactus = new Page(); $contactus->Title = _t('SiteTree.DEFAULTCONTACTTITLE', 'Contact Us'); $contactus->Content = _t('SiteTree.DEFAULTCONTACTCONTENT', '<p>You can fill this page out with your own content, or delete it and create your own pages.<br /></p>'); $contactus->URLSegment = "contact-us"; $contactus->Status = "Published"; $contactus->write(); $contactus->publish("Stage", "Live"); $contactus->flushCache(); } } }
protected function createPageWithChanges($seed = null) { $page = new Page(); $seed = array_merge(array('Title' => 'My Title', 'Content' => 'My Content'), $seed); $page->update($seed); $page->write(); $page->publish('Stage', 'Live'); $page->update(array('Title' => 'Changed: ' . $seed['Title'], 'Content' => 'Changed: ' . $seed['Content'])); $page->write(); $page->publish('Stage', 'Live'); $page->update(array('Title' => 'Changed again: ' . $seed['Title'], 'Content' => 'Changed again: ' . $seed['Content'])); $page->write(); $page->publish('Stage', 'Live'); $page->update(array('Title' => 'Unpublished: ' . $seed['Title'], 'Content' => 'Unpublished: ' . $seed['Content'])); $page->write(); return $page; }
function testCmsActionsLimited() { // For 2.3 and 2.4 compatibility $bt = defined('DB::USE_ANSI_SQL') ? "\"" : "`"; $custompublisherspage = $this->objFromFixture('SiteTree', 'custompublisherpage'); $custompublishersgroup = $this->objFromFixture('Group', 'custompublishergroup'); $custompublisher = $this->objFromFixture('Member', 'custompublisher'); $workflowadmin = $this->objFromFixture('Member', 'workflowadmin'); $custompublisher->Groups()->add($custompublishersgroup); $customauthorsgroup = $this->objFromFixture('Group', 'customauthorsgroup'); $customauthor = $this->objFromFixture('Member', 'customauthor'); $customauthor->Groups()->add($customauthorsgroup); $unpublishedRecord = new Page(); $unpublishedRecord->CanEditType = 'LoggedInUsers'; $unpublishedRecord->write(); $unpublishedRecord->PublisherGroups()->add($custompublishersgroup); $custompublisher->logIn(); $publishedRecord = new Page(); $publishedRecord->CanEditType = 'LoggedInUsers'; $publishedRecord->write(); $publishedRecord->doPublish(); $publishedRecord->PublisherGroups()->add($custompublishersgroup); $deletedFromLiveRecord = new Page(); $deletedFromLiveRecord->CanEditType = 'LoggedInUsers'; $deletedFromLiveRecord->write(); $deletedFromLiveRecord->doPublish(); $deletedFromLiveRecord->deleteFromStage('Live'); $deletedFromLiveRecord->PublisherGroups()->add($custompublishersgroup); $deletedFromStageRecord = new Page(); $deletedFromStageRecord->CanEditType = 'LoggedInUsers'; $deletedFromStageRecord->write(); $deletedFromStageRecord->PublisherGroups()->add($custompublishersgroup); $deletedFromStageRecord->doPublish(); $deletedFromStageRecordID = $deletedFromStageRecord->ID; $deletedFromStageRecord->deleteFromStage('Stage'); $deletedFromStageRecord = Versioned::get_one_by_stage("SiteTree", "Live", "{$bt}SiteTree{$bt}.{$bt}ID{$bt} = {$deletedFromStageRecordID}"); $changedOnStageRecord = new Page(); $changedOnStageRecord->CanEditType = 'LoggedInUsers'; $changedOnStageRecord->write(); $changedOnStageRecord->publish('Stage', 'Live'); $changedOnStageRecord->Content = 'Changed on Stage'; $changedOnStageRecord->write(); $changedOnStageRecord->PublisherGroups()->add($custompublishersgroup); // test "publish" action for author $this->session()->inst_set('loggedInAs', $customauthor->ID); $this->assertNotContains('action_publish', $unpublishedRecord->getCMSActions()->column('Name'), 'Author cant trigger publish button'); $this->assertNotContains('action_publish', $publishedRecord->getCMSActions()->column('Name'), 'Author cant trigger publish button'); $this->assertNotContains('action_publish', $deletedFromLiveRecord->getCMSActions()->column('Name'), 'Author cant trigger publish button'); $this->assertNotContains('action_publish', $changedOnStageRecord->getCMSActions()->column('Name'), 'Author cant trigger publish button'); // test "publish" action for publisher $this->session()->inst_set('loggedInAs', $custompublisher->ID); WorkflowRequest::set_force_publishers_to_use_workflow(false); $this->assertContains('action_publish', $unpublishedRecord->getCMSActions()->column('Name'), 'Publisher cant trigger publish button'); $this->assertContains('action_publish', $publishedRecord->getCMSActions()->column('Name'), 'Publisher cant trigger publish button'); $this->assertContains('action_publish', $changedOnStageRecord->getCMSActions()->column('Name'), 'Publisher cant trigger publish button'); WorkflowRequest::set_force_publishers_to_use_workflow(true); $this->assertFalse(in_array('action_publish', $unpublishedRecord->getCMSActions()->column('Name')), 'Publisher can trigger publish button even when forced to use workflow'); $this->assertFalse(in_array('action_publish', $publishedRecord->getCMSActions()->column('Name')), 'Publisher can trigger publish button even when forced to use workflow'); $this->assertFalse(in_array('action_publish', $changedOnStageRecord->getCMSActions()->column('Name')), 'Publisher can trigger publish button even when forced to use workflow'); // test "request publication" action for author $this->session()->inst_set('loggedInAs', $customauthor->ID); $this->assertContains('action_cms_requestpublication', $unpublishedRecord->getCMSActions()->column('Name'), 'Author can trigger request publication button if page is not published'); $this->assertNotContains('action_cms_requestpublication', $publishedRecord->getCMSActions()->column('Name'), 'Author cant trigger request publication button if page has been published but not altered on stage'); $this->assertContains('action_cms_requestpublication', $changedOnStageRecord->getCMSActions()->column('Name'), 'Author can trigger request publication button if page has been changed on stage'); // test "request removal" action for author $this->session()->inst_set('loggedInAs', $customauthor->ID); $this->assertNotContains('action_cms_requestdeletefromlive', $unpublishedRecord->getCMSActions()->column('Name'), 'Author cant trigger request removal button if page hasnt been altered'); $this->assertNotContains('action_cms_requestdeletefromlive', $publishedRecord->getCMSActions()->column('Name'), 'Author cant trigger request removal button if page has been published but not altered on stage'); $this->assertNotContains('action_cms_requestdeletefromlive', $changedOnStageRecord->getCMSActions()->column('Name'), 'Author cant trigger request removal button if page has been changed on stage but not deleted from stage'); // test "request removal" action for publisher $this->session()->inst_set('loggedInAs', $custompublisher->ID); // reset login $this->session()->inst_set('loggedInAs', null); }
/** * * NOTE: This test requires nested_urls * */ function testFindOldPage() { $page = new Page(); $page->Title = 'First Level'; $page->URLSegment = 'oldurl'; $page->write(); $page->publish('Stage', 'Live'); $page->URLSegment = 'newurl'; $page->write(); $page->publish('Stage', 'Live'); $response = ModelAsController::find_old_page('oldurl'); $this->assertEquals('First Level', $response->Title); $page2 = new Page(); $page2->Title = 'Second Level Page'; $page2->URLSegment = 'oldpage2'; $page2->ParentID = $page->ID; $page2->write(); $page2->publish('Stage', 'Live'); $page2->URLSegment = 'newpage2'; $page2->write(); $page2->publish('Stage', 'Live'); $response = ModelAsController::find_old_page('oldpage2', $page2->ParentID); $this->assertEquals('Second Level Page', $response->Title); $response = ModelAsController::find_old_page('oldpage2', $page2->ID); $this->assertEquals(false, $response); }