2016-01-07 07:59:10 +01:00
|
|
|
<?php
|
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
class CommentingTest extends SapphireTest
|
|
|
|
{
|
2016-01-07 07:59:10 +01:00
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
public function setUpOnce()
|
|
|
|
{
|
2016-01-07 07:59:10 +01:00
|
|
|
parent::setUpOnce();
|
|
|
|
}
|
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
public function testDeprecatedMethods()
|
|
|
|
{
|
2016-01-07 07:59:10 +01:00
|
|
|
$methods = array('add', 'remove', 'has_commenting');
|
|
|
|
foreach ($methods as $methodName) {
|
|
|
|
try {
|
|
|
|
Commenting::$methodName('Member');
|
|
|
|
} catch (PHPUnit_Framework_Error_Deprecated $e) {
|
|
|
|
$expected = 'Using Commenting:' . $methodName .' is deprecated.'
|
|
|
|
. ' Please use the config API instead';
|
|
|
|
$this->assertEquals($expected, $e->getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
public function test_set_config_value()
|
|
|
|
{
|
|
|
|
// public static function set_config_value($class, $key, $value = false) {
|
2016-01-07 07:59:10 +01:00
|
|
|
Commenting::set_config_value(
|
|
|
|
'CommentableItem',
|
|
|
|
'comments_holder_id',
|
|
|
|
'commentable_item'
|
|
|
|
);
|
|
|
|
|
|
|
|
$config = Config::inst()->get(
|
|
|
|
'CommentableItem',
|
|
|
|
'comments'
|
|
|
|
);
|
|
|
|
$actual = $config['comments_holder_id'];
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
'commentable_item',
|
|
|
|
$actual
|
|
|
|
);
|
|
|
|
Commenting::set_config_value(
|
|
|
|
'all',
|
|
|
|
'comments_holder_id',
|
|
|
|
'all_items_actually_commentsextension'
|
|
|
|
);
|
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
$config = Config::inst()->get(
|
2016-01-07 07:59:10 +01:00
|
|
|
'CommentsExtension',
|
|
|
|
'comments'
|
|
|
|
);
|
|
|
|
$actual = $config['comments_holder_id'];
|
|
|
|
$this->assertEquals(
|
|
|
|
'all_items_actually_commentsextension',
|
|
|
|
$actual
|
|
|
|
);
|
2016-02-19 01:48:25 +01:00
|
|
|
}
|
2016-01-07 07:59:10 +01:00
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
public function test_get_config_value()
|
|
|
|
{
|
|
|
|
Config::inst()->update('CommentableItem', 'comments',
|
2016-01-07 07:59:10 +01:00
|
|
|
array(
|
|
|
|
'comments_holder_id' => 'commentable_item'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
'commentable_item',
|
|
|
|
Commenting::get_config_value('CommentableItem', 'comments_holder_id')
|
|
|
|
);
|
|
|
|
|
|
|
|
Config::inst()->update('CommentsExtension', 'comments',
|
|
|
|
array(
|
|
|
|
'comments_holder_id' => 'comments_extension'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
// if class is null, method uses the CommentsExtension property
|
|
|
|
$this->assertEquals(
|
|
|
|
'comments_extension',
|
|
|
|
Commenting::get_config_value(null, 'comments_holder_id')
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->setExpectedException(
|
|
|
|
'InvalidArgumentException',
|
|
|
|
'Member does not have commenting enabled'
|
|
|
|
);
|
|
|
|
Commenting::get_config_value('Member', 'comments_holder_id');
|
2016-02-19 01:48:25 +01:00
|
|
|
}
|
2016-01-07 07:59:10 +01:00
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
public function test_config_value_equals()
|
|
|
|
{
|
|
|
|
Config::inst()->update('CommentableItem', 'comments',
|
2016-01-07 07:59:10 +01:00
|
|
|
array(
|
|
|
|
'comments_holder_id' => 'some_value'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertTrue(
|
|
|
|
Commenting::config_value_equals(
|
|
|
|
'CommentableItem',
|
|
|
|
'comments_holder_id',
|
|
|
|
'some_value'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertNull(
|
|
|
|
Commenting::config_value_equals(
|
|
|
|
'CommentableItem',
|
|
|
|
'comments_holder_id',
|
|
|
|
'not_some_value'
|
|
|
|
)
|
|
|
|
);
|
2016-02-19 01:48:25 +01:00
|
|
|
}
|
2016-01-07 07:59:10 +01:00
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
public function test_add()
|
|
|
|
{
|
2016-01-07 07:59:10 +01:00
|
|
|
Commenting::add('Member', array('comments_holder_id' => 'test_add_value'));
|
|
|
|
|
|
|
|
$config = Config::inst()->get(
|
|
|
|
'Member',
|
|
|
|
'comments'
|
|
|
|
);
|
|
|
|
$actual = $config['comments_holder_id'];
|
|
|
|
$this->assertEquals(
|
|
|
|
'test_add_value',
|
|
|
|
$actual
|
|
|
|
);
|
|
|
|
|
|
|
|
Commenting::add('Member');
|
|
|
|
|
|
|
|
$config = Config::inst()->get(
|
|
|
|
'Member',
|
|
|
|
'comments'
|
|
|
|
);
|
|
|
|
$actual = $config['comments_holder_id'];
|
|
|
|
// no settings updated
|
|
|
|
$this->assertEquals(
|
|
|
|
'test_add_value',
|
|
|
|
$actual
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->setExpectedException('InvalidArgumentException', "\$settings needs to be an array or null");
|
|
|
|
Commenting::add('Member', 'illegal format, not an array');
|
|
|
|
}
|
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
public function test_can_member_post()
|
|
|
|
{
|
2016-01-07 07:59:10 +01:00
|
|
|
// logout
|
2016-02-19 01:48:25 +01:00
|
|
|
if ($member = Member::currentUser()) {
|
|
|
|
$member->logOut();
|
|
|
|
}
|
2016-01-07 07:59:10 +01:00
|
|
|
|
|
|
|
Config::inst()->update('CommentableItem', 'comments',
|
|
|
|
array(
|
|
|
|
'require_login' => false
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertTrue(Commenting::can_member_post('CommentableItem'));
|
|
|
|
|
|
|
|
Config::inst()->update('CommentableItem', 'comments',
|
|
|
|
array(
|
|
|
|
'require_login' => true
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertFalse(Commenting::can_member_post('CommentableItem'));
|
|
|
|
|
|
|
|
$this->logInWithPermission('CMS_ACCESS_CommentAdmin');
|
|
|
|
$this->assertTrue(Commenting::can_member_post('CommentableItem'));
|
|
|
|
|
|
|
|
Config::inst()->update('CommentableItem', 'comments',
|
|
|
|
array(
|
|
|
|
'require_login' => false
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertTrue(Commenting::can_member_post('CommentableItem'));
|
2016-02-19 01:48:25 +01:00
|
|
|
}
|
2016-01-07 07:59:10 +01:00
|
|
|
}
|