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
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* Test class for \Magento\Framework\AuthorizationInterface.
*/
namespace Magento\Framework\Test\Unit;
class AuthorizationTest extends \PHPUnit\Framework\TestCase
{
/**
* Authorization model
*
* @var \Magento\Framework\AuthorizationInterface
*/
protected $_model;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $_policyMock;
protected function setUp()
{
$this->_policyMock = $this->createMock(\Magento\Framework\Authorization\PolicyInterface::class);
$roleLocatorMock = $this->createMock(\Magento\Framework\Authorization\RoleLocatorInterface::class);
$roleLocatorMock->expects($this->any())->method('getAclRoleId')->will($this->returnValue('U1'));
$this->_model = new \Magento\Framework\Authorization($this->_policyMock, $roleLocatorMock);
}
protected function tearDown()
{
unset($this->_model);
}
public function testIsAllowedReturnPositiveValue()
{
$this->_policyMock->expects($this->once())->method('isAllowed')->will($this->returnValue(true));
$this->assertTrue($this->_model->isAllowed('Magento_Module::acl_resource'));
}
public function testIsAllowedReturnNegativeValue()
{
$this->_policyMock->expects($this->once())->method('isAllowed')->will($this->returnValue(false));
$this->assertFalse($this->_model->isAllowed('Magento_Module::acl_resource'));
}
}