2016-01-25 12:23:27 +01:00
|
|
|
<?php
|
|
|
|
|
2017-01-26 09:28:42 +01:00
|
|
|
namespace SilverStripe\Blog\Tests;
|
|
|
|
|
2017-01-16 20:58:00 +01:00
|
|
|
use SilverStripe\Blog\Model\BlogPost;
|
2018-04-06 00:22:58 +02:00
|
|
|
use SilverStripe\CommentNotifications\Extensions\CommentNotifier;
|
|
|
|
use SilverStripe\Comments\Model\Comment;
|
2016-12-15 04:41:49 +01:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
|
2016-01-25 12:23:27 +01:00
|
|
|
class BlogPostNotificationsTest extends SapphireTest
|
|
|
|
{
|
2017-01-26 09:28:42 +01:00
|
|
|
protected static $fixture_file = 'blog.yml';
|
2016-01-25 12:23:27 +01:00
|
|
|
|
|
|
|
public function testUpdateNotificationRecipients()
|
|
|
|
{
|
2018-04-06 00:22:58 +02:00
|
|
|
if (!class_exists(CommentNotifier::class)) {
|
2016-01-25 12:23:27 +01:00
|
|
|
$this->markTestSkipped('Comments Notification module is not installed');
|
|
|
|
}
|
|
|
|
|
2017-07-04 19:01:39 +02:00
|
|
|
$blogPost = $this->objFromFixture(BlogPost::class, 'PostC');
|
2018-04-06 00:22:58 +02:00
|
|
|
$comment = new Comment();
|
2016-01-25 12:23:27 +01:00
|
|
|
$comment->Comment = 'This is a comment';
|
|
|
|
$comment->write();
|
|
|
|
$recipients = $blogPost->notificationRecipients(
|
|
|
|
$comment
|
|
|
|
)->toArray();
|
|
|
|
|
2017-09-14 00:59:01 +02:00
|
|
|
$segments = [];
|
2016-01-25 12:23:27 +01:00
|
|
|
foreach ($recipients as $recipient) {
|
|
|
|
array_push($segments, $recipient->URLSegment);
|
|
|
|
}
|
|
|
|
|
|
|
|
sort($segments);
|
2016-12-15 04:41:49 +01:00
|
|
|
$this->assertEquals(
|
2017-09-14 00:59:01 +02:00
|
|
|
['blog-contributor', 'blog-editor', 'blog-writer'],
|
2016-12-15 04:41:49 +01:00
|
|
|
$segments
|
|
|
|
);
|
2016-01-25 12:23:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateNotificationSubject()
|
|
|
|
{
|
2018-04-06 00:22:58 +02:00
|
|
|
if (!class_exists(CommentNotifier::class)) {
|
2016-01-25 12:23:27 +01:00
|
|
|
$this->markTestSkipped('Comments Notification module is not installed');
|
|
|
|
}
|
2017-07-04 19:01:39 +02:00
|
|
|
$blogPost = $this->objFromFixture(BlogPost::class, 'PostC');
|
2018-04-06 00:22:58 +02:00
|
|
|
$comment = new 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
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|