1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\Comments\Tests; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Comments\Admin\CommentAdmin; |
6
|
|
|
use SilverStripe\Control\Session; |
7
|
|
|
use SilverStripe\Dev\SapphireTest; |
8
|
|
|
use SilverStripe\i18n\i18n; |
9
|
|
|
|
10
|
|
|
class CommentAdminTest extends SapphireTest |
11
|
|
|
{ |
12
|
|
|
protected $usesDatabase = true; |
13
|
|
|
|
14
|
|
|
public function testProvidePermissions() |
15
|
|
|
{ |
16
|
|
|
$commentAdmin = new CommentAdmin(); |
17
|
|
|
$commentAdmin->getRequest()->setSession(new Session([])); |
18
|
|
|
|
19
|
|
|
i18n::set_locale('fr'); |
20
|
|
|
$this->assertEquals( |
21
|
|
|
'Accès au CMS', |
22
|
|
|
$commentAdmin->providePermissions()['CMS_ACCESS_CommentAdmin']['category'] |
23
|
|
|
); |
24
|
|
|
|
25
|
|
|
i18n::set_locale('en'); |
26
|
|
|
$expected = [ |
27
|
|
|
'CMS_ACCESS_CommentAdmin' => [ |
28
|
|
|
'name' => 'Access to \'Comments\' section', |
29
|
|
|
'category' => 'CMS Access', |
30
|
|
|
] |
31
|
|
|
]; |
32
|
|
|
$this->assertEquals($expected, $commentAdmin->providePermissions()); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testGetEditForm() |
36
|
|
|
{ |
37
|
|
|
$commentAdmin = new CommentAdmin(); |
38
|
|
|
$commentAdmin->getRequest()->setSession(new Session([])); |
39
|
|
|
|
40
|
|
|
$this->logInWithPermission('CMS_ACCESS_CommentAdmin'); |
41
|
|
|
$form = $commentAdmin->getEditForm(); |
42
|
|
|
$names = $this->getFormFieldNames($form); |
43
|
|
|
$expected = [ |
44
|
|
|
'NewComments', |
45
|
|
|
'ApprovedComments', |
46
|
|
|
'SpamComments', |
47
|
|
|
]; |
48
|
|
|
$this->assertEquals($expected, $names); |
49
|
|
|
|
50
|
|
|
$this->logOut(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
private function getFormFieldNames($form) |
54
|
|
|
{ |
55
|
|
|
$result = []; |
56
|
|
|
$fields = $form->Fields(); |
57
|
|
|
$tab = $fields->findOrMakeTab('Root'); |
58
|
|
|
$fields = $tab->FieldList(); |
59
|
|
|
foreach ($fields as $field) { |
60
|
|
|
array_push($result, $field->getName()); |
61
|
|
|
} |
62
|
|
|
return $result; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|