Corrected fix for #8032

This commit is contained in:
Alexander Makarov
2015-04-12 12:17:35 +03:00
parent 8ac5776a0d
commit b806fc7108
2 changed files with 45 additions and 24 deletions

View File

@ -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;
}

View File

@ -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);
}
}