1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class CommentingTest extends SapphireTest |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
|
6
|
|
|
public function setUpOnce() |
7
|
|
|
{ |
8
|
|
|
parent::setUpOnce(); |
9
|
|
|
} |
10
|
|
|
|
11
|
|
|
public function testDeprecatedMethods() |
12
|
|
|
{ |
13
|
|
|
$methods = array('add', 'remove', 'has_commenting'); |
14
|
|
|
foreach ($methods as $methodName) { |
15
|
|
|
try { |
16
|
|
|
Commenting::$methodName('Member'); |
17
|
|
|
} catch (PHPUnit_Framework_Error_Deprecated $e) { |
18
|
|
|
$expected = 'Using Commenting:' . $methodName .' is deprecated.' |
19
|
|
|
. ' Please use the config API instead'; |
20
|
|
|
$this->assertEquals($expected, $e->getMessage()); |
|
|
|
|
21
|
|
|
} |
22
|
|
|
} |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
public function test_set_config_value() |
27
|
|
|
{ |
28
|
|
|
// public static function set_config_value($class, $key, $value = false) { |
|
|
|
|
29
|
|
|
Commenting::set_config_value( |
|
|
|
|
30
|
|
|
'CommentableItem', |
31
|
|
|
'comments_holder_id', |
32
|
|
|
'commentable_item' |
33
|
|
|
); |
34
|
|
|
|
35
|
|
|
$config = Config::inst()->get( |
36
|
|
|
'CommentableItem', |
37
|
|
|
'comments' |
38
|
|
|
); |
39
|
|
|
$actual = $config['comments_holder_id']; |
40
|
|
|
|
41
|
|
|
$this->assertEquals( |
|
|
|
|
42
|
|
|
'commentable_item', |
43
|
|
|
$actual |
44
|
|
|
); |
45
|
|
|
Commenting::set_config_value( |
|
|
|
|
46
|
|
|
'all', |
47
|
|
|
'comments_holder_id', |
48
|
|
|
'all_items_actually_commentsextension' |
49
|
|
|
); |
50
|
|
|
|
51
|
|
|
$config = Config::inst()->get( |
52
|
|
|
'CommentsExtension', |
53
|
|
|
'comments' |
54
|
|
|
); |
55
|
|
|
$actual = $config['comments_holder_id']; |
56
|
|
|
$this->assertEquals( |
|
|
|
|
57
|
|
|
'all_items_actually_commentsextension', |
58
|
|
|
$actual |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function test_get_config_value() |
63
|
|
|
{ |
64
|
|
|
Config::inst()->update('CommentableItem', 'comments', |
65
|
|
|
array( |
66
|
|
|
'comments_holder_id' => 'commentable_item' |
67
|
|
|
) |
68
|
|
|
); |
69
|
|
|
$this->assertEquals( |
|
|
|
|
70
|
|
|
'commentable_item', |
71
|
|
|
Commenting::get_config_value('CommentableItem', 'comments_holder_id') |
|
|
|
|
72
|
|
|
); |
73
|
|
|
|
74
|
|
|
Config::inst()->update('CommentsExtension', 'comments', |
75
|
|
|
array( |
76
|
|
|
'comments_holder_id' => 'comments_extension' |
77
|
|
|
) |
78
|
|
|
); |
79
|
|
|
// if class is null, method uses the CommentsExtension property |
80
|
|
|
$this->assertEquals( |
|
|
|
|
81
|
|
|
'comments_extension', |
82
|
|
|
Commenting::get_config_value(null, 'comments_holder_id') |
|
|
|
|
83
|
|
|
); |
84
|
|
|
|
85
|
|
|
$this->setExpectedException( |
|
|
|
|
86
|
|
|
'InvalidArgumentException', |
87
|
|
|
'Member does not have commenting enabled' |
88
|
|
|
); |
89
|
|
|
Commenting::get_config_value('Member', 'comments_holder_id'); |
|
|
|
|
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function test_config_value_equals() |
93
|
|
|
{ |
94
|
|
|
Config::inst()->update('CommentableItem', 'comments', |
95
|
|
|
array( |
96
|
|
|
'comments_holder_id' => 'some_value' |
97
|
|
|
) |
98
|
|
|
); |
99
|
|
|
|
100
|
|
|
$this->assertTrue( |
|
|
|
|
101
|
|
|
Commenting::config_value_equals( |
|
|
|
|
102
|
|
|
'CommentableItem', |
103
|
|
|
'comments_holder_id', |
104
|
|
|
'some_value' |
105
|
|
|
) |
106
|
|
|
); |
107
|
|
|
|
108
|
|
|
$this->assertNull( |
|
|
|
|
109
|
|
|
Commenting::config_value_equals( |
|
|
|
|
110
|
|
|
'CommentableItem', |
111
|
|
|
'comments_holder_id', |
112
|
|
|
'not_some_value' |
113
|
|
|
) |
114
|
|
|
); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function test_add() |
118
|
|
|
{ |
119
|
|
|
Commenting::add('Member', array('comments_holder_id' => 'test_add_value')); |
|
|
|
|
120
|
|
|
|
121
|
|
|
$config = Config::inst()->get( |
122
|
|
|
'Member', |
123
|
|
|
'comments' |
124
|
|
|
); |
125
|
|
|
$actual = $config['comments_holder_id']; |
126
|
|
|
$this->assertEquals( |
|
|
|
|
127
|
|
|
'test_add_value', |
128
|
|
|
$actual |
129
|
|
|
); |
130
|
|
|
|
131
|
|
|
Commenting::add('Member'); |
|
|
|
|
132
|
|
|
|
133
|
|
|
$config = Config::inst()->get( |
134
|
|
|
'Member', |
135
|
|
|
'comments' |
136
|
|
|
); |
137
|
|
|
$actual = $config['comments_holder_id']; |
138
|
|
|
// no settings updated |
139
|
|
|
$this->assertEquals( |
|
|
|
|
140
|
|
|
'test_add_value', |
141
|
|
|
$actual |
142
|
|
|
); |
143
|
|
|
|
144
|
|
|
$this->setExpectedException('InvalidArgumentException', "\$settings needs to be an array or null"); |
|
|
|
|
145
|
|
|
Commenting::add('Member', 'illegal format, not an array'); |
|
|
|
|
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
public function test_can_member_post() |
149
|
|
|
{ |
150
|
|
|
// logout |
151
|
|
|
if ($member = Member::currentUser()) { |
152
|
|
|
$member->logOut(); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
Config::inst()->update('CommentableItem', 'comments', |
156
|
|
|
array( |
157
|
|
|
'require_login' => false |
158
|
|
|
) |
159
|
|
|
); |
160
|
|
|
$this->assertTrue(Commenting::can_member_post('CommentableItem')); |
|
|
|
|
161
|
|
|
|
162
|
|
|
Config::inst()->update('CommentableItem', 'comments', |
163
|
|
|
array( |
164
|
|
|
'require_login' => true |
165
|
|
|
) |
166
|
|
|
); |
167
|
|
|
$this->assertFalse(Commenting::can_member_post('CommentableItem')); |
|
|
|
|
168
|
|
|
|
169
|
|
|
$this->logInWithPermission('CMS_ACCESS_CommentAdmin'); |
170
|
|
|
$this->assertTrue(Commenting::can_member_post('CommentableItem')); |
|
|
|
|
171
|
|
|
|
172
|
|
|
Config::inst()->update('CommentableItem', 'comments', |
173
|
|
|
array( |
174
|
|
|
'require_login' => false |
175
|
|
|
) |
176
|
|
|
); |
177
|
|
|
|
178
|
|
|
$this->assertTrue(Commenting::can_member_post('CommentableItem')); |
|
|
|
|
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
|
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.