MINOR: added unit test for checking whether viewing an unpublished version directly selects the checkbox option

This commit is contained in:
Will Rossiter 2011-08-30 14:33:03 +12:00 committed by Ingo Schommer
parent 11821f3e43
commit ecae94e8c2
3 changed files with 32 additions and 21 deletions

View File

@ -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);
}

View File

@ -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 File

@ -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);
}
}