Browse Source

Fixes #12810: getChildRoles() throws an exception when role has no children

tags/2.0.11
Pavel Dovlatov 8 years ago committed by Alexander Makarov
parent
commit
73a30780b3
  1. 1
      framework/CHANGELOG.md
  2. 2
      framework/rbac/DbManager.php
  3. 2
      framework/rbac/PhpManager.php
  4. 8
      tests/framework/rbac/ManagerTestCase.php

1
framework/CHANGELOG.md

@ -5,6 +5,7 @@ Yii Framework 2 Change Log
------------------------
- Bug #12791: Fixed `yii\behaviors\AttributeTypecastBehavior` unable to automatically detect `attributeTypes`, triggering PHP Fatal Error (klimov-paul)
- Bug #12810: Fixed `yii\rbac\DbManager::getChildRoles()` and `yii\rbac\PhpManager::getChildRoles()` throws an exception when role has no child roles (mysterydragon)
- Enh #12790: Added `scrollToErrorOffset` option for `ActiveForm` which adds ability to specify offset in pixels when scrolling to error (mg-code)
- Enh #12807: Added console controller checks for `yii\console\controllers\HelpController` (schmunk42)

2
framework/rbac/DbManager.php

@ -481,7 +481,7 @@ class DbManager extends BaseManager
throw new InvalidParamException("Role \"$roleName\" not found.");
}
/** @var $result Item[] */
$result = [];
$this->getChildrenRecursive($roleName, $this->getChildrenList(), $result);
$roles = [$roleName => $role];

2
framework/rbac/PhpManager.php

@ -407,7 +407,7 @@ class PhpManager extends BaseManager
throw new InvalidParamException("Role \"$roleName\" not found.");
}
/** @var $result Item[] */
$result = [];
$this->getChildrenRecursive($roleName, $result);
$roles = [$roleName => $role];

8
tests/framework/rbac/ManagerTestCase.php

@ -223,6 +223,9 @@ abstract class ManagerTestCase extends TestCase
$updateAnyPost->description = 'update any post';
$this->auth->add($updateAnyPost);
$withoutChildren = $this->auth->createRole('withoutChildren');
$this->auth->add($withoutChildren);
$reader = $this->auth->createRole('reader');
$this->auth->add($reader);
$this->auth->addChild($reader, $readPost);
@ -292,6 +295,11 @@ abstract class ManagerTestCase extends TestCase
{
$this->prepareData();
$roles = $this->auth->getChildRoles('withoutChildren');
$this->assertCount(1, $roles);
$this->assertInstanceOf(Role::className(), reset($roles));
$this->assertTrue(reset($roles)->name === 'withoutChildren');
$roles = $this->auth->getChildRoles('reader');
$this->assertCount(1, $roles);
$this->assertInstanceOf(Role::className(), reset($roles));

Loading…
Cancel
Save