FIX Update CommentAdmin test to create a mock session and not assert missing translation

This commit is contained in:
Robbie Averill 2017-12-19 09:32:56 +13:00
parent b02928e02a
commit 4bf0a83ad3
1 changed files with 18 additions and 23 deletions

View File

@ -3,6 +3,7 @@
namespace SilverStripe\Comments\Tests; namespace SilverStripe\Comments\Tests;
use SilverStripe\Comments\Admin\CommentAdmin; use SilverStripe\Comments\Admin\CommentAdmin;
use SilverStripe\Control\Session;
use SilverStripe\Dev\SapphireTest; use SilverStripe\Dev\SapphireTest;
use SilverStripe\i18n\i18n; use SilverStripe\i18n\i18n;
@ -13,51 +14,45 @@ class CommentAdminTest extends SapphireTest
public function testProvidePermissions() public function testProvidePermissions()
{ {
$commentAdmin = new CommentAdmin(); $commentAdmin = new CommentAdmin();
$locale = i18n::get_locale(); $commentAdmin->getRequest()->setSession(new Session([]));
i18n::set_locale('fr'); i18n::set_locale('fr');
$expected = array( $this->assertEquals(
'CMS_ACCESS_CommentAdmin' => array( 'Accès au CMS',
'name' => 'Accès à la section Commentaires', $commentAdmin->providePermissions()['CMS_ACCESS_CommentAdmin']['category']
'category' => 'Accès au CMS',
)
); );
$this->assertEquals($expected, $commentAdmin->providePermissions()); i18n::set_locale('en');
$expected = [
i18n::set_locale($locale); 'CMS_ACCESS_CommentAdmin' => [
$expected = array(
'CMS_ACCESS_CommentAdmin' => array(
'name' => 'Access to \'Comments\' section', 'name' => 'Access to \'Comments\' section',
'category' => 'CMS Access' 'category' => 'CMS Access',
) ]
); ];
$this->assertEquals($expected, $commentAdmin->providePermissions()); $this->assertEquals($expected, $commentAdmin->providePermissions());
} }
public function testGetEditForm() public function testGetEditForm()
{ {
$commentAdmin = new CommentAdmin(); $commentAdmin = new CommentAdmin();
$commentAdmin->getRequest()->setSession(new Session([]));
$this->logInWithPermission('CMS_ACCESS_CommentAdmin'); $this->logInWithPermission('CMS_ACCESS_CommentAdmin');
$form = $commentAdmin->getEditForm(); $form = $commentAdmin->getEditForm();
$names = $this->getFormFieldNames($form); $names = $this->getFormFieldNames($form);
$expected = array( $expected = [
'NewComments', 'NewComments',
'ApprovedComments', 'ApprovedComments',
'SpamComments' 'SpamComments',
); ];
$this->assertEquals($expected, $names); $this->assertEquals($expected, $names);
if ($member = Member::currentUser()) { $this->logOut();
$member->logOut();
}
$form = $commentAdmin->getEditForm();
} }
private function getFormFieldNames($form) private function getFormFieldNames($form)
{ {
$result = array(); $result = [];
$fields = $form->Fields(); $fields = $form->Fields();
$tab = $fields->findOrMakeTab('Root'); $tab = $fields->findOrMakeTab('Root');
$fields = $tab->FieldList(); $fields = $tab->FieldList();