MINOR unit tests for the content review module

This commit is contained in:
Tom Rix 2010-02-25 03:34:39 +00:00
parent e0fa54c7bb
commit 2ec23039ed
5 changed files with 155 additions and 5 deletions

View File

@ -15,7 +15,7 @@ class ContentReviewEmails extends DailyTask {
Subsite::$disable_subsite_filter = true;
}
$pages = DataObject::get('Page', "SiteTree.NextReviewDate = '".date('Y-m-d')."' AND SiteTree.OwnerID != 0");
$pages = DataObject::get('Page', "SiteTree.NextReviewDate = '".(class_exists('SS_Datetime') ? SS_Datetime::now()->URLDate() : SSDatetime::now()->URLDate())."' AND SiteTree.OwnerID != 0");
if ($pages && $pages->Count()) {
foreach($pages as $page) {
$owner = $page->Owner();

View File

@ -92,14 +92,14 @@ class PagesDueForReviewReport extends SS_Report {
} else {
// Review date before
if(!empty($params['ReviewDateBefore'])) {
list($day, $month, $year) = explode('/', $_REQUEST['ReviewDateBefore']);
list($day, $month, $year) = explode('/', $params['ReviewDateBefore']);
$reviewDate = "$year-$month-$day";
$wheres[] = 'NextReviewDate < \'' . Convert::raw2sql($reviewDate) . '\' + INTERVAL 1 DAY';
}
// Review date after
if(!empty($params['ReviewDateAfter'])) {
list($day, $month, $year) = explode('/', $_REQUEST['ReviewDateAfter']);
list($day, $month, $year) = explode('/', $params['ReviewDateAfter']);
$reviewDate = "$year-$month-$day";
$wheres[] = 'NextReviewDate >= \'' . Convert::raw2sql($reviewDate) . '\'';
}
@ -148,7 +148,7 @@ class PagesDueForReviewReport extends SS_Report {
// var_dump($records);
if($records) {
foreach($records as $record) {
$record->LastEditedByName = $record->LastEditedBy()->Title;
$record->LastEditedByName = $record->LastEditedBy() ? $record->LastEditedBy()->Title : null;
}
if($sort && $field != "LastEditedByName") $records->sort($sort);

View File

@ -21,7 +21,7 @@ class SiteTreeContentReview extends DataObjectDecorator implements PermissionPro
}
function getOwnerName() {
if($this->owner->Owner()) return $this->owner->Owner()->FirstName . ' ' . $this->owner->Owner()->Surname;
if($this->owner->OwnerID && $this->owner->Owner()) return $this->owner->Owner()->FirstName . ' ' . $this->owner->Owner()->Surname;
}
public function updateCMSFields(&$fields) {

102
tests/ContentReviewTest.php Normal file
View File

@ -0,0 +1,102 @@
<?php
class ContentReviewTest extends FunctionalTest {
static $fixture_file = 'contentreview/tests/ContentReviewTest.yml';
function testPermissions() {
$editor = $this->objFromFixture('Member', 'editor');
$author = $this->objFromFixture('Member', 'author');
// Assert the permission code exists
$perms = singleton('SiteTreeContentReview')->providePermissions();
$this->assertTrue(isset($perms['EDIT_CONTENT_REVIEW_FIELDS']));
// Check a user with permission can edit fields
$this->logInAs($editor);
$page = new Page();
$fields = $page->getCMSFields();
$this->assertNotNull($fields->fieldByName('Root.Review'));
// Check a user without permission can see tab
$this->logInAs($author);
$page = new Page();
$fields = $page->getCMSFields();
$this->assertNull($fields->fieldByName('Root.Review'));
}
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();
}
function testAutomaticallySettingReviewDate() {
$editor = $this->objFromFixture('Member', 'editor');
$this->logInAs($editor);
$page = new Page();
$page->ReviewPeriodDays = 10;
$page->write();
$this->assertTrue($page->doPublish());
$this->assertEquals(date('Y-m-d', strtotime('now + 10 days')), $page->NextReviewDate);
}
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 12:00:00');
$results = $report->sourceRecords(array(
), 'NextReviewDate ASC', false);
$this->assertEquals($results->column('Title'), array(
'Home',
'About Us'
));
SS_Datetime::clear_mock_now();
}
function testOwnerName() {
$editor = $this->objFromFixture('Member', 'editor');
$this->logInAs($editor);
$page = new Page();
$page->ReviewPeriodDays = 10;
$page->OwnerID = $editor->ID;
$page->write();
$this->assertTrue($page->doPublish());
$this->assertEquals($page->OwnerName, "Test Editor");
$page = $this->objFromFixture('Page', 'about');
$page->OwnerID = 0;
$page->write();
$this->assertTrue($page->doPublish());
$this->assertNull($page->OwnerName);
}
}

View File

@ -0,0 +1,48 @@
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:
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:
author:
FirstName: Test
Surname: Author
Email: author@example.com
Groups: =>Group.authorgroup
editor:
FirstName: Test
Surname: Editor
Groups: =>Group.editorgroup
Page:
home:
Title: Home
NextReviewDate: 2010-02-01
about:
Title: About Us
NextReviewDate: 2010-02-07
staff:
Title: Staff
NextReviewDate: 2010-02-14
Owner: =>Member.author
contact:
Title: Contact Us
NextReviewDate: 2010-02-21