Completed
Push — master ( 187618...8c43e0 )
by Will
12s
created

tests/CommentAdminTest.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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()) {
0 ignored issues
show
Deprecated Code introduced by
The method SilverStripe\Security\Member::currentUser() has been deprecated with message: 5.0.0 use Security::getCurrentUser()

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
57
            $member->logOut();
0 ignored issues
show
Deprecated Code introduced by
The method SilverStripe\Security\Member::logOut() has been deprecated with message: Use Security::setCurrentUser(null) or an IdentityStore
Logs this member out.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
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