9 use \Magento\Authorization\Model\CompositeUserContext;
34 $this->compositeHelperMock = $this->getMockBuilder(\
Magento\Framework\
ObjectManager\Helper\Composite::class)
35 ->disableOriginalConstructor()
36 ->setMethods([
'filterAndSortDeclaredComponents'])
38 $this->compositeHelperMock
39 ->expects($this->any())
40 ->method(
'filterAndSortDeclaredComponents')
41 ->will($this->returnArgument(0));
42 $this->userContext = $this->objectManager->getObject(
43 \
Magento\Authorization\Model\CompositeUserContext::class,
44 [
'compositeHelper' => $this->compositeHelperMock]
54 'type' => $userContextMock,
57 $model = $this->objectManager->getObject(
58 \
Magento\Authorization\Model\CompositeUserContext::class,
59 [
'compositeHelper' => $this->compositeHelperMock,
'userContexts' => $contexts]
67 $expectedUserType =
'Customer';
68 $userContextMock = $this->getMockBuilder(\
Magento\Authorization\Model\CompositeUserContext::class)
69 ->disableOriginalConstructor()->setMethods([
'getUserId',
'getUserType'])->getMock();
70 $userContextMock->expects($this->any())->method(
'getUserId')->will($this->returnValue($expectedUserId));
71 $userContextMock->expects($this->any())->method(
'getUserType')->will($this->returnValue($expectedUserType));
75 'type' => $userContextMock,
78 $this->userContext = $this->objectManager->getObject(
79 \
Magento\Authorization\Model\CompositeUserContext::class,
80 [
'compositeHelper' => $this->compositeHelperMock,
'userContexts' => $contexts]
82 $actualUserId = $this->userContext->getUserId();
83 $this->assertEquals($expectedUserId, $actualUserId,
'User ID is defined incorrectly.');
89 $expectedUserType =
'Customer';
90 $userContextMock = $this->getMockBuilder(\
Magento\Authorization\Model\CompositeUserContext::class)
91 ->disableOriginalConstructor()->setMethods([
'getUserId',
'getUserType'])->getMock();
92 $userContextMock->expects($this->any())->method(
'getUserId')->will($this->returnValue($expectedUserId));
93 $userContextMock->expects($this->any())->method(
'getUserType')->will($this->returnValue($expectedUserType));
97 'type' => $userContextMock,
100 $this->userContext = $this->objectManager->getObject(
101 \
Magento\Authorization\Model\CompositeUserContext::class,
102 [
'compositeHelper' => $this->compositeHelperMock,
'userContexts' => $contexts]
104 $actualUserType = $this->userContext->getUserType();
105 $this->assertEquals($expectedUserType, $actualUserType,
'User Type is defined incorrectly.');
111 $expectedUserType =
'Customer';
112 $userContextMock = $this->getMockBuilder(\
Magento\Authorization\Model\CompositeUserContext::class)
113 ->disableOriginalConstructor()->setMethods([
'getUserId',
'getUserType'])->getMock();
114 $userContextMock->expects($this->exactly(3))->method(
'getUserType')
115 ->will($this->returnValue($expectedUserType));
116 $userContextMock->expects($this->exactly(3))->method(
'getUserId')
117 ->will($this->returnValue($expectedUserId));
121 'type' => $userContextMock,
124 $this->userContext = $this->objectManager->getObject(
125 \
Magento\Authorization\Model\CompositeUserContext::class,
126 [
'compositeHelper' => $this->compositeHelperMock,
'userContexts' => $contexts]
128 $this->userContext->getUserId();
129 $this->userContext->getUserId();
130 $this->userContext->getUserType();
131 $this->userContext->getUserType();
136 $expectedUserId =
null;
137 $userContextMock = $this->getMockBuilder(\
Magento\Authorization\Model\CompositeUserContext::class)
138 ->disableOriginalConstructor()->setMethods([
'getUserId'])->getMock();
139 $userContextMock->expects($this->any())->method(
'getUserId')
140 ->will($this->returnValue($expectedUserId));
144 'type' => $userContextMock,
147 $this->userContext = $this->objectManager->getObject(
148 \
Magento\Authorization\Model\CompositeUserContext::class,
149 [
'compositeHelper' => $this->compositeHelperMock,
'userContexts' => $contexts]
151 $actualUserId = $this->userContext->getUserId();
152 $this->assertEquals($expectedUserId, $actualUserId,
'User ID is defined incorrectly.');
162 $useContextMock = $this->getMockBuilder(\
Magento\Authorization\Model\CompositeUserContext::class)
163 ->disableOriginalConstructor()->setMethods([
'getUserId',
'getUserType'])->getMock();
164 if ($userId !==
null && $userType !==
null) {
165 $useContextMock->expects($this->any())->method(
'getUserId')->will($this->returnValue($userId));
166 $useContextMock->expects($this->any())->method(
'getUserType')->will($this->returnValue($userType));
168 return $useContextMock;
178 \
Magento\Authorization\Model\CompositeUserContext::class,
183 $this->assertCount(1,
$values,
'User context is not registered.');
184 $this->assertEquals($userContextMock,
$values[0],
'User context is registered incorrectly.');
createUserContextMock($userId=null, $userType=null)
verifyUserContextIsAdded($model, $userContextMock)