|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverStripe\Blog\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\Blog\Model\BlogPost; |
|
6
|
|
|
use SilverStripe\CommentNotifications\Extensions\CommentNotifier; |
|
7
|
|
|
use SilverStripe\Comments\Model\Comment; |
|
8
|
|
|
use SilverStripe\Dev\SapphireTest; |
|
9
|
|
|
|
|
10
|
|
|
class BlogPostNotificationsTest extends SapphireTest |
|
11
|
|
|
{ |
|
12
|
|
|
protected static $fixture_file = 'blog.yml'; |
|
13
|
|
|
|
|
14
|
|
|
public function testUpdateNotificationRecipients() |
|
15
|
|
|
{ |
|
16
|
|
|
if (!class_exists(CommentNotifier::class)) { |
|
17
|
|
|
$this->markTestSkipped('Comments Notification module is not installed'); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
$blogPost = $this->objFromFixture(BlogPost::class, 'PostC'); |
|
21
|
|
|
$comment = new Comment(); |
|
22
|
|
|
$comment->Comment = 'This is a comment'; |
|
23
|
|
|
$comment->write(); |
|
24
|
|
|
$recipients = $blogPost->notificationRecipients( |
|
25
|
|
|
$comment |
|
26
|
|
|
)->toArray(); |
|
27
|
|
|
|
|
28
|
|
|
$segments = []; |
|
29
|
|
|
foreach ($recipients as $recipient) { |
|
30
|
|
|
array_push($segments, $recipient->URLSegment); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
sort($segments); |
|
34
|
|
|
$this->assertEquals( |
|
35
|
|
|
['blog-contributor', 'blog-editor', 'blog-writer'], |
|
36
|
|
|
$segments |
|
37
|
|
|
); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function testUpdateNotificationSubject() |
|
41
|
|
|
{ |
|
42
|
|
|
if (!class_exists(CommentNotifier::class)) { |
|
43
|
|
|
$this->markTestSkipped('Comments Notification module is not installed'); |
|
44
|
|
|
} |
|
45
|
|
|
$blogPost = $this->objFromFixture(BlogPost::class, 'PostC'); |
|
46
|
|
|
$comment = new Comment(); |
|
47
|
|
|
$comment->Comment = 'This is a comment'; |
|
48
|
|
|
$comment->write(); |
|
49
|
|
|
$recipients = $blogPost->notificationRecipients( |
|
50
|
|
|
$comment |
|
51
|
|
|
)->toArray(); |
|
52
|
|
|
$subject = $blogPost->notificationSubject($comment, $recipients[0]); |
|
53
|
|
|
$this->assertEquals( |
|
54
|
|
|
'A new comment has been posted on Third Post', |
|
55
|
|
|
$subject |
|
56
|
|
|
); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|