12 use Magento\Authorization\Model\ResourceModel\Role\CollectionFactory as RoleCollectionFactory;
14 use Magento\Authorization\Model\ResourceModel\Rules\CollectionFactory as RulesCollectionFactory;
33 $this->aclRetriever = $this->createAclRetriever();
38 $expectedResources = [
'anonymous'];
43 'Allowed resources for guests should be \'anonymous\'.' 49 $expectedResources = [
'self'];
57 'Allowed resources for customers should be \'self\'.' 67 $this->roleMock->expects($this->once())->method(
'getId')->will($this->returnValue(
null));
73 $this->roleMock->expects($this->any())->method(
'getId')->will($this->returnValue(1));
74 $expectedResources = [
'Magento_Backend::dashboard',
'Magento_Cms::page'];
84 protected function createAclRetriever()
86 $this->roleMock = $this->createPartialMock(\
Magento\Authorization\Model\Role::class, [
'getId',
'__wakeup']);
89 $roleCollectionMock = $this->createPartialMock(
91 [
'setUserFilter',
'getFirstItem']
93 $roleCollectionMock->expects($this->any())->method(
'setUserFilter')->will($this->returnSelf());
94 $roleCollectionMock->expects($this->any())->method(
'getFirstItem')->will($this->returnValue($this->roleMock));
97 $roleCollectionFactoryMock = $this->createPartialMock(
101 $roleCollectionFactoryMock->expects($this->any())->method(
'create')->will(
102 $this->returnValue($roleCollectionMock)
106 $rulesMock1 = $this->createPartialMock(
107 \
Magento\Authorization\Model\Rules::class,
108 [
'getResourceId',
'__wakeup']
110 $rulesMock1->expects($this->any())->method(
'getResourceId')->will(
111 $this->returnValue(
'Magento_Backend::dashboard')
114 $rulesMock2 = $this->createPartialMock(
115 \
Magento\Authorization\Model\Rules::class,
116 [
'getResourceId',
'__wakeup']
118 $rulesMock2->expects($this->any())->method(
'getResourceId')->will($this->returnValue(
'Magento_Cms::page'));
121 $rulesCollectionMock = $this->createPartialMock(
123 [
'getByRoles',
'load',
'getItems']
125 $rulesCollectionMock->expects($this->any())->method(
'getByRoles')->will($this->returnSelf());
126 $rulesCollectionMock->expects($this->any())->method(
'load')->will($this->returnSelf());
127 $rulesCollectionMock->expects($this->any())->method(
'getItems')->will(
128 $this->returnValue([$rulesMock1, $rulesMock2])
132 $rulesCollectionFactoryMock = $this->createPartialMock(
136 $rulesCollectionFactoryMock->expects($this->any())->method(
'create')->will(
137 $this->returnValue($rulesCollectionMock)
141 $aclMock = $this->createPartialMock(\
Magento\Framework\Acl::class, [
'has',
'isAllowed']);
142 $aclMock->expects($this->any())->method(
'has')->will($this->returnValue(
true));
143 $aclMock->expects($this->any())->method(
'isAllowed')->will($this->returnValue(
true));
146 $aclBuilderMock = $this->createPartialMock(\
Magento\Framework\Acl\Builder::class, [
'getAcl']);
147 $aclBuilderMock->expects($this->any())->method(
'getAcl')->will($this->returnValue($aclMock));
151 $roleCollectionFactoryMock,
152 $rulesCollectionFactoryMock,
153 $this->createMock(\Psr\Log\LoggerInterface::class)
testGetAllowedResourcesByUser()
testGetAllowedResourcesByUserTypeCustomer()
testGetAllowedResourcesByUserTypeGuest()
const USER_TYPE_INTEGRATION
testGetAllowedResourcesByUserRoleNotFound()