1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\CommentNotifications\Tests; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Dev\SapphireTest; |
6
|
|
|
use SilverStripe\Core\Config\Config; |
7
|
|
|
use SilverStripe\Comments\Model\Comment; |
8
|
|
|
use SilverStripe\Security\Member; |
9
|
|
|
use SilverStripe\Control\Email\Email; |
10
|
|
|
use SilverStripe\CommentNotifications\Tests\Model\CommentNotifiableTestDataObject; |
11
|
|
|
|
12
|
|
|
class CommentNotifiableTest extends SapphireTest |
13
|
|
|
{ |
14
|
|
|
protected static $fixture_file = 'CommentNotifications.yml'; |
15
|
|
|
|
16
|
|
|
protected $oldhost = null; |
17
|
|
|
|
18
|
|
|
protected static $extra_dataobjects = [ |
19
|
|
|
CommentNotifiableTestDataObject::class |
20
|
|
|
]; |
21
|
|
|
|
22
|
|
|
protected function setUp() |
23
|
|
|
{ |
24
|
|
|
parent::setUp(); |
25
|
|
|
|
26
|
|
|
Config::modify()->set(Email::class, 'admin_email', '[email protected]'); |
27
|
|
|
|
28
|
|
|
$this->oldhost = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null; |
29
|
|
|
$_SERVER['HTTP_HOST'] = 'www.mysite.com'; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
protected function tearDown() |
33
|
|
|
{ |
34
|
|
|
$_SERVER['HTTP_HOST'] = $this->oldhost; |
35
|
|
|
|
36
|
|
|
parent::tearDown(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testGetRecipients() |
40
|
|
|
{ |
41
|
|
|
$comment1 = $this->objFromFixture(Comment::class, 'comment1'); |
42
|
|
|
$comment2 = $this->objFromFixture(Comment::class, 'comment2'); |
43
|
|
|
$item1 = $this->objFromFixture(CommentNotifiableTestDataObject::class, 'item1'); |
44
|
|
|
$item2 = $this->objFromFixture(CommentNotifiableTestDataObject::class, 'item2'); |
45
|
|
|
|
46
|
|
|
$this->assertEquals(['[email protected]', '[email protected]'], $item1->notificationRecipients($comment1)); |
47
|
|
|
$this->assertEquals(['[email protected]'], $item2->notificationRecipients($comment2)); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testNotificationSubject() |
51
|
|
|
{ |
52
|
|
|
$recipient = $this->objFromFixture(Member::class, 'author'); |
53
|
|
|
$comment1 = $this->objFromFixture(Comment::class, 'comment1'); |
54
|
|
|
$comment2 = $this->objFromFixture(Comment::class, 'comment2'); |
55
|
|
|
$item1 = $this->objFromFixture(CommentNotifiableTestDataObject::class, 'item1'); |
56
|
|
|
$item2 = $this->objFromFixture(CommentNotifiableTestDataObject::class, 'item2'); |
57
|
|
|
|
58
|
|
|
$this->assertEquals('A new comment has been posted', $item1->notificationSubject($comment1, $recipient)); |
59
|
|
|
$this->assertEquals('A new comment has been posted', $item2->notificationSubject($comment2, $recipient)); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testNotificationSender() |
63
|
|
|
{ |
64
|
|
|
$comment1 = $this->objFromFixture(Comment::class, 'comment1'); |
65
|
|
|
$author = $this->objFromFixture(Member::class, 'author'); |
66
|
|
|
$item1 = $this->objFromFixture(CommentNotifiableTestDataObject::class, 'item1'); |
67
|
|
|
|
68
|
|
|
$this->assertEquals('[email protected]', $item1->notificationSender($comment1, $author)); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|