2014-02-18 03:39:13 +01:00
|
|
|
<?php
|
|
|
|
|
2017-09-06 05:49:23 +02:00
|
|
|
namespace SilverStripe\ContentReview\Tests;
|
|
|
|
|
|
|
|
use Page;
|
|
|
|
use SilverStripe\CMS\Controllers\CMSPageEditController;
|
|
|
|
use SilverStripe\CMS\Model\SiteTree;
|
|
|
|
use SilverStripe\ContentReview\Extensions\SiteTreeContentReview;
|
|
|
|
use SilverStripe\ContentReview\Extensions\ContentReviewOwner;
|
|
|
|
use SilverStripe\ContentReview\Extensions\ContentReviewCMSExtension;
|
|
|
|
use SilverStripe\ContentReview\Extensions\ContentReviewDefaultSettings;
|
|
|
|
use SilverStripe\Security\Group;
|
|
|
|
use SilverStripe\Security\Member;
|
|
|
|
use SilverStripe\SiteConfig\SiteConfig;
|
|
|
|
use SilverStripe\ORM\FieldType\DBDatetime;
|
|
|
|
use SilverStripe\Versioned\Versioned;
|
|
|
|
|
2015-11-02 00:27:42 +01:00
|
|
|
/**
|
|
|
|
* @mixin PHPUnit_Framework_TestCase
|
|
|
|
*/
|
|
|
|
class SiteTreeContentReviewTest extends ContentReviewBaseTest
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2017-09-06 05:49:23 +02:00
|
|
|
protected static $fixture_file = 'ContentReviewTest.yml';
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2017-09-06 05:49:23 +02:00
|
|
|
protected static $required_extensions = [
|
|
|
|
SiteTree::class => [SiteTreeContentReview::class],
|
|
|
|
Group::class => [ContentReviewOwner::class],
|
|
|
|
Member::class => [ContentReviewOwner::class],
|
|
|
|
CMSPageEditController::class => [ContentReviewCMSExtension::class],
|
|
|
|
SiteConfig::class => [ContentReviewDefaultSettings::class],
|
|
|
|
];
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
public function testOwnerNames()
|
|
|
|
{
|
|
|
|
/** @var Member $editor */
|
2017-09-06 05:49:23 +02:00
|
|
|
$editor = $this->objFromFixture(Member::class, "editor");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
$this->logInAs($editor);
|
|
|
|
|
|
|
|
/** @var Page|SiteTreeContentReview $page */
|
|
|
|
$page = new Page();
|
|
|
|
$page->ReviewPeriodDays = 10;
|
|
|
|
$page->ContentReviewType = "Custom";
|
|
|
|
|
|
|
|
$page->ContentReviewUsers()->push($editor);
|
|
|
|
$page->write();
|
|
|
|
|
|
|
|
$this->assertTrue($page->canPublish());
|
|
|
|
$this->assertTrue($page->doPublish());
|
|
|
|
$this->assertEquals($page->OwnerNames, "Test Editor", "Test Editor should be the owner");
|
|
|
|
|
|
|
|
/** @var Page|SiteTreeContentReview $page */
|
2017-09-06 05:49:23 +02:00
|
|
|
$page = $this->objFromFixture(Page::class, "about");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
$page->OwnerUsers()->removeAll();
|
|
|
|
$page->write();
|
|
|
|
|
|
|
|
$this->assertTrue($page->canPublish());
|
|
|
|
$this->assertTrue($page->doPublish());
|
|
|
|
$this->assertEquals("", $page->OwnerNames);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testPermissionsExists()
|
|
|
|
{
|
2017-09-06 05:49:23 +02:00
|
|
|
$perms = singleton(SiteTreeContentReview::class)->providePermissions();
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
$this->assertTrue(isset($perms["EDIT_CONTENT_REVIEW_FIELDS"]));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUserWithPermissionCanEdit()
|
|
|
|
{
|
|
|
|
/** @var Member $editor */
|
2017-09-06 05:49:23 +02:00
|
|
|
$editor = $this->objFromFixture(Member::class, "editor");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
$this->logInAs($editor);
|
|
|
|
|
|
|
|
/** @var Page|SiteTreeContentReview $page */
|
|
|
|
$page = new Page();
|
|
|
|
|
|
|
|
$fields = $page->getSettingsFields();
|
|
|
|
|
|
|
|
$this->assertNotNull($fields->dataFieldByName("NextReviewDate"));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUserWithoutPermissionCannotEdit()
|
|
|
|
{
|
|
|
|
/** @var Member $author */
|
2017-09-06 05:49:23 +02:00
|
|
|
$author = $this->objFromFixture(Member::class, "author");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
$this->logInAs($author);
|
|
|
|
|
|
|
|
/** @var Page|SiteTreeContentReview $page */
|
|
|
|
$page = new Page();
|
|
|
|
|
|
|
|
$fields = $page->getSettingsFields();
|
|
|
|
|
|
|
|
$this->assertNull($fields->dataFieldByName("NextReviewDate"));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAutomaticallyToNotSetReviewDate()
|
|
|
|
{
|
|
|
|
/** @var Member $editor */
|
2017-09-06 05:49:23 +02:00
|
|
|
$editor = $this->objFromFixture(Member::class, "editor");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
$this->logInAs($editor);
|
|
|
|
|
|
|
|
/** @var Page|SiteTreeContentReview $page */
|
|
|
|
$page = new Page();
|
|
|
|
|
|
|
|
$page->ReviewPeriodDays = 10;
|
|
|
|
$page->write();
|
|
|
|
|
|
|
|
$this->assertTrue($page->doPublish());
|
|
|
|
$this->assertEquals(null, $page->NextReviewDate);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAddReviewNote()
|
|
|
|
{
|
|
|
|
/** @var Member $author */
|
2017-09-06 05:49:23 +02:00
|
|
|
$author = $this->objFromFixture(Member::class, "author");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
/** @var Page|SiteTreeContentReview $page */
|
2017-09-06 05:49:23 +02:00
|
|
|
$page = $this->objFromFixture(Page::class, "home");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
$page->addReviewNote($author, "This is a message");
|
|
|
|
|
|
|
|
/** @var Page|SiteTreeContentReview $page */
|
2017-09-06 05:49:23 +02:00
|
|
|
$homepage = $this->objFromFixture(Page::class, "home");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
$this->assertEquals(1, $homepage->ReviewLogs()->count());
|
|
|
|
$this->assertEquals("This is a message", $homepage->ReviewLogs()->first()->Note);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetContentReviewOwners()
|
|
|
|
{
|
|
|
|
/** @var Page|SiteTreeContentReview $page */
|
2017-09-06 05:49:23 +02:00
|
|
|
$page = $this->objFromFixture(Page::class, "group-owned");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
$owners = $page->ContentReviewOwners();
|
|
|
|
|
|
|
|
$this->assertEquals(1, $owners->count());
|
|
|
|
$this->assertEquals("author@example.com", $owners->first()->Email);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCanNotBeReviewBecauseNoReviewDate()
|
|
|
|
{
|
2017-09-06 05:49:23 +02:00
|
|
|
DBDatetime::set_mock_now("2010-01-01 12:00:00");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
/** @var Member $author */
|
2017-09-06 05:49:23 +02:00
|
|
|
$author = $this->objFromFixture(Member::class, "author");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
/** @var Page|SiteTreeContentReview $page */
|
2017-09-06 05:49:23 +02:00
|
|
|
$page = $this->objFromFixture(Page::class, "no-review");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
$this->assertFalse($page->canBeReviewedBy($author));
|
|
|
|
|
2017-09-06 05:49:23 +02:00
|
|
|
DBDatetime::clear_mock_now();
|
2015-11-02 00:27:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testCanNotBeReviewedBecauseInFuture()
|
|
|
|
{
|
2017-09-06 05:49:23 +02:00
|
|
|
DBDatetime::set_mock_now("2010-01-01 12:00:00");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
/** @var Member $author */
|
2017-09-06 05:49:23 +02:00
|
|
|
$author = $this->objFromFixture(Member::class, "author");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
/** @var Page|SiteTreeContentReview $page */
|
2017-09-06 05:49:23 +02:00
|
|
|
$page = $this->objFromFixture(Page::class, "staff");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
$this->assertFalse($page->canBeReviewedBy($author));
|
|
|
|
|
2017-09-06 05:49:23 +02:00
|
|
|
DBDatetime::clear_mock_now();
|
2015-11-02 00:27:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testCanNotBeReviewedByUser()
|
|
|
|
{
|
2017-09-06 05:49:23 +02:00
|
|
|
DBDatetime::set_mock_now("2010-03-01 12:00:00");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
/** @var Member $author */
|
2017-09-06 05:49:23 +02:00
|
|
|
$author = $this->objFromFixture(Member::class, "author");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
/** @var Page|SiteTreeContentReview $page */
|
2017-09-06 05:49:23 +02:00
|
|
|
$page = $this->objFromFixture(Page::class, "home");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
$this->assertFalse($page->canBeReviewedBy($author));
|
|
|
|
|
2017-09-06 05:49:23 +02:00
|
|
|
DBDatetime::clear_mock_now();
|
2015-11-02 00:27:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testCanBeReviewedByUser()
|
|
|
|
{
|
2017-09-06 05:49:23 +02:00
|
|
|
DBDatetime::set_mock_now("2010-03-01 12:00:00");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
/** @var Member $author */
|
2017-09-06 05:49:23 +02:00
|
|
|
$author = $this->objFromFixture(Member::class, "author");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
/** @var Page|SiteTreeContentReview $page */
|
2017-09-06 05:49:23 +02:00
|
|
|
$page = $this->objFromFixture(Page::class, "staff");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
$this->assertTrue($page->canBeReviewedBy($author));
|
|
|
|
|
2017-09-06 05:49:23 +02:00
|
|
|
DBDatetime::clear_mock_now();
|
2015-11-02 00:27:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testCanNotBeReviewedByGroup()
|
|
|
|
{
|
2017-09-06 05:49:23 +02:00
|
|
|
DBDatetime::set_mock_now("2010-03-01 12:00:00");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
/** @var Member $author */
|
2017-09-06 05:49:23 +02:00
|
|
|
$author = $this->objFromFixture(Member::class, "editor");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
/** @var Page|SiteTreeContentReview $page */
|
2017-09-06 05:49:23 +02:00
|
|
|
$page = $this->objFromFixture(Page::class, "contact");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
$this->assertFalse($page->canBeReviewedBy($author));
|
|
|
|
|
2017-09-06 05:49:23 +02:00
|
|
|
DBDatetime::clear_mock_now();
|
2015-11-02 00:27:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testCanBeReviewedByGroup()
|
|
|
|
{
|
2017-09-06 05:49:23 +02:00
|
|
|
DBDatetime::set_mock_now("2010-03-01 12:00:00");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
/** @var Member $author */
|
2017-09-06 05:49:23 +02:00
|
|
|
$author = $this->objFromFixture(Member::class, "author");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
/** @var Page|SiteTreeContentReview $page */
|
2017-09-06 05:49:23 +02:00
|
|
|
$page = $this->objFromFixture(Page::class, "contact");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
$this->assertTrue($page->canBeReviewedBy($author));
|
|
|
|
|
2017-09-06 05:49:23 +02:00
|
|
|
DBDatetime::clear_mock_now();
|
2015-11-02 00:27:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testCanBeReviewedFromInheritedSetting()
|
|
|
|
{
|
2017-09-06 05:49:23 +02:00
|
|
|
DBDatetime::set_mock_now("2013-03-01 12:00:00");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
/** @var Member $author */
|
2017-09-06 05:49:23 +02:00
|
|
|
$author = $this->objFromFixture(Member::class, "author");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
/** @var Page|SiteTreeContentReview $parentPage */
|
2017-09-06 05:49:23 +02:00
|
|
|
$parentPage = $this->objFromFixture(Page::class, "contact");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
$parentPage->NextReviewDate = "2013-01-01";
|
|
|
|
$parentPage->write();
|
|
|
|
|
|
|
|
/** @var Page|SiteTreeContentReview $page */
|
2017-09-06 05:49:23 +02:00
|
|
|
$page = $this->objFromFixture(Page::class, "contact-child");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
$this->assertTrue($page->canBeReviewedBy($author));
|
|
|
|
|
2017-09-06 05:49:23 +02:00
|
|
|
DBDatetime::clear_mock_now();
|
2015-11-02 00:27:42 +01:00
|
|
|
}
|
|
|
|
|
2017-09-06 05:49:23 +02:00
|
|
|
public function testUnModifiedPagesDontChangeEditor()
|
|
|
|
{
|
|
|
|
DBDatetime::set_mock_now("2013-03-01 12:00:00");
|
2016-05-17 06:34:00 +02:00
|
|
|
|
|
|
|
/** @var Member $author */
|
2017-09-06 05:49:23 +02:00
|
|
|
$author = $this->objFromFixture(Member::class, "author");
|
2016-05-17 06:34:00 +02:00
|
|
|
$this->logInAs($author);
|
|
|
|
|
|
|
|
// Page which is un-modified doesn't advance version of have an editor assigned
|
2017-09-06 05:49:23 +02:00
|
|
|
$contactPage = $this->objFromFixture(Page::class, "contact");
|
2016-05-17 06:34:00 +02:00
|
|
|
$contactPageVersion = $contactPage->Version;
|
|
|
|
$contactPage->write();
|
|
|
|
$this->assertEmpty($contactPage->LastEditedByName);
|
|
|
|
$this->assertEquals(
|
|
|
|
$contactPageVersion,
|
2017-09-06 05:49:23 +02:00
|
|
|
Versioned::get_versionnumber_by_stage(SiteTree::class, 'Stage', $contactPage->ID, false)
|
2016-05-17 06:34:00 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
// Page with modifications gets marked
|
2017-09-06 05:49:23 +02:00
|
|
|
$homePage = $this->objFromFixture(Page::class, "home");
|
2016-05-17 06:34:00 +02:00
|
|
|
$homePageVersion = $homePage->Version;
|
|
|
|
$homePage->Content = '<p>Welcome!</p>';
|
|
|
|
$homePage->write();
|
|
|
|
$this->assertNotEmpty($homePage->LastEditedByName);
|
|
|
|
$this->assertEquals($author->getTitle(), $homePage->LastEditedByName);
|
|
|
|
$this->assertGreaterThan(
|
|
|
|
$homePageVersion,
|
2017-09-06 05:49:23 +02:00
|
|
|
Versioned::get_versionnumber_by_stage(SiteTree::class, 'Stage', $homePage->ID, false)
|
2016-05-17 06:34:00 +02:00
|
|
|
);
|
|
|
|
|
2017-09-06 05:49:23 +02:00
|
|
|
DBDatetime::clear_mock_now();
|
2016-05-17 06:34:00 +02:00
|
|
|
}
|
|
|
|
|
2015-11-02 00:27:42 +01:00
|
|
|
public function testReviewActionVisibleForAuthor()
|
|
|
|
{
|
2017-09-06 05:49:23 +02:00
|
|
|
DBDatetime::set_mock_now("2020-03-01 12:00:00");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
/** @var Page|SiteTreeContentReview $page */
|
2017-09-06 05:49:23 +02:00
|
|
|
$page = $this->objFromFixture(Page::class, "contact");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
/** @var Member $author */
|
2017-09-06 05:49:23 +02:00
|
|
|
$author = $this->objFromFixture(Member::class, "author");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
$this->logInAs($author);
|
|
|
|
|
|
|
|
$fields = $page->getCMSActions();
|
|
|
|
|
2015-11-12 03:56:19 +01:00
|
|
|
$this->assertNotNull($fields->fieldByName("ActionMenus.ReviewContent"));
|
2015-11-02 00:27:42 +01:00
|
|
|
|
2017-09-06 05:49:23 +02:00
|
|
|
DBDatetime::clear_mock_now();
|
2015-11-02 00:27:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testReviewActionNotVisibleForEditor()
|
|
|
|
{
|
2017-09-06 05:49:23 +02:00
|
|
|
DBDatetime::set_mock_now("2020-03-01 12:00:00");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
/** @var Page|SiteTreeContentReview $page */
|
2017-09-06 05:49:23 +02:00
|
|
|
$page = $this->objFromFixture(Page::class, "contact");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
/** @var Member $author */
|
2017-09-06 05:49:23 +02:00
|
|
|
$author = $this->objFromFixture(Member::class, "editor");
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
$this->logInAs($author);
|
|
|
|
|
|
|
|
$fields = $page->getCMSActions();
|
|
|
|
|
2015-11-12 03:56:19 +01:00
|
|
|
$this->assertNull($fields->fieldByName("ActionMenus.ReviewContent"));
|
2015-11-02 00:27:42 +01:00
|
|
|
|
2017-09-06 05:49:23 +02:00
|
|
|
DBDatetime::clear_mock_now();
|
2015-11-02 00:27:42 +01:00
|
|
|
}
|
2014-02-18 03:39:13 +01:00
|
|
|
}
|