From a9124dd8c2fcbd0e18eae9e096ad4c7349f9df40 Mon Sep 17 00:00:00 2001 From: SilverFire - Dmitry Naumenko Date: Sat, 12 Nov 2016 15:43:28 +0200 Subject: [PATCH] Added unit tests for rules with private fields --- tests/framework/rbac/ActionRule.php | 8 +++++++- tests/framework/rbac/ManagerTestCase.php | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/framework/rbac/ActionRule.php b/tests/framework/rbac/ActionRule.php index 2db99f4..2754a59 100644 --- a/tests/framework/rbac/ActionRule.php +++ b/tests/framework/rbac/ActionRule.php @@ -2,13 +2,19 @@ namespace yiiunit\framework\rbac; +use yii\rbac\Rule; + /** * Description of ActionRule */ -class ActionRule extends \yii\rbac\Rule +class ActionRule extends Rule { public $name = 'action_rule'; public $action = 'read'; + + private $somePrivateProperty; + protected $someProtectedProperty; + public function execute($user, $item, $params) { return $this->action === 'all' || $this->action === $params['action']; diff --git a/tests/framework/rbac/ManagerTestCase.php b/tests/framework/rbac/ManagerTestCase.php index 67a3248..4fc10d2 100644 --- a/tests/framework/rbac/ManagerTestCase.php +++ b/tests/framework/rbac/ManagerTestCase.php @@ -480,4 +480,22 @@ abstract class ManagerTestCase extends TestCase $auth->update('Reader', $role); $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); + } }