1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class CommentNotifiableTest extends SapphireTest { |
|
|
|
|
4
|
|
|
|
5
|
|
|
protected static $fixture_file = 'CommentNotifications.yml'; |
6
|
|
|
|
7
|
|
|
protected $oldhost = null; |
8
|
|
|
|
9
|
|
|
protected $extraDataObjects = array( |
10
|
|
|
'CommentNotifiableTest_DataObject' |
11
|
|
|
); |
12
|
|
|
|
13
|
|
View Code Duplication |
public function setUp() { |
|
|
|
|
14
|
|
|
parent::setUp(); |
15
|
|
|
Config::nest(); |
16
|
|
|
|
17
|
|
|
Config::inst()->update('Email', 'admin_email', '[email protected]'); |
18
|
|
|
$this->oldhost = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null; |
19
|
|
|
$_SERVER['HTTP_HOST'] = 'www.mysite.com'; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function tearDown() { |
|
|
|
|
23
|
|
|
$_SERVER['HTTP_HOST'] = $this->oldhost; |
24
|
|
|
Config::unnest(); |
25
|
|
|
parent::tearDown(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testGetRecipients() { |
29
|
|
|
$comment1 = $this->objFromFixture('Comment', 'comment1'); |
30
|
|
|
$comment2 = $this->objFromFixture('Comment', 'comment2'); |
31
|
|
|
$item1 = $this->objFromFixture('CommentNotifiableTest_DataObject', 'item1'); |
32
|
|
|
$item2 = $this->objFromFixture('CommentNotifiableTest_DataObject', 'item2'); |
33
|
|
|
$this->assertEquals(array('[email protected]'), $item1->notificationRecipients($comment1)->column('Email')); |
|
|
|
|
34
|
|
|
$this->assertEquals(array('[email protected]'), $item2->notificationRecipients($comment2)); |
|
|
|
|
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testNotificationSubject() { |
38
|
|
|
$recipient = $this->objFromFixture('Member', 'author'); |
39
|
|
|
$comment1 = $this->objFromFixture('Comment', 'comment1'); |
40
|
|
|
$comment2 = $this->objFromFixture('Comment', 'comment2'); |
41
|
|
|
$item1 = $this->objFromFixture('CommentNotifiableTest_DataObject', 'item1'); |
42
|
|
|
$item2 = $this->objFromFixture('CommentNotifiableTest_DataObject', 'item2'); |
43
|
|
|
|
44
|
|
|
$this->assertEquals('A new comment has been posted', $item1->notificationSubject($comment1, $recipient)); |
|
|
|
|
45
|
|
|
$this->assertEquals('A new comment has been posted', $item2->notificationSubject($comment2, $recipient)); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testNotificationSender() { |
49
|
|
|
$comment1 = $this->objFromFixture('Comment', 'comment1'); |
50
|
|
|
$author = $this->objFromFixture('Member', 'author'); |
51
|
|
|
$item1 = $this->objFromFixture('CommentNotifiableTest_DataObject', 'item1'); |
52
|
|
|
$this->assertEquals('[email protected]', $item1->notificationSender($comment1, $author)); |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @mixin CommentNotifiable |
59
|
|
|
*/ |
60
|
|
|
class CommentNotifiableTest_DataObject extends DataObject implements TestOnly { |
|
|
|
|
61
|
|
|
|
62
|
|
|
private static $db = array( |
|
|
|
|
63
|
|
|
"Title" => "Varchar(255)", |
64
|
|
|
"URLSegment" => "Varchar(255)", |
65
|
|
|
); |
66
|
|
|
|
67
|
|
|
private static $has_one = array( |
|
|
|
|
68
|
|
|
'Author' => 'Member', |
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
private static $extensions = array( |
|
|
|
|
72
|
|
|
'CommentNotifiable', |
73
|
|
|
'CommentsExtension', |
74
|
|
|
); |
75
|
|
|
|
76
|
|
|
public function notificationRecipients($comment) { |
|
|
|
|
77
|
|
|
$author = $this->Author(); |
|
|
|
|
78
|
|
|
if($author && $author->exists()) return new ArrayList(array($author)); |
79
|
|
|
return parent::notificationRecipients($comment); |
|
|
|
|
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function Link($action = false) { |
|
|
|
|
83
|
|
|
return Controller::join_links( |
84
|
|
|
Director::baseURL(), |
85
|
|
|
$this->URLSegment |
|
|
|
|
86
|
|
|
); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.