ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
ilMailTest Class Reference
+ Inheritance diagram for ilMailTest:
+ Collaboration diagram for ilMailTest:

Public Member Functions

 testExternalMailDeliveryWorksAsExpected ()
 
 testGetMailObjectReferenceId ()
 
 testFormatNamesForOutput ()
 
 testGetPreviousMail (array $row_data)
 
 testGetNextMail ()
 
 testGetMailsOfFolder ()
 
 testCountMailsOfFolder ()
 
 testGetMail ()
 
 testMarkRead ()
 
 testMarkUnread ()
 
 testMoveMailsToFolder ()
 
 testMoveMailsToFolderFalse ()
 
 testGetNewDraftId ()
 
 testUpdateDraft ()
 
 testPersistingToStage ()
 
 testRetrievalFromStage ()
 
 testValidateRecipients ($errors=[])
 
 provideValidateRecipients ()
 
 testGetIliasMailerName ()
 
 testSaveAttachments ()
 

Static Public Member Functions

static provideGetPreviousMail ()
 

Private Member Functions

 queryCallback ($return_value, array $expected_types, array $expected_values)
 
 createAndExpectDatabaseCall (int $some_mail_id, array $row_data)
 
 create (int $ref_id=234, int $usr_id=123)
 

Private Attributes

MockObject &ilDBInterface $mock_database
 
MockObject &ilMailAddressTypeFactory $mock_address_type_factory
 
MockObject &ilLogger $mock_log
 
MockObject &ilMailRfc822AddressParserFactory $mock_parser_factory
 
MockObject &ilLanguage $mock_language
 

Additional Inherited Members

- Protected Member Functions inherited from ilMailBaseTestCase
 brutallyTrimHTML (string $html)
 
 setUp ()
 
 tearDown ()
 
 setGlobalVariable (string $name, $value)
 

Detailed Description

Definition at line 30 of file ilMailTest.php.

Member Function Documentation

◆ create()

ilMailTest::create ( int  $ref_id = 234,
int  $usr_id = 123 
)
private

Definition at line 657 of file ilMailTest.php.

657 : ilMail
658 {
659 $refinery = $this->getMockBuilder(\ILIAS\Refinery\Factory::class)->disableOriginalConstructor()->getMock();
660 $this->setGlobalVariable('refinery', $refinery);
661
662 $instance = new ilMail(
663 $usr_id,
664 ($this->mock_address_type_factory = $this->getMockBuilder(ilMailAddressTypeFactory::class)->disableOriginalConstructor()->getMock()),
665 ($this->mock_parser_factory = $this->getMockBuilder(ilMailRfc822AddressParserFactory::class)->disableOriginalConstructor()->getMock()),
666 $this->getMockBuilder(ilAppEventHandler::class)->disableOriginalConstructor()->getMock(),
667 ($this->mock_log = $this->getMockBuilder(ilLogger::class)->disableOriginalConstructor()->getMock()),
668 ($this->mock_database = $this->getMockBuilder(ilDBInterface::class)->disableOriginalConstructor()->getMock()),
669 ($this->mock_language = $this->getMockBuilder(ilLanguage::class)->disableOriginalConstructor()->getMock()),
670 $this->getMockBuilder(ilFileDataMail::class)->disableOriginalConstructor()->getMock(),
671 $this->getMockBuilder(ilMailOptions::class)->disableOriginalConstructor()->getMock(),
672 $this->getMockBuilder(ilMailbox::class)->disableOriginalConstructor()->getMock(),
673 $this->getMockBuilder(ilMailMimeSenderFactory::class)->disableOriginalConstructor()->getMock(),
674 static fn(string $login): int => 780,
675 $this->createMock(AutoresponderService::class),
676 0,
677 $ref_id,
678 $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->getMock(),
679 $this->getMockBuilder(ilMailTemplatePlaceholderResolver::class)->disableOriginalConstructor()->getMock(),
680 null,
681 null,
682 $this->getMockBuilder(MailSignatureService::class)->disableOriginalConstructor()->getMock(),
683 );
684
685 return $instance;
686 }
setGlobalVariable(string $name, $value)
$ref_id
Definition: ltiauth.php:66
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.

References $ref_id, ILIAS\UI\examples\Layout\Page\Mail\$refinery, and ilMailBaseTestCase\setGlobalVariable().

Referenced by createAndExpectDatabaseCall(), testCountMailsOfFolder(), testFormatNamesForOutput(), testGetMailObjectReferenceId(), testGetMailsOfFolder(), testGetNewDraftId(), testMarkRead(), testMarkUnread(), testMoveMailsToFolder(), testMoveMailsToFolderFalse(), testPersistingToStage(), testRetrievalFromStage(), testSaveAttachments(), testUpdateDraft(), and testValidateRecipients().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createAndExpectDatabaseCall()

ilMailTest::createAndExpectDatabaseCall ( int  $some_mail_id,
array  $row_data 
)
private

Definition at line 646 of file ilMailTest.php.

646 : ilMail
647 {
648 $usr_id = 900;
649 $instance = $this->create(234, $usr_id);
650 $mock_statement = $this->getMockBuilder(ilDBStatement::class)->getMock();
651 $this->mock_database->expects($this->once())->method('fetchAssoc')->with($mock_statement)->willReturn($row_data);
652 $this->mock_database->expects($this->once())->method('queryF')->willReturnCallback($this->queryCallback($mock_statement, ['integer', 'integer'], [$usr_id, $some_mail_id]));
653
654 return $instance;
655 }
queryCallback($return_value, array $expected_types, array $expected_values)
Definition: ilMailTest.php:636
create(int $ref_id=234, int $usr_id=123)
Definition: ilMailTest.php:657

References create(), and queryCallback().

Referenced by testGetMail(), testGetNextMail(), and testGetPreviousMail().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ provideGetPreviousMail()

static ilMailTest::provideGetPreviousMail ( )
static

Definition at line 293 of file ilMailTest.php.

293 : array
294 {
295 return [
296 [[]],
297 [[
298 'attachments' => '',
299 'folder_id' => '',
300 'mail_id' => '',
301 'sender_id' => '',
302 'tpl_ctx_params' => '[]',
303 'use_placeholders' => '',
304 'user_id' => 0
305 ]],
306 [[
307 'folder_id' => '',
308 'mail_id' => '',
309 'sender_id' => '',
310 'use_placeholders' => '',
311 'user_id' => 0
312 ]],
313 ];
314 }

◆ provideValidateRecipients()

ilMailTest::provideValidateRecipients ( )

Definition at line 598 of file ilMailTest.php.

598 : array
599 {
600 return [
601 [[]],
602 [['some error']]
603 ];
604 }

◆ queryCallback()

ilMailTest::queryCallback (   $return_value,
array  $expected_types,
array  $expected_values 
)
private

Definition at line 636 of file ilMailTest.php.

636 : Closure
637 {
638 return function (string $query, array $types, array $values) use ($expected_types, $expected_values, $return_value) {
639 $this->assertEquals($expected_types, $types);
640 $this->assertEquals($expected_values, $values);
641
642 return $return_value;
643 };
644 }

Referenced by createAndExpectDatabaseCall(), testCountMailsOfFolder(), testGetMailsOfFolder(), testMarkRead(), testMarkUnread(), testMoveMailsToFolder(), testPersistingToStage(), and testRetrievalFromStage().

+ Here is the caller graph for this function:

◆ testCountMailsOfFolder()

ilMailTest::testCountMailsOfFolder ( )

Definition at line 351 of file ilMailTest.php.

351 : void
352 {
353 $usr_id = 46;
354 $folder_id = 68;
355 $num_rows = 89;
356 $instance = $this->create(345, $usr_id);
357 $mock_statement = $this->getMockBuilder(ilDBStatement::class)->getMock();
358 $this->mock_database->expects($this->once())->method('queryF')->willReturnCallback($this->queryCallback($mock_statement, ['integer', 'integer'], [$usr_id, $folder_id]));
359 $this->mock_database->expects($this->once())->method('numRows')->with($mock_statement)->willReturn($num_rows);
360
361 $this->assertSame($num_rows, $instance->countMailsOfFolder($folder_id));
362 }

References create(), and queryCallback().

+ Here is the call graph for this function:

◆ testExternalMailDeliveryWorksAsExpected()

ilMailTest::testExternalMailDeliveryWorksAsExpected ( )

Definition at line 38 of file ilMailTest.php.

38 : void
39 {
40 $refinery = $this->getMockBuilder(Factory::class)->disableOriginalConstructor()->getMock();
41 $this->setGlobalVariable('refinery', $refinery);
42
43 $legal_documents = $this->createMock(Conductor::class);
44 $this->setGlobalVariable('legalDocuments', $legal_documents);
45
46 $this->setGlobalVariable('ilIliasIniFile', $this->createMock(ilIniFile::class));
47 $this->setGlobalVariable('ilDB', $this->createMock(ilDBInterface::class));
48 $this->setGlobalVariable('ilClientIniFile', $this->createMock(ilIniFile::class));
49 $this->setGlobalVariable('lng', $this->createMock(ilLanguage::class));
50 $this->setGlobalVariable('ilCtrl', $this->createMock(ilCtrl::class));
51
52 $web_dir = 'public/data';
53 define('ILIAS_WEB_DIR', $web_dir);
54
55 $sender_usr_id = 666;
56 $active_users_login_to_id_map = [
57 'phpunit1' => 1,
58 'phpunit2' => 2,
59 'phpunit3' => 3,
60 'phpunit4' => 4,
61 'phpunit5' => 5,
62 'phpunit6' => 6,
63 'phpunit7' => 7,
64 ];
65 $expired_users_login_to_id_map = [
66 'phpunit8' => 8,
67 ];
68 $inactive_users_login_to_id_map = [
69 'phpunit9' => 9,
70 ];
71 $inactive_and_expired_users_login_to_id_map = [
72 'phpunit10' => 10,
73 ];
74 $all_users_login_to_id_map = array_merge(
75 $active_users_login_to_id_map,
76 $expired_users_login_to_id_map,
77 $inactive_users_login_to_id_map,
78 $inactive_and_expired_users_login_to_id_map
79 );
80
81 $transformation = $this->createMock(Transformation::class);
82 $transformation->method('applyTo')->willReturn(
83 new Ok(null)
84 );
85 $legal_documents->expects($this->exactly(count($active_users_login_to_id_map)))->method(
86 'userCanReadInternalMail'
87 )->willReturn($transformation);
88
89 $usr_instances_by_id = [];
90 $mail_options_by_id = [];
91
92 $user_groups = [
93 'Active And Not Expired' => [
94 $active_users_login_to_id_map,
95 true,
96 true
97 ],
98 'Active But Expired' => [
99 $expired_users_login_to_id_map,
100 true,
101 false
102 ],
103 'Inactive And Not Expired' => [
104 $inactive_users_login_to_id_map,
105 false,
106 true
107 ],
108 'Inactive And Expired' => [
109 $inactive_and_expired_users_login_to_id_map,
110 false,
111 false
112 ],
113 ];
114
115 foreach ($user_groups as $user_group) {
116 foreach ($user_group[0] as $usr_id) {
117 $user = $this
118 ->getMockBuilder(ilObjUser::class)
119 ->disableOriginalConstructor()
120 ->onlyMethods(['getId', 'checkTimeLimit', 'getActive'])
121 ->getMock();
122 $user->method('getId')->willReturn($usr_id);
123 $user->method('getActive')->willReturn($user_group[1]);
124 $user->method('checkTimeLimit')->willReturn($user_group[2]);
125 $usr_instances_by_id[$usr_id] = $user;
126
127 $mail_options = $this
128 ->getMockBuilder(ilMailOptions::class)
129 ->disableOriginalConstructor()
130 ->onlyMethods(['getExternalEmailAddresses', 'getIncomingType'])
131 ->getMock();
132 $mail_options->method('getExternalEmailAddresses')->willReturn([
133 'phpunit' . $usr_id . '@ilias.de',
134 ]);
135 $mail_options->method('getIncomingType')->willReturn(ilMailOptions::INCOMING_EMAIL);
136 $mail_options_by_id[$usr_id] = $mail_options;
137 }
138 }
139
140 $user = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->getMock();
141 ilMailMimeSenderUserById::addUserToCache($sender_usr_id, $user);
142
143 $address_type_factory = $this
144 ->getMockBuilder(ilMailAddressTypeFactory::class)
145 ->disableOriginalConstructor()
146 ->onlyMethods(['getByPrefix'])
147 ->getMock();
148 $address_type_factory
149 ->method('getByPrefix')
150 ->willReturnCallback(function ($arg) use ($all_users_login_to_id_map): object {
151 return new class ($arg, $all_users_login_to_id_map) implements ilMailAddressType {
152 protected array $login_to_id_map = [];
153
154 public function __construct(protected ilMailAddress $address, $login_to_id_map)
155 {
156 $this->login_to_id_map = array_map(static function (int $usr_id): array {
157 return [$usr_id];
158 }, $login_to_id_map);
159 }
160
161 public function resolve(): array
162 {
163 return $this->login_to_id_map[$this->address->getMailbox()] ?? [];
164 }
165
166 public function validate(int $sender_id): bool
167 {
168 return true;
169 }
170
171 public function getErrors(): array
172 {
173 return [];
174 }
175
176 public function getAddress(): ilMailAddress
177 {
178 return $this->address;
179 }
180 };
181 });
182
183 $db = $this->getMockBuilder(ilDBInterface::class)->getMock();
184 $next_id = 0;
185 $db->method('nextId')->willReturnCallback(function () use (&$next_id): int {
186 ++$next_id;
187
188 return $next_id;
189 });
190
191 $event_handler = $this->getMockBuilder(ilAppEventHandler::class)->disableOriginalConstructor()->getMock();
192 $logger = $this->getMockBuilder(ilLogger::class)->disableOriginalConstructor()->getMock();
193 $lng = $this->getMockBuilder(ilLanguage::class)->disableOriginalConstructor()->getMock();
194 $settings = $this->getMockBuilder(ilSetting::class)->disableOriginalConstructor()->getMock();
195 $settings->method('get')->willReturn('');
196 $this->setGlobalVariable('ilSetting', $settings);
197
198 $mail_file_data = $this->getMockBuilder(ilFileDataMail::class)->disableOriginalConstructor()->getMock();
199 $mail_options = $this->getMockBuilder(ilMailOptions::class)->disableOriginalConstructor()->getMock();
200 $mail_box = $this->getMockBuilder(ilMailbox::class)->disableOriginalConstructor()->getMock();
201 $actor = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->getMock();
202 $mustache_factory = $this->getMockBuilder(ilMustacheFactory::class)->getMock();
203
204 $mail_service = new ilMail(
205 $sender_usr_id,
206 $address_type_factory,
208 $event_handler,
209 $logger,
210 $db,
211 $lng,
212 $mail_file_data,
213 $mail_options,
214 $mail_box,
215 new ilMailMimeSenderFactory($settings, $mustache_factory),
216 static fn(string $login): int => $all_users_login_to_id_map[$login] ?? 0,
217 $this->createMock(AutoresponderService::class),
218 0,
219 4711,
220 $actor,
221 new ilMailTemplatePlaceholderResolver(new Mustache_Engine())
222 );
223
224 $old_transport = ilMimeMail::getDefaultTransport();
225
226 $mail_transport = $this
227 ->getMockBuilder(ilMailMimeTransport::class)
228 ->getMock();
229 $mail_transport->expects($this->once())->method('send')->with($this->callback(function (
230 ilMimeMail $mailer
231 ) use ($active_users_login_to_id_map): bool {
232 $total_bcc = [];
233 foreach ($mailer->getBcc() as $bcc) {
234 $total_bcc = array_filter(array_map('trim', explode(',', $bcc))) + $total_bcc;
235 }
236
237 return count($total_bcc) === count($active_users_login_to_id_map);
238 }))->willReturn(true);
239 ilMimeMail::setDefaultTransport($mail_transport);
240
241 $mail_service->setUserInstanceById($usr_instances_by_id);
242 $mail_service->setMailOptionsByUserIdMap($mail_options_by_id);
243
244 $mail_data = new MailDeliveryData(
245 implode(
246 ',',
247 array_merge(
248 array_slice(array_keys($active_users_login_to_id_map), 0, 3),
249 $expired_users_login_to_id_map,
250 $inactive_users_login_to_id_map,
251 $inactive_and_expired_users_login_to_id_map
252 )
253 ),
254 implode(',', array_slice(array_keys($active_users_login_to_id_map), 3, 2)),
255 implode(',', array_slice(array_keys($active_users_login_to_id_map), 5, 2)),
256 'Subject',
257 'Message',
258 [],
259 false
260 );
261 $mail_service->sendMail($mail_data);
262
263 ilMimeMail::setDefaultTransport($old_transport);
264 }
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:31
return true
static addUserToCache(int $usr_id, ilObjUser $user)
final const int INCOMING_EMAIL
static getDefaultTransport()
static setDefaultTransport(?ilMailMimeTransport $transport)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $lng
Definition: privfeed.php:31

References $lng, ILIAS\UI\examples\Layout\Page\Mail\$refinery, ILIAS\GlobalScreen\Provider\__construct(), ilMailMimeSenderUserById\addUserToCache(), ilMimeMail\getBcc(), ilMimeMail\getDefaultTransport(), ilMailOptions\INCOMING_EMAIL, ilMimeMail\setDefaultTransport(), ilMailBaseTestCase\setGlobalVariable(), and true.

+ Here is the call graph for this function:

◆ testFormatNamesForOutput()

ilMailTest::testFormatNamesForOutput ( )

Definition at line 274 of file ilMailTest.php.

274 : void
275 {
276 $instance = $this->create();
277
278 $this->mock_language->expects($this->once())->method('txt')->with('not_available')->willReturn('not_available');
279
280 $this->assertSame('not_available', $instance->formatNamesForOutput(''));
281 $this->assertSame('', $instance->formatNamesForOutput(','));
282 }

References create().

+ Here is the call graph for this function:

◆ testGetIliasMailerName()

ilMailTest::testGetIliasMailerName ( )

Definition at line 606 of file ilMailTest.php.

606 : void
607 {
608 $expected = 'Phasellus lacus';
609 $settings = $this->getMockBuilder(ilSetting::class)->disableOriginalConstructor()->getMock();
610 $settings->method('get')->with('mail_system_sys_from_name')->willReturn($expected);
611 $this->setGlobalVariable('ilSetting', $settings);
612
613
614 $this->assertSame($expected, ilMail::_getIliasMailerName());
615 }
static _getIliasMailerName()

References ilMail\_getIliasMailerName(), and ilMailBaseTestCase\setGlobalVariable().

+ Here is the call graph for this function:

◆ testGetMail()

ilMailTest::testGetMail ( )

Definition at line 364 of file ilMailTest.php.

364 : void
365 {
366 $mail_id = 7890;
367 $instance = $this->createAndExpectDatabaseCall($mail_id, []);
368 $instance->getMail($mail_id);
369 }
createAndExpectDatabaseCall(int $some_mail_id, array $row_data)
Definition: ilMailTest.php:646

References createAndExpectDatabaseCall().

+ Here is the call graph for this function:

◆ testGetMailObjectReferenceId()

ilMailTest::testGetMailObjectReferenceId ( )

Definition at line 266 of file ilMailTest.php.

266 : void
267 {
268 $ref_id = 364;
269 $instance = $this->create($ref_id);
270
271 $this->assertSame($ref_id, $instance->getMailObjectReferenceId());
272 }

References $ref_id, and create().

+ Here is the call graph for this function:

◆ testGetMailsOfFolder()

ilMailTest::testGetMailsOfFolder ( )

Definition at line 324 of file ilMailTest.php.

324 : void
325 {
326 $filter = ['status' => 'yes'];
327 $row_data = ['mail_id' => 8908];
328 $one = $row_data + [
329 'attachments' => null,
330 'tpl_ctx_params' => [],
331 'm_subject' => '',
332 'm_message' => '',
333 'rcp_to' => '',
334 'rcp_cc' => '',
335 'rcp_bcc' => '',
336 ];
337 $expected = [$one, $one];
338 $folder_id = 89;
339 $usr_id = 901;
340 $instance = $this->create(234, $usr_id);
341 $mock_statement = $this->getMockBuilder(ilDBStatement::class)->getMock();
342 $this->mock_database->expects($this->never())->method('setLimit');
343 $this->mock_database->expects($this->exactly(3))->method('fetchAssoc')->with($mock_statement)->willReturnOnConsecutiveCalls($row_data, $row_data, null);
344 $this->mock_database->expects($this->once())->method('queryF')->willReturnCallback($this->queryCallback($mock_statement, ['integer', 'integer'], [$usr_id, $folder_id]));
345
346 $this->mock_database->expects($this->once())->method('quote')->with($filter['status'], 'text')->willReturn($filter['status']);
347
348 $this->assertEquals($expected, $instance->getMailsOfFolder($folder_id, $filter));
349 }

References create(), and queryCallback().

+ Here is the call graph for this function:

◆ testGetNewDraftId()

ilMailTest::testGetNewDraftId ( )

Definition at line 417 of file ilMailTest.php.

417 : void
418 {
419 $next_id = 789;
420 $usr_id = 5678;
421 $folder_id = 47;
422 $instance = $this->create(4749, $usr_id);
423
424 $this->mock_database->expects($this->once())->method('nextId')->with('mail')->willReturn($next_id);
425 $this->mock_database->expects($this->once())->method('insert')->with('mail', [
426 'mail_id' => ['integer', $next_id],
427 'user_id' => ['integer', $usr_id],
428 'folder_id' => ['integer', $folder_id],
429 'sender_id' => ['integer', $usr_id],
430 ]);
431
432 $this->assertSame($next_id, $instance->getNewDraftId($folder_id));
433 }

References create().

+ Here is the call graph for this function:

◆ testGetNextMail()

ilMailTest::testGetNextMail ( )

Definition at line 316 of file ilMailTest.php.

316 : void
317 {
318 $mail_id = 8484;
319 $instance = $this->createAndExpectDatabaseCall($mail_id, []);
320 $this->mock_database->expects($this->once())->method('setLimit')->with(1, 0);
321 $instance->getNextMail($mail_id);
322 }

References createAndExpectDatabaseCall().

+ Here is the call graph for this function:

◆ testGetPreviousMail()

ilMailTest::testGetPreviousMail ( array  $row_data)

Definition at line 285 of file ilMailTest.php.

285 : void
286 {
287 $mail_id = 3454;
288 $instance = $this->createAndExpectDatabaseCall($mail_id, $row_data);
289 $this->mock_database->expects($this->once())->method('setLimit')->with(1, 0);
290 $instance->getPreviousMail($mail_id);
291 }

References createAndExpectDatabaseCall().

+ Here is the call graph for this function:

◆ testMarkRead()

ilMailTest::testMarkRead ( )

Definition at line 371 of file ilMailTest.php.

371 : void
372 {
373 $mail_ids = [1, 2, 3, 4, 5, 6];
374 $usr_id = 987;
375 $instance = $this->create(567, $usr_id);
376 $this->getMockBuilder(ilDBStatement::class)->getMock();
377 $this->mock_database->expects($this->once())->method('in')->with('mail_id', $mail_ids, false, 'integer')->willReturn('');
378 $this->mock_database->expects($this->once())->method('manipulateF')->willReturnCallback($this->queryCallback(0, ['text', 'integer'], ['read', $usr_id]));
379
380 $instance->markRead($mail_ids);
381 }

References create(), and queryCallback().

+ Here is the call graph for this function:

◆ testMarkUnread()

ilMailTest::testMarkUnread ( )

Definition at line 383 of file ilMailTest.php.

383 : void
384 {
385 $mail_ids = [1, 2, 3, 4, 5, 6];
386 $usr_id = 987;
387 $instance = $this->create(567, $usr_id);
388 $this->getMockBuilder(ilDBStatement::class)->getMock();
389 $this->mock_database->expects($this->once())->method('in')->with('mail_id', $mail_ids, false, 'integer')->willReturn('');
390 $this->mock_database->expects($this->once())->method('manipulateF')->willReturnCallback($this->queryCallback(0, ['text', 'integer'], ['unread', $usr_id]));
391
392 $instance->markUnread($mail_ids);
393 }

References create(), and queryCallback().

+ Here is the call graph for this function:

◆ testMoveMailsToFolder()

ilMailTest::testMoveMailsToFolder ( )

Definition at line 395 of file ilMailTest.php.

395 : void
396 {
397 $mail_ids = [1, 2, 3, 4, 5, 6];
398 $folder_id = 890;
399 $usr_id = 987;
400 $instance = $this->create(567, $usr_id);
401 $this->mock_database->expects($this->once())->method('in')->with('mail_id', $mail_ids, false, 'integer')->willReturn('');
402 $this->mock_database->expects($this->once())->method('manipulateF')->willReturnCallback($this->queryCallback(1, ['integer', 'integer', 'integer'], [$folder_id, $usr_id, $usr_id]));
403
404 $this->assertTrue($instance->moveMailsToFolder($mail_ids, $folder_id));
405 }

References create(), and queryCallback().

+ Here is the call graph for this function:

◆ testMoveMailsToFolderFalse()

ilMailTest::testMoveMailsToFolderFalse ( )

Definition at line 407 of file ilMailTest.php.

407 : void
408 {
409 $mail_ids = [];
410 $instance = $this->create();
411 $this->mock_database->expects($this->never())->method('in');
412 $this->mock_database->expects($this->never())->method('manipulateF');
413
414 $this->assertFalse($instance->moveMailsToFolder($mail_ids, 892));
415 }

References create().

+ Here is the call graph for this function:

◆ testPersistingToStage()

ilMailTest::testPersistingToStage ( )

Definition at line 491 of file ilMailTest.php.

491 : void
492 {
493 $usr_id = 897;
494 $attachments = null;
495 $rcp_to = 'jlh';
496 $rcp_cc = 'jhkjh';
497 $rcp_bcc = 'ououi';
498 $subject = 'hbansn';
499 $message = 'message';
500 $use_placeholders = false;
501 $context_id = '9080';
502 $params = [];
503
504 $instance = $this->create(789, $usr_id);
505
506 $this->mock_database->expects($this->once())->method('replace')->with('mail_saved', [
507 'user_id' => ['integer', $usr_id],
508 ], [
509 'attachments' => ['text', $attachments],
510 'rcp_to' => ['clob', $rcp_to],
511 'rcp_cc' => ['clob', $rcp_cc],
512 'rcp_bcc' => ['clob', $rcp_bcc],
513 'm_subject' => ['text', $subject],
514 'm_message' => ['clob', $message],
515 'use_placeholders' => ['integer', (int) $use_placeholders],
516 'tpl_ctx_id' => ['text', $context_id],
517 'tpl_ctx_params' => ['blob', json_encode($params, JSON_THROW_ON_ERROR)],
518 ]);
519
520 $mock_statement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
521 $this->mock_database->expects($this->once())->method('queryF')->willReturnCallback($this->queryCallback($mock_statement, ['integer'], [$usr_id]));
522 $this->mock_database->expects($this->once())->method('fetchAssoc')->with($mock_statement)->willReturn([
523 'rcp_to' => 'phpunit'
524 ]);
525
526 $instance->persistToStage(
527 $usr_id,
528 $rcp_to,
529 $rcp_cc,
530 $rcp_bcc,
531 $subject,
532 $message,
533 $attachments,
534 $use_placeholders,
535 $context_id,
536 $params,
537 );
538 }
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:31

References $params, create(), and queryCallback().

+ Here is the call graph for this function:

◆ testRetrievalFromStage()

ilMailTest::testRetrievalFromStage ( )

Definition at line 540 of file ilMailTest.php.

540 : void
541 {
542 $usr_id = 789;
543 $instance = $this->create(67, $usr_id);
544 $mock_statement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
545 $this->mock_database->expects($this->once())->method('queryF')->willReturnCallback($this->queryCallback($mock_statement, ['integer'], [$usr_id]));
546 $this->mock_database->expects($this->once())->method('fetchAssoc')->with($mock_statement)->willReturn([
547 'rcp_to' => 'phpunit'
548 ]);
549
550 $mail_data = $instance->retrieveFromStage();
551
552 $this->assertIsArray($mail_data);
553 $this->assertEquals('phpunit', $mail_data['rcp_to']);
554 }

References create(), and queryCallback().

+ Here is the call graph for this function:

◆ testSaveAttachments()

ilMailTest::testSaveAttachments ( )

Definition at line 617 of file ilMailTest.php.

617 : void
618 {
619 $usr_id = 89;
620 $attachments = new \ILIAS\ResourceStorage\Identification\ResourceCollectionIdentification('657497dc-5079-4f95-b19d-aecdaf81ff1a');
621 $instance = $this->create(789, $usr_id);
622
623 $this->mock_database->expects($this->once())->method('update')->with(
624 'mail_saved',
625 [
626 'attachments' => ['text', $attachments->serialize()],
627 ],
628 [
629 'user_id' => ['integer', $usr_id],
630 ]
631 );
632
633 $instance->saveAttachments($attachments);
634 }

References create().

+ Here is the call graph for this function:

◆ testUpdateDraft()

ilMailTest::testUpdateDraft ( )

Definition at line 435 of file ilMailTest.php.

435 : void
436 {
437 $send_time = '2022-01-01 00:00:00';
438 $tz = new DateTimeZone('Europe/Berlin');
439 $date_time = new DateTimeImmutable($send_time, $tz);
440
441 $folder_id = 7890;
442 $instance = $this->create();
443 $to = 'abc';
444 $cc = 'bcde';
445 $bcc = 'jkl';
446 $subject = 'jlh';
447 $message = 'some message';
448 $use_placeholders = true;
449 $context_id = '87';
450 $params = [];
451 $draft_id = 78;
452
453 $this->mock_database->expects($this->once())->method('update')->with('mail', [
454 'folder_id' => ['integer', $folder_id],
455 'attachments' => ['clob', serialize([])],
456 'send_time' => ['timestamp', date('Y-m-d H:i:s')],
457 'rcp_to' => ['clob', $to],
458 'rcp_cc' => ['clob', $cc],
459 'rcp_bcc' => ['clob', $bcc],
460 'm_status' => ['text', 'read'],
461 'm_subject' => ['text', $subject],
462 'm_message' => ['clob', $message],
463 'use_placeholders' => ['integer', (int) $use_placeholders],
464 'tpl_ctx_id' => ['text', $context_id],
465 'tpl_ctx_params' => ['blob', json_encode($params, JSON_THROW_ON_ERROR)],
466 'schedule_datetime' => ['timestamp', $date_time->format('Y-m-d H:i:s')],
467 'schedule_timezone' => ['text', $tz->getName()],
468 ], [
469 'mail_id' => ['integer', $draft_id],
470 ]);
471
472 $this->assertSame(
473 $draft_id,
474 $instance->updateDraft(
475 $folder_id,
476 [],
477 $to,
478 $cc,
479 $bcc,
480 $subject,
481 $message,
482 $draft_id,
483 $date_time,
484 $use_placeholders,
485 $context_id,
486 $params,
487 )
488 );
489 }

References $params, and create().

+ Here is the call graph for this function:

◆ testValidateRecipients()

ilMailTest::testValidateRecipients (   $errors = [])

Definition at line 556 of file ilMailTest.php.

556 : void
557 {
558 $to = 'jkhk';
559 $cc = 'hjhjkl';
560 $bcc = 'jklhjk';
561
562 $instance = $this->create();
563 $consecutive_debug = [
564 'Started parsing of recipient string: ' . $to,
565 'Parsed addresses: hello',
566 'Started parsing of recipient string: ' . $cc,
567 'Parsed addresses: hello',
568 'Started parsing of recipient string: ' . $bcc,
569 'Parsed addresses: hello'
570 ];
571 $this->mock_log->expects($this->exactly(6))->method('debug')->with(
572 $this->callback(function ($value) use (&$consecutive_debug) {
573 $this->assertSame(array_shift($consecutive_debug), $value);
574 return true;
575 }),
576 );
577
578 $mock_address = $this->getMockBuilder(ilMailAddress::class)->disableOriginalConstructor()->getMock();
579 $mock_address->expects($this->exactly(3))->method('__toString')->willReturn('hello');
580 $mock_parser = $this->getMockBuilder(ilMailRecipientParser::class)->disableOriginalConstructor()->getMock();
581 $mock_parser->expects($this->exactly(3))->method('parse')->willReturn([$mock_address]);
582 $consecutive_get = [$to, $cc, $bcc];
583 $this->mock_parser_factory->expects($this->exactly(3))->method('getParser')->with(
584 $this->callback(function ($value) use (&$consecutive_get) {
585 $this->assertSame(array_shift($consecutive_get), $value);
586 return true;
587 }),
588 )->willReturn($mock_parser);
589
590 $mock_addressType = $this->getMockBuilder(ilMailAddressType::class)->disableOriginalConstructor()->getMock();
591 $mock_addressType->expects($this->exactly(3))->method('validate')->willReturn(empty($errors));
592 $mock_addressType->expects($this->exactly(empty($errors) ? 0 : 3))->method('getErrors')->willReturn($errors);
593 $this->mock_address_type_factory->expects($this->exactly(3))->method('getByPrefix')->with($mock_address)->willReturn($mock_addressType);
594
595 $this->assertSame([], $instance->validateRecipients($to, $cc, $bcc));
596 }

References create().

+ Here is the call graph for this function:

Field Documentation

◆ $mock_address_type_factory

MockObject& ilMailAddressTypeFactory ilMailTest::$mock_address_type_factory
private

Definition at line 33 of file ilMailTest.php.

◆ $mock_database

MockObject& ilDBInterface ilMailTest::$mock_database
private

Definition at line 32 of file ilMailTest.php.

◆ $mock_language

MockObject& ilLanguage ilMailTest::$mock_language
private

Definition at line 36 of file ilMailTest.php.

◆ $mock_log

MockObject& ilLogger ilMailTest::$mock_log
private

Definition at line 34 of file ilMailTest.php.

◆ $mock_parser_factory

MockObject& ilMailRfc822AddressParserFactory ilMailTest::$mock_parser_factory
private

Definition at line 35 of file ilMailTest.php.


The documentation for this class was generated from the following file: