Completed
Push — master ( 1a94d1...3541dd )
by Daniel
10s
created

CommentAdminTest::testProvidePermissions()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 25
rs 8.8571
cc 1
eloc 15
nc 1
nop 0
1
<?php
2
3
class CommentAdminTest extends SapphireTest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
6
    protected $usesDatabase = true;
7
    
8
    public function testProvidePermissions()
9
    {
10
        $commentAdmin = new CommentAdmin();
11
        $locale = i18n::get_locale();
12
13
        i18n::set_locale('fr');
14
        $expected = array(
15
            'CMS_ACCESS_CommentAdmin' => array(
16
                # FIXME - this is a bug, missing from lang.yml files
17
                'name' => 'Access to \'Comments\' section',
18
                'category' => 'Accès au CMS'
19
            )
20
        );
21
        $this->assertEquals($expected, $commentAdmin->providePermissions());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<CommentAdminTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
22
23
        i18n::set_locale($locale);
24
        $expected = array(
25
            'CMS_ACCESS_CommentAdmin' => array(
26
                # FIXME - this is a bug, missing from lang.yml files
27
                'name' => 'Access to \'Comments\' section',
28
                'category' => 'CMS Access'
29
            )
30
        );
31
        $this->assertEquals($expected, $commentAdmin->providePermissions());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<CommentAdminTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
32
    }
33
34
    public function testGetEditForm()
35
    {
36
        $commentAdmin = new CommentAdmin();
37
        $this->logInWithPermission('CMS_ACCESS_CommentAdmin');
38
        $form = $commentAdmin->getEditForm();
39
        $names = $this->getFormFieldNames($form);
40
        $expected = array(
41
            'NewComments',
42
            'ApprovedComments',
43
            'SpamComments'
44
        );
45
        $this->assertEquals($expected, $names);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<CommentAdminTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
46
47
        if ($member = Member::currentUser()) {
48
            $member->logOut();
49
        }
50
51
        $form = $commentAdmin->getEditForm();
0 ignored issues
show
Unused Code introduced by
$form is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
52
    }
53
54
    private function getFormFieldNames($form)
55
    {
56
        $result = array();
57
        $fields = $form->Fields();
58
        $tab = $fields->findOrMakeTab('Root');
59
        $fields = $tab->FieldList();
60
        foreach ($fields as $field) {
61
            array_push($result, $field->getName());
62
        }
63
        return $result;
64
    }
65
}
66