Browse Source

Added unit tests for rules with private fields

tags/2.0.11
SilverFire - Dmitry Naumenko 8 years ago
parent
commit
a9124dd8c2
  1. 8
      tests/framework/rbac/ActionRule.php
  2. 18
      tests/framework/rbac/ManagerTestCase.php

8
tests/framework/rbac/ActionRule.php

@ -2,13 +2,19 @@
namespace yiiunit\framework\rbac; namespace yiiunit\framework\rbac;
use yii\rbac\Rule;
/** /**
* Description of ActionRule * Description of ActionRule
*/ */
class ActionRule extends \yii\rbac\Rule class ActionRule extends Rule
{ {
public $name = 'action_rule'; public $name = 'action_rule';
public $action = 'read'; public $action = 'read';
private $somePrivateProperty;
protected $someProtectedProperty;
public function execute($user, $item, $params) public function execute($user, $item, $params)
{ {
return $this->action === 'all' || $this->action === $params['action']; return $this->action === 'all' || $this->action === $params['action'];

18
tests/framework/rbac/ManagerTestCase.php

@ -480,4 +480,22 @@ abstract class ManagerTestCase extends TestCase
$auth->update('Reader', $role); $auth->update('Reader', $role);
$this->assertTrue($auth->checkAccess($userId, 'AdminPost', ['action' => 'print'])); $this->assertTrue($auth->checkAccess($userId, 'AdminPost', ['action' => 'print']));
} }
/**
* https://github.com/yiisoft/yii2/issues/10176
* https://github.com/yiisoft/yii2/issues/12681
*/
public function testRuleWithPrivateFields()
{
$auth = $this->auth;
$auth->removeAll();
$rule = new ActionRule();
$auth->add($rule);
/** @var ActionRule $rule */
$rule = $this->auth->getRule('action_rule');
$this->assertTrue($rule instanceof ActionRule);
}
} }

Loading…
Cancel
Save