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

BlogPostNotificationsTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 50
rs 10
c 0
b 0
f 0
1
<?php
2
3
use SilverStripe\Blog\Model\BlogPost;
4
use SilverStripe\Dev\SapphireTest;
5
6
class BlogPostNotificationsTest extends SapphireTest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
{
8
    /**
9
     * {@inheritDoc}
10
     * @var string
11
     */
12
    public static $fixture_file = 'blog.yml';
13
14
    public function testUpdateNotificationRecipients()
15
    {
16
        if (!class_exists('CommentNotifier')) {
17
            $this->markTestSkipped('Comments Notification module is not installed');
18
        }
19
20
        $blogPost = $this->objFromFixture(BlogPost::class, 'PostC');
21
        $comment = new \SilverStripe\Comments\Model\Comment();
22
        $comment->Comment = 'This is a comment';
23
        $comment->write();
24
        $recipients = $blogPost->notificationRecipients(
25
            $comment
26
        )->toArray();
27
28
        $segments = array();
29
        foreach ($recipients as $recipient) {
30
            array_push($segments, $recipient->URLSegment);
31
        }
32
33
        sort($segments);
34
        $this->assertEquals(
35
            array('blog-contributor', 'blog-editor', 'blog-writer'),
36
            $segments
37
        );
38
    }
39
40
    public function testUpdateNotificationSubject()
41
    {
42
        if (!class_exists('CommentNotifier')) {
43
            $this->markTestSkipped('Comments Notification module is not installed');
44
        }
45
        $blogPost = $this->objFromFixture(BlogPost::class, 'PostC');
46
        $comment = new use SilverStripe\Comments\Model\Comment();
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_USE
Loading history...
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