10 use Magento\Authorization\Model\ResourceModel\Role\CollectionFactory as RoleCollectionFactory;
48 $this->_objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
51 $userType =
'userType';
53 $this->userContext = $this->getMockBuilder(\
Magento\Authorization\Model\CompositeUserContext::class)
54 ->disableOriginalConstructor()
55 ->setMethods([
'getUserId',
'getUserType'])
57 $this->userContext->expects($this->once())
59 ->will($this->returnValue($userId));
60 $this->userContext->expects($this->once())
61 ->method(
'getUserType')
62 ->will($this->returnValue($userType));
64 $this->roleCollectionFactory = $this->getMockBuilder(
66 )->disableOriginalConstructor()->setMethods([
'create'])->getMock();
69 ->disableOriginalConstructor()
70 ->setMethods([
'setUserFilter',
'getFirstItem'])
72 $this->roleCollectionFactory->expects($this->once())
74 ->will($this->returnValue($this->roleCollection));
75 $this->roleCollection->expects($this->once())
76 ->method(
'setUserFilter')
77 ->with($userId, $userType)
78 ->will($this->returnValue($this->roleCollection));
80 $this->role = $this->getMockBuilder(\
Magento\Authorization\Model\Role::class)
81 ->disableOriginalConstructor()
82 ->setMethods([
'getId',
'__wakeup'])
85 $this->roleCollection->expects($this->once())
86 ->method(
'getFirstItem')
87 ->will($this->returnValue($this->role));
89 $this->locator = $this->_objectManager->getObject(
92 'userContext' => $this->userContext,
93 'roleCollectionFactory' => $this->roleCollectionFactory
100 $this->role->expects($this->once())
102 ->will($this->returnValue(
null));
104 $this->assertEquals(
'', $this->locator->getAclRoleId());
111 $this->role->expects($this->exactly(2))
113 ->will($this->returnValue(
$roleId));
115 $this->assertEquals(
$roleId, $this->locator->getAclRoleId());