2010-02-25 04:34:39 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class ContentReviewTest extends FunctionalTest {
|
|
|
|
|
2014-02-13 02:07:39 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public static $fixture_file = 'contentreview/tests/ContentReviewTest.yml';
|
|
|
|
|
2014-02-13 04:35:13 +01:00
|
|
|
public function testPermissionsExists() {
|
2010-02-25 04:34:39 +01:00
|
|
|
$perms = singleton('SiteTreeContentReview')->providePermissions();
|
|
|
|
$this->assertTrue(isset($perms['EDIT_CONTENT_REVIEW_FIELDS']));
|
2014-02-13 04:35:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUserWithPermissionCanEdit() {
|
|
|
|
$editor = $this->objFromFixture('Member', 'editor');
|
2010-02-25 04:34:39 +01:00
|
|
|
$this->logInAs($editor);
|
|
|
|
$page = new Page();
|
|
|
|
$fields = $page->getCMSFields();
|
|
|
|
$this->assertNotNull($fields->fieldByName('Root.Review'));
|
2014-02-13 04:35:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUserWithoutPermissionCannotEdit() {
|
|
|
|
$author = $this->objFromFixture('Member', 'author');
|
2010-02-25 04:34:39 +01:00
|
|
|
$this->logInAs($author);
|
|
|
|
$page = new Page();
|
|
|
|
$fields = $page->getCMSFields();
|
|
|
|
$this->assertNull($fields->fieldByName('Root.Review'));
|
|
|
|
}
|
|
|
|
|
2014-02-13 02:07:39 +01:00
|
|
|
public function testContentReviewEmails() {
|
2010-02-25 04:34:39 +01:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2014-02-13 02:07:39 +01:00
|
|
|
public function testAutomaticallySettingReviewDate() {
|
2010-02-25 04:34:39 +01:00
|
|
|
$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);
|
|
|
|
}
|
|
|
|
|
2014-02-13 02:07:39 +01:00
|
|
|
public function testReportContent() {
|
2010-02-25 04:34:39 +01:00
|
|
|
$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'
|
|
|
|
));
|
|
|
|
|
2010-05-24 07:12:43 +02:00
|
|
|
SS_Datetime::set_mock_now('2010-02-13 00:00:00');
|
2010-02-25 04:34:39 +01:00
|
|
|
$results = $report->sourceRecords(array(
|
|
|
|
), 'NextReviewDate ASC', false);
|
|
|
|
$this->assertEquals($results->column('Title'), array(
|
|
|
|
'Home',
|
|
|
|
'About Us'
|
|
|
|
));
|
|
|
|
|
|
|
|
SS_Datetime::clear_mock_now();
|
|
|
|
}
|
|
|
|
|
2014-02-13 04:35:13 +01:00
|
|
|
public function testOwnerNames() {
|
2010-02-25 04:34:39 +01:00
|
|
|
$editor = $this->objFromFixture('Member', 'editor');
|
|
|
|
$this->logInAs($editor);
|
|
|
|
|
|
|
|
$page = new Page();
|
|
|
|
$page->ReviewPeriodDays = 10;
|
2014-02-13 04:35:13 +01:00
|
|
|
$page->ContentReviewUsers()->push($editor);
|
2010-02-25 04:34:39 +01:00
|
|
|
$page->write();
|
|
|
|
|
|
|
|
$this->assertTrue($page->doPublish());
|
2014-02-13 04:35:13 +01:00
|
|
|
$this->assertEquals($page->OwnerNames, "Test Editor", 'Test Editor should be the owner');
|
2010-02-25 04:34:39 +01:00
|
|
|
|
|
|
|
$page = $this->objFromFixture('Page', 'about');
|
2013-03-18 03:20:51 +01:00
|
|
|
$page->ContentReviewOwnerID = 0;
|
2010-02-25 04:34:39 +01:00
|
|
|
$page->write();
|
|
|
|
|
|
|
|
$this->assertTrue($page->doPublish());
|
2014-02-13 04:35:13 +01:00
|
|
|
$this->assertEquals('', $page->OwnerNames);
|
2010-02-25 04:34:39 +01:00
|
|
|
}
|
|
|
|
}
|