AuthorizationTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Test class for \Magento\Framework\AuthorizationInterface.
  8. */
  9. namespace Magento\Framework\Test\Unit;
  10. class AuthorizationTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * Authorization model
  14. *
  15. * @var \Magento\Framework\AuthorizationInterface
  16. */
  17. protected $_model;
  18. /**
  19. * @var \PHPUnit_Framework_MockObject_MockObject
  20. */
  21. protected $_policyMock;
  22. protected function setUp()
  23. {
  24. $this->_policyMock = $this->createMock(\Magento\Framework\Authorization\PolicyInterface::class);
  25. $roleLocatorMock = $this->createMock(\Magento\Framework\Authorization\RoleLocatorInterface::class);
  26. $roleLocatorMock->expects($this->any())->method('getAclRoleId')->will($this->returnValue('U1'));
  27. $this->_model = new \Magento\Framework\Authorization($this->_policyMock, $roleLocatorMock);
  28. }
  29. protected function tearDown()
  30. {
  31. unset($this->_model);
  32. }
  33. public function testIsAllowedReturnPositiveValue()
  34. {
  35. $this->_policyMock->expects($this->once())->method('isAllowed')->will($this->returnValue(true));
  36. $this->assertTrue($this->_model->isAllowed('Magento_Module::acl_resource'));
  37. }
  38. public function testIsAllowedReturnNegativeValue()
  39. {
  40. $this->_policyMock->expects($this->once())->method('isAllowed')->will($this->returnValue(false));
  41. $this->assertFalse($this->_model->isAllowed('Magento_Module::acl_resource'));
  42. }
  43. }