ENHANCEMENT: implemented further tests for CMSPageHistoryController::getEditForm()

This commit is contained in:
Will Rossiter 2011-08-30 12:36:02 +12:00 committed by Ingo Schommer
parent 18471e8878
commit 11821f3e43
2 changed files with 45 additions and 19 deletions

View File

@ -75,7 +75,7 @@ class CMSPageHistoryController extends CMSMain {
$form = parent::getEditForm($record, ($record) ? $record->getCMSFields() : null); $form = parent::getEditForm($record, ($record) ? $record->getCMSFields() : null);
$form->setActions(new FieldSet( $form->setActions(new FieldSet(
$revert = new FormAction('doRevert', _t('CMSPageHistoryController.REVERTTOTHISVERSION', 'Revert to this version')) $revert = new FormAction('doRollback', _t('CMSPageHistoryController.REVERTTOTHISVERSION', 'Revert to this version'))
)); ));
$fields = $form->Fields(); $fields = $form->Fields();
@ -120,7 +120,6 @@ class CMSPageHistoryController extends CMSMain {
"Title" "Title"
); );
$form->setFields($fields->makeReadonly()); $form->setFields($fields->makeReadonly());
$form->loadDataFrom(array( $form->loadDataFrom(array(
"ID" => $id, "ID" => $id,
@ -160,7 +159,8 @@ class CMSPageHistoryController extends CMSMain {
if($page) { if($page) {
$versions = $page->allVersions(); $versions = $page->allVersions();
$versionID = (!$versionID) ? $page->Version : $versionID;
if($versions) { if($versions) {
foreach($versions as $k => $version) { foreach($versions as $k => $version) {
$active = false; $active = false;
@ -303,6 +303,7 @@ class CMSPageHistoryController extends CMSMain {
*/ */
function doRollback($data, $form) { function doRollback($data, $form) {
$this->extend('onBeforeRollback', $data['ID']); $this->extend('onBeforeRollback', $data['ID']);
$id = (isset($data['ID'])) ? (int) $data['ID'] : null; $id = (isset($data['ID'])) ? (int) $data['ID'] : null;
$version = (isset($data['Version'])) ? (int) $data['Version'] : null; $version = (isset($data['Version'])) ? (int) $data['Version'] : null;

View File

@ -41,11 +41,48 @@ class CMSPageHistoryControllerTest extends FunctionalTest {
} }
function testGetEditForm() { function testGetEditForm() {
$controller = new CMSPageHistoryController();
// should get the latest version which we cannot rollback to
$form = $controller->getEditForm($this->page->ID);
$this->assertTrue($form->Actions()->dataFieldByName('action_doRollback')->isReadonly());
$this->assertEquals($this->page->ID, $form->dataFieldByName('ID')->Value());
$this->assertEquals($this->versionPublishCheck2, $form->dataFieldByName('Version')->Value());
$this->assertContains(
sprintf("Currently viewing version %s.", $this->versionPublishCheck2),
$form->Fields()->fieldByName('Root.Main.CurrentlyViewingMessage')->getContent()
);
// edit form with a given version
$form = $controller->getEditForm($this->page->ID, null, $this->versionPublishCheck);
$this->assertFalse($form->Actions()->dataFieldByName('action_doRollback')->isReadonly());
$this->assertEquals($this->page->ID, $form->dataFieldByName('ID')->Value());
$this->assertEquals($this->versionPublishCheck, $form->dataFieldByName('Version')->Value());
$this->assertContains(
sprintf("Currently viewing version %s.", $this->versionPublishCheck),
$form->Fields()->fieldByName('Root.Main.CurrentlyViewingMessage')->getContent()
);
// check that compare mode updates the message
$form = $controller->getEditForm($this->page->ID, null, $this->versionPublishCheck, $this->versionPublishCheck2);
$this->assertContains(
sprintf("Comparing versions %s", $this->versionPublishCheck),
$form->Fields()->fieldByName('Root.Main.CurrentlyViewingMessage')->getContent()
);
$this->assertContains(
sprintf("and %s", $this->versionPublishCheck2),
$form->Fields()->fieldByName('Root.Main.CurrentlyViewingMessage')->getContent()
);
} }
/** /**
* @todo should be less tied to cms theme * @todo should be less tied to cms theme.
* @todo check highlighting for comparing pages.
*/ */
function testVersionsForm() { function testVersionsForm() {
$history = $this->get('admin/page/history/show/'. $this->page->ID); $history = $this->get('admin/page/history/show/'. $this->page->ID);
@ -82,21 +119,9 @@ class CMSPageHistoryControllerTest extends FunctionalTest {
$this->assertContains($expected[$i]['status'], (string) $tr->attributes()->class); $this->assertContains($expected[$i]['status'], (string) $tr->attributes()->class);
$i++; $i++;
} }
}
function testDoForm() {
}
function testCompareForm() {
}
function testRevertForm() {
}
function testIsCompareMode() {
// test highlighting
$this->assertContains('active', (string) $rows[0]->attributes()->class);
$this->assertThat((string) $rows[1]->attributes()->class, $this->logicalNot($this->stringContains('active')));
} }
} }