@@ -11,36 +11,36 @@ |
||
| 11 | 11 | |
| 12 | 12 | class CommentNotifiableTestDataObject extends DataObject implements TestOnly |
| 13 | 13 | { |
| 14 | - private static $db = [ |
|
| 15 | - "Title" => "Varchar(255)", |
|
| 16 | - "URLSegment" => "Varchar(255)", |
|
| 17 | - ]; |
|
| 18 | - |
|
| 19 | - private static $has_one = [ |
|
| 20 | - 'Author' => 'SilverStripe\Security\Member' |
|
| 21 | - ]; |
|
| 22 | - |
|
| 23 | - private static $extensions = [ |
|
| 24 | - CommentNotifiable::class, |
|
| 25 | - CommentsExtension::class |
|
| 26 | - ]; |
|
| 27 | - |
|
| 28 | - private static $table_name = 'CommentNotifiableTestDataObject'; |
|
| 29 | - |
|
| 30 | - public function updateNotificationRecipients(&$list, $comment) |
|
| 31 | - { |
|
| 32 | - $author = $this->Author(); |
|
| 33 | - |
|
| 34 | - if ($author && $author->exists()) { |
|
| 35 | - $list[] = $author->Email; |
|
| 36 | - } |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - public function Link($action = false) |
|
| 40 | - { |
|
| 41 | - return Controller::join_links( |
|
| 42 | - Director::baseURL(), |
|
| 43 | - $this->URLSegment |
|
| 44 | - ); |
|
| 45 | - } |
|
| 14 | + private static $db = [ |
|
| 15 | + "Title" => "Varchar(255)", |
|
| 16 | + "URLSegment" => "Varchar(255)", |
|
| 17 | + ]; |
|
| 18 | + |
|
| 19 | + private static $has_one = [ |
|
| 20 | + 'Author' => 'SilverStripe\Security\Member' |
|
| 21 | + ]; |
|
| 22 | + |
|
| 23 | + private static $extensions = [ |
|
| 24 | + CommentNotifiable::class, |
|
| 25 | + CommentsExtension::class |
|
| 26 | + ]; |
|
| 27 | + |
|
| 28 | + private static $table_name = 'CommentNotifiableTestDataObject'; |
|
| 29 | + |
|
| 30 | + public function updateNotificationRecipients(&$list, $comment) |
|
| 31 | + { |
|
| 32 | + $author = $this->Author(); |
|
| 33 | + |
|
| 34 | + if ($author && $author->exists()) { |
|
| 35 | + $list[] = $author->Email; |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + public function Link($action = false) |
|
| 40 | + { |
|
| 41 | + return Controller::join_links( |
|
| 42 | + Director::baseURL(), |
|
| 43 | + $this->URLSegment |
|
| 44 | + ); |
|
| 45 | + } |
|
| 46 | 46 | } |
@@ -12,102 +12,102 @@ |
||
| 12 | 12 | |
| 13 | 13 | class CommentNotifierTest extends SapphireTest |
| 14 | 14 | { |
| 15 | - protected static $fixture_file = 'CommentNotifications.yml'; |
|
| 15 | + protected static $fixture_file = 'CommentNotifications.yml'; |
|
| 16 | 16 | |
| 17 | - protected $oldhost = null; |
|
| 17 | + protected $oldhost = null; |
|
| 18 | 18 | |
| 19 | - protected static $extra_dataobjects = [ |
|
| 20 | - CommentNotifiableTestDataObject::class |
|
| 21 | - ]; |
|
| 19 | + protected static $extra_dataobjects = [ |
|
| 20 | + CommentNotifiableTestDataObject::class |
|
| 21 | + ]; |
|
| 22 | 22 | |
| 23 | - protected static $extra_controllers = [ |
|
| 24 | - CommentNotifierTestController::class |
|
| 25 | - ]; |
|
| 23 | + protected static $extra_controllers = [ |
|
| 24 | + CommentNotifierTestController::class |
|
| 25 | + ]; |
|
| 26 | 26 | |
| 27 | - protected function setUp() |
|
| 28 | - { |
|
| 29 | - parent::setUp(); |
|
| 27 | + protected function setUp() |
|
| 28 | + { |
|
| 29 | + parent::setUp(); |
|
| 30 | 30 | |
| 31 | - Config::modify()->set('Email', 'admin_email', '[email protected]'); |
|
| 32 | - $this->oldhost = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null; |
|
| 33 | - $_SERVER['HTTP_HOST'] = 'www.mysite.com'; |
|
| 34 | - } |
|
| 31 | + Config::modify()->set('Email', 'admin_email', '[email protected]'); |
|
| 32 | + $this->oldhost = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null; |
|
| 33 | + $_SERVER['HTTP_HOST'] = 'www.mysite.com'; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - protected function tearDown() |
|
| 37 | - { |
|
| 38 | - $_SERVER['HTTP_HOST'] = $this->oldhost; |
|
| 36 | + protected function tearDown() |
|
| 37 | + { |
|
| 38 | + $_SERVER['HTTP_HOST'] = $this->oldhost; |
|
| 39 | 39 | |
| 40 | - parent::tearDown(); |
|
| 41 | - } |
|
| 40 | + parent::tearDown(); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - public function testSendEmail() |
|
| 44 | - { |
|
| 45 | - $author = $this->objFromFixture(Member::class, 'author'); |
|
| 46 | - $item1 = $this->objFromFixture(CommentNotifiableTestDataObject::class, 'item1'); |
|
| 47 | - $item2 = $this->objFromFixture(CommentNotifiableTestDataObject::class, 'item2'); |
|
| 48 | - $comment1 = $this->objFromFixture(Comment::class, 'comment1'); |
|
| 49 | - $comment2 = $this->objFromFixture(Comment::class, 'comment2'); |
|
| 50 | - $comment3 = $this->objFromFixture(Comment::class, 'comment3'); |
|
| 51 | - $controller = new CommentNotifierTestController(); |
|
| 43 | + public function testSendEmail() |
|
| 44 | + { |
|
| 45 | + $author = $this->objFromFixture(Member::class, 'author'); |
|
| 46 | + $item1 = $this->objFromFixture(CommentNotifiableTestDataObject::class, 'item1'); |
|
| 47 | + $item2 = $this->objFromFixture(CommentNotifiableTestDataObject::class, 'item2'); |
|
| 48 | + $comment1 = $this->objFromFixture(Comment::class, 'comment1'); |
|
| 49 | + $comment2 = $this->objFromFixture(Comment::class, 'comment2'); |
|
| 50 | + $comment3 = $this->objFromFixture(Comment::class, 'comment3'); |
|
| 51 | + $controller = new CommentNotifierTestController(); |
|
| 52 | 52 | |
| 53 | - // Comment 1 |
|
| 54 | - $result = $controller->notifyCommentRecipient($comment1, $item1, $author); |
|
| 55 | - $this->assertEmailSent('[email protected]', '[email protected]', 'A new comment has been posted'); |
|
| 53 | + // Comment 1 |
|
| 54 | + $result = $controller->notifyCommentRecipient($comment1, $item1, $author); |
|
| 55 | + $this->assertEmailSent('[email protected]', '[email protected]', 'A new comment has been posted'); |
|
| 56 | 56 | |
| 57 | - $email = $this->findEmail('[email protected]', '[email protected]', 'A new comment has been posted'); |
|
| 57 | + $email = $this->findEmail('[email protected]', '[email protected]', 'A new comment has been posted'); |
|
| 58 | 58 | |
| 59 | - $this->assertContains('<li>Bob Bobberson</li>', $email['Content']); |
|
| 60 | - $this->assertContains('<li>[email protected]</li>', $email['Content']); |
|
| 61 | - $this->assertContains('<blockquote>Hey what a lovely comment</blockquote>', $email['Content']); |
|
| 59 | + $this->assertContains('<li>Bob Bobberson</li>', $email['Content']); |
|
| 60 | + $this->assertContains('<li>[email protected]</li>', $email['Content']); |
|
| 61 | + $this->assertContains('<blockquote>Hey what a lovely comment</blockquote>', $email['Content']); |
|
| 62 | 62 | |
| 63 | - $this->clearEmails(); |
|
| 63 | + $this->clearEmails(); |
|
| 64 | 64 | |
| 65 | - // Comment 2 |
|
| 66 | - $result = $controller->notifyCommentRecipient($comment2, $item2, $author); |
|
| 67 | - $this->assertEmailSent('[email protected]', '[email protected]', 'A new comment has been posted'); |
|
| 65 | + // Comment 2 |
|
| 66 | + $result = $controller->notifyCommentRecipient($comment2, $item2, $author); |
|
| 67 | + $this->assertEmailSent('[email protected]', '[email protected]', 'A new comment has been posted'); |
|
| 68 | 68 | |
| 69 | - $email = $this->findEmail('[email protected]', '[email protected]', 'A new comment has been posted'); |
|
| 70 | - $this->assertContains('<li>Secret</li>', $email['Content']); |
|
| 71 | - $this->assertContains('<li>[email protected]</li>', $email['Content']); |
|
| 72 | - $this->assertContains('<blockquote>I don't want to disclose my details</blockquote>', $email['Content']); |
|
| 69 | + $email = $this->findEmail('[email protected]', '[email protected]', 'A new comment has been posted'); |
|
| 70 | + $this->assertContains('<li>Secret</li>', $email['Content']); |
|
| 71 | + $this->assertContains('<li>[email protected]</li>', $email['Content']); |
|
| 72 | + $this->assertContains('<blockquote>I don't want to disclose my details</blockquote>', $email['Content']); |
|
| 73 | 73 | |
| 74 | - $this->clearEmails(); |
|
| 74 | + $this->clearEmails(); |
|
| 75 | 75 | |
| 76 | - // Comment 3 |
|
| 77 | - $result = $controller->notifyCommentRecipient($comment3, $item1, $author); |
|
| 78 | - $this->assertEmailSent('[email protected]', '[email protected]', 'A new comment has been posted'); |
|
| 76 | + // Comment 3 |
|
| 77 | + $result = $controller->notifyCommentRecipient($comment3, $item1, $author); |
|
| 78 | + $this->assertEmailSent('[email protected]', '[email protected]', 'A new comment has been posted'); |
|
| 79 | 79 | |
| 80 | - $email = $this->findEmail('[email protected]', '[email protected]', 'A new comment has been posted'); |
|
| 80 | + $email = $this->findEmail('[email protected]', '[email protected]', 'A new comment has been posted'); |
|
| 81 | 81 | |
| 82 | - $this->assertContains('<li>Anonymous</li>', $email['Content']); |
|
| 83 | - $this->assertContains('<li>[email protected]</li>', $email['Content']); |
|
| 84 | - $this->assertContains('<blockquote>I didn't log in</blockquote>', $email['Content']); |
|
| 82 | + $this->assertContains('<li>Anonymous</li>', $email['Content']); |
|
| 83 | + $this->assertContains('<li>[email protected]</li>', $email['Content']); |
|
| 84 | + $this->assertContains('<blockquote>I didn't log in</blockquote>', $email['Content']); |
|
| 85 | 85 | |
| 86 | - $this->clearEmails(); |
|
| 86 | + $this->clearEmails(); |
|
| 87 | 87 | |
| 88 | - // Comment 3 without an author |
|
| 89 | - $result = $controller->notifyCommentRecipient($comment3, $item1, '[email protected]'); |
|
| 90 | - $this->assertEmailSent('[email protected]', '[email protected]', 'A new comment has been posted'); |
|
| 88 | + // Comment 3 without an author |
|
| 89 | + $result = $controller->notifyCommentRecipient($comment3, $item1, '[email protected]'); |
|
| 90 | + $this->assertEmailSent('[email protected]', '[email protected]', 'A new comment has been posted'); |
|
| 91 | 91 | |
| 92 | - $this->clearEmails(); |
|
| 92 | + $this->clearEmails(); |
|
| 93 | 93 | |
| 94 | - // Comment 3 without a valid email |
|
| 95 | - $result = $controller->notifyCommentRecipient($comment3, $item1, '<foobar1>'); |
|
| 96 | - $noEmail = (bool) $this->findEmail('<foobar1>', '[email protected]', 'A new comment has been posted'); |
|
| 94 | + // Comment 3 without a valid email |
|
| 95 | + $result = $controller->notifyCommentRecipient($comment3, $item1, '<foobar1>'); |
|
| 96 | + $noEmail = (bool) $this->findEmail('<foobar1>', '[email protected]', 'A new comment has been posted'); |
|
| 97 | 97 | |
| 98 | - $this->assertFalse($noEmail); |
|
| 99 | - } |
|
| 98 | + $this->assertFalse($noEmail); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - public function testOnAfterPostComment() |
|
| 102 | - { |
|
| 103 | - $this->clearEmails(); |
|
| 101 | + public function testOnAfterPostComment() |
|
| 102 | + { |
|
| 103 | + $this->clearEmails(); |
|
| 104 | 104 | |
| 105 | - $comment1 = $this->objFromFixture(Comment::class, 'comment1'); |
|
| 105 | + $comment1 = $this->objFromFixture(Comment::class, 'comment1'); |
|
| 106 | 106 | |
| 107 | - $controller = new CommentNotifierTestController(); |
|
| 108 | - $controller->invokeWithExtensions('onAfterPostComment', $comment1); |
|
| 107 | + $controller = new CommentNotifierTestController(); |
|
| 108 | + $controller->invokeWithExtensions('onAfterPostComment', $comment1); |
|
| 109 | 109 | |
| 110 | - // test that after posting a comment the notifications are sent. |
|
| 111 | - $this->assertEmailSent('[email protected]', '[email protected]', 'A new comment has been posted'); |
|
| 112 | - } |
|
| 110 | + // test that after posting a comment the notifications are sent. |
|
| 111 | + $this->assertEmailSent('[email protected]', '[email protected]', 'A new comment has been posted'); |
|
| 112 | + } |
|
| 113 | 113 | } |
@@ -8,9 +8,9 @@ |
||
| 8 | 8 | |
| 9 | 9 | class CommentNotifierTestController extends Controller implements TestOnly |
| 10 | 10 | { |
| 11 | - private static $extensions = array( |
|
| 12 | - CommentNotifier::class |
|
| 13 | - ); |
|
| 11 | + private static $extensions = array( |
|
| 12 | + CommentNotifier::class |
|
| 13 | + ); |
|
| 14 | 14 | |
| 15 | - private static $url_segment = 'commentnotifiertest'; |
|
| 15 | + private static $url_segment = 'commentnotifiertest'; |
|
| 16 | 16 | } |
@@ -11,60 +11,60 @@ |
||
| 11 | 11 | |
| 12 | 12 | class CommentNotifiableTest extends SapphireTest |
| 13 | 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(array('[email protected]', '[email protected]'), $item1->notificationRecipients($comment1)); |
|
| 47 | - $this->assertEquals(array('[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 | - } |
|
| 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(array('[email protected]', '[email protected]'), $item1->notificationRecipients($comment1)); |
|
| 47 | + $this->assertEquals(array('[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 | 70 | } |