2008-08-12 04:59:27 +02:00
|
|
|
<?php
|
2009-03-22 23:58:18 +01:00
|
|
|
/**
|
|
|
|
* @package cms
|
|
|
|
* @subpackage tests
|
|
|
|
*/
|
2009-04-29 04:49:43 +02:00
|
|
|
class CMSMainTest extends FunctionalTest {
|
2011-03-30 09:04:31 +02:00
|
|
|
static $fixture_file = 'CMSMainTest.yml';
|
2008-08-12 04:59:27 +02:00
|
|
|
|
2009-04-29 04:49:43 +02:00
|
|
|
protected $autoFollowRedirection = false;
|
|
|
|
|
2009-10-21 21:57:47 +02:00
|
|
|
static protected $orig = array();
|
|
|
|
|
|
|
|
static function set_up_once() {
|
|
|
|
self::$orig['CMSBatchActionHandler_batch_actions'] = CMSBatchActionHandler::$batch_actions;
|
|
|
|
CMSBatchActionHandler::$batch_actions = array(
|
|
|
|
'publish' => 'CMSBatchAction_Publish',
|
|
|
|
'delete' => 'CMSBatchAction_Delete',
|
|
|
|
'deletefromlive' => 'CMSBatchAction_DeleteFromLive',
|
|
|
|
);
|
|
|
|
|
|
|
|
parent::set_up_once();
|
|
|
|
}
|
|
|
|
|
|
|
|
static function tear_down_once() {
|
|
|
|
CMSBatchActionHandler::$batch_actions = self::$orig['CMSBatchActionHandler_batch_actions'];
|
|
|
|
|
|
|
|
parent::tear_down_once();
|
|
|
|
}
|
|
|
|
|
2008-08-12 04:59:27 +02:00
|
|
|
/**
|
|
|
|
* @todo Test the results of a publication better
|
|
|
|
*/
|
|
|
|
function testPublish() {
|
2010-10-15 05:31:30 +02:00
|
|
|
$page1 = $this->objFromFixture('Page', "page1");
|
|
|
|
$page2 = $this->objFromFixture('Page', "page2");
|
2009-04-29 04:49:43 +02:00
|
|
|
$this->session()->inst_set('loggedInAs', $this->idFromFixture('Member', 'admin'));
|
|
|
|
|
2010-11-01 02:29:02 +01:00
|
|
|
$response = $this->get("admin/cms/publishall?confirm=1");
|
2008-08-12 04:59:27 +02:00
|
|
|
|
2008-11-01 14:42:19 +01:00
|
|
|
$this->assertContains(
|
2010-12-14 02:29:38 +01:00
|
|
|
sprintf(_t('CMSMain.PUBPAGES',"Done: Published %d pages"), 30),
|
2008-11-01 14:42:19 +01:00
|
|
|
$response->getBody()
|
|
|
|
);
|
2009-11-21 04:20:50 +01:00
|
|
|
|
2010-04-12 12:04:49 +02:00
|
|
|
// Some modules (e.g., cmsworkflow) will remove this action
|
|
|
|
if(isset(CMSBatchActionHandler::$batch_actions['publish'])) {
|
2010-10-15 05:31:30 +02:00
|
|
|
$response = Director::test("admin/cms/batchactions/publish", array('csvIDs' => implode(',', array($page1->ID, $page2->ID)), 'ajax' => 1), $this->session());
|
2010-04-12 12:04:49 +02:00
|
|
|
|
|
|
|
$responseData = Convert::json2array($response->getBody());
|
2010-11-11 23:26:39 +01:00
|
|
|
$this->assertTrue(property_exists($responseData['modified'], $page1->ID));
|
|
|
|
$this->assertTrue(property_exists($responseData['modified'], $page2->ID));
|
2010-04-12 12:04:49 +02:00
|
|
|
}
|
2010-10-15 04:35:17 +02:00
|
|
|
|
2010-10-15 04:35:52 +02:00
|
|
|
// 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();
|
2010-10-15 04:35:17 +02:00
|
|
|
$this->assertEquals(1, $dsCount, "Published page has no duplicate version records: it has " . $dsCount . " for version " . $latestID);
|
2008-08-12 04:59:27 +02:00
|
|
|
|
2009-04-29 04:49:43 +02:00
|
|
|
$this->session()->clear('loggedInAs');
|
2008-08-12 04:59:27 +02:00
|
|
|
|
|
|
|
//$this->assertRegexp('/Done: Published 4 pages/', $response->getBody())
|
|
|
|
|
|
|
|
/*
|
2012-01-24 14:02:02 +01:00
|
|
|
$response = Director::test("admin/page/publishitems", array(
|
2008-08-12 04:59:27 +02:00
|
|
|
'ID' => ''
|
|
|
|
'Title' => ''
|
|
|
|
'action_publish' => 'Save and publish',
|
|
|
|
), $session);
|
|
|
|
$this->assertRegexp('/Done: Published 4 pages/', $response->getBody())
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2008-10-08 05:38:32 +02:00
|
|
|
/**
|
|
|
|
* Test publication of one of every page type
|
|
|
|
*/
|
|
|
|
function testPublishOneOfEachKindOfPage() {
|
|
|
|
return;
|
|
|
|
$classes = ClassInfo::subclassesFor("SiteTree");
|
|
|
|
array_shift($classes);
|
2010-04-14 05:07:25 +02:00
|
|
|
|
2008-10-08 05:38:32 +02:00
|
|
|
foreach($classes as $class) {
|
|
|
|
$page = new $class();
|
|
|
|
if($class instanceof TestOnly) continue;
|
|
|
|
|
|
|
|
$page->Title = "Test $class page";
|
|
|
|
|
|
|
|
$page->write();
|
2008-11-23 23:58:18 +01:00
|
|
|
$this->assertEquals("Test $class page", DB::query("SELECT \"Title\" FROM \"SiteTree\" WHERE \"ID\" = $page->ID")->value());
|
2008-10-08 05:38:32 +02:00
|
|
|
|
|
|
|
$page->doPublish();
|
2008-11-23 23:58:18 +01:00
|
|
|
$this->assertEquals("Test $class page", DB::query("SELECT \"Title\" FROM \"SiteTree_Live\" WHERE \"ID\" = $page->ID")->value());
|
2008-10-08 05:38:32 +02:00
|
|
|
|
|
|
|
// Check that you can visit the page
|
2009-04-29 04:49:43 +02:00
|
|
|
$this->get($page->URLSegment);
|
2008-10-08 05:38:32 +02:00
|
|
|
}
|
|
|
|
}
|
2010-04-14 05:07:25 +02:00
|
|
|
|
2008-10-08 05:38:32 +02:00
|
|
|
/**
|
|
|
|
* Test that getCMSFields works on each page type.
|
|
|
|
* Mostly, this is just checking that the method doesn't return an error
|
|
|
|
*/
|
|
|
|
function testThatGetCMSFieldsWorksOnEveryPageType() {
|
|
|
|
$classes = ClassInfo::subclassesFor("SiteTree");
|
|
|
|
array_shift($classes);
|
2010-04-14 05:07:25 +02:00
|
|
|
|
2008-10-08 05:38:32 +02:00
|
|
|
foreach($classes as $class) {
|
|
|
|
$page = new $class();
|
2009-04-22 06:23:56 +02:00
|
|
|
if($page instanceof TestOnly) continue;
|
2012-01-30 17:31:22 +01:00
|
|
|
if(!$page->stat('can_be_root')) continue;
|
2010-04-14 05:07:25 +02:00
|
|
|
|
2008-10-08 05:38:32 +02:00
|
|
|
$page->Title = "Test $class page";
|
|
|
|
$page->write();
|
|
|
|
$page->flushCache();
|
|
|
|
$page = DataObject::get_by_id("SiteTree", $page->ID);
|
|
|
|
|
2011-10-26 07:35:51 +02:00
|
|
|
$this->assertTrue($page->getCMSFields(null) instanceof FieldList);
|
2008-10-08 05:38:32 +02:00
|
|
|
}
|
2010-10-04 07:27:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function testCanPublishPageWithUnpublishedParentWithStrictHierarchyOff() {
|
2010-10-13 04:06:29 +02:00
|
|
|
$this->logInWithPermission('ADMIN');
|
2010-10-04 07:27:20 +02:00
|
|
|
|
2010-10-04 07:29:48 +02:00
|
|
|
SiteTree::set_enforce_strict_hierarchy(true);
|
2010-10-04 07:27:20 +02:00
|
|
|
$parentPage = $this->objFromFixture('Page','page3');
|
|
|
|
$childPage = $this->objFromFixture('Page','page1');
|
|
|
|
|
|
|
|
$parentPage->doUnpublish();
|
|
|
|
$childPage->doUnpublish();
|
|
|
|
|
|
|
|
$this->assertContains(
|
|
|
|
'action_publish',
|
|
|
|
$childPage->getCMSActions()->column('Name'),
|
|
|
|
'Can publish a page with an unpublished parent with strict hierarchy off'
|
|
|
|
);
|
2010-10-04 07:29:48 +02:00
|
|
|
SiteTree::set_enforce_strict_hierarchy(false);
|
2008-10-08 05:38:32 +02:00
|
|
|
}
|
2010-04-14 05:07:25 +02:00
|
|
|
|
2009-05-01 00:47:28 +02:00
|
|
|
/**
|
|
|
|
* Test that a draft-deleted page can still be opened in the CMS
|
|
|
|
*/
|
|
|
|
function testDraftDeletedPageCanBeOpenedInCMS() {
|
2009-10-19 07:26:03 +02:00
|
|
|
$this->session()->inst_set('loggedInAs', $this->idFromFixture('Member', 'admin'));
|
2010-04-14 05:07:25 +02:00
|
|
|
|
2009-05-01 00:47:28 +02:00
|
|
|
// Set up a page that is delete from live
|
|
|
|
$page = $this->objFromFixture('Page','page1');
|
|
|
|
$pageID = $page->ID;
|
|
|
|
$page->doPublish();
|
|
|
|
$page->delete();
|
|
|
|
|
2009-09-01 08:35:29 +02:00
|
|
|
$response = $this->get('admin/cms/getitem?ID=' . $pageID . '&ajax=1');
|
2010-04-14 05:07:25 +02:00
|
|
|
|
2009-10-19 07:26:03 +02:00
|
|
|
$livePage = Versioned::get_one_by_stage("SiteTree", "Live", "\"SiteTree\".\"ID\" = $pageID");
|
2011-03-11 04:10:38 +01:00
|
|
|
$this->assertType('SiteTree', $livePage);
|
2009-10-19 07:26:03 +02:00
|
|
|
$this->assertTrue($livePage->canDelete());
|
2010-04-14 05:07:25 +02:00
|
|
|
|
2010-04-12 12:04:49 +02:00
|
|
|
// Check that the 'restore' button exists as a simple way of checking that the correct page is returned.
|
2012-02-16 22:59:47 +01:00
|
|
|
$this->assertRegExp('/<button[^>]+name="action_(restore|revert)"/i', $response->getBody());
|
2009-05-01 00:47:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test CMSMain::getRecord()
|
|
|
|
*/
|
|
|
|
function testGetRecord() {
|
|
|
|
// Set up a page that is delete from live
|
|
|
|
$page1 = $this->objFromFixture('Page','page1');
|
|
|
|
$page1ID = $page1->ID;
|
|
|
|
$page1->doPublish();
|
|
|
|
$page1->delete();
|
|
|
|
|
|
|
|
$cmsMain = new CMSMain();
|
2010-04-14 05:07:25 +02:00
|
|
|
|
2009-05-01 00:47:28 +02:00
|
|
|
// Bad calls
|
|
|
|
$this->assertNull($cmsMain->getRecord('0'));
|
|
|
|
$this->assertNull($cmsMain->getRecord('asdf'));
|
|
|
|
|
|
|
|
// Pages that are on draft and aren't on draft should both work
|
2011-03-11 04:10:38 +01:00
|
|
|
$this->assertType('Page', $cmsMain->getRecord($page1ID));
|
|
|
|
$this->assertType('Page', $cmsMain->getRecord($this->idFromFixture('Page','page2')));
|
2010-04-14 05:07:25 +02:00
|
|
|
|
2009-05-01 00:47:28 +02:00
|
|
|
// This functionality isn't actually used any more.
|
|
|
|
$newPage = $cmsMain->getRecord('new-Page-5');
|
2011-03-11 04:10:38 +01:00
|
|
|
$this->assertType('Page', $newPage);
|
2009-05-01 00:47:28 +02:00
|
|
|
$this->assertEquals('5', $newPage->ParentID);
|
2010-04-14 05:07:25 +02:00
|
|
|
|
2009-05-01 00:47:28 +02:00
|
|
|
}
|
2010-04-12 12:08:00 +02:00
|
|
|
|
|
|
|
function testDeletedPagesSiteTreeFilter() {
|
|
|
|
$id = $this->idFromFixture('Page', 'page3');
|
2010-04-28 09:16:31 +02:00
|
|
|
$this->logInWithPermission('ADMIN');
|
2012-01-24 14:02:02 +01:00
|
|
|
$result = $this->get('admin/pages/getsubtree?filter=CMSSiteTreeFilter_DeletedPages&ajax=1&ID=' . $id);
|
2010-04-12 12:08:00 +02:00
|
|
|
$this->assertEquals(200, $result->getStatusCode());
|
|
|
|
}
|
2010-04-14 03:36:42 +02:00
|
|
|
|
|
|
|
function testCreationOfTopLevelPage(){
|
|
|
|
$cmsUser = $this->objFromFixture('Member', 'allcmssectionsuser');
|
|
|
|
$rootEditUser = $this->objFromFixture('Member', 'rootedituser');
|
|
|
|
|
|
|
|
// with insufficient permissions
|
|
|
|
$cmsUser->logIn();
|
2012-03-09 23:35:43 +01:00
|
|
|
$this->get('admin/page/add');
|
2011-07-06 11:42:17 +02:00
|
|
|
$response = $this->post(
|
2012-03-09 23:35:43 +01:00
|
|
|
'admin/page/add/AddForm',
|
2011-07-06 11:42:17 +02:00
|
|
|
array('ParentID' => '0', 'ClassName' => 'Page', 'Locale' => 'en_US', 'action_doAdd' => 1)
|
2010-04-14 05:07:25 +02:00
|
|
|
);
|
2010-04-14 03:36:42 +02:00
|
|
|
// should redirect, which is a permission error
|
|
|
|
$this->assertEquals(403, $response->getStatusCode(), 'Add TopLevel page must fail for normal user');
|
|
|
|
|
|
|
|
// with correct permissions
|
|
|
|
$rootEditUser->logIn();
|
2012-03-09 23:35:43 +01:00
|
|
|
$response = $this->get('admin/page/add');
|
2011-07-06 11:42:17 +02:00
|
|
|
|
|
|
|
$response = $this->post(
|
2012-03-09 23:35:43 +01:00
|
|
|
'admin/page/add/AddForm',
|
2011-07-06 11:42:17 +02:00
|
|
|
array('ParentID' => '0', 'ClassName' => 'Page', 'Locale' => 'en_US', 'action_doAdd' => 1)
|
2010-04-14 05:07:25 +02:00
|
|
|
);
|
2011-07-06 11:42:17 +02:00
|
|
|
|
2010-04-14 03:36:42 +02:00
|
|
|
$this->assertEquals(302, $response->getStatusCode(), 'Must be a redirect on success');
|
|
|
|
$location=$response->getHeader('Location');
|
|
|
|
$this->assertContains('/show/',$location, 'Must redirect to /show/ the new page');
|
|
|
|
// TODO Logout
|
|
|
|
$this->session()->inst_set('loggedInAs', NULL);
|
|
|
|
}
|
2012-02-14 16:01:07 +01:00
|
|
|
|
|
|
|
function testBreadcrumbs() {
|
|
|
|
$page3 = $this->objFromFixture('Page', 'page3');
|
|
|
|
$page31 = $this->objFromFixture('Page', 'page31');
|
|
|
|
$adminuser = $this->objFromFixture('Member', 'admin');
|
|
|
|
$this->session()->inst_set('loggedInAs', $adminuser->ID);
|
|
|
|
|
|
|
|
$response = $this->get('admin/page/edit/show/' . $page31->ID);
|
|
|
|
$parser = new CSSContentParser($response->getBody());
|
|
|
|
$crumbs = $parser->getBySelector('#page-title-heading .crumb');
|
|
|
|
|
|
|
|
$this->assertNotNull($crumbs);
|
|
|
|
$this->assertEquals(3, count($crumbs));
|
|
|
|
$this->assertEquals('Pages', (string)$crumbs[0]);
|
|
|
|
$this->assertEquals('Page 3', (string)$crumbs[1]);
|
|
|
|
$this->assertEquals('Page 3.1', (string)$crumbs[2]);
|
|
|
|
|
|
|
|
$this->session()->inst_set('loggedInAs', null);
|
|
|
|
}
|
2010-12-14 02:29:38 +01:00
|
|
|
}
|