2016-01-07 07:59:10 +01:00
|
|
|
<?php
|
|
|
|
|
2017-01-16 20:57:37 +01:00
|
|
|
namespace SilverStripe\Comments\Tests;
|
|
|
|
|
|
|
|
use SilverStripe\Comments\Admin\CommentAdmin;
|
2017-12-18 21:32:56 +01:00
|
|
|
use SilverStripe\Control\Session;
|
2017-01-16 20:57:37 +01:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use SilverStripe\i18n\i18n;
|
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
class CommentAdminTest extends SapphireTest
|
|
|
|
{
|
2016-07-05 10:26:08 +02:00
|
|
|
protected $usesDatabase = true;
|
2017-01-16 20:57:37 +01:00
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
public function testProvidePermissions()
|
|
|
|
{
|
2016-01-07 07:59:10 +01:00
|
|
|
$commentAdmin = new CommentAdmin();
|
2017-12-18 21:32:56 +01:00
|
|
|
$commentAdmin->getRequest()->setSession(new Session([]));
|
2016-01-07 07:59:10 +01:00
|
|
|
|
|
|
|
i18n::set_locale('fr');
|
2017-12-18 21:32:56 +01:00
|
|
|
$this->assertEquals(
|
|
|
|
'Accès au CMS',
|
|
|
|
$commentAdmin->providePermissions()['CMS_ACCESS_CommentAdmin']['category']
|
2016-01-07 07:59:10 +01:00
|
|
|
);
|
2017-09-18 04:16:24 +02:00
|
|
|
|
2017-12-18 21:32:56 +01:00
|
|
|
i18n::set_locale('en');
|
|
|
|
$expected = [
|
|
|
|
'CMS_ACCESS_CommentAdmin' => [
|
2016-01-07 07:59:10 +01:00
|
|
|
'name' => 'Access to \'Comments\' section',
|
2017-12-18 21:32:56 +01:00
|
|
|
'category' => 'CMS Access',
|
|
|
|
]
|
|
|
|
];
|
2016-01-07 07:59:10 +01:00
|
|
|
$this->assertEquals($expected, $commentAdmin->providePermissions());
|
2016-02-19 01:48:25 +01:00
|
|
|
}
|
2017-12-18 21:14:47 +01:00
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
public function testGetEditForm()
|
|
|
|
{
|
2016-01-07 07:59:10 +01:00
|
|
|
$commentAdmin = new CommentAdmin();
|
2017-12-18 21:32:56 +01:00
|
|
|
$commentAdmin->getRequest()->setSession(new Session([]));
|
|
|
|
|
2016-01-07 07:59:10 +01:00
|
|
|
$this->logInWithPermission('CMS_ACCESS_CommentAdmin');
|
2016-02-19 01:48:25 +01:00
|
|
|
$form = $commentAdmin->getEditForm();
|
2016-01-07 07:59:10 +01:00
|
|
|
$names = $this->getFormFieldNames($form);
|
2017-12-18 21:32:56 +01:00
|
|
|
$expected = [
|
2016-01-07 07:59:10 +01:00
|
|
|
'NewComments',
|
|
|
|
'ApprovedComments',
|
2017-12-18 21:32:56 +01:00
|
|
|
'SpamComments',
|
|
|
|
];
|
2016-01-07 07:59:10 +01:00
|
|
|
$this->assertEquals($expected, $names);
|
|
|
|
|
2017-12-18 21:32:56 +01:00
|
|
|
$this->logOut();
|
2016-02-19 01:48:25 +01:00
|
|
|
}
|
2016-01-07 07:59:10 +01:00
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
private function getFormFieldNames($form)
|
|
|
|
{
|
2017-12-18 21:32:56 +01:00
|
|
|
$result = [];
|
2016-01-07 07:59:10 +01:00
|
|
|
$fields = $form->Fields();
|
|
|
|
$tab = $fields->findOrMakeTab('Root');
|
|
|
|
$fields = $tab->FieldList();
|
|
|
|
foreach ($fields as $field) {
|
|
|
|
array_push($result, $field->getName());
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|