FIX Missing namespace imports, incorrect date formats and array keys

This commit is contained in:
Robbie Averill 2017-09-06 16:53:45 +12:00
parent 42fb360fb2
commit c5f9da17d0
7 changed files with 62 additions and 22 deletions

View File

@ -211,7 +211,7 @@ class SiteTreeContentReview extends DataExtension implements PermissionProvider
} }
// Failover to check on ReviewPeriodDays + LastEdited // Failover to check on ReviewPeriodDays + LastEdited
$nextReviewUnixSec = strtotime('now + ' . $options->ReviewPeriodDays . ' days'); $nextReviewUnixSec = strtotime(' + ' . $options->ReviewPeriodDays . ' days', DBDatetime::now()->getTimestamp());
$date = DBDate::create('NextReviewDate'); $date = DBDate::create('NextReviewDate');
$date->setValue($nextReviewUnixSec); $date->setValue($nextReviewUnixSec);
@ -457,17 +457,20 @@ class SiteTreeContentReview extends DataExtension implements PermissionProvider
*/ */
public function advanceReviewDate() public function advanceReviewDate()
{ {
$nextDate = false; $nextDateTimestamp = false;
$options = $this->getOptions(); $options = $this->getOptions();
if ($options && $options->ReviewPeriodDays) { if ($options && $options->ReviewPeriodDays) {
$nextDateTimestamp = strtotime('now + ' . $options->ReviewPeriodDays . ' days'); $nextDateTimestamp = strtotime(
' + ' . $options->ReviewPeriodDays . ' days',
DBDatetime::now()->getTimestamp()
);
$this->owner->NextReviewDate = DBDate::create()->setValue($nextDateTimestamp)->Format('y-MM-dd'); $this->owner->NextReviewDate = DBDate::create()->setValue($nextDateTimestamp)->Format('y-MM-dd');
$this->owner->write(); $this->owner->write();
} }
return (bool) $nextDate; return (bool) $nextDateTimestamp;
} }
/** /**
@ -554,7 +557,10 @@ class SiteTreeContentReview extends DataExtension implements PermissionProvider
// parent page change its review period // parent page change its review period
// && !$this->owner->isChanged('ContentReviewType', 2) // && !$this->owner->isChanged('ContentReviewType', 2)
if ($this->owner->isChanged('ReviewPeriodDays', 2)) { if ($this->owner->isChanged('ReviewPeriodDays', 2)) {
$nextReviewUnixSec = strtotime('now + ' . $this->owner->ReviewPeriodDays . ' days'); $nextReviewUnixSec = strtotime(
' + ' . $this->owner->ReviewPeriodDays . ' days',
DBDatetime::now()->getTimestamp()
);
$this->owner->NextReviewDate = DBDate::create()->setValue($nextReviewUnixSec)->Format('y-MM-dd'); $this->owner->NextReviewDate = DBDate::create()->setValue($nextReviewUnixSec)->Format('y-MM-dd');
} }
} }

View File

@ -161,21 +161,36 @@ class PagesDueForReviewReport extends Report
if (empty($params['ReviewDateBefore']) && empty($params['ReviewDateAfter'])) { if (empty($params['ReviewDateBefore']) && empty($params['ReviewDateAfter'])) {
// If there's no review dates set, default to all pages due for review now // If there's no review dates set, default to all pages due for review now
$nextReviewUnixSec = strtotime(' + 1 day', DBDatetime::now()->format('U')); $records = $records->where(
$records = $records->where(sprintf('"NextReviewDate" < \'%s\'', date('Y-m-d', $nextReviewUnixSec))); sprintf(
'"NextReviewDate" < \'%s\'',
DBDatetime::now()->Format('y-MM-dd')
)
);
} else { } else {
// Review date before // Review date before
if (!empty($params['ReviewDateBefore'])) { if (!empty($params['ReviewDateBefore'])) {
// TODO Get value from DateField->dataValue() once we have access to form elements here // TODO Get value from DateField->dataValue() once we have access to form elements here
$nextReviewUnixSec = strtotime(' + 1 day', strtotime($params['ReviewDateBefore'])); $nextReviewUnixSec = strtotime(
$records = $records->where(sprintf("\"NextReviewDate\" < '%s'", date('Y-m-d', $nextReviewUnixSec))); ' + 1 day',
strtotime($params['ReviewDateBefore'])
);
$records = $records->where(
sprintf(
"\"NextReviewDate\" < '%s'",
DBDatetime::create()->setValue($nextReviewUnixSec)->Format('y-MM-dd')
)
);
} }
// Review date after // Review date after
if (!empty($params['ReviewDateAfter'])) { if (!empty($params['ReviewDateAfter'])) {
// TODO Get value from DateField->dataValue() once we have access to form elements here // TODO Get value from DateField->dataValue() once we have access to form elements here
$records = $records->where( $records = $records->where(
sprintf("\"NextReviewDate\" >= '%s'", date('Y-m-d', strtotime($params['ReviewDateAfter']))) sprintf(
"\"NextReviewDate\" >= '%s'",
DBDatetime::create()->setValue(strtotime($params['ReviewDateAfter']))->Format('y-MM-dd')
)
); );
} }
} }

View File

@ -9,11 +9,11 @@
$EmailBody $EmailBody
</td> </td>
</tr> </tr>
<% loop Pages %> <% loop $Pages %>
<tr> <tr>
<td valign="top">$Title</td> <td valign="top">$Title</td>
<td><a href="{$BaseURL}admin/pages/edit/show/$ID"><%t ContentReviewEmails.REVIEWPAGELINK 'Review the page in the CMS' %></a><br /> <td><a href="{$BaseURL}admin/pages/edit/show/$ID"><%t ContentReviewEmails.REVIEWPAGELINK 'Review the page in the CMS' %></a><br />
<a href="$AbsoluteLink"><%t ContentReviewEmails.VIEWPUBLISHEDLINK View this page on the website' %></a> <a href="$AbsoluteLink"><%t ContentReviewEmails.VIEWPUBLISHEDLINK 'View this page on the website' %></a>
</td> </td>
</tr> </tr>
<% end_loop %> <% end_loop %>

View File

@ -9,6 +9,7 @@ use SilverStripe\ContentReview\Extensions\SiteTreeContentReview;
use SilverStripe\ContentReview\Extensions\ContentReviewOwner; use SilverStripe\ContentReview\Extensions\ContentReviewOwner;
use SilverStripe\ContentReview\Extensions\ContentReviewCMSExtension; use SilverStripe\ContentReview\Extensions\ContentReviewCMSExtension;
use SilverStripe\ContentReview\Extensions\ContentReviewDefaultSettings; use SilverStripe\ContentReview\Extensions\ContentReviewDefaultSettings;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse_Exception; use SilverStripe\Control\HTTPResponse_Exception;
use SilverStripe\Forms\FieldList; use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form; use SilverStripe\Forms\Form;
@ -72,7 +73,7 @@ class ContentReviewCMSPageEditControllerTest extends ContentReviewBaseTest
/** @var Member $author */ /** @var Member $author */
$author = $this->objFromFixture(Member::class, "author"); $author = $this->objFromFixture(Member::class, "author");
$this->loginAs($author); $this->logInAs($author);
/** @var Page|SiteTreeContentReview $page */ /** @var Page|SiteTreeContentReview $page */
$page = $this->objFromFixture(Page::class, "home"); $page = $this->objFromFixture(Page::class, "home");
@ -83,7 +84,7 @@ class ContentReviewCMSPageEditControllerTest extends ContentReviewBaseTest
); );
$this->get('admin/pages/edit/show/' . $page->ID); $this->get('admin/pages/edit/show/' . $page->ID);
$response = $this->post(singleton(CMSPageEditController::class)->getEditForm($page->ID)->FormAction(), $data); $response = $this->post($this->getFormAction($page), $data);
$this->assertEquals("OK", $response->getStatusDescription()); $this->assertEquals("OK", $response->getStatusDescription());
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
@ -106,7 +107,7 @@ class ContentReviewCMSPageEditControllerTest extends ContentReviewBaseTest
); );
$this->get('admin/pages/edit/show/' . $page->ID); $this->get('admin/pages/edit/show/' . $page->ID);
$response = $this->post(singleton(CMSPageEditController::class)->getEditForm($page->ID)->FormAction(), $data); $response = $this->post($this->getFormAction($page), $data);
$this->assertEquals("OK", $response->getStatusDescription()); $this->assertEquals("OK", $response->getStatusDescription());
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
@ -116,4 +117,19 @@ class ContentReviewCMSPageEditControllerTest extends ContentReviewBaseTest
$this->assertEquals($data["ReviewNotes"], $reviewLog->Note); $this->assertEquals($data["ReviewNotes"], $reviewLog->Note);
} }
/**
* Return a CMS page edit form action via using a dummy request and session
*
* @param Page $page
* @return string
*/
protected function getFormAction(Page $page)
{
$controller = singleton(CMSPageEditController::class);
$controller->setRequest(new HTTPRequest('GET', '/'));
$controller->getRequest()->setSession($this->session());
return $controller->getEditForm($page->ID)->FormAction();
}
} }

View File

@ -4,6 +4,7 @@ namespace SilverStripe\ContentReview\Tests;
use Page; use Page;
use SilverStripe\CMS\Model\SiteTree; use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\CMS\Controllers\CMSPageEditController;
use SilverStripe\ContentReview\Extensions\ContentReviewCMSExtension; use SilverStripe\ContentReview\Extensions\ContentReviewCMSExtension;
use SilverStripe\ContentReview\Extensions\ContentReviewDefaultSettings; use SilverStripe\ContentReview\Extensions\ContentReviewDefaultSettings;
use SilverStripe\ContentReview\Extensions\ContentReviewOwner; use SilverStripe\ContentReview\Extensions\ContentReviewOwner;
@ -12,6 +13,8 @@ use SilverStripe\ContentReview\Tasks\ContentReviewEmails;
use SilverStripe\Control\HTTPRequest; use SilverStripe\Control\HTTPRequest;
use SilverStripe\Dev\SapphireTest; use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\FieldType\DBDatetime; use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\Security\Group;
use SilverStripe\Security\Member;
use SilverStripe\SiteConfig\SiteConfig; use SilverStripe\SiteConfig\SiteConfig;
/** /**
@ -68,11 +71,11 @@ class ContentReviewNotificationTest extends SapphireTest
$this->assertNotNull($email, "Email haven't been sent."); $this->assertNotNull($email, "Email haven't been sent.");
$this->assertContains( $this->assertContains(
"<h1>$Subject</h1><p>There are $PagesCount pages that are due for review today by you, $ToFirstName.</p><p>This email was sent to $ToEmail</p>", "<h1>$Subject</h1><p>There are $PagesCount pages that are due for review today by you, $ToFirstName.</p><p>This email was sent to $ToEmail</p>",
$email['htmlContent'] $email['HtmlContent']
); );
$this->assertContains('Staff', $email['htmlContent']); $this->assertContains('Staff', $email['HtmlContent']);
$this->assertContains('Contact Us', $email['htmlContent']); $this->assertContains('Contact Us', $email['HtmlContent']);
$this->assertContains('Contact Us Child', $email['htmlContent']); $this->assertContains('Contact Us Child', $email['HtmlContent']);
DBDatetime::clear_mock_now(); DBDatetime::clear_mock_now();
} }

View File

@ -48,8 +48,8 @@ class ContentReviewReportTest extends FunctionalTest
$report->title(); $report->title();
$results = $report->sourceRecords(array( $results = $report->sourceRecords(array(
"ReviewDateAfter" => "01/01/2010", "ReviewDateAfter" => "2010-01-01",
"ReviewDateBefore" => "12/12/2010", "ReviewDateBefore" => "2010-12-12",
)); ));
$this->assertEquals(array( $this->assertEquals(array(

View File

@ -170,7 +170,7 @@ class ContentReviewSettingsTest extends SapphireTest
$page = $this->objFromFixture(Page::class, "inherit"); $page = $this->objFromFixture(Page::class, "inherit");
$this->assertEquals("Inherit", $page->ContentReviewType); $this->assertEquals("Inherit", $page->ContentReviewType);
$this->assertEquals($this->objFromFixture(SiteConfig::class, "default"), $page->getOptions()); $this->assertEquals($this->objFromFixture(SiteConfig::class, "default")->ID, $page->getOptions()->ID);
} }
public function testGetNextReviewDateFromCustomSettings() public function testGetNextReviewDateFromCustomSettings()