1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/**
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\Acl\Test\Unit\Role;
use \Magento\Framework\Acl\Role\Registry;
class RegistryTest extends \PHPUnit\Framework\TestCase
{
/**
* @var Registry
*/
protected $model;
protected function setUp()
{
$this->model = new Registry();
}
/**
* @param $roleId
* @param $parentRoleId
* @return array
* @throws \Zend_Acl_Role_Registry_Exception
*/
protected function initRoles($roleId, $parentRoleId)
{
$parentRole = $this->createMock(\Zend_Acl_Role_Interface::class);
$parentRole->expects($this->any())->method('getRoleId')->will($this->returnValue($parentRoleId));
$role = $this->createMock(\Zend_Acl_Role_Interface::class);
$role->expects($this->any())->method('getRoleId')->will($this->returnValue($roleId));
$this->model->add($role);
$this->model->add($parentRole);
return [$role, $parentRole];
}
public function testAddParent()
{
$roleId = 1;
$parentRoleId = 2;
list($role, $parentRole) = $this->initRoles($roleId, $parentRoleId);
$this->assertEmpty($this->model->getParents($roleId));
$this->model->addParent($role, $parentRole);
$this->model->getParents($roleId);
$this->assertEquals([$parentRoleId => $parentRole], $this->model->getParents($roleId));
}
public function testAddParentByIds()
{
$roleId = 14;
$parentRoleId = 25;
list(, $parentRole) = $this->initRoles($roleId, $parentRoleId);
$this->assertEmpty($this->model->getParents($roleId));
$this->model->addParent($roleId, $parentRoleId);
$this->model->getParents($roleId);
$this->assertEquals([$parentRoleId => $parentRole], $this->model->getParents($roleId));
}
/**
* @expectedException \Zend_Acl_Role_Registry_Exception
* @expectedExceptionMessage Child Role id '20' does not exist
*/
public function testAddParentWrongChildId()
{
$roleId = 1;
$parentRoleId = 2;
list(, $parentRole) = $this->initRoles($roleId, $parentRoleId);
$this->model->addParent(20, $parentRole);
}
/**
* @expectedException \Zend_Acl_Role_Registry_Exception
* @expectedExceptionMessage Parent Role id '26' does not exist
*/
public function testAddParentWrongParentId()
{
$roleId = 1;
$parentRoleId = 2;
list($role,) = $this->initRoles($roleId, $parentRoleId);
$this->model->addParent($role, 26);
}
}