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 {
|
2008-08-12 04:59:27 +02:00
|
|
|
static $fixture_file = 'cms/tests/CMSMainTest.yml';
|
|
|
|
|
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() {
|
2009-04-29 04:49:43 +02:00
|
|
|
$this->session()->inst_set('loggedInAs', $this->idFromFixture('Member', 'admin'));
|
|
|
|
|
2009-05-15 02:13:11 +02:00
|
|
|
$response = Director::test("admin/cms/publishall", array('confirm' => 1), $this->session());
|
2008-08-12 04:59:27 +02:00
|
|
|
|
2008-11-01 14:42:19 +01:00
|
|
|
$this->assertContains(
|
|
|
|
sprintf(_t('CMSMain.PUBPAGES',"Done: Published %d pages"), 5),
|
|
|
|
$response->getBody()
|
|
|
|
);
|
2008-08-12 04:59:27 +02:00
|
|
|
|
2009-05-14 23:56:20 +02:00
|
|
|
$response = Director::test("admin/cms/batchactions/publish", array('csvIDs' => '1,2', 'ajax' => 1), $this->session());
|
2009-05-15 02:13:11 +02:00
|
|
|
|
2008-08-12 04:59:27 +02:00
|
|
|
$this->assertContains('setNodeTitle(1, \'Page 1\');', $response->getBody());
|
|
|
|
$this->assertContains('setNodeTitle(2, \'Page 2\');', $response->getBody());
|
|
|
|
|
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())
|
|
|
|
|
|
|
|
/*
|
|
|
|
$response = Director::test("admin/publishitems", array(
|
|
|
|
'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);
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
|
|
|
foreach($classes as $class) {
|
|
|
|
$page = new $class();
|
2009-04-22 06:23:56 +02:00
|
|
|
if($page instanceof TestOnly) continue;
|
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);
|
|
|
|
|
|
|
|
$this->assertTrue($page->getCMSFields(null) instanceof FieldSet);
|
|
|
|
}
|
|
|
|
}
|
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'));
|
|
|
|
|
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');
|
2009-05-01 00:47:28 +02:00
|
|
|
|
2009-10-19 07:26:03 +02:00
|
|
|
$livePage = Versioned::get_one_by_stage("SiteTree", "Live", "\"SiteTree\".\"ID\" = $pageID");
|
|
|
|
$this->assertType('SiteTree', $livePage);
|
|
|
|
$this->assertTrue($livePage->canDelete());
|
|
|
|
|
2009-05-01 00:47:28 +02:00
|
|
|
// Check that the 'delete from live' button exists as a simple way of checking that the correct page is returned.
|
|
|
|
$this->assertRegExp('/<input[^>]+type="submit"[^>]+name="action_deletefromlive"/i', $response->getBody());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
|
|
|
|
// 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
|
|
|
|
$this->assertType('Page', $cmsMain->getRecord($page1ID));
|
|
|
|
$this->assertType('Page', $cmsMain->getRecord($this->idFromFixture('Page','page2')));
|
|
|
|
|
|
|
|
// This functionality isn't actually used any more.
|
|
|
|
$newPage = $cmsMain->getRecord('new-Page-5');
|
|
|
|
$this->assertType('Page', $newPage);
|
|
|
|
$this->assertEquals('5', $newPage->ParentID);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|