2014-02-24 01:38:16 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class tests that settings are inherited correctly based on the inherited, custom or disabled settings
|
|
|
|
*/
|
|
|
|
class ContentReviewSettingsTest extends SapphireTest {
|
2014-02-24 09:10:10 +01:00
|
|
|
|
2014-02-24 01:38:16 +01:00
|
|
|
public static $fixture_file = 'contentreview/tests/ContentReviewSettingsTest.yml';
|
|
|
|
|
2014-02-26 23:07:34 +01:00
|
|
|
protected $requiredExtensions = array(
|
|
|
|
"SiteTree" => array("SiteTreeContentReview"),
|
|
|
|
"Group" => array("ContentReviewOwner"),
|
|
|
|
"Member" => array("ContentReviewOwner"),
|
|
|
|
"CMSPageEditController" => array("ContentReviewCMSExtension"),
|
|
|
|
"SiteConfig" => array("ContentReviewDefaultSettings"),
|
|
|
|
);
|
|
|
|
|
2014-02-24 12:50:52 +01:00
|
|
|
public function testAdvanceReviewDate10Days() {
|
|
|
|
$page = new Page();
|
|
|
|
$page->ContentReviewType = 'Custom';
|
|
|
|
$page->ReviewPeriodDays = 10;
|
|
|
|
$this->assertTrue($page->advanceReviewDate());
|
|
|
|
$page->write();
|
|
|
|
$this->assertEquals(date('Y-m-d', strtotime('now + 10 days')), $page->NextReviewDate);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAdvanceReviewDateNull() {
|
|
|
|
$page = new Page();
|
|
|
|
$page->ContentReviewType = 'Custom';
|
|
|
|
$page->ReviewPeriodDays = 0;
|
|
|
|
$this->assertFalse($page->advanceReviewDate());
|
|
|
|
$page->write();
|
|
|
|
$this->assertEquals(null, $page->NextReviewDate);
|
|
|
|
}
|
|
|
|
|
2014-02-24 08:19:44 +01:00
|
|
|
public function testAdvanceReviewFromCustomSettings() {
|
|
|
|
$page = $this->objFromFixture('Page', 'custom');
|
|
|
|
$this->assertTrue($page->advanceReviewDate());
|
|
|
|
$page->write();
|
|
|
|
$this->assertEquals(date('Y-m-d', strtotime('now + '.$page->ReviewPeriodDays.' days')), $page->NextReviewDate);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAdvanceReviewFromInheritedSettings() {
|
|
|
|
$page = $this->objFromFixture('Page', 'page-1-1');
|
|
|
|
$parentPage = $this->objFromFixture('Page', 'page-1');
|
|
|
|
$this->assertTrue($page->advanceReviewDate());
|
|
|
|
$page->write();
|
|
|
|
$this->assertEquals(date('Y-m-d', strtotime('now + '.$parentPage->ReviewPeriodDays.' days')), $page->NextReviewDate);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAdvanceReviewFromInheritedSiteConfigSettings() {
|
|
|
|
$page = $this->objFromFixture('Page', 'inherit');
|
|
|
|
$siteConfig = $this->objFromFixture('SiteConfig', 'default');
|
|
|
|
$this->assertTrue($page->advanceReviewDate());
|
|
|
|
$page->write();
|
|
|
|
$this->assertEquals(date('Y-m-d', strtotime('now + '.$siteConfig->ReviewPeriodDays.' days')), $page->NextReviewDate);
|
|
|
|
}
|
|
|
|
|
2014-02-24 01:38:16 +01:00
|
|
|
public function testGetSettingsObjectFromCustom() {
|
|
|
|
$page = $this->objFromFixture('Page', 'custom');
|
|
|
|
$this->assertEquals('Custom', $page->ContentReviewType);
|
2014-02-24 09:10:10 +01:00
|
|
|
$this->assertEquals($page, $page->getOptions());
|
2014-02-24 01:38:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetSettingsObjectFromDisabled() {
|
|
|
|
$page = $this->objFromFixture('Page', 'disabled');
|
|
|
|
$this->assertEquals('Disabled', $page->ContentReviewType);
|
2014-02-24 09:10:10 +01:00
|
|
|
$this->assertFalse($page->getOptions());
|
2014-02-24 01:38:16 +01:00
|
|
|
}
|
|
|
|
|
2014-02-24 10:14:26 +01:00
|
|
|
public function testGetOptionObjectFromInheritedDisabled() {
|
|
|
|
$page = $this->objFromFixture('Page', 'page-2-1-1');
|
|
|
|
$this->assertEquals('Inherit', $page->ContentReviewType);
|
|
|
|
$this->assertFalse($page->getOptions());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetOptionObjectFromDeeplyInheritedPage() {
|
|
|
|
$page = $this->objFromFixture('Page', 'page-3-1-1-1');
|
|
|
|
$this->assertEquals('Inherit', $page->ContentReviewType);
|
|
|
|
$this->assertInstanceOf('SiteConfig', $page->getOptions());
|
|
|
|
}
|
|
|
|
|
2014-02-24 01:38:16 +01:00
|
|
|
public function testGetSettingsObjectFromInheritPage() {
|
|
|
|
$page = $this->objFromFixture('Page', 'page-1-1');
|
|
|
|
$this->assertEquals('Inherit', $page->ContentReviewType);
|
2014-02-24 09:10:10 +01:00
|
|
|
$this->assertEquals($this->objFromFixture('Page', 'page-1'), $page->getOptions());
|
2014-02-24 01:38:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetSettingsObjectFromInheritedRootPage() {
|
|
|
|
$page = $this->objFromFixture('Page', 'inherit');
|
|
|
|
$this->assertEquals('Inherit', $page->ContentReviewType);
|
2014-02-24 09:10:10 +01:00
|
|
|
$this->assertEquals($this->objFromFixture('SiteConfig', 'default'), $page->getOptions());
|
2014-02-24 01:38:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetNextReviewDateFromCustomSettings() {
|
|
|
|
$page = $this->objFromFixture('Page', 'custom');
|
2014-02-24 09:17:09 +01:00
|
|
|
$date = $page->getReviewDate();
|
2014-02-24 01:38:16 +01:00
|
|
|
$this->assertEquals('2010-02-01', $date->format('Y-m-d'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetNextReviewDateFromSiteConfigInheritedSetting() {
|
2014-02-24 08:19:44 +01:00
|
|
|
$page = $this->objFromFixture('Page', 'inherit');
|
2014-02-24 09:17:09 +01:00
|
|
|
$nextReviewDate = $page->getReviewDate();
|
2014-02-24 01:38:16 +01:00
|
|
|
|
2014-02-24 08:19:44 +01:00
|
|
|
$this->assertInstanceOf('Date', $nextReviewDate);
|
|
|
|
$expected = $this->addDaysToDate(SS_Datetime::now(), $this->objFromFixture('SiteConfig', 'default')->ReviewPeriodDays);
|
|
|
|
$this->assertEquals($expected , $nextReviewDate->format('Y-m-d'));
|
2014-02-24 01:38:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetNextReviewDateFromPageInheritedSetting() {
|
2014-02-24 08:19:44 +01:00
|
|
|
$page = $this->objFromFixture('Page', 'page-1-1');
|
2014-02-24 09:17:09 +01:00
|
|
|
$nextReviewDate = $page->getReviewDate();
|
2014-02-24 01:38:16 +01:00
|
|
|
|
|
|
|
$this->assertInstanceOf('Date', $nextReviewDate);
|
2014-02-24 08:19:44 +01:00
|
|
|
// It should be the same as the parents reviewdate
|
|
|
|
$expected = $this->objFromFixture('Page', 'page-1')->NextReviewDate;
|
|
|
|
$this->assertEquals($expected, $nextReviewDate->format('Y-m-d'));
|
2014-02-24 01:38:16 +01:00
|
|
|
}
|
|
|
|
|
2014-02-24 08:19:44 +01:00
|
|
|
public function testUpdateNextReviewDateFromCustomToDisabled() {
|
|
|
|
$page = $this->objFromFixture('Page', 'custom');
|
|
|
|
// before write()
|
|
|
|
$this->assertEquals('2010-02-01', $page->NextReviewDate);
|
|
|
|
|
|
|
|
// Change and write
|
|
|
|
$page->ContentReviewType = 'Disabled';
|
|
|
|
$page->write();
|
|
|
|
|
|
|
|
// clear cache
|
|
|
|
DataObject::flush_and_destroy_cache();
|
|
|
|
unset($page);
|
|
|
|
|
|
|
|
// After write()
|
|
|
|
$page = $this->objFromFixture('Page', 'custom');
|
|
|
|
$this->assertNull($page->NextReviewDate);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateNextReviewDateFromDisabledToCustom() {
|
|
|
|
$page = $this->objFromFixture('Page', 'disabled');
|
|
|
|
// before
|
|
|
|
$this->assertNull($page->NextReviewDate);
|
|
|
|
|
|
|
|
// Change and write
|
|
|
|
$page->ContentReviewType = 'Custom';
|
|
|
|
$page->ReviewPeriodDays = '7';
|
|
|
|
$page->write();
|
|
|
|
// clear cache
|
|
|
|
DataObject::flush_and_destroy_cache();
|
|
|
|
unset($page);
|
|
|
|
|
|
|
|
// After write()
|
|
|
|
$page = $this->objFromFixture('Page', 'disabled');
|
|
|
|
$expected = date('Y-m-d', strtotime('+ '.$page->ReviewPeriodDays.' days'));
|
|
|
|
$this->assertEquals($expected, $page->NextReviewDate);
|
|
|
|
}
|
2014-02-24 01:38:16 +01:00
|
|
|
|
2014-02-24 08:19:44 +01:00
|
|
|
public function testParentChangedOptionsAndChildShouldToo() {
|
|
|
|
$parentPage = $this->objFromFixture('Page', 'page-1');
|
|
|
|
$childPage = $this->objFromFixture('Page', 'page-1-1');
|
|
|
|
|
|
|
|
// BEFORE: parent page have a period of five days, so childPage should have a
|
|
|
|
// review date LastEdited + 5 days
|
|
|
|
$expected = $this->addDaysToDate($childPage->obj('LastEdited'), $parentPage->ReviewPeriodDays);
|
|
|
|
$this->assertEquals($parentPage->NextReviewDate, $childPage->NextReviewDate);
|
|
|
|
|
|
|
|
$oldChildDate = $childPage->NextReviewDate;
|
|
|
|
// But if we change the parent page ReviewPeriodDays to 10, the childs should
|
|
|
|
// change as well
|
|
|
|
$parentPage->ReviewPeriodDays = 10;
|
|
|
|
$parentPage->write();
|
|
|
|
|
|
|
|
// Flush all the caches!
|
|
|
|
DataObject::flush_and_destroy_cache();
|
|
|
|
|
|
|
|
$parentPage = $this->objFromFixture('Page', 'page-1');
|
|
|
|
$childPage = $this->objFromFixture('Page', 'page-1-1');
|
|
|
|
|
2014-02-26 23:07:34 +01:00
|
|
|
// AFTER: parent page have a period of 10 days, so childPage should have a
|
|
|
|
// review date now + 10 days
|
2014-02-24 08:19:44 +01:00
|
|
|
$this->assertNotEquals($oldChildDate, $childPage->NextReviewDate);
|
2014-02-26 23:07:34 +01:00
|
|
|
$this->assertEquals($this->addDaysToDate(date('Y-m-d'), 10), $childPage->NextReviewDate);
|
2014-02-24 08:19:44 +01:00
|
|
|
$this->assertEquals($parentPage->NextReviewDate, $childPage->NextReviewDate);
|
|
|
|
}
|
2014-02-24 01:38:16 +01:00
|
|
|
|
2014-02-24 08:19:44 +01:00
|
|
|
// helper method for this test class
|
|
|
|
private function addDaysToDate($date, $days, $format='Y-m-d') {
|
2014-02-26 23:07:34 +01:00
|
|
|
if(is_object($date)) {
|
|
|
|
$sec = strtotime('+ '. $days .' days', $date->format('U'));
|
|
|
|
} else {
|
|
|
|
$sec = strtotime('+ '. $days .' days', strtotime($date));
|
|
|
|
}
|
2014-02-24 08:19:44 +01:00
|
|
|
return date($format, $sec);
|
|
|
|
}
|
2014-02-24 01:38:16 +01:00
|
|
|
}
|