diff --git a/code/controllers/CMSPageHistoryController.php b/code/controllers/CMSPageHistoryController.php index b73c2627..1d83e705 100644 --- a/code/controllers/CMSPageHistoryController.php +++ b/code/controllers/CMSPageHistoryController.php @@ -160,7 +160,7 @@ class CMSPageHistoryController extends CMSMain { if($page) { $versions = $page->allVersions(); $versionID = (!$versionID) ? $page->Version : $versionID; - + if($versions) { foreach($versions as $k => $version) { $active = false; @@ -168,15 +168,8 @@ class CMSPageHistoryController extends CMSMain { if($version->Version == $versionID || $version->Version == $otherVersionID) { $active = true; - if(!$version->WasPublished) { - $showUnpublishedChecked = 1; - } + if(!$version->WasPublished) $showUnpublishedChecked = 1; } - $version->CMSLink = sprintf('%s/%s/%s', - $this->Link('show'), - $version->ID, - $version->Version - ); $version->Active = ($active); } diff --git a/templates/CMSPageHistoryController_versions.ss b/templates/CMSPageHistoryController_versions.ss index 98c281bf..c6d9117c 100755 --- a/templates/CMSPageHistoryController_versions.ss +++ b/templates/CMSPageHistoryController_versions.ss @@ -10,8 +10,8 @@ <% control Versions %> - - checked="checked"<% end_if %> /> + + checked="checked"<% end_if %> /> <% control LastEdited %> $Nice <% end_control %> diff --git a/tests/controller/CMSPageHistoryControllerTest.php b/tests/controller/CMSPageHistoryControllerTest.php index b3ff6ae6..09d3fca5 100644 --- a/tests/controller/CMSPageHistoryControllerTest.php +++ b/tests/controller/CMSPageHistoryControllerTest.php @@ -86,20 +86,25 @@ class CMSPageHistoryControllerTest extends FunctionalTest { */ function testVersionsForm() { $history = $this->get('admin/page/history/show/'. $this->page->ID); - $form = $this->cssParser()->getBySelector("#Form_VersionsForm"); + $this->assertEquals(1, count($form)); // check the page ID is present $hidden = $form[0]->xpath("fieldset/input[@type='hidden']"); - $this->assertFalse($hidden == null, 'Hidden ID field exists'); + + $this->assertThat($hidden, $this->logicalNot($this->isNull()), 'Hidden ID field exists'); $this->assertEquals(4, (int) $hidden[0]->attributes()->value); // ensure that all the versions are present in the table and displayed $rows = $form[0]->xpath("fieldset/table/tbody/tr"); - - $this->assertFalse($hidden == null, "Versions exist in table"); $this->assertEquals(4, count($rows)); + } + + function testVersionsFormTableContainsInformation() { + $history = $this->get('admin/page/history/show/'. $this->page->ID); + $form = $this->cssParser()->getBySelector("#Form_VersionsForm"); + $rows = $form[0]->xpath("fieldset/table/tbody/tr"); $expected = array( array('version' => $this->versionPublishCheck2, 'status' => 'published'), @@ -108,14 +113,10 @@ class CMSPageHistoryControllerTest extends FunctionalTest { array('version' => $this->versionUnpublishedCheck, 'status' => 'internal') ); - // goes the reverse order that we created in setUp(); + // goes the reverse order that we created in setUp() $i = 0; foreach($rows as $tr) { - $this->assertEquals( - sprintf('admin/page/history/show/%d/%d', $this->page->ID, $expected[$i]['version']), - (string) $tr->attributes()->{'data-link'} - ); - + // data-link must be present for the javascript to load new $this->assertContains($expected[$i]['status'], (string) $tr->attributes()->class); $i++; } @@ -124,4 +125,21 @@ class CMSPageHistoryControllerTest extends FunctionalTest { $this->assertContains('active', (string) $rows[0]->attributes()->class); $this->assertThat((string) $rows[1]->attributes()->class, $this->logicalNot($this->stringContains('active'))); } + + function testVersionsFormSelectsUnpublishedCheckbox() { + $history = $this->get('admin/page/history/show/'. $this->page->ID); + $checkbox = $this->cssParser()->getBySelector("#Form_VersionsForm #ShowUnpublished input"); + + $this->assertThat($checkbox[0], $this->logicalNot($this->isNull())); + $checked = $checkbox[0]->attributes()->checked; + + $this->assertThat($checked, $this->logicalNot($this->stringContains('checked'))); + + // viewing an unpublished + $history = $this->get('admin/page/history/show/'.$this->page->ID .'/'.$this->versionUnpublishedCheck); + $checkbox = $this->cssParser()->getBySelector("#Form_VersionsForm #ShowUnpublished input"); + + $this->assertThat($checkbox[0], $this->logicalNot($this->isNull())); + $this->assertEquals('checked', (string) $checkbox[0]->attributes()->checked); + } } \ No newline at end of file