From 11821f3e431deb797f7404185cc3870dde7087a5 Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Tue, 30 Aug 2011 12:36:02 +1200 Subject: [PATCH] ENHANCEMENT: implemented further tests for CMSPageHistoryController::getEditForm() --- code/controllers/CMSPageHistoryController.php | 7 ++- .../CMSPageHistoryControllerTest.php | 57 +++++++++++++------ 2 files changed, 45 insertions(+), 19 deletions(-) diff --git a/code/controllers/CMSPageHistoryController.php b/code/controllers/CMSPageHistoryController.php index 98420774..b73c2627 100644 --- a/code/controllers/CMSPageHistoryController.php +++ b/code/controllers/CMSPageHistoryController.php @@ -75,7 +75,7 @@ class CMSPageHistoryController extends CMSMain { $form = parent::getEditForm($record, ($record) ? $record->getCMSFields() : null); $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(); @@ -120,7 +120,6 @@ class CMSPageHistoryController extends CMSMain { "Title" ); - $form->setFields($fields->makeReadonly()); $form->loadDataFrom(array( "ID" => $id, @@ -160,7 +159,8 @@ class CMSPageHistoryController extends CMSMain { if($page) { $versions = $page->allVersions(); - + $versionID = (!$versionID) ? $page->Version : $versionID; + if($versions) { foreach($versions as $k => $version) { $active = false; @@ -303,6 +303,7 @@ class CMSPageHistoryController extends CMSMain { */ function doRollback($data, $form) { $this->extend('onBeforeRollback', $data['ID']); + $id = (isset($data['ID'])) ? (int) $data['ID'] : null; $version = (isset($data['Version'])) ? (int) $data['Version'] : null; diff --git a/tests/controller/CMSPageHistoryControllerTest.php b/tests/controller/CMSPageHistoryControllerTest.php index ef27243e..b3ff6ae6 100644 --- a/tests/controller/CMSPageHistoryControllerTest.php +++ b/tests/controller/CMSPageHistoryControllerTest.php @@ -41,11 +41,48 @@ class CMSPageHistoryControllerTest extends FunctionalTest { } 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() { $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); $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'))); } } \ No newline at end of file