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

@ -168,15 +168,8 @@ class CMSPageHistoryController extends CMSMain {
if($version->Version == $versionID || $version->Version == $otherVersionID) { if($version->Version == $versionID || $version->Version == $otherVersionID) {
$active = true; $active = true;
if(!$version->WasPublished) { if(!$version->WasPublished) $showUnpublishedChecked = 1;
$showUnpublishedChecked = 1;
} }
}
$version->CMSLink = sprintf('%s/%s/%s',
$this->Link('show'),
$version->ID,
$version->Version
);
$version->Active = ($active); $version->Active = ($active);
} }

View File

@ -10,8 +10,8 @@
<tbody> <tbody>
<% control Versions %> <% 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"> <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" value="$Version"<% if Active %> checked="checked"<% end_if %> /></td> <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 %> <% control LastEdited %>
<td class="last-edited first-column" title="$Ago - $Nice">$Nice</td> <td class="last-edited first-column" title="$Ago - $Nice">$Nice</td>
<% end_control %> <% end_control %>

View File

@ -86,20 +86,25 @@ class CMSPageHistoryControllerTest extends FunctionalTest {
*/ */
function testVersionsForm() { function testVersionsForm() {
$history = $this->get('admin/page/history/show/'. $this->page->ID); $history = $this->get('admin/page/history/show/'. $this->page->ID);
$form = $this->cssParser()->getBySelector("#Form_VersionsForm"); $form = $this->cssParser()->getBySelector("#Form_VersionsForm");
$this->assertEquals(1, count($form)); $this->assertEquals(1, count($form));
// check the page ID is present // check the page ID is present
$hidden = $form[0]->xpath("fieldset/input[@type='hidden']"); $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); $this->assertEquals(4, (int) $hidden[0]->attributes()->value);
// ensure that all the versions are present in the table and displayed // ensure that all the versions are present in the table and displayed
$rows = $form[0]->xpath("fieldset/table/tbody/tr"); $rows = $form[0]->xpath("fieldset/table/tbody/tr");
$this->assertFalse($hidden == null, "Versions exist in table");
$this->assertEquals(4, count($rows)); $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( $expected = array(
array('version' => $this->versionPublishCheck2, 'status' => 'published'), array('version' => $this->versionPublishCheck2, 'status' => 'published'),
@ -108,14 +113,10 @@ class CMSPageHistoryControllerTest extends FunctionalTest {
array('version' => $this->versionUnpublishedCheck, 'status' => 'internal') 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; $i = 0;
foreach($rows as $tr) { foreach($rows as $tr) {
$this->assertEquals( // data-link must be present for the javascript to load new
sprintf('admin/page/history/show/%d/%d', $this->page->ID, $expected[$i]['version']),
(string) $tr->attributes()->{'data-link'}
);
$this->assertContains($expected[$i]['status'], (string) $tr->attributes()->class); $this->assertContains($expected[$i]['status'], (string) $tr->attributes()->class);
$i++; $i++;
} }
@ -124,4 +125,21 @@ class CMSPageHistoryControllerTest extends FunctionalTest {
$this->assertContains('active', (string) $rows[0]->attributes()->class); $this->assertContains('active', (string) $rows[0]->attributes()->class);
$this->assertThat((string) $rows[1]->attributes()->class, $this->logicalNot($this->stringContains('active'))); $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);
}
} }