|
6 | 6 |
|
7 | 7 | namespace Magento\Customer\Test\Unit\Controller\Plugin;
|
8 | 8 |
|
| 9 | +use Closure; |
9 | 10 | use Magento\Customer\Controller\AccountInterface;
|
10 | 11 | use Magento\Customer\Controller\Plugin\Account;
|
11 | 12 | use Magento\Customer\Model\Session;
|
@@ -83,40 +84,38 @@ protected function setUp()
|
83 | 84 | /**
|
84 | 85 | * @param string $action
|
85 | 86 | * @param array $allowedActions
|
86 |
| - * @param boolean $isActionAllowed |
| 87 | + * @param boolean $isAllowed |
87 | 88 | * @param boolean $isAuthenticated
|
88 | 89 | *
|
89 | 90 | * @dataProvider beforeExecuteDataProvider
|
90 | 91 | */
|
91 |
| - public function testBeforeExecute($action, $allowedActions, $isActionAllowed, $isAuthenticated) |
| 92 | + public function testAroundExecuteInterruptsOriginalCallWhenNotAllowed(string $action, array $allowedActions, bool $isAllowed, bool $isAuthenticated) |
92 | 93 | {
|
| 94 | + /** @var callable|MockObject $proceedMock */ |
| 95 | + $proceedMock = $this->getMockBuilder(\stdClass::class) |
| 96 | + ->setMethods(['__invoke']) |
| 97 | + ->getMock(); |
| 98 | + |
| 99 | + $closureMock = Closure::fromCallable($proceedMock); |
| 100 | + |
93 | 101 | $this->requestMock->expects($this->once())
|
94 | 102 | ->method('getActionName')
|
95 | 103 | ->willReturn($action);
|
96 | 104 |
|
97 |
| - if ($isActionAllowed) { |
98 |
| - $this->sessionMock->expects($this->once()) |
99 |
| - ->method('setNoReferer') |
100 |
| - ->with(true) |
101 |
| - ->willReturnSelf(); |
| 105 | + if ($isAllowed) { |
| 106 | + $proceedMock->expects($this->once())->method('__invoke')->willReturn($this->resultMock); |
102 | 107 | } else {
|
103 |
| - $this->sessionMock->expects($this->once()) |
104 |
| - ->method('authenticate') |
105 |
| - ->willReturn($isAuthenticated); |
106 |
| - if (!$isAuthenticated) { |
107 |
| - $this->actionMock->expects($this->once()) |
108 |
| - ->method('getActionFlag') |
109 |
| - ->willReturn($this->actionFlagMock); |
110 |
| - |
111 |
| - $this->actionFlagMock->expects($this->once()) |
112 |
| - ->method('set') |
113 |
| - ->with('', ActionInterface::FLAG_NO_DISPATCH, true) |
114 |
| - ->willReturnSelf(); |
115 |
| - } |
| 108 | + $proceedMock->expects($this->never())->method('__invoke'); |
116 | 109 | }
|
117 | 110 |
|
118 | 111 | $plugin = new Account($this->requestMock, $this->sessionMock, $allowedActions);
|
119 |
| - $plugin->beforeExecute($this->actionMock); |
| 112 | + $result = $plugin->aroundExecute($this->actionMock, $closureMock); |
| 113 | + |
| 114 | + if ($isAllowed) { |
| 115 | + $this->assertSame($this->resultMock, $result); |
| 116 | + } else { |
| 117 | + $this->assertNull($result); |
| 118 | + } |
120 | 119 | }
|
121 | 120 |
|
122 | 121 | /**
|
@@ -157,24 +156,4 @@ public function beforeExecuteDataProvider()
|
157 | 156 | ],
|
158 | 157 | ];
|
159 | 158 | }
|
160 |
| - |
161 |
| - public function testAfterExecute() |
162 |
| - { |
163 |
| - $this->sessionMock->expects($this->once()) |
164 |
| - ->method('unsNoReferer') |
165 |
| - ->with(false) |
166 |
| - ->willReturnSelf(); |
167 |
| - |
168 |
| - $plugin = (new ObjectManager($this))->getObject( |
169 |
| - Account::class, |
170 |
| - [ |
171 |
| - 'session' => $this->sessionMock, |
172 |
| - 'allowedActions' => ['testaction'] |
173 |
| - ] |
174 |
| - ); |
175 |
| - $this->assertSame( |
176 |
| - $this->resultMock, |
177 |
| - $plugin->afterExecute($this->actionMock, $this->resultMock, $this->requestMock) |
178 |
| - ); |
179 |
| - } |
180 | 159 | }
|
0 commit comments