2016-01-25 12:23:27 +01:00
|
|
|
<?php
|
|
|
|
|
2017-01-16 20:58:00 +01:00
|
|
|
use SilverStripe\Blog\Model\BlogPost;
|
2016-12-15 04:41:49 +01:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
|
2016-01-25 12:23:27 +01:00
|
|
|
class BlogPostNotificationsTest extends SapphireTest
|
|
|
|
{
|
|
|
|
/**
|
2016-12-15 04:41:49 +01:00
|
|
|
* {@inheritDoc}
|
2016-01-25 12:23:27 +01:00
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public static $fixture_file = 'blog.yml';
|
|
|
|
|
|
|
|
public function testUpdateNotificationRecipients()
|
|
|
|
{
|
|
|
|
if (!class_exists('CommentNotifier')) {
|
|
|
|
$this->markTestSkipped('Comments Notification module is not installed');
|
|
|
|
}
|
|
|
|
|
2017-01-16 20:58:00 +01:00
|
|
|
$blogPost = $this->objFromFixture(BlogPost::class, 'PostC');
|
|
|
|
$comment = new \SilverStripe\Comments\Model\Comment();
|
2016-01-25 12:23:27 +01:00
|
|
|
$comment->Comment = 'This is a comment';
|
|
|
|
$comment->write();
|
|
|
|
$recipients = $blogPost->notificationRecipients(
|
|
|
|
$comment
|
|
|
|
)->toArray();
|
|
|
|
|
|
|
|
$segments = array();
|
|
|
|
foreach ($recipients as $recipient) {
|
|
|
|
array_push($segments, $recipient->URLSegment);
|
|
|
|
}
|
|
|
|
|
|
|
|
sort($segments);
|
2016-12-15 04:41:49 +01:00
|
|
|
$this->assertEquals(
|
|
|
|
array('blog-contributor', 'blog-editor', 'blog-writer'),
|
|
|
|
$segments
|
|
|
|
);
|
2016-01-25 12:23:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateNotificationSubject()
|
|
|
|
{
|
|
|
|
if (!class_exists('CommentNotifier')) {
|
|
|
|
$this->markTestSkipped('Comments Notification module is not installed');
|
|
|
|
}
|
2017-01-16 20:58:00 +01:00
|
|
|
$blogPost = $this->objFromFixture(BlogPost::class, 'PostC');
|
|
|
|
$comment = new use SilverStripe\Comments\Model\Comment();
|
2016-01-25 12:23:27 +01:00
|
|
|
$comment->Comment = 'This is a comment';
|
|
|
|
$comment->write();
|
|
|
|
$recipients = $blogPost->notificationRecipients(
|
|
|
|
$comment
|
|
|
|
)->toArray();
|
|
|
|
$subject = $blogPost->notificationSubject($comment, $recipients[0]);
|
|
|
|
$this->assertEquals(
|
|
|
|
'A new comment has been posted on Third Post',
|
|
|
|
$subject
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|