Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Rotua Panjaitan
yii2
Commits
740f5325
Commit
740f5325
authored
Apr 15, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3110 from tof06/rbac-php-manager
Implement new RBAC PhpManager
parents
d552bc26
22596ca2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
0 deletions
+72
-0
PhpManager.php
framework/rbac/PhpManager.php
+0
-0
ManagerTestCase.php
tests/unit/framework/rbac/ManagerTestCase.php
+31
-0
PhpManagerTestCase.php
tests/unit/framework/rbac/PhpManagerTestCase.php
+41
-0
No files found.
framework/rbac/PhpManager.php
0 → 100644
View file @
740f5325
This diff is collapsed.
Click to expand it.
tests/unit/framework/rbac/ManagerTestCase.php
View file @
740f5325
...
...
@@ -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'
);
}
}
tests/unit/framework/rbac/PhpManagerTestCase.php
0 → 100644
View file @
740f5325
<?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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment