|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class CommentNotifierTest 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
|
|
|
Email::set_mailer(new EmailTest_Mailer()); |
|
|
|
|
|
|
16
|
|
|
Config::nest(); |
|
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
|
|
|
Email::set_mailer(new Mailer()); |
|
|
|
|
|
|
26
|
|
|
parent::tearDown(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function testSendEmail() { |
|
30
|
|
|
$author = $this->objFromFixture('Member', 'author'); |
|
31
|
|
|
$item1 = $this->objFromFixture('CommentNotifiableTest_DataObject', 'item1'); |
|
32
|
|
|
$item2 = $this->objFromFixture('CommentNotifiableTest_DataObject', 'item2'); |
|
33
|
|
|
$comment1 = $this->objFromFixture('Comment', 'comment1'); |
|
34
|
|
|
$comment2 = $this->objFromFixture('Comment', 'comment2'); |
|
35
|
|
|
$comment3 = $this->objFromFixture('Comment', 'comment3'); |
|
36
|
|
|
$controller = new CommentNotifierTest_Controller(); |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
// Commen 1 |
|
40
|
|
|
$result = $controller->notifyCommentRecipient($comment1, $item1, $author); |
|
|
|
|
|
|
41
|
|
|
$this->assertEquals('[email protected]', $result['to']); |
|
|
|
|
|
|
42
|
|
|
$this->assertEquals('[email protected]', $result['from']); |
|
|
|
|
|
|
43
|
|
|
$this->assertEquals('A new comment has been posted', $result['subject']); |
|
|
|
|
|
|
44
|
|
|
$this->assertContains('<li>Bob Bobberson</li>', $result['content']); |
|
45
|
|
|
$this->assertContains('<li>[email protected]</li>', $result['content']); |
|
46
|
|
|
$this->assertContains('<blockquote>Hey what a lovely comment</blockquote>', $result['content']); |
|
47
|
|
|
$this->assertContains( |
|
48
|
|
|
'You can view or moderate this comment at <a href="http://www.mysite.com/item1#comment-' . |
|
49
|
|
|
$comment1->ID . '">An Object</a>', |
|
50
|
|
|
$result['content'] |
|
51
|
|
|
); |
|
52
|
|
|
|
|
53
|
|
|
// Comment 2 |
|
54
|
|
|
$result = $controller->notifyCommentRecipient($comment2, $item2, $author); |
|
|
|
|
|
|
55
|
|
|
$this->assertEquals('[email protected]', $result['to']); |
|
|
|
|
|
|
56
|
|
|
$this->assertEquals('[email protected]', $result['from']); |
|
|
|
|
|
|
57
|
|
|
$this->assertEquals('A new comment has been posted', $result['subject']); |
|
|
|
|
|
|
58
|
|
|
$this->assertContains('<li>Secret</li>', $result['content']); |
|
59
|
|
|
$this->assertContains('<li>[email protected]</li>', $result['content']); |
|
60
|
|
|
$this->assertContains('<blockquote>I don't want to disclose my details</blockquote>', $result['content']); |
|
61
|
|
|
$this->assertContains( |
|
62
|
|
|
'You can view or moderate this comment at <a href="http://www.mysite.com/item2#comment-' . |
|
63
|
|
|
$comment2->ID . '">Another One</a>', |
|
64
|
|
|
$result['content'] |
|
65
|
|
|
); |
|
66
|
|
|
|
|
67
|
|
|
// Comment 3 |
|
68
|
|
|
$result = $controller->notifyCommentRecipient($comment3, $item1, $author); |
|
|
|
|
|
|
69
|
|
|
$this->assertEquals('[email protected]', $result['to']); |
|
|
|
|
|
|
70
|
|
|
$this->assertEquals('[email protected]', $result['from']); |
|
|
|
|
|
|
71
|
|
|
$this->assertEquals('A new comment has been posted', $result['subject']); |
|
|
|
|
|
|
72
|
|
|
$this->assertContains('<li>Anonymous</li>', $result['content']); |
|
73
|
|
|
$this->assertContains('<li>[email protected]</li>', $result['content']); |
|
74
|
|
|
$this->assertContains('<blockquote>I didn't log in</blockquote>', $result['content']); |
|
75
|
|
|
$this->assertContains( |
|
76
|
|
|
'You can view or moderate this comment at <a href="http://www.mysite.com/item1#comment-' . |
|
77
|
|
|
$comment3->ID . '">An Object</a>', |
|
78
|
|
|
$result['content'] |
|
79
|
|
|
); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
class CommentNotifierTest_Controller extends Controller implements TestOnly { |
|
|
|
|
|
|
84
|
|
|
private static $extensions = array( |
|
|
|
|
|
|
85
|
|
|
'CommentNotifier' |
|
86
|
|
|
); |
|
87
|
|
|
} |
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.