mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 14:26:54 +08:00
Corrected fix for #8032
This commit is contained in:
@ -571,13 +571,11 @@ class PhpManager extends BaseManager
|
||||
*/
|
||||
protected function updateItem($name, $item)
|
||||
{
|
||||
if ($name !== $item->name) {
|
||||
if (isset($this->items[$item->name])) {
|
||||
throw new InvalidParamException("Unable to change the item name. The name '{$item->name}' is already used by another item.");
|
||||
}
|
||||
|
||||
$this->items[$item->name] = $item;
|
||||
|
||||
if ($name !== $item->name && isset($this->items[$name])) {
|
||||
} else {
|
||||
// Remove old item in case of renaming
|
||||
unset($this->items[$name]);
|
||||
|
||||
if (isset($this->children[$name])) {
|
||||
@ -597,6 +595,10 @@ class PhpManager extends BaseManager
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->items[$item->name] = $item;
|
||||
|
||||
$this->saveItems();
|
||||
return true;
|
||||
}
|
||||
|
@ -110,14 +110,33 @@ class PhpManagerTest extends ManagerTestCase
|
||||
$this->assertEquals($rules, $this->auth->rules);
|
||||
}
|
||||
|
||||
public function testUpdateItem()
|
||||
public function testUpdateItemName()
|
||||
{
|
||||
$this->prepareData();
|
||||
|
||||
$name = 'readPost';
|
||||
$permission = $this->auth->getPermission($name);
|
||||
$permission->name = 'UPDATED-NAME';
|
||||
$this->assertTrue($this->auth->update($name, $permission));
|
||||
$this->assertTrue($this->auth->update($name, $permission), 'You should be able to update name.');
|
||||
}
|
||||
|
||||
public function testUpdateDescription() {
|
||||
$this->prepareData();
|
||||
$name = 'readPost';
|
||||
$permission = $this->auth->getPermission($name);
|
||||
$permission->description = 'UPDATED-DESCRIPTION';
|
||||
$this->assertTrue($this->auth->update($name, $permission), 'You should be able to save w/o changing name.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \yii\base\InvalidParamException
|
||||
*/
|
||||
public function testOverwriteName()
|
||||
{
|
||||
$this->prepareData();
|
||||
$name = 'readPost';
|
||||
$permission = $this->auth->getPermission($name);
|
||||
$permission->name = 'createPost';
|
||||
$this->auth->update($name, $permission);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user