|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class CommentAdminTest extends SapphireTest { |
|
|
|
|
|
|
4
|
|
|
public function testProvidePermissions() { |
|
5
|
|
|
$commentAdmin = new CommentAdmin(); |
|
6
|
|
|
$locale = i18n::get_locale(); |
|
7
|
|
|
|
|
8
|
|
|
i18n::set_locale('fr'); |
|
9
|
|
|
$expected = array( |
|
10
|
|
|
'CMS_ACCESS_CommentAdmin' => array( |
|
11
|
|
|
# FIXME - this is a bug, missing from lang.yml files |
|
12
|
|
|
'name' => 'Access to \'Comments\' section', |
|
13
|
|
|
'category' => 'Accès au CMS' |
|
14
|
|
|
) |
|
15
|
|
|
); |
|
16
|
|
|
$this->assertEquals($expected, $commentAdmin->providePermissions()); |
|
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
i18n::set_locale($locale); |
|
19
|
|
|
$expected = array( |
|
20
|
|
|
'CMS_ACCESS_CommentAdmin' => array( |
|
21
|
|
|
# FIXME - this is a bug, missing from lang.yml files |
|
22
|
|
|
'name' => 'Access to \'Comments\' section', |
|
23
|
|
|
'category' => 'CMS Access' |
|
24
|
|
|
) |
|
25
|
|
|
); |
|
26
|
|
|
$this->assertEquals($expected, $commentAdmin->providePermissions()); |
|
|
|
|
|
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function testGetEditForm() { |
|
30
|
|
|
$commentAdmin = new CommentAdmin(); |
|
31
|
|
|
$this->logInWithPermission('CMS_ACCESS_CommentAdmin'); |
|
32
|
|
|
$form = $commentAdmin->getEditForm(); |
|
33
|
|
|
$names = $this->getFormFieldNames($form); |
|
34
|
|
|
$expected = array( |
|
35
|
|
|
'NewComments', |
|
36
|
|
|
'ApprovedComments', |
|
37
|
|
|
'SpamComments' |
|
38
|
|
|
); |
|
39
|
|
|
$this->assertEquals($expected, $names); |
|
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
if($member = Member::currentUser()) $member->logOut(); |
|
42
|
|
|
|
|
43
|
|
|
$form = $commentAdmin->getEditForm(); |
|
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
private function getFormFieldNames($form) { |
|
47
|
|
|
$result = array(); |
|
48
|
|
|
$fields = $form->Fields(); |
|
49
|
|
|
$tab = $fields->findOrMakeTab('Root'); |
|
50
|
|
|
$fields = $tab->FieldList(); |
|
51
|
|
|
foreach ($fields as $field) { |
|
52
|
|
|
array_push($result, $field->getName()); |
|
53
|
|
|
} |
|
54
|
|
|
return $result; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
|
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.