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