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

BlogPostNotificationsTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 53
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B testUpdateNotificationRecipients() 0 25 3
A testUpdateNotificationSubject() 0 18 2
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