ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ilMailTaskProcessorTest.php
Go to the documentation of this file.
1 <?php declare(strict_types=1);
2 
3 /* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
8 
14 {
16  private $languageMock;
17 
19  private $dicMock;
20 
22  private $loggerMock;
23 
27  public function setUp() : void
28  {
29  $this->languageMock = $this->getMockBuilder(ilLanguage::class)
30  ->disableOriginalConstructor()
31  ->getMock();
32 
33  $this->dicMock = $this->getMockBuilder(Container::class)
34  ->disableOriginalConstructor()
35  ->getMock();
36 
37  $this->loggerMock = $this->getMockBuilder(ilLogger::class)
38  ->disableOriginalConstructor()
39  ->getMock();
40  }
41 
46  public function testOneTask() : void
47  {
48  $taskManager = $this->getMockBuilder(BasicTaskManager::class)
49  ->onlyMethods(['run'])
50  ->disableOriginalConstructor()
51  ->getMock();
52 
53  $taskManager
54  ->expects($this->exactly(1))
55  ->method('run');
56 
57  $taskFactory = $this->getMockBuilder(ILIAS\BackgroundTasks\Task\TaskFactory::class)
58  ->onlyMethods(['createTask'])
59  ->disableOriginalConstructor()
60  ->getMock();
61 
62  $backgroundTask = $this->getMockbuilder(ilMailDeliveryJob::class)
63  ->disableOriginalConstructor()
64  ->getMock();
65 
66  $backgroundTask->expects($this->any())->method('unfoldTask')
67  ->willReturn([]);
68 
69  $taskFactory
70  ->expects($this->exactly(2))
71  ->method('createTask')
72  ->willReturn($backgroundTask);
73 
74 
75  $worker = new ilMassMailTaskProcessor(
76  $taskManager,
77  $taskFactory,
78  $this->languageMock,
79  $this->loggerMock,
80  $this->dicMock,
82  'SomeAnonymousUserId'
83  );
84 
85  $mailValueObject = new ilMailValueObject(
86  'ilias@server.com',
87  'somebody@iliase.de',
88  '',
89  '',
90  'That is awesome!',
91  'Dear Steve, great!',
92  []
93  );
94 
95  $mailValueObjects = [
96  $mailValueObject
97  ];
98 
99  $userId = 100;
100  $contextId = '5';
101  $contextParameters = [];
102 
103  $worker->run(
104  $mailValueObjects,
105  $userId,
106  $contextId,
107  $contextParameters
108  );
109  }
110 
115  public function testRunTwoTasks() : void
116  {
117  $taskManager = $this->getMockBuilder(BasicTaskManager::class)
118  ->onlyMethods(['run'])
119  ->disableOriginalConstructor()
120  ->getMock();
121 
122  $taskManager
123  ->expects($this->exactly(1))
124  ->method('run');
125 
126  $taskFactory = $this->getMockBuilder(TaskFactory::class)
127  ->onlyMethods(['createTask'])
128  ->disableOriginalConstructor()
129  ->getMock();
130 
131  $backgroundTask = $this->getMockbuilder(ilMailDeliveryJob::class)
132  ->disableOriginalConstructor()
133  ->getMock();
134 
135  $backgroundTask
136  ->expects($this->any())
137  ->method('unfoldTask')
138  ->willReturn([]);
139 
140  $taskFactory
141  ->expects($this->exactly(2))
142  ->method('createTask')
143  ->willReturn($backgroundTask);
144 
145  $worker = new ilMassMailTaskProcessor(
146  $taskManager,
147  $taskFactory,
148  $this->languageMock,
149  $this->loggerMock,
150  $this->dicMock,
152  'SomeAnonymousUserId'
153  );
154 
155  $mailValueObjects = [];
156 
157  $mailValueObjects[] = new ilMailValueObject(
158  'ilias@server.com',
159  'somebody@iliase.de',
160  '',
161  '',
162  'That is awesome!',
163  'Dear Steve, great!',
164  []
165  );
166 
167  $mailValueObjects[] = new ilMailValueObject(
168  'ilias@server.com',
169  'somebodyelse@iliase.de',
170  '',
171  '',
172  'Greate',
173  'Steve, Steve, Steve. Wait that is not Steve',
174  []
175  );
176 
177  $userId = 100;
178  $contextId = '5';
179  $contextParameters = [];
180 
181  $worker->run(
182  $mailValueObjects,
183  $userId,
184  $contextId,
185  $contextParameters
186  );
187  }
188 
193  public function testRunThreeTasksInDifferentBuckets() : void
194  {
195  $taskManager = $this->getMockBuilder(BasicTaskManager::class)
196  ->onlyMethods(['run'])
197  ->disableOriginalConstructor()
198  ->getMock();
199 
200  $taskManager
201  ->expects($this->exactly(2))
202  ->method('run');
203 
204  $taskFactory = $this->getMockBuilder(TaskFactory::class)
205  ->onlyMethods(['createTask'])
206  ->disableOriginalConstructor()
207  ->getMock();
208 
209  $backgroundTask = $this->getMockbuilder(ilMailDeliveryJob::class)
210  ->disableOriginalConstructor()
211  ->getMock();
212 
213  $backgroundTask
214  ->expects($this->any())
215  ->method('unfoldTask')
216  ->willReturn([]);
217 
218  $taskFactory
219  ->expects($this->exactly(4))
220  ->method('createTask')
221  ->willReturn($backgroundTask);
222 
223  $worker = new ilMassMailTaskProcessor(
224  $taskManager,
225  $taskFactory,
226  $this->languageMock,
227  $this->loggerMock,
228  $this->dicMock,
230  'SomeAnonymousUserId'
231  );
232 
233  $mailValueObjects = [];
234 
235  $mailValueObjects[] = new ilMailValueObject(
236  'ilias@server.com',
237  'somebody@iliase.de',
238  '',
239  '',
240  'That is awesome!',
241  'Dear Steve, great!',
242  []
243  );
244 
245  $mailValueObjects[] = new ilMailValueObject(
246  'ilias@server.com',
247  'somebodyelse@iliase.de',
248  '',
249  '',
250  'Greate',
251  'Steve, Steve, Steve. Wait that is not Steve',
252  []
253  );
254 
255  $mailValueObjects[] = new ilMailValueObject(
256  'ilias@server.com',
257  'somebody@iliase.de',
258  '',
259  '',
260  'That is awesome!',
261  'Hey Alan! Alan! Alan!',
262  []
263  );
264 
265  $userId = 100;
266  $contextId = '5';
267  $contextParameters = [];
268 
269  $worker->run(
270  $mailValueObjects,
271  $userId,
272  $contextId,
273  $contextParameters,
274  2
275  );
276  }
277 
283  {
284  $this->expectException(ilException::class);
285 
286  $taskManager = $this->getMockBuilder(BasicTaskManager::class)
287  ->onlyMethods(['run'])
288  ->disableOriginalConstructor()
289  ->getMock();
290 
291  $taskManager
292  ->expects($this->never())
293  ->method('run');
294 
295  $taskFactory = $this->getMockBuilder(TaskFactory::class)
296  ->onlyMethods(['createTask'])
297  ->disableOriginalConstructor()
298  ->getMock();
299 
300  $backgroundTask = $this->getMockbuilder(ilMailDeliveryJob::class)
301  ->disableOriginalConstructor()
302  ->getMock();
303 
304  $backgroundTask
305  ->expects($this->any())
306  ->method('unfoldTask')
307  ->willReturn([]);
308 
309  $taskFactory
310  ->expects($this->never())
311  ->method('createTask')
312  ->willReturn($backgroundTask);
313 
314  $worker = new ilMassMailTaskProcessor(
315  $taskManager,
316  $taskFactory,
317  $this->languageMock,
318  $this->loggerMock,
319  $this->dicMock,
321  'SomeAnonymousUserId'
322  );
323 
324  $mailValueObjects = [];
325 
326  $mailValueObjects[] = new ilMailValueObject(
327  'ilias@server.com',
328  'somebody@iliase.de',
329  '',
330  '',
331  'That is awesome!',
332  'Dear Steve, great!',
333  []
334  );
335 
336  $mailValueObjects[] = new ilMailValueObject(
337  'ilias@server.com',
338  'somebodyelse@iliase.de',
339  '',
340  '',
341  'Greate',
342  'Steve, Steve, Steve. Wait that is not Steve',
343  []
344  );
345 
346  $mailValueObjects[] = 'This should fail';
347 
348  $userId = 100;
349  $contextId = '5';
350  $contextParameters = [];
351 
352  $worker->run(
353  $mailValueObjects,
354  $userId,
355  $contextId,
356  $contextParameters,
357  2
358  );
359  }
360 }
Class ChatMainBarProvider .
Class ilMailBaseTest.
Class ilMailTaskProcessorTest.