Refactorings

This commit is contained in:
Stig Lindqvist 2014-02-24 21:17:09 +13:00
parent 638d2fc331
commit 32378bb269
2 changed files with 13 additions and 7 deletions

View File

@ -66,10 +66,16 @@ class SiteTreeContentReview extends DataExtension implements PermissionProvider
* @param SiteTree $page * @param SiteTree $page
* @return Date | false - returns false if the content review have disabled * @return Date | false - returns false if the content review have disabled
*/ */
public function getReviewDate(DataObject $options, SiteTree $page) { public function getReviewDate(SiteTree $page=null) {
if($page === null) {
$page = $this->owner;
}
if($page->obj('NextReviewDate')->exists()) { if($page->obj('NextReviewDate')->exists()) {
return $page->obj('NextReviewDate'); return $page->obj('NextReviewDate');
} }
$options = $this->owner->getOptions();
if(!$options) { if(!$options) {
return false; return false;
} }
@ -385,10 +391,10 @@ class SiteTreeContentReview extends DataExtension implements PermissionProvider
$this->owner->NextReviewDate = null; $this->owner->NextReviewDate = null;
// Take from Parent page // Take from Parent page
if($settings && $this->owner->parent()->exists()) { if($settings && $this->owner->parent()->exists()) {
$nextDate = $this->getReviewDate($settings, $this->owner->parent()); $nextDate = $this->getReviewDate($this->owner->parent());
// Inherit from siteconfig // Inherit from siteconfig
} elseif($settings instanceof SiteConfig) { } elseif($settings instanceof SiteConfig) {
$nextDate = $this->getReviewDate($settings, $this->owner); $nextDate = $this->getReviewDate();
// No setting, parent disabled // No setting, parent disabled
} else { } else {
$nextDate = null; $nextDate = null;
@ -400,7 +406,7 @@ class SiteTreeContentReview extends DataExtension implements PermissionProvider
// No review date provided, use today + period // No review date provided, use today + period
} else { } else {
$this->owner->NextReviewDate = null; $this->owner->NextReviewDate = null;
$nextDate = $this->getReviewDate($settings, $this->owner); $nextDate = $this->getReviewDate();
} }
} }
if(is_object($nextDate)) { if(is_object($nextDate)) {

View File

@ -56,13 +56,13 @@ class ContentReviewSettingsTest extends SapphireTest {
public function testGetNextReviewDateFromCustomSettings() { public function testGetNextReviewDateFromCustomSettings() {
$page = $this->objFromFixture('Page', 'custom'); $page = $this->objFromFixture('Page', 'custom');
$date = $page->getReviewDate($page->getOptions(), $page); $date = $page->getReviewDate();
$this->assertEquals('2010-02-01', $date->format('Y-m-d')); $this->assertEquals('2010-02-01', $date->format('Y-m-d'));
} }
public function testGetNextReviewDateFromSiteConfigInheritedSetting() { public function testGetNextReviewDateFromSiteConfigInheritedSetting() {
$page = $this->objFromFixture('Page', 'inherit'); $page = $this->objFromFixture('Page', 'inherit');
$nextReviewDate = $page->getReviewDate($page->getOptions(), $page); $nextReviewDate = $page->getReviewDate();
$this->assertInstanceOf('Date', $nextReviewDate); $this->assertInstanceOf('Date', $nextReviewDate);
$expected = $this->addDaysToDate(SS_Datetime::now(), $this->objFromFixture('SiteConfig', 'default')->ReviewPeriodDays); $expected = $this->addDaysToDate(SS_Datetime::now(), $this->objFromFixture('SiteConfig', 'default')->ReviewPeriodDays);
@ -71,7 +71,7 @@ class ContentReviewSettingsTest extends SapphireTest {
public function testGetNextReviewDateFromPageInheritedSetting() { public function testGetNextReviewDateFromPageInheritedSetting() {
$page = $this->objFromFixture('Page', 'page-1-1'); $page = $this->objFromFixture('Page', 'page-1-1');
$nextReviewDate = $page->getReviewDate($page->getOptions(), $page); $nextReviewDate = $page->getReviewDate();
$this->assertInstanceOf('Date', $nextReviewDate); $this->assertInstanceOf('Date', $nextReviewDate);
// It should be the same as the parents reviewdate // It should be the same as the parents reviewdate