2011-08-30 00:26:40 +02:00
|
|
|
<?php
|
|
|
|
|
2016-06-16 06:57:19 +02:00
|
|
|
use SilverStripe\ORM\Versioning\Versioned;
|
2016-07-22 01:32:32 +02:00
|
|
|
use SilverStripe\CMS\Controllers\CMSPageHistoryController;
|
2016-08-23 04:36:06 +02:00
|
|
|
use SilverStripe\Dev\FunctionalTest;
|
|
|
|
|
2016-07-22 01:32:32 +02:00
|
|
|
|
2016-06-16 06:57:19 +02:00
|
|
|
|
2011-08-30 00:26:40 +02:00
|
|
|
/**
|
|
|
|
* @package cms
|
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
class CMSPageHistoryControllerTest extends FunctionalTest {
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2013-03-18 11:47:15 +01:00
|
|
|
protected static $fixture_file = 'CMSPageHistoryControllerTest.yml';
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-08-30 00:26:40 +02:00
|
|
|
private $versionUnpublishedCheck, $versionPublishCheck, $versionUnpublishedCheck2;
|
|
|
|
private $page;
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function setUp() {
|
2011-08-30 00:26:40 +02:00
|
|
|
parent::setUp();
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-08-30 00:26:40 +02:00
|
|
|
$this->loginWithPermission('ADMIN');
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-08-30 00:26:40 +02:00
|
|
|
// creates a series of published, unpublished versions of a page
|
|
|
|
$this->page = new Page();
|
|
|
|
$this->page->URLSegment = "test";
|
|
|
|
$this->page->Content = "new content";
|
2016-01-06 00:42:07 +01:00
|
|
|
$this->page->write();
|
2011-08-30 00:26:40 +02:00
|
|
|
$this->versionUnpublishedCheck = $this->page->Version;
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-08-30 00:26:40 +02:00
|
|
|
$this->page->Content = "some further content";
|
|
|
|
$this->page->write();
|
2016-04-01 05:17:37 +02:00
|
|
|
$this->page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
2011-08-30 00:26:40 +02:00
|
|
|
$this->versionPublishCheck = $this->page->Version;
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-08-30 00:26:40 +02:00
|
|
|
$this->page->Content = "No, more changes please";
|
|
|
|
$this->page->Title = "Changing titles too";
|
|
|
|
$this->page->write();
|
|
|
|
$this->versionUnpublishedCheck2 = $this->page->Version;
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-08-30 00:26:40 +02:00
|
|
|
$this->page->Title = "Final Change";
|
|
|
|
$this->page->write();
|
2016-04-01 05:17:37 +02:00
|
|
|
$this->page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
2011-08-30 00:26:40 +02:00
|
|
|
$this->versionPublishCheck2 = $this->page->Version;
|
|
|
|
}
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testGetEditForm() {
|
2011-08-30 02:36:02 +02:00
|
|
|
$controller = new CMSPageHistoryController();
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-08-30 02:36:02 +02:00
|
|
|
// should get the latest version which we cannot rollback to
|
|
|
|
$form = $controller->getEditForm($this->page->ID);
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-08-30 02:36:02 +02:00
|
|
|
$this->assertTrue($form->Actions()->dataFieldByName('action_doRollback')->isReadonly());
|
|
|
|
|
2011-12-21 17:22:47 +01:00
|
|
|
$this->assertEquals($this->page->ID, $form->Fields()->dataFieldByName('ID')->Value());
|
|
|
|
$this->assertEquals($this->versionPublishCheck2, $form->Fields()->dataFieldByName('Version')->Value());
|
2011-08-30 02:36:02 +02:00
|
|
|
|
|
|
|
$this->assertContains(
|
2013-05-07 06:04:24 +02:00
|
|
|
'Currently viewing the latest version',
|
2011-08-30 02:36:02 +02:00
|
|
|
$form->Fields()->fieldByName('Root.Main.CurrentlyViewingMessage')->getContent()
|
|
|
|
);
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-08-30 02:36:02 +02:00
|
|
|
// edit form with a given version
|
|
|
|
$form = $controller->getEditForm($this->page->ID, null, $this->versionPublishCheck);
|
|
|
|
$this->assertFalse($form->Actions()->dataFieldByName('action_doRollback')->isReadonly());
|
2011-08-30 00:26:40 +02:00
|
|
|
|
2011-12-21 17:22:47 +01:00
|
|
|
$this->assertEquals($this->page->ID, $form->Fields()->dataFieldByName('ID')->Value());
|
|
|
|
$this->assertEquals($this->versionPublishCheck, $form->Fields()->dataFieldByName('Version')->Value());
|
2011-08-30 02:36:02 +02:00
|
|
|
$this->assertContains(
|
|
|
|
sprintf("Currently viewing version %s.", $this->versionPublishCheck),
|
|
|
|
$form->Fields()->fieldByName('Root.Main.CurrentlyViewingMessage')->getContent()
|
|
|
|
);
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-08-30 02:36:02 +02:00
|
|
|
// 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()
|
|
|
|
);
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-08-30 02:36:02 +02:00
|
|
|
$this->assertContains(
|
|
|
|
sprintf("and %s", $this->versionPublishCheck2),
|
|
|
|
$form->Fields()->fieldByName('Root.Main.CurrentlyViewingMessage')->getContent()
|
|
|
|
);
|
2011-08-30 00:26:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-08-30 02:36:02 +02:00
|
|
|
* @todo should be less tied to cms theme.
|
|
|
|
* @todo check highlighting for comparing pages.
|
2011-08-30 00:26:40 +02:00
|
|
|
*/
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testVersionsForm() {
|
2012-04-18 23:33:37 +02:00
|
|
|
$history = $this->get('admin/pages/history/show/'. $this->page->ID);
|
2012-09-27 02:14:14 +02:00
|
|
|
$form = $this->cssParser()->getBySelector('#Form_VersionsForm');
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-08-30 00:26:40 +02:00
|
|
|
$this->assertEquals(1, count($form));
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-08-30 00:26:40 +02:00
|
|
|
// check the page ID is present
|
|
|
|
$hidden = $form[0]->xpath("fieldset/input[@type='hidden']");
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-08-30 04:33:03 +02:00
|
|
|
$this->assertThat($hidden, $this->logicalNot($this->isNull()), 'Hidden ID field exists');
|
2011-10-29 13:19:26 +02:00
|
|
|
$this->assertEquals($this->page->ID, (int) $hidden[0]->attributes()->value);
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-08-30 00:26:40 +02:00
|
|
|
// ensure that all the versions are present in the table and displayed
|
|
|
|
$rows = $form[0]->xpath("fieldset/table/tbody/tr");
|
|
|
|
$this->assertEquals(4, count($rows));
|
2011-08-30 04:33:03 +02:00
|
|
|
}
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testVersionsFormTableContainsInformation() {
|
2012-04-18 23:33:37 +02:00
|
|
|
$history = $this->get('admin/pages/history/show/'. $this->page->ID);
|
2012-09-27 02:14:14 +02:00
|
|
|
$form = $this->cssParser()->getBySelector('#Form_VersionsForm');
|
2011-08-30 04:33:03 +02:00
|
|
|
$rows = $form[0]->xpath("fieldset/table/tbody/tr");
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-08-30 00:26:40 +02:00
|
|
|
$expected = array(
|
|
|
|
array('version' => $this->versionPublishCheck2, 'status' => 'published'),
|
|
|
|
array('version' => $this->versionUnpublishedCheck2, 'status' => 'internal'),
|
|
|
|
array('version' => $this->versionPublishCheck, 'status' => 'published'),
|
|
|
|
array('version' => $this->versionUnpublishedCheck, 'status' => 'internal')
|
|
|
|
);
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-08-30 04:33:03 +02:00
|
|
|
// goes the reverse order that we created in setUp()
|
2011-08-30 00:26:40 +02:00
|
|
|
$i = 0;
|
|
|
|
foreach($rows as $tr) {
|
2011-08-30 04:33:03 +02:00
|
|
|
// data-link must be present for the javascript to load new
|
2011-08-30 00:26:40 +02:00
|
|
|
$this->assertContains($expected[$i]['status'], (string) $tr->attributes()->class);
|
|
|
|
$i++;
|
|
|
|
}
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-08-30 02:36:02 +02:00
|
|
|
// test highlighting
|
|
|
|
$this->assertContains('active', (string) $rows[0]->attributes()->class);
|
|
|
|
$this->assertThat((string) $rows[1]->attributes()->class, $this->logicalNot($this->stringContains('active')));
|
2011-08-30 00:26:40 +02:00
|
|
|
}
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testVersionsFormSelectsUnpublishedCheckbox() {
|
2012-04-18 23:33:37 +02:00
|
|
|
$history = $this->get('admin/pages/history/show/'. $this->page->ID);
|
2012-09-27 02:14:14 +02:00
|
|
|
$checkbox = $this->cssParser()->getBySelector('#Form_VersionsForm_ShowUnpublished');
|
2011-08-30 04:33:03 +02:00
|
|
|
|
|
|
|
$this->assertThat($checkbox[0], $this->logicalNot($this->isNull()));
|
|
|
|
$checked = $checkbox[0]->attributes()->checked;
|
|
|
|
|
|
|
|
$this->assertThat($checked, $this->logicalNot($this->stringContains('checked')));
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-08-30 04:33:03 +02:00
|
|
|
// viewing an unpublished
|
2012-04-18 23:33:37 +02:00
|
|
|
$history = $this->get('admin/pages/history/show/'.$this->page->ID .'/'.$this->versionUnpublishedCheck);
|
2012-09-27 02:14:14 +02:00
|
|
|
$checkbox = $this->cssParser()->getBySelector('#Form_VersionsForm_ShowUnpublished');
|
2011-08-30 04:33:03 +02:00
|
|
|
|
|
|
|
$this->assertThat($checkbox[0], $this->logicalNot($this->isNull()));
|
|
|
|
$this->assertEquals('checked', (string) $checkbox[0]->attributes()->checked);
|
|
|
|
}
|
2012-04-12 09:23:20 +02:00
|
|
|
}
|