Skip to content
Browse files

MINOR: added unit test for checking whether viewing an unpublished ve…

…rsion directly selects the checkbox option
  • Loading branch information...
1 parent 11821f3 commit ecae94e8c27b924fe3955e4a38056f79c5f1c624 @wilr wilr committed with chillu
View
11 code/controllers/CMSPageHistoryController.php
@@ -160,7 +160,7 @@ function VersionsForm() {
if($page) {
$versions = $page->allVersions();
$versionID = (!$versionID) ? $page->Version : $versionID;
-
+
if($versions) {
foreach($versions as $k => $version) {
$active = false;
@@ -168,15 +168,8 @@ function VersionsForm() {
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);
}
View
4 templates/CMSPageHistoryController_versions.ss
@@ -10,8 +10,8 @@
<tbody>
<% control Versions %>
- <tr id="page-$RecordID-version-$Version" class="$EvenOdd $PublishedClass<% if not WasPublished %><% if not Active %> ui-helper-hidden<% end_if %><% end_if %><% if Active %> active<% end_if %>" data-published="<% if WasPublished %>true<% else %>false<% end_if %>"data-link="$CMSLink">
- <td class="ui-helper-hidden"><input type="checkbox" name="Versions[]" id="cms-_$Version" value="$Version"<% if Active %> checked="checked"<% end_if %> /></td>
+ <tr id="page-$RecordID-version-$Version" class="$EvenOdd $PublishedClass<% if not WasPublished %><% if not Active %> ui-helper-hidden<% end_if %><% end_if %><% if Active %> active<% end_if %>" data-published="<% if WasPublished %>true<% else %>false<% end_if %>">
+ <td class="ui-helper-hidden"><input type="checkbox" name="Versions[]" id="cms-version-{$Version}" value="$Version"<% if Active %> checked="checked"<% end_if %> /></td>
<% control LastEdited %>
<td class="last-edited first-column" title="$Ago - $Nice">$Nice</td>
<% end_control %>
View
38 tests/controller/CMSPageHistoryControllerTest.php
@@ -86,20 +86,25 @@ function testGetEditForm() {
*/
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 @@ function testVersionsForm() {
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 @@ function testVersionsForm() {
$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);
+ }
}

0 comments on commit ecae94e

Please sign in to comment.
Something went wrong with that request. Please try again.