2010-11-29 23:24:17 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @package comments
|
|
|
|
*/
|
|
|
|
class CommentsTest extends FunctionalTest {
|
|
|
|
|
|
|
|
static $fixture_file = 'comments/tests/CommentsTest.yml';
|
|
|
|
|
|
|
|
function testCanView() {
|
|
|
|
$visitor = $this->objFromFixture('Member', 'visitor');
|
|
|
|
$admin = $this->objFromFixture('Member', 'commentadmin');
|
2010-12-11 05:59:46 +01:00
|
|
|
$comment = $this->objFromFixture('Comment', 'firstComA');
|
2010-11-29 23:24:17 +01:00
|
|
|
|
|
|
|
$this->assertTrue($comment->canView($visitor),
|
|
|
|
'Unauthenticated members can view comments associated to a page with ProvideComments=1'
|
|
|
|
);
|
|
|
|
$this->assertTrue($comment->canView($admin),
|
|
|
|
'Admins with CMS_ACCESS_CommentAdmin permissions can view comments associated to a page with ProvideComments=1'
|
|
|
|
);
|
|
|
|
|
2010-12-11 05:59:46 +01:00
|
|
|
$disabledComment = $this->objFromFixture('Comment', 'disabledCom');
|
2010-11-29 23:24:17 +01:00
|
|
|
|
|
|
|
$this->assertFalse($disabledComment->canView($visitor),
|
|
|
|
'Unauthenticated members can not view comments associated to a page with ProvideComments=0'
|
|
|
|
);
|
|
|
|
$this->assertTrue($disabledComment->canView($admin),
|
|
|
|
'Admins with CMS_ACCESS_CommentAdmin permissions can view comments associated to a page with ProvideComments=0'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testCanEdit() {
|
|
|
|
$visitor = $this->objFromFixture('Member', 'visitor');
|
|
|
|
$admin = $this->objFromFixture('Member', 'commentadmin');
|
2010-12-11 05:59:46 +01:00
|
|
|
$comment = $this->objFromFixture('Comment', 'firstComA');
|
2010-11-29 23:24:17 +01:00
|
|
|
|
|
|
|
$this->assertFalse($comment->canEdit($visitor));
|
|
|
|
$this->assertTrue($comment->canEdit($admin));
|
|
|
|
}
|
|
|
|
|
|
|
|
function testCanDelete() {
|
|
|
|
$visitor = $this->objFromFixture('Member', 'visitor');
|
|
|
|
$admin = $this->objFromFixture('Member', 'commentadmin');
|
2010-12-11 05:59:46 +01:00
|
|
|
$comment = $this->objFromFixture('Comment', 'firstComA');
|
2010-11-29 23:24:17 +01:00
|
|
|
|
|
|
|
$this->assertFalse($comment->canEdit($visitor));
|
|
|
|
$this->assertTrue($comment->canEdit($admin));
|
|
|
|
}
|
|
|
|
|
|
|
|
function testDeleteComment() {
|
|
|
|
$firstPage = $this->objFromFixture('Page', 'first');
|
|
|
|
$this->autoFollowRedirection = false;
|
|
|
|
$this->logInAs('commentadmin');
|
|
|
|
|
2010-12-11 05:59:46 +01:00
|
|
|
$firstComment = $this->objFromFixture('Comment', 'firstComA');
|
2010-11-29 23:24:17 +01:00
|
|
|
$firstCommentID = $firstComment->ID;
|
|
|
|
Director::test($firstPage->RelativeLink(), null, $this->session());
|
2010-12-11 05:59:46 +01:00
|
|
|
$delete = $this->get('CommentingController/delete/'.$firstComment->ID);
|
2010-11-29 23:24:17 +01:00
|
|
|
|
2010-12-11 05:59:46 +01:00
|
|
|
$this->assertFalse(DataObject::get_by_id('Comment', $firstCommentID));
|
2010-11-29 23:24:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function testCommenterURLWrite() {
|
2010-12-11 05:59:46 +01:00
|
|
|
$comment = new Comment();
|
2010-11-29 23:24:17 +01:00
|
|
|
// We only care about the CommenterURL, so only set that
|
|
|
|
// Check a http and https URL. Add more test urls here as needed.
|
|
|
|
$protocols = array(
|
|
|
|
'Http',
|
|
|
|
'Https',
|
|
|
|
);
|
|
|
|
$url = '://example.com';
|
|
|
|
foreach($protocols as $protocol) {
|
|
|
|
$comment->CommenterURL = $protocol . $url;
|
|
|
|
// The protocol should stay as if, assuming it is valid
|
|
|
|
$comment->write();
|
|
|
|
$this->assertEquals($comment->CommenterURL, $protocol . $url, $protocol . ':// is a valid protocol');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|