1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\Comments\Tests; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Comments\Admin\CommentAdmin; |
6
|
|
|
use SilverStripe\Dev\SapphireTest; |
7
|
|
|
use SilverStripe\i18n\i18n; |
8
|
|
|
use SilverStripe\Security\Member; |
9
|
|
|
|
10
|
|
|
class CommentAdminTest extends SapphireTest |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* {@inheritDoc} |
14
|
|
|
*/ |
15
|
|
|
protected $usesDatabase = true; |
16
|
|
|
|
17
|
|
|
public function testProvidePermissions() |
18
|
|
|
{ |
19
|
|
|
$commentAdmin = new CommentAdmin(); |
20
|
|
|
$locale = i18n::get_locale(); |
21
|
|
|
|
22
|
|
|
i18n::set_locale('fr'); |
23
|
|
|
$expected = array( |
24
|
|
|
'CMS_ACCESS_CommentAdmin' => array( |
25
|
|
|
# FIXME - this is a bug, missing from lang.yml files |
26
|
|
|
'name' => 'Access to \'Comments\' section', |
27
|
|
|
'category' => 'Accès au CMS' |
28
|
|
|
) |
29
|
|
|
); |
30
|
|
|
$this->assertEquals($expected, $commentAdmin->providePermissions()); |
31
|
|
|
|
32
|
|
|
i18n::set_locale($locale); |
33
|
|
|
$expected = array( |
34
|
|
|
'CMS_ACCESS_CommentAdmin' => array( |
35
|
|
|
# FIXME - this is a bug, missing from lang.yml files |
36
|
|
|
'name' => 'Access to \'Comments\' section', |
37
|
|
|
'category' => 'CMS Access' |
38
|
|
|
) |
39
|
|
|
); |
40
|
|
|
$this->assertEquals($expected, $commentAdmin->providePermissions()); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testGetEditForm() |
44
|
|
|
{ |
45
|
|
|
$commentAdmin = new CommentAdmin(); |
46
|
|
|
$this->logInWithPermission('CMS_ACCESS_CommentAdmin'); |
47
|
|
|
$form = $commentAdmin->getEditForm(); |
48
|
|
|
$names = $this->getFormFieldNames($form); |
49
|
|
|
$expected = array( |
50
|
|
|
'NewComments', |
51
|
|
|
'ApprovedComments', |
52
|
|
|
'SpamComments' |
53
|
|
|
); |
54
|
|
|
$this->assertEquals($expected, $names); |
55
|
|
|
|
56
|
|
|
if ($member = Member::currentUser()) { |
57
|
|
|
$member->logOut(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$form = $commentAdmin->getEditForm(); |
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
private function getFormFieldNames($form) |
64
|
|
|
{ |
65
|
|
|
$result = array(); |
66
|
|
|
$fields = $form->Fields(); |
67
|
|
|
$tab = $fields->findOrMakeTab('Root'); |
68
|
|
|
$fields = $tab->FieldList(); |
69
|
|
|
foreach ($fields as $field) { |
70
|
|
|
array_push($result, $field->getName()); |
71
|
|
|
} |
72
|
|
|
return $result; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.