2016-01-07 07:59:10 +01:00
|
|
|
<?php
|
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
class CommentAdminTest extends SapphireTest
|
|
|
|
{
|
2016-07-05 10:26:08 +02:00
|
|
|
|
|
|
|
protected $usesDatabase = true;
|
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
public function testProvidePermissions()
|
|
|
|
{
|
2016-01-07 07:59:10 +01:00
|
|
|
$commentAdmin = new CommentAdmin();
|
|
|
|
$locale = i18n::get_locale();
|
|
|
|
|
|
|
|
i18n::set_locale('fr');
|
|
|
|
$expected = array(
|
|
|
|
'CMS_ACCESS_CommentAdmin' => array(
|
|
|
|
# FIXME - this is a bug, missing from lang.yml files
|
|
|
|
'name' => 'Access to \'Comments\' section',
|
|
|
|
'category' => 'Accès au CMS'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $commentAdmin->providePermissions());
|
|
|
|
|
|
|
|
i18n::set_locale($locale);
|
|
|
|
$expected = array(
|
|
|
|
'CMS_ACCESS_CommentAdmin' => array(
|
|
|
|
# FIXME - this is a bug, missing from lang.yml files
|
|
|
|
'name' => 'Access to \'Comments\' section',
|
|
|
|
'category' => 'CMS Access'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $commentAdmin->providePermissions());
|
2016-02-19 01:48:25 +01:00
|
|
|
}
|
2016-01-07 07:59:10 +01:00
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
public function testGetEditForm()
|
|
|
|
{
|
2016-01-07 07:59:10 +01:00
|
|
|
$commentAdmin = new CommentAdmin();
|
|
|
|
$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);
|
|
|
|
$expected = array(
|
|
|
|
'NewComments',
|
|
|
|
'ApprovedComments',
|
|
|
|
'SpamComments'
|
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $names);
|
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
if ($member = Member::currentUser()) {
|
|
|
|
$member->logOut();
|
|
|
|
}
|
2016-01-07 07:59:10 +01:00
|
|
|
|
|
|
|
$form = $commentAdmin->getEditForm();
|
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)
|
|
|
|
{
|
2016-01-07 07:59:10 +01:00
|
|
|
$result = array();
|
|
|
|
$fields = $form->Fields();
|
|
|
|
$tab = $fields->findOrMakeTab('Root');
|
|
|
|
$fields = $tab->FieldList();
|
|
|
|
foreach ($fields as $field) {
|
|
|
|
array_push($result, $field->getName());
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|