2014-02-24 01:38:16 +01:00
|
|
|
<?php
|
|
|
|
|
2017-09-06 05:49:23 +02:00
|
|
|
namespace SilverStripe\ContentReview\Tests;
|
|
|
|
|
|
|
|
use Page;
|
|
|
|
use SilverStripe\CMS\Model\SiteTree;
|
2017-09-06 06:53:45 +02:00
|
|
|
use SilverStripe\CMS\Controllers\CMSPageEditController;
|
2017-09-06 05:49:23 +02:00
|
|
|
use SilverStripe\ContentReview\Extensions\ContentReviewCMSExtension;
|
|
|
|
use SilverStripe\ContentReview\Extensions\ContentReviewDefaultSettings;
|
|
|
|
use SilverStripe\ContentReview\Extensions\ContentReviewOwner;
|
|
|
|
use SilverStripe\ContentReview\Extensions\SiteTreeContentReview;
|
|
|
|
use SilverStripe\ContentReview\Tasks\ContentReviewEmails;
|
|
|
|
use SilverStripe\Control\HTTPRequest;
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use SilverStripe\ORM\FieldType\DBDatetime;
|
2017-09-06 06:53:45 +02:00
|
|
|
use SilverStripe\Security\Group;
|
|
|
|
use SilverStripe\Security\Member;
|
2017-09-06 05:49:23 +02:00
|
|
|
use SilverStripe\SiteConfig\SiteConfig;
|
2018-08-14 05:43:10 +02:00
|
|
|
use SilverStripe\ContentReview\Models\ContentReviewLog;
|
2017-09-06 05:49:23 +02:00
|
|
|
|
2015-11-02 00:27:42 +01:00
|
|
|
/**
|
|
|
|
* @mixin PHPUnit_Framework_TestCase
|
|
|
|
*/
|
|
|
|
class ContentReviewNotificationTest extends SapphireTest
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2017-09-06 05:49:23 +02:00
|
|
|
protected static $fixture_file = 'ContentReviewTest.yml';
|
2015-11-17 02:17:54 +01:00
|
|
|
|
2017-09-06 05:49:23 +02:00
|
|
|
protected function setUp()
|
2015-11-17 02:17:54 +01:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
// Hack to ensure only desired siteconfig is scaffolded
|
2017-09-06 05:49:23 +02:00
|
|
|
$desiredID = $this->idFromFixture(SiteConfig::class, 'mysiteconfig');
|
2015-11-17 02:17:54 +01:00
|
|
|
foreach (SiteConfig::get()->exclude('ID', $desiredID) as $config) {
|
|
|
|
$config->delete();
|
|
|
|
}
|
|
|
|
}
|
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 testContentReviewEmails()
|
|
|
|
{
|
2017-09-06 05:49:23 +02:00
|
|
|
DBDatetime::set_mock_now('2010-02-24 12:00:00');
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
/** @var Page|SiteTreeContentReview $childParentPage */
|
2017-09-06 05:49:23 +02:00
|
|
|
$childParentPage = $this->objFromFixture(Page::class, 'contact');
|
2015-11-17 02:17:54 +01:00
|
|
|
$childParentPage->NextReviewDate = '2010-02-23';
|
2015-11-02 00:27:42 +01:00
|
|
|
$childParentPage->write();
|
|
|
|
|
|
|
|
$task = new ContentReviewEmails();
|
2017-09-06 05:49:23 +02:00
|
|
|
$task->run(new HTTPRequest('GET', '/dev/tasks/ContentReviewEmails'));
|
2015-11-02 00:27:42 +01:00
|
|
|
|
2015-11-17 02:17:54 +01:00
|
|
|
// Set template variables (as per variable case)
|
|
|
|
$ToEmail = 'author@example.com';
|
|
|
|
$Subject = 'Please log in to review some content!';
|
|
|
|
$PagesCount = 3;
|
|
|
|
$ToFirstName = 'Test';
|
2015-11-02 00:27:42 +01:00
|
|
|
|
2015-11-17 02:17:54 +01:00
|
|
|
$email = $this->findEmail($ToEmail, null, $Subject);
|
2015-11-02 00:27:42 +01:00
|
|
|
$this->assertNotNull($email, "Email haven't been sent.");
|
2015-11-17 02:17:54 +01:00
|
|
|
$this->assertContains(
|
2018-01-08 22:11:31 +01:00
|
|
|
"<h1>$Subject</h1>".
|
|
|
|
"<p>There are $PagesCount pages that are due for review today by you, $ToFirstName.</p>".
|
|
|
|
"<p>This email was sent to $ToEmail</p>",
|
2017-09-06 06:53:45 +02:00
|
|
|
$email['HtmlContent']
|
2015-11-17 02:17:54 +01:00
|
|
|
);
|
2017-09-06 06:53:45 +02:00
|
|
|
$this->assertContains('Staff', $email['HtmlContent']);
|
|
|
|
$this->assertContains('Contact Us', $email['HtmlContent']);
|
|
|
|
$this->assertContains('Contact Us Child', $email['HtmlContent']);
|
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
|
|
|
}
|
2018-08-14 05:43:10 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* When a content review is left after a review date, we want to ensure that
|
|
|
|
* overdue notifications aren't sent.
|
|
|
|
*/
|
|
|
|
public function testContentReviewNeeded()
|
|
|
|
{
|
|
|
|
DBDatetime::set_mock_now('2018-08-10 12:00:00');
|
|
|
|
|
|
|
|
/** @var Page|SiteTreeContentReview $childParentPage */
|
|
|
|
$childParentPage = $this->objFromFixture(Page::class, 'no-review');
|
|
|
|
$childParentPage->NextReviewDate = '2018-08-10';
|
|
|
|
$childParentPage->write();
|
|
|
|
|
|
|
|
// we need to ensure only our test page is being ran. If we don't do this
|
|
|
|
// then it may notify for other pages which fails our test
|
|
|
|
$this->deleteAllPagesExcept([$childParentPage->ID]);
|
|
|
|
|
|
|
|
// Grabbing the 'author' from member class
|
|
|
|
$member = $this->objFromFixture(Member::class, 'author');
|
|
|
|
|
|
|
|
// Assigning member as contentreviewer to page
|
|
|
|
$childParentPage->ContentReviewUsers()->add($member);
|
|
|
|
|
|
|
|
// Assert that only one reviewer is assigned to page
|
|
|
|
$this->assertCount(1, $childParentPage->ContentReviewUsers());
|
|
|
|
|
|
|
|
// Create new log
|
|
|
|
$log = new ContentReviewLog();
|
|
|
|
|
|
|
|
// Assign log reviewer as current member
|
|
|
|
$log->ReviewerID = $member->ID;
|
|
|
|
|
|
|
|
// Assign log ID to page ID
|
|
|
|
$log->SiteTreeID = $childParentPage->ID;
|
|
|
|
|
|
|
|
// Write to DB
|
|
|
|
$log->write();
|
|
|
|
|
|
|
|
// assert that log was created day of review
|
|
|
|
$this->assertEquals('2018-08-10 12:00:00', $log->Created);
|
|
|
|
$this->assertCount(1, $childParentPage->ReviewLogs());
|
|
|
|
|
|
|
|
$task = new ContentReviewEmails();
|
|
|
|
$task->run(new HTTPRequest('GET', '/dev/tasks/ContentReviewEmails'));
|
|
|
|
|
|
|
|
// Expecting to not send the email as content review for page is done
|
|
|
|
$email = $this->findEmail($member->Email);
|
|
|
|
$this->assertNull($email);
|
|
|
|
|
|
|
|
DBDatetime::clear_mock_now();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes all pages except those passes in to the $ids parameter
|
|
|
|
*
|
|
|
|
* @param array $ids Page IDs which will NOT be deleted
|
|
|
|
*/
|
|
|
|
private function deleteAllPagesExcept(array $ids)
|
|
|
|
{
|
|
|
|
$pages = SiteTree::get()->exclude('ID', $ids);
|
|
|
|
|
|
|
|
foreach ($pages as $page) {
|
|
|
|
$page->delete();
|
|
|
|
}
|
|
|
|
}
|
2014-02-24 01:38:16 +01:00
|
|
|
}
|