ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilMailTaskProcessorTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
30 {
34  protected const SOME_USER_ID = 113;
35 
39  protected function setUp(): void
40  {
41  parent::setUp();
42 
43  $this->languageMock = $this->getMockBuilder(ilLanguage::class)
44  ->disableOriginalConstructor()
45  ->getMock();
46 
47  $this->dicMock = $this->getMockBuilder(Container::class)
48  ->disableOriginalConstructor()
49  ->getMock();
50 
51  $this->loggerMock = $this->getMockBuilder(ilLogger::class)
52  ->disableOriginalConstructor()
53  ->getMock();
54  }
55 
57  {
58  $this->expectException(InvalidArgumentException::class);
59 
60  $mailValueObject = new ilMailValueObject(
61  'ilias@server.com',
62  'somebody@iliase.de',
63  '',
64  '',
65  'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce mollis posuere tincidunt. Phasellus et euismod ligula. Suspendisse dignissim eget dui nec imperdiet. Donec in pretium tellus. Maecenas lacinia eleifend erat ut euismod. Aenean eu malesuada est.',
66  'Dear Steve, great!',
67  []
68  );
69  }
70 
75  public function testOneTask(): void
76  {
77  $taskManager = $this->getMockBuilder(BasicTaskManager::class)
78  ->onlyMethods(['run'])
79  ->disableOriginalConstructor()
80  ->getMock();
81 
82  $taskManager
83  ->expects($this->once())
84  ->method('run');
85 
86  $taskFactory = $this->getMockBuilder(ILIAS\BackgroundTasks\Task\TaskFactory::class)
87  ->onlyMethods(['createTask'])
88  ->disableOriginalConstructor()
89  ->getMock();
90 
91  $backgroundTask = $this->getMockBuilder(ilMailDeliveryJob::class)
92  ->disableOriginalConstructor()
93  ->getMock();
94 
95  $backgroundTask->method('unfoldTask')
96  ->willReturn([]);
97 
98  $taskFactory
99  ->expects($this->exactly(2))
100  ->method('createTask')
101  ->willReturn($backgroundTask);
102 
103 
104  $worker = new ilMassMailTaskProcessor(
105  self::SOME_USER_ID,
106  $taskManager,
107  $taskFactory,
108  $this->languageMock,
109  $this->loggerMock,
110  $this->dicMock,
112  );
113 
114  $mailValueObject = new ilMailValueObject(
115  'ilias@server.com',
116  'somebody@iliase.de',
117  '',
118  '',
119  'That is awesome!',
120  'Dear Steve, great!',
121  []
122  );
123 
124  $mailValueObjects = [
125  $mailValueObject,
126  ];
127 
128  $userId = 100;
129  $contextId = '5';
130  $contextParameters = [];
131 
132  $worker->run(
133  $mailValueObjects,
134  $userId,
135  $contextId,
136  $contextParameters
137  );
138  }
139 
144  public function testRunTwoTasks(): void
145  {
146  $taskManager = $this->getMockBuilder(BasicTaskManager::class)
147  ->onlyMethods(['run'])
148  ->disableOriginalConstructor()
149  ->getMock();
150 
151  $taskManager
152  ->expects($this->once())
153  ->method('run');
154 
155  $taskFactory = $this->getMockBuilder(TaskFactory::class)
156  ->onlyMethods(['createTask'])
157  ->disableOriginalConstructor()
158  ->getMock();
159 
160  $backgroundTask = $this->getMockBuilder(ilMailDeliveryJob::class)
161  ->disableOriginalConstructor()
162  ->getMock();
163 
164  $backgroundTask
165  ->method('unfoldTask')
166  ->willReturn([]);
167 
168  $taskFactory
169  ->expects($this->exactly(2))
170  ->method('createTask')
171  ->willReturn($backgroundTask);
172 
173  $worker = new ilMassMailTaskProcessor(
174  self::SOME_USER_ID,
175  $taskManager,
176  $taskFactory,
177  $this->languageMock,
178  $this->loggerMock,
179  $this->dicMock,
181  );
182 
183  $mailValueObjects = [];
184 
185  $mailValueObjects[] = new ilMailValueObject(
186  'ilias@server.com',
187  'somebody@iliase.de',
188  '',
189  '',
190  'That is awesome!',
191  'Dear Steve, great!',
192  []
193  );
194 
195  $mailValueObjects[] = new ilMailValueObject(
196  'ilias@server.com',
197  'somebodyelse@iliase.de',
198  '',
199  '',
200  'Greate',
201  'Steve, Steve, Steve. Wait that is not Steve',
202  []
203  );
204 
205  $userId = 100;
206  $contextId = '5';
207  $contextParameters = [];
208 
209  $worker->run(
210  $mailValueObjects,
211  $userId,
212  $contextId,
213  $contextParameters
214  );
215  }
216 
221  public function testRunThreeTasksInDifferentBuckets(): void
222  {
223  $taskManager = $this->getMockBuilder(BasicTaskManager::class)
224  ->onlyMethods(['run'])
225  ->disableOriginalConstructor()
226  ->getMock();
227 
228  $taskManager
229  ->expects($this->exactly(2))
230  ->method('run');
231 
232  $taskFactory = $this->getMockBuilder(TaskFactory::class)
233  ->onlyMethods(['createTask'])
234  ->disableOriginalConstructor()
235  ->getMock();
236 
237  $backgroundTask = $this->getMockBuilder(ilMailDeliveryJob::class)
238  ->disableOriginalConstructor()
239  ->getMock();
240 
241  $backgroundTask
242  ->method('unfoldTask')
243  ->willReturn([]);
244 
245  $taskFactory
246  ->expects($this->exactly(4))
247  ->method('createTask')
248  ->willReturn($backgroundTask);
249 
250  $worker = new ilMassMailTaskProcessor(
251  self::SOME_USER_ID,
252  $taskManager,
253  $taskFactory,
254  $this->languageMock,
255  $this->loggerMock,
256  $this->dicMock,
258  );
259 
260  $mailValueObjects = [];
261 
262  $mailValueObjects[] = new ilMailValueObject(
263  'ilias@server.com',
264  'somebody@iliase.de',
265  '',
266  '',
267  'That is awesome!',
268  'Dear Steve, great!',
269  []
270  );
271 
272  $mailValueObjects[] = new ilMailValueObject(
273  'ilias@server.com',
274  'somebodyelse@iliase.de',
275  '',
276  '',
277  'Greate',
278  'Steve, Steve, Steve. Wait that is not Steve',
279  []
280  );
281 
282  $mailValueObjects[] = new ilMailValueObject(
283  'ilias@server.com',
284  'somebody@iliase.de',
285  '',
286  '',
287  'That is awesome!',
288  'Hey Alan! Alan! Alan!',
289  []
290  );
291 
292  $userId = 100;
293  $contextId = '5';
294  $contextParameters = [];
295 
296  $worker->run(
297  $mailValueObjects,
298  $userId,
299  $contextId,
300  $contextParameters,
301  2
302  );
303  }
304 
310  {
311  $this->expectException(ilMailException::class);
312 
313  $taskManager = $this->getMockBuilder(BasicTaskManager::class)
314  ->onlyMethods(['run'])
315  ->disableOriginalConstructor()
316  ->getMock();
317 
318  $taskManager
319  ->expects($this->never())
320  ->method('run');
321 
322  $taskFactory = $this->getMockBuilder(TaskFactory::class)
323  ->onlyMethods(['createTask'])
324  ->disableOriginalConstructor()
325  ->getMock();
326 
327  $backgroundTask = $this->getMockBuilder(ilMailDeliveryJob::class)
328  ->disableOriginalConstructor()
329  ->getMock();
330 
331  $backgroundTask
332  ->method('unfoldTask')
333  ->willReturn([]);
334 
335  $taskFactory
336  ->expects($this->never())
337  ->method('createTask')
338  ->willReturn($backgroundTask);
339 
340  $worker = new ilMassMailTaskProcessor(
341  self::SOME_USER_ID,
342  $taskManager,
343  $taskFactory,
344  $this->languageMock,
345  $this->loggerMock,
346  $this->dicMock,
348  );
349 
350  $mailValueObjects = [];
351 
352  $mailValueObjects[] = new ilMailValueObject(
353  'ilias@server.com',
354  'somebody@iliase.de',
355  '',
356  '',
357  'That is awesome!',
358  'Dear Steve, great!',
359  []
360  );
361 
362  $mailValueObjects[] = new ilMailValueObject(
363  'ilias@server.com',
364  'somebodyelse@iliase.de',
365  '',
366  '',
367  'Greate',
368  'Steve, Steve, Steve. Wait that is not Steve',
369  []
370  );
371 
372  $mailValueObjects[] = 'This should fail';
373 
374  $userId = 100;
375  $contextId = '5';
376  $contextParameters = [];
377 
378  $worker->run(
379  $mailValueObjects,
380  $userId,
381  $contextId,
382  $contextParameters,
383  2
384  );
385  }
386 }
Interface Observer Contains several chained tasks and infos about them.
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:35
Class ilMailBaseTest.
Class ilMailTaskProcessorTest.