Commit 22596ca2 by tof06

Implement new RBAC PhpManager

parent d552bc26
......@@ -366,4 +366,35 @@ abstract class ManagerTestCase extends TestCase
$this->auth->assign($author, 'author B');
$this->auth->assign($admin, 'admin C');
}
public function testGetPermissionsByRole()
{
$this->prepareData();
$roles = $this->auth->getPermissionsByRole('admin');
$expectedPermissions = ['createPost', 'updatePost', 'readPost', 'updateAnyPost'];
$this->assertEquals(count($roles), count($expectedPermissions));
foreach ($expectedPermissions as $permission) {
$this->assertTrue($roles[$permission] instanceof Permission);
}
}
public function testGetPermissionsByUser()
{
$this->prepareData();
$roles = $this->auth->getPermissionsByUser('author B');
$expectedPermissions = ['createPost', 'updatePost', 'readPost'];
$this->assertEquals(count($roles), count($expectedPermissions));
foreach ($expectedPermissions as $permission) {
$this->assertTrue($roles[$permission] instanceof Permission);
}
}
public function testGetRolesByUser()
{
$this->prepareData();
$roles = $this->auth->getRolesByUser('reader A');
$this->assertTrue(reset($roles) instanceof Role);
$this->assertEquals($roles['reader']->name, 'reader');
}
}
<?php
namespace yiiunit\framework\rbac;
use Yii;
use yii\rbac\PhpManager;
/**
* @group rbac
* @property \yii\rbac\PhpManager $auth
*/
class PhpManagerTestCase extends ManagerTestCase
{
protected function setUp()
{
parent::setUp();
$this->mockApplication();
$authFile = Yii::$app->getRuntimePath() . '/rbac.php';
@unlink($authFile);
$this->auth = new PhpManager();
$this->auth->authFile = $authFile;
$this->auth->init();
}
protected function tearDown()
{
parent::tearDown();
@unlink($this->auth->authFile);
}
public function testSaveLoad()
{
$this->prepareData();
$this->auth->save();
$this->auth->clearAll();
$this->auth->load();
// TODO : Check if loaded and saved data are the same.
}
}
\ No newline at end of file
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