|
27 | 27 | */
|
28 | 28 | class PluginTest extends TestCase
|
29 | 29 | {
|
| 30 | + private const MESSAGES_LIMIT = 5; |
30 | 31 | /**
|
31 | 32 | * @var Plugin
|
32 | 33 | */
|
@@ -163,6 +164,60 @@ public function testAfterTo($operationDetails)
|
163 | 164 | $this->assertEquals(2, $result2['totalRecords']);
|
164 | 165 | }
|
165 | 166 |
|
| 167 | + /** |
| 168 | + * Tests that message building operations don't get called more than Plugin::MESSAGES_LIMIT times |
| 169 | + * |
| 170 | + * @return void |
| 171 | + */ |
| 172 | + public function testAfterToWithMessageLimit() |
| 173 | + { |
| 174 | + $result = ['items' =>[], 'totalRecords' => 1]; |
| 175 | + $messagesCount = self::MESSAGES_LIMIT + 1; |
| 176 | + $userId = 1; |
| 177 | + $bulkUuid = 2; |
| 178 | + $bulkArray = [ |
| 179 | + 'status' => BulkSummaryInterface::NOT_STARTED |
| 180 | + ]; |
| 181 | + |
| 182 | + $bulkMock = $this->getMockBuilder(BulkSummary::class) |
| 183 | + ->addMethods(['getStatus']) |
| 184 | + ->onlyMethods(['getBulkId', 'getDescription', 'getStartTime']) |
| 185 | + ->disableOriginalConstructor() |
| 186 | + ->getMock(); |
| 187 | + $userBulks = array_fill(0, $messagesCount, $bulkMock); |
| 188 | + $bulkMock->expects($this->exactly($messagesCount)) |
| 189 | + ->method('getBulkId')->willReturn($bulkUuid); |
| 190 | + $this->operationsDetailsMock |
| 191 | + ->expects($this->exactly(self::MESSAGES_LIMIT)) |
| 192 | + ->method('getDetails') |
| 193 | + ->with($bulkUuid) |
| 194 | + ->willReturn([ |
| 195 | + 'operations_successful' => 1, |
| 196 | + 'operations_failed' => 0 |
| 197 | + ]); |
| 198 | + $bulkMock->expects($this->exactly(self::MESSAGES_LIMIT)) |
| 199 | + ->method('getDescription')->willReturn('Bulk Description'); |
| 200 | + $this->messagefactoryMock->expects($this->exactly($messagesCount)) |
| 201 | + ->method('create')->willReturn($this->messageMock); |
| 202 | + $this->messageMock->expects($this->exactly($messagesCount))->method('toArray')->willReturn($bulkArray); |
| 203 | + $this->authorizationMock |
| 204 | + ->expects($this->once()) |
| 205 | + ->method('isAllowed') |
| 206 | + ->with($this->resourceName) |
| 207 | + ->willReturn(true); |
| 208 | + $this->userContextMock->expects($this->once())->method('getUserId')->willReturn($userId); |
| 209 | + $this->bulkNotificationMock |
| 210 | + ->expects($this->once()) |
| 211 | + ->method('getAcknowledgedBulksByUser') |
| 212 | + ->with($userId) |
| 213 | + ->willReturn([]); |
| 214 | + $this->statusMapper->expects($this->exactly(self::MESSAGES_LIMIT)) |
| 215 | + ->method('operationStatusToBulkSummaryStatus'); |
| 216 | + $this->bulkStatusMock->expects($this->once())->method('getBulksByUser')->willReturn($userBulks); |
| 217 | + $result2 = $this->plugin->afterToArray($this->collectionMock, $result); |
| 218 | + $this->assertEquals($result['totalRecords'] + $messagesCount, $result2['totalRecords']); |
| 219 | + } |
| 220 | + |
166 | 221 | /**
|
167 | 222 | * @return array
|
168 | 223 | */
|
|
0 commit comments