Completed
Pull Request — master (#421)
by Robbie
02:52
created

testUpdateNotificationSubject()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

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