Commit 7b7064d8 authored by Nicolas Widart's avatar Nicolas Widart

Adding the permission manager test

parent b982a164
<?php namespace Modules\Core\Tests;
use Mockery;
use Modules\Core\Permissions\PermissionManager;
class PermissionManagerTest extends \TestCase
{
/**
* @var PermissionManager
*/
protected $permissions;
public function setUp()
{
parent::setUp();
$enabledModules = [
'Session',
'User',
'Dashboard',
'Core'
];
$moduleMock = Mockery::mock('Pingpong\Modules\Module');
$moduleMock->shouldReceive('enabled')->once()->andReturn($enabledModules);
$this->permissions = new PermissionManager($moduleMock);
}
/** @test */
public function itShouldReturnAllPermissions()
{
$expected = [
'Dashboard' => [
'dashboard' => ['index']
],
'User' => [
'users' => [
'index',
'create',
'store',
'edit',
'update',
'destroy'
],
'roles' => [
'index',
'create',
'store',
'edit',
'update',
'destroy'
]
],
];
$permissions = $this->permissions->all();
$this->assertEquals($expected, $permissions);
}
/** @test */
public function itShouldCleanPermissionsCorrectlyTypeCasted()
{
$requestData = [
'dashboard.index' => 'true',
'users.index' => 'true',
'users.create' => 'true',
'users.edit' => 'true',
'users.delete' => 'true',
'roles.create' => 'true',
];
$expected = [
'dashboard.index' => true,
'users.index' => true,
'users.create' => true,
'users.edit' => true,
'users.delete' => true,
'roles.create' => true,
];
$cleanedPermissions = $this->permissions->clean($requestData);
$this->assertEquals($expected, $cleanedPermissions);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment