mirror of
https://github.com/silverstripe/silverstripe-comments
synced 2024-10-22 11:05:49 +02:00
ab3f35257b
* Remove CommentList and replace with a polymorphic has_one relationship * Tweaks for unit tests. Add tests for encode/decodeClassName.
75 lines
2.1 KiB
PHP
75 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace SilverStripe\Comments\Tests;
|
|
|
|
use SilverStripe\Comments\Admin\CommentAdmin;
|
|
use SilverStripe\Dev\SapphireTest;
|
|
use SilverStripe\i18n\i18n;
|
|
use SilverStripe\Security\Member;
|
|
|
|
class CommentAdminTest extends SapphireTest
|
|
{
|
|
/**
|
|
* {@inheritDoc}
|
|
*/
|
|
protected $usesDatabase = true;
|
|
|
|
public function testProvidePermissions()
|
|
{
|
|
$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());
|
|
}
|
|
|
|
public function testGetEditForm()
|
|
{
|
|
$commentAdmin = new CommentAdmin();
|
|
$this->logInWithPermission('CMS_ACCESS_CommentAdmin');
|
|
$form = $commentAdmin->getEditForm();
|
|
$names = $this->getFormFieldNames($form);
|
|
$expected = array(
|
|
'NewComments',
|
|
'ApprovedComments',
|
|
'SpamComments'
|
|
);
|
|
$this->assertEquals($expected, $names);
|
|
|
|
if ($member = Member::currentUser()) {
|
|
$member->logOut();
|
|
}
|
|
|
|
$form = $commentAdmin->getEditForm();
|
|
}
|
|
|
|
private function getFormFieldNames($form)
|
|
{
|
|
$result = array();
|
|
$fields = $form->Fields();
|
|
$tab = $fields->findOrMakeTab('Root');
|
|
$fields = $tab->FieldList();
|
|
foreach ($fields as $field) {
|
|
array_push($result, $field->getName());
|
|
}
|
|
return $result;
|
|
}
|
|
}
|