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\ContentReviewCMSExtension;
|
|
|
|
use SilverStripe\ContentReview\Extensions\ContentReviewDefaultSettings;
|
2018-01-08 04:47:31 +01:00
|
|
|
use SilverStripe\ContentReview\Extensions\ContentReviewOwner;
|
|
|
|
use SilverStripe\ContentReview\Extensions\SiteTreeContentReview;
|
2022-06-22 02:25:59 +02:00
|
|
|
use SilverStripe\Core\Injector\Injector;
|
2017-09-11 07:53:59 +02:00
|
|
|
use SilverStripe\Forms\LiteralField;
|
2021-05-14 11:42:45 +02:00
|
|
|
use SilverStripe\ORM\FieldType\DBDate;
|
2018-01-08 04:47:31 +01:00
|
|
|
use SilverStripe\ORM\FieldType\DBDatetime;
|
2017-09-06 05:49:23 +02:00
|
|
|
use SilverStripe\Security\Group;
|
|
|
|
use SilverStripe\Security\Member;
|
|
|
|
use SilverStripe\SiteConfig\SiteConfig;
|
|
|
|
use SilverStripe\Versioned\Versioned;
|
2022-06-22 02:25:59 +02:00
|
|
|
use SilverStripe\ORM\ArrayList;
|
2024-09-18 03:53:15 +02:00
|
|
|
use SilverStripe\Dev\FunctionalTest;
|
|
|
|
use SilverStripe\ContentReview\Tests\SiteTreeContentReviewTestPage;
|
2017-09-06 05:49:23 +02:00
|
|
|
|
2024-09-18 03:53:15 +02:00
|
|
|
class SiteTreeContentReviewTest extends FunctionalTest
|
2015-11-02 00:27:42 +01:00
|
|
|
{
|
2018-06-20 08:51:00 +02:00
|
|
|
protected $usesTransactions = false;
|
|
|
|
|
2024-09-18 03:53:15 +02:00
|
|
|
protected static $extra_dataobjects = [
|
|
|
|
SiteTreeContentReviewTestPage::class,
|
|
|
|
];
|
|
|
|
|
2015-11-02 00:27:42 +01:00
|
|
|
/**
|
|
|
|
* @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());
|
2022-11-24 01:04:34 +01:00
|
|
|
$this->assertTrue($page->publishRecursive());
|
2015-11-02 00:27:42 +01:00
|
|
|
$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());
|
2018-01-08 04:47:31 +01:00
|
|
|
$this->assertTrue($page->publishRecursive());
|
2015-11-02 00:27:42 +01:00
|
|
|
$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();
|
|
|
|
|
2022-11-24 01:04:34 +01:00
|
|
|
$this->assertTrue($page->publishRecursive());
|
2015-11-02 00:27:42 +01:00
|
|
|
$this->assertEquals(null, $page->NextReviewDate);
|
|
|
|
}
|
|
|
|
|
2021-05-14 11:42:45 +02:00
|
|
|
public function testAdvanceReviewDate()
|
|
|
|
{
|
|
|
|
$page = new Page();
|
|
|
|
$page->Title = 'Test page';
|
|
|
|
$page->ReviewPeriodDays = 0;
|
|
|
|
// Set timestamp to a time in the past
|
|
|
|
$timestamp = DBDatetime::now()->getTimestamp() - 100000;
|
|
|
|
$page->NextReviewDate = DBDate::create()->setValue($timestamp)->Format(DBDate::ISO_DATE);
|
|
|
|
$page->write();
|
|
|
|
$page->advanceReviewDate();
|
|
|
|
$this->assertNull(Page::get()->find('Title', 'Test page')->NextReviewDate);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-02 00:27:42 +01:00
|
|
|
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-11 07:53:59 +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-11 07:53:59 +02:00
|
|
|
$page = $this->objFromFixture(Page::class, 'contact');
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
/** @var Member $author */
|
2017-09-11 07:53:59 +02:00
|
|
|
$author = $this->objFromFixture(Member::class, 'author');
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
$this->logInAs($author);
|
|
|
|
|
|
|
|
$fields = $page->getCMSActions();
|
|
|
|
|
2017-09-11 07:53:59 +02:00
|
|
|
$this->assertInstanceOf(LiteralField::class, $fields->fieldByName('ContentReviewButton'));
|
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
|
|
|
}
|
2017-10-06 05:39:53 +02:00
|
|
|
|
|
|
|
public function testSiteConfigSettingsAreUsedAsDefaults()
|
|
|
|
{
|
2017-10-12 02:22:24 +02:00
|
|
|
DBDatetime::set_mock_now("2020-03-01 12:00:00");
|
2017-10-06 05:39:53 +02:00
|
|
|
|
|
|
|
/** @var Member $author */
|
2017-10-12 02:22:24 +02:00
|
|
|
$author = $this->objFromFixture(Member::class, 'editor');
|
2017-10-06 05:39:53 +02:00
|
|
|
|
|
|
|
/** @var SiteConfig $siteConfig */
|
|
|
|
$siteConfig = SiteConfig::current_site_config();
|
|
|
|
|
|
|
|
// Set the author to a default user for reviewing
|
|
|
|
$siteConfig->OwnerUsers()->add($author);
|
|
|
|
|
|
|
|
$emptyPage = new Page;
|
|
|
|
$emptyPage->NextReviewDate = '2020-02-20 12:00:00';
|
|
|
|
|
|
|
|
$this->assertTrue($emptyPage->canBeReviewedBy($author));
|
|
|
|
|
2017-10-12 02:22:24 +02:00
|
|
|
DBDatetime::clear_mock_now();
|
2017-10-06 05:39:53 +02:00
|
|
|
}
|
2022-06-22 02:25:59 +02:00
|
|
|
|
|
|
|
public function testPermissionCheckByOnDataObject()
|
|
|
|
{
|
|
|
|
$reviewer = $this->objFromFixture(Member::class, 'editor');
|
|
|
|
|
2024-09-18 03:53:15 +02:00
|
|
|
$mock = new SiteTreeContentReviewTestPage();
|
|
|
|
$mock->setReviewer($reviewer);
|
2022-06-22 02:25:59 +02:00
|
|
|
|
|
|
|
/** @var SiteTreeContentReview $extension */
|
|
|
|
$extension = Injector::inst()->get(SiteTreeContentReview::class);
|
|
|
|
$extension->setOwner($mock);
|
|
|
|
|
|
|
|
// Assert that the user is not allowed to review content
|
|
|
|
$author = $this->objFromFixture(Member::class, 'author');
|
|
|
|
$this->assertFalse($extension->canBeReviewedBy($author));
|
|
|
|
|
|
|
|
DBDatetime::set_mock_now("2020-03-01 12:00:00");
|
|
|
|
|
|
|
|
// Assert that the user is allowed to review content
|
|
|
|
$this->assertTrue($extension->canBeReviewedBy($reviewer));
|
|
|
|
|
|
|
|
// Assert tht canBeReviewedBy return true if no user logged in
|
|
|
|
// This is for CLI execution for ContentReviewEmails task
|
|
|
|
$this->logOut();
|
|
|
|
$this->assertTrue($extension->canBeReviewedBy());
|
|
|
|
|
|
|
|
DBDatetime::clear_mock_now();
|
|
|
|
}
|
2014-02-18 03:39:13 +01:00
|
|
|
}
|