Tests and fixes for inherited settings

This commit is contained in:
Stig Lindqvist 2014-02-24 13:38:16 +13:00
parent 0ad06c49fd
commit d340004933
8 changed files with 273 additions and 47 deletions

View File

@ -23,6 +23,22 @@ class ContentReviewDefaultSettings extends DataExtension {
'ContentReviewUsers' => 'Member'
);
/**
*
* @return string
*/
public function getOwnerNames() {
$names = array();
foreach($this->OwnerGroups() as $group) {
$names[] = $group->getBreadcrumbs(' > ');
}
foreach($this->OwnerUsers() as $group) {
$names[] = $group->getName();
}
return implode(', ', $names);
}
/**
* @return ManyManyList
*/

View File

@ -255,6 +255,27 @@ class SiteTreeContentReview extends DataExtension implements PermissionProvider
return $hasNextReview;
}
/**
*
*/
public function getNextReviewDatePlease(DataObject $settings, SiteTree $page) {
if(!($settings instanceof DataObject)) {
throw new BadMethodCallException('$settings must be a DataObject');
}
if($page->obj('NextReviewDate')->exists()) {
return $page->obj('NextReviewDate');
}
if(!$settings->ReviewPeriodDays) {
return false;
}
// Failover to check on ReviewPeriodDays + LastEdited
$nextReviewUnixSec = strtotime($page->LastEdited . ' + '.$settings->ReviewPeriodDays . ' days');
$date = Date::create('NextReviewDate');
$date->setValue(date('Y-m-d H:i:s', $nextReviewUnixSec));
return $date;
}
/**
*
* @param \FieldList $actions
@ -328,6 +349,12 @@ class SiteTreeContentReview extends DataExtension implements PermissionProvider
if($page->ContentReviewType == 'Custom') {
return $page;
}
if($page->ContentReviewType == 'Disabled') {
return false;
}
// $page is inheriting it's settings from it's parent, find
// the first valid parent with a valid setting
while($parent = $page->Parent()) {
// Root page, use siteconfig
if(!$parent->exists()) {

View File

@ -25,7 +25,8 @@ class PagesDueForReviewReport extends SS_Report {
// We need to be a bit fancier when subsites is enabled
if(class_exists('Subsite') && $subsites = DataObject::get('Subsite')) {
throw new Exception('feature missing, check with subsites');
// javascript for subsite specific owner dropdown
Requirements::javascript(THIRDPARTY_DIR . '/jquery-livequery/jquery.livequery.js');
Requirements::javascript('contentreview/javascript/PagesDueForReview.js');
@ -86,12 +87,44 @@ class PagesDueForReviewReport extends SS_Report {
'title' => 'Page name',
'formatting' => '<a href=\"' . $linkBase . '/$ID\" title=\"Edit page\">$value</a>'
),
'ContentReviewType' => array(
'title' => 'Settings are',
'formatting' => function($value, $item) {
return $value;
}
),
'NextReviewDate' => array(
'title' => 'Review Date',
'casting' => 'Date->Full'
'casting' => 'Date->Full',
'formatting' => function($value, $item) {
if($item->ContentReviewType == 'Disabled') {
return 'disabled';
}
if($item->ContentReviewType == 'Inherit') {
$setting = $item->getContentReviewSetting($item);
if(!$setting) {
return 'disabled';
}
return $item->getNextReviewDatePlease($setting, $item)->Full();
}
return $value;
}
),
'OwnerNames' => array(
'title' => 'Owner'
'title' => 'Owner',
'formatting' => function($value, $item) {
if($item->ContentReviewType == 'Disabled') {
return 'disabled';
}
if($item->ContentReviewType == 'Inherit') {
$setting = $item->getContentReviewSetting($item);
if(!$setting) {
return 'disabled';
}
return $setting->getOwnerNames();
}
return $value;
}
),
'LastEditedByName' => 'Last edited by',
'AbsoluteLink' => array(
@ -125,7 +158,9 @@ class PagesDueForReviewReport extends SS_Report {
// If there's no review dates set, default to all pages due for review now
$reviewDate = new Zend_Date(SS_Datetime::now()->Format('U'));
$reviewDate->add(1, Zend_Date::DAY);
$records = $records->where(sprintf('"NextReviewDate" < \'%s\'', $reviewDate->toString('YYYY-MM-dd')));
$records = $records->where('"ContentReviewType" != \'Disabled\'');
//$records = $records->where(sprintf('"NextReviewDate" < \'%s\'', $reviewDate->toString('YYYY-MM-dd')));
} else {
// Review date before
if(!empty($params['ReviewDateBefore'])) {

View File

@ -0,0 +1,15 @@
<?php
class ContentReviewNotificationTest extends SapphireTest {
public function testContentReviewEmails() {
SS_Datetime::set_mock_now('2010-02-14 12:00:00');
$task = new ContentReviewEmails();
$task->run(new SS_HTTPRequest('GET', '/dev/tasks/ContentReviewEmails'));
$this->assertEmailSent('author@example.com', null, sprintf(_t('ContentReviewEmails.SUBJECT', 'Page %s due for content review'), 'Staff'));
SS_Datetime::clear_mock_now();
}
}

View File

@ -0,0 +1,40 @@
<?php
class ContentReviewReportTest extends FunctionalTest {
public static $fixture_file = 'contentreview/tests/ContentReviewTest.yml';
public function testReportContent() {
$editor = $this->objFromFixture('Member', 'editor');
$this->logInAs($editor);
$report = new PagesDueForReviewReport();
$report->parameterFields();
$report->columns();
$report->title();
$results = $report->sourceRecords(array(
'ReviewDateAfter' => '01/01/2010',
'ReviewDateBefore' => '12/12/2010'
), 'NextReviewDate ASC', false);
$this->assertEquals($results->column('Title'), array(
'Home',
'About Us',
'Staff',
'Contact Us'
));
SS_Datetime::set_mock_now('2010-02-13 00:00:00');
$results = $report->sourceRecords(array(
), 'NextReviewDate ASC', false);
$this->assertEquals($results->column('Title'), array(
'Home',
'About Us'
));
SS_Datetime::clear_mock_now();
}
}

View File

@ -0,0 +1,68 @@
<?php
/**
* This class tests that settings are inherited correctly based on the inherited, custom or disabled settings
*/
class ContentReviewSettingsTest extends SapphireTest {
public static $fixture_file = 'contentreview/tests/ContentReviewSettingsTest.yml';
public function testGetSettingsObjectFromCustom() {
$page = $this->objFromFixture('Page', 'custom');
$this->assertEquals('Custom', $page->ContentReviewType);
$setting = $page->getContentReviewSetting($page);
$this->assertEquals($page, $setting);
}
public function testGetSettingsObjectFromDisabled() {
$page = $this->objFromFixture('Page', 'disabled');
$this->assertEquals('Disabled', $page->ContentReviewType);
$setting = $page->getContentReviewSetting($page);
$this->assertFalse($setting);
}
public function testGetSettingsObjectFromInheritPage() {
$page = $this->objFromFixture('Page', 'page-1-1');
$this->assertEquals('Inherit', $page->ContentReviewType);
$settings = $page->getContentReviewSetting($page);
$this->assertEquals($this->objFromFixture('Page', 'page-1'), $settings);
}
public function testGetSettingsObjectFromInheritedRootPage() {
$page = $this->objFromFixture('Page', 'inherit');
$this->assertEquals('Inherit', $page->ContentReviewType);
$settings = $page->getContentReviewSetting($page);
$this->assertEquals($this->objFromFixture('SiteConfig', 'default'), $settings);
}
public function testGetNextReviewDateFromCustomSettings() {
$page = $this->objFromFixture('Page', 'custom');
$settings = $page->getContentReviewSetting($page);
$date = $page->getNextReviewDatePlease($settings, $page);
$this->assertEquals('2010-02-01', $date->format('Y-m-d'));
}
public function testGetNextReviewDateFromSiteConfigInheritedSetting() {
$page = $this->objFromFixture('Page', 'page-1-1');
$settings = $page->getContentReviewSetting($page);
$nextReviewDate = $page->getNextReviewDatePlease($settings, $page);
$this->assertInstanceOf('Date', $nextReviewDate);
$expected = strtotime('+ '.$settings->ReviewPeriodDays.' days', $page->obj('LastEdited')->format('U'));
$this->assertEquals(date('Y-m-d', $expected), $nextReviewDate->format('Y-m-d'));
}
public function testGetNextReviewDateFromPageInheritedSetting() {
$page = $this->objFromFixture('Page', 'inherit');
$settings = $page->getContentReviewSetting($page);
$nextReviewDate = $page->getNextReviewDatePlease($settings, $page);
$this->assertInstanceOf('Date', $nextReviewDate);
$expected = strtotime('+ '.$settings->ReviewPeriodDays.' days', $page->obj('LastEdited')->format('U'));
$this->assertEquals(date('Y-m-d', $expected), $nextReviewDate->format('Y-m-d'));
}
}

View File

@ -0,0 +1,68 @@
Permission:
cmsmain1:
Code: CMS_ACCESS_CMSMain
cmsmain2:
Code: CMS_ACCESS_CMSMain
setreviewdates:
Code: EDIT_CONTENT_REVIEW_FIELDS
workflowadmin1:
Code: IS_WORKFLOW_ADMIN
workflowadmin2:
Code: IS_WORKFLOW_ADMIN
Group:
webmastergroup:
Title: Edit existing pages
Code: editorgroup
Permissions: =>Permission.cmsmain1,=>Permission.workflowadmin1,=>Permission.setreviewdates
editorgroup:
Title: Edit existing pages
Code: editorgroup
Permissions: =>Permission.cmsmain1,=>Permission.workflowadmin1,=>Permission.setreviewdates
authorgroup:
Title: Author existing pages
Code: authorgroup
Permissions: =>Permission.cmsmain2,=>Permission.workflowadmin2
Member:
webmaster:
FirstName: Web
Surname: Master
Email: webmaster@example.com
Groups: =>Group.webmastergroup
author:
FirstName: Test
Surname: Author
Email: author@example.com
Groups: =>Group.authorgroup
editor:
FirstName: Test
Surname: Editor
Groups: =>Group.editorgroup
SiteConfig:
default:
ContentReviewUsers: =>Member.webmaster
ContentReviewGroups: =>Group.webmastergroup
ReviewPeriodDays: 30
Page:
custom:
Title: custom
ContentReviewType: Custom
NextReviewDate: 2010-02-01
ContentReviewUsers: =>Member.editor
ReviewPeriodDays: 10
disabled:
Title: Disabled
ContentReviewType: Disabled
inherit:
Title: inherit
ContentReviewType: Inherit
page-1:
Title: About Us
ContentReviewType: Custom
NextReviewDate: 2010-02-07
ReviewPeriodDays: 5
page-1-1:
Title: Staff
ContentReviewType: Inherit
Parent: =>Page.page-1

View File

@ -4,49 +4,6 @@ class ContentReviewTest extends FunctionalTest {
public static $fixture_file = 'contentreview/tests/ContentReviewTest.yml';
public function testContentReviewEmails() {
SS_Datetime::set_mock_now('2010-02-14 12:00:00');
$task = new ContentReviewEmails();
$task->run(new SS_HTTPRequest('GET', '/dev/tasks/ContentReviewEmails'));
$this->assertEmailSent('author@example.com', null, sprintf(_t('ContentReviewEmails.SUBJECT', 'Page %s due for content review'), 'Staff'));
SS_Datetime::clear_mock_now();
}
public function testReportContent() {
$editor = $this->objFromFixture('Member', 'editor');
$this->logInAs($editor);
$report = new PagesDueForReviewReport();
$report->parameterFields();
$report->columns();
$report->title();
$results = $report->sourceRecords(array(
'ReviewDateAfter' => '01/01/2010',
'ReviewDateBefore' => '12/12/2010'
), 'NextReviewDate ASC', false);
$this->assertEquals($results->column('Title'), array(
'Home',
'About Us',
'Staff',
'Contact Us'
));
SS_Datetime::set_mock_now('2010-02-13 00:00:00');
$results = $report->sourceRecords(array(
), 'NextReviewDate ASC', false);
$this->assertEquals($results->column('Title'), array(
'Home',
'About Us'
));
SS_Datetime::clear_mock_now();
}
public function testOwnerNames() {
$editor = $this->objFromFixture('Member', 'editor');
$this->logInAs($editor);