ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
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 32 of file ilMailTest.php.

Member Function Documentation

◆ create()

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

Definition at line 666 of file ilMailTest.php.

666 : ilMail
667 {
668 $refinery = $this->getMockBuilder(Factory::class)->disableOriginalConstructor()->getMock();
669 $this->setGlobalVariable('refinery', $refinery);
670
671 $instance = new ilMail(
672 $usr_id,
673 ($this->mock_address_type_factory = $this->getMockBuilder(ilMailAddressTypeFactory::class)->disableOriginalConstructor()->getMock()),
674 ($this->mock_parser_factory = $this->getMockBuilder(ilMailRfc822AddressParserFactory::class)->disableOriginalConstructor()->getMock()),
675 $this->getMockBuilder(ilAppEventHandler::class)->disableOriginalConstructor()->getMock(),
676 ($this->mock_log = $this->getMockBuilder(ilLogger::class)->disableOriginalConstructor()->getMock()),
677 ($this->mock_database = $this->createMock(ilDBInterface::class)),
678 ($this->mock_language = $this->getMockBuilder(ilLanguage::class)->disableOriginalConstructor()->getMock()),
679 $this->getMockBuilder(ilFileDataMail::class)->disableOriginalConstructor()->getMock(),
680 $this->getMockBuilder(ilMailOptions::class)->disableOriginalConstructor()->getMock(),
681 $this->getMockBuilder(ilMailbox::class)->disableOriginalConstructor()->getMock(),
682 $this->getMockBuilder(ilMailMimeSenderFactory::class)->disableOriginalConstructor()->getMock(),
683 static fn(string $login): int => 780,
684 $this->createMock(AutoresponderService::class),
685 0,
686 $ref_id,
687 $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->getMock(),
688 $this->getMockBuilder(ilMailTemplatePlaceholderResolver::class)->disableOriginalConstructor()->getMock(),
689 null,
690 null,
691 $this->getMockBuilder(MailSignatureService::class)->disableOriginalConstructor()->getMock(),
692 );
693
694 return $instance;
695 }
setGlobalVariable(string $name, $value)
$ref_id
Definition: ltiauth.php:66

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 655 of file ilMailTest.php.

655 : ilMail
656 {
657 $usr_id = 900;
658 $instance = $this->create(234, $usr_id);
659 $mock_statement = $this->getMockBuilder(ilDBStatement::class)->getMock();
660 $this->mock_database->expects($this->once())->method('fetchAssoc')->with($mock_statement)->willReturn($row_data);
661 $this->mock_database->expects($this->once())->method('queryF')->willReturnCallback($this->queryCallback($mock_statement, ['integer', 'integer'], [$usr_id, $some_mail_id]));
662
663 return $instance;
664 }
queryCallback($return_value, array $expected_types, array $expected_values)
Definition: ilMailTest.php:645
create(int $ref_id=234, int $usr_id=123)
Definition: ilMailTest.php:666

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 302 of file ilMailTest.php.

302 : array
303 {
304 return [
305 [[]],
306 [[
307 'attachments' => '',
308 'folder_id' => '',
309 'mail_id' => '',
310 'sender_id' => '',
311 'tpl_ctx_params' => '[]',
312 'use_placeholders' => '',
313 'user_id' => 0
314 ]],
315 [[
316 'folder_id' => '',
317 'mail_id' => '',
318 'sender_id' => '',
319 'use_placeholders' => '',
320 'user_id' => 0
321 ]],
322 ];
323 }

◆ provideValidateRecipients()

ilMailTest::provideValidateRecipients ( )

Definition at line 607 of file ilMailTest.php.

607 : array
608 {
609 return [
610 [[]],
611 [['some error']]
612 ];
613 }

◆ queryCallback()

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

Definition at line 645 of file ilMailTest.php.

645 : Closure
646 {
647 return function (string $query, array $types, array $values) use ($expected_types, $expected_values, $return_value) {
648 $this->assertEquals($expected_types, $types);
649 $this->assertEquals($expected_values, $values);
650
651 return $return_value;
652 };
653 }

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 360 of file ilMailTest.php.

360 : void
361 {
362 $usr_id = 46;
363 $folder_id = 68;
364 $num_rows = 89;
365 $instance = $this->create(345, $usr_id);
366 $mock_statement = $this->getMockBuilder(ilDBStatement::class)->getMock();
367 $this->mock_database->expects($this->once())->method('queryF')->willReturnCallback($this->queryCallback($mock_statement, ['integer', 'integer'], [$usr_id, $folder_id]));
368 $this->mock_database->expects($this->once())->method('numRows')->with($mock_statement)->willReturn($num_rows);
369
370 $this->assertSame($num_rows, $instance->countMailsOfFolder($folder_id));
371 }

References create(), and queryCallback().

+ Here is the call graph for this function:

◆ testExternalMailDeliveryWorksAsExpected()

ilMailTest::testExternalMailDeliveryWorksAsExpected ( )

Definition at line 40 of file ilMailTest.php.

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

283 : void
284 {
285 $instance = $this->create();
286
287 $this->mock_language->expects($this->once())->method('txt')->with('not_available')->willReturn('not_available');
288
289 $this->assertSame('not_available', $instance->formatNamesForOutput(''));
290 $this->assertSame('', $instance->formatNamesForOutput(','));
291 }

References create().

+ Here is the call graph for this function:

◆ testGetIliasMailerName()

ilMailTest::testGetIliasMailerName ( )

Definition at line 615 of file ilMailTest.php.

615 : void
616 {
617 $expected = 'Phasellus lacus';
618 $settings = $this->getMockBuilder(ilSetting::class)->disableOriginalConstructor()->getMock();
619 $settings->method('get')->with('mail_system_sys_from_name')->willReturn($expected);
620 $this->setGlobalVariable('ilSetting', $settings);
621
622
623 $this->assertSame($expected, ilMail::_getIliasMailerName());
624 }
static _getIliasMailerName()

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

+ Here is the call graph for this function:

◆ testGetMail()

ilMailTest::testGetMail ( )

Definition at line 373 of file ilMailTest.php.

373 : void
374 {
375 $mail_id = 7890;
376 $instance = $this->createAndExpectDatabaseCall($mail_id, []);
377 $instance->getMail($mail_id);
378 }
createAndExpectDatabaseCall(int $some_mail_id, array $row_data)
Definition: ilMailTest.php:655

References createAndExpectDatabaseCall().

+ Here is the call graph for this function:

◆ testGetMailObjectReferenceId()

ilMailTest::testGetMailObjectReferenceId ( )

Definition at line 275 of file ilMailTest.php.

275 : void
276 {
277 $ref_id = 364;
278 $instance = $this->create($ref_id);
279
280 $this->assertSame($ref_id, $instance->getMailObjectReferenceId());
281 }

References $ref_id, and create().

+ Here is the call graph for this function:

◆ testGetMailsOfFolder()

ilMailTest::testGetMailsOfFolder ( )

Definition at line 333 of file ilMailTest.php.

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

References create(), and queryCallback().

+ Here is the call graph for this function:

◆ testGetNewDraftId()

ilMailTest::testGetNewDraftId ( )

Definition at line 426 of file ilMailTest.php.

426 : void
427 {
428 $next_id = 789;
429 $usr_id = 5678;
430 $folder_id = 47;
431 $instance = $this->create(4749, $usr_id);
432
433 $this->mock_database->expects($this->once())->method('nextId')->with('mail')->willReturn($next_id);
434 $this->mock_database->expects($this->once())->method('insert')->with('mail', [
435 'mail_id' => ['integer', $next_id],
436 'user_id' => ['integer', $usr_id],
437 'folder_id' => ['integer', $folder_id],
438 'sender_id' => ['integer', $usr_id],
439 ]);
440
441 $this->assertSame($next_id, $instance->getNewDraftId($folder_id));
442 }

References create().

+ Here is the call graph for this function:

◆ testGetNextMail()

ilMailTest::testGetNextMail ( )

Definition at line 325 of file ilMailTest.php.

325 : void
326 {
327 $mail_id = 8484;
328 $instance = $this->createAndExpectDatabaseCall($mail_id, []);
329 $this->mock_database->expects($this->once())->method('setLimit')->with(1, 0);
330 $instance->getNextMail($mail_id);
331 }

References createAndExpectDatabaseCall().

+ Here is the call graph for this function:

◆ testGetPreviousMail()

ilMailTest::testGetPreviousMail ( array  $row_data)

Definition at line 294 of file ilMailTest.php.

294 : void
295 {
296 $mail_id = 3454;
297 $instance = $this->createAndExpectDatabaseCall($mail_id, $row_data);
298 $this->mock_database->expects($this->once())->method('setLimit')->with(1, 0);
299 $instance->getPreviousMail($mail_id);
300 }

References createAndExpectDatabaseCall().

+ Here is the call graph for this function:

◆ testMarkRead()

ilMailTest::testMarkRead ( )

Definition at line 380 of file ilMailTest.php.

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

References create(), and queryCallback().

+ Here is the call graph for this function:

◆ testMarkUnread()

ilMailTest::testMarkUnread ( )

Definition at line 392 of file ilMailTest.php.

392 : void
393 {
394 $mail_ids = [1, 2, 3, 4, 5, 6];
395 $usr_id = 987;
396 $instance = $this->create(567, $usr_id);
397 $this->getMockBuilder(ilDBStatement::class)->getMock();
398 $this->mock_database->expects($this->once())->method('in')->with('mail_id', $mail_ids, false, 'integer')->willReturn('');
399 $this->mock_database->expects($this->once())->method('manipulateF')->willReturnCallback($this->queryCallback(0, ['text', 'integer'], ['unread', $usr_id]));
400
401 $instance->markUnread($mail_ids);
402 }

References create(), and queryCallback().

+ Here is the call graph for this function:

◆ testMoveMailsToFolder()

ilMailTest::testMoveMailsToFolder ( )

Definition at line 404 of file ilMailTest.php.

404 : void
405 {
406 $mail_ids = [1, 2, 3, 4, 5, 6];
407 $folder_id = 890;
408 $usr_id = 987;
409 $instance = $this->create(567, $usr_id);
410 $this->mock_database->expects($this->once())->method('in')->with('mail_id', $mail_ids, false, 'integer')->willReturn('');
411 $this->mock_database->expects($this->once())->method('manipulateF')->willReturnCallback($this->queryCallback(1, ['integer', 'integer', 'integer'], [$folder_id, $usr_id, $usr_id]));
412
413 $this->assertTrue($instance->moveMailsToFolder($mail_ids, $folder_id));
414 }

References create(), and queryCallback().

+ Here is the call graph for this function:

◆ testMoveMailsToFolderFalse()

ilMailTest::testMoveMailsToFolderFalse ( )

Definition at line 416 of file ilMailTest.php.

416 : void
417 {
418 $mail_ids = [];
419 $instance = $this->create();
420 $this->mock_database->expects($this->never())->method('in');
421 $this->mock_database->expects($this->never())->method('manipulateF');
422
423 $this->assertFalse($instance->moveMailsToFolder($mail_ids, 892));
424 }

References create().

+ Here is the call graph for this function:

◆ testPersistingToStage()

ilMailTest::testPersistingToStage ( )

Definition at line 500 of file ilMailTest.php.

500 : void
501 {
502 $usr_id = 897;
503 $attachments = null;
504 $rcp_to = 'jlh';
505 $rcp_cc = 'jhkjh';
506 $rcp_bcc = 'ououi';
507 $subject = 'hbansn';
508 $message = 'message';
509 $use_placeholders = false;
510 $context_id = '9080';
511 $params = [];
512
513 $instance = $this->create(789, $usr_id);
514
515 $this->mock_database->expects($this->once())->method('replace')->with('mail_saved', [
516 'user_id' => ['integer', $usr_id],
517 ], [
518 'attachments' => ['text', $attachments],
519 'rcp_to' => ['clob', $rcp_to],
520 'rcp_cc' => ['clob', $rcp_cc],
521 'rcp_bcc' => ['clob', $rcp_bcc],
522 'm_subject' => ['text', $subject],
523 'm_message' => ['clob', $message],
524 'use_placeholders' => ['integer', (int) $use_placeholders],
525 'tpl_ctx_id' => ['text', $context_id],
526 'tpl_ctx_params' => ['blob', json_encode($params, JSON_THROW_ON_ERROR)],
527 ]);
528
529 $mock_statement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
530 $this->mock_database->expects($this->once())->method('queryF')->willReturnCallback($this->queryCallback($mock_statement, ['integer'], [$usr_id]));
531 $this->mock_database->expects($this->once())->method('fetchAssoc')->with($mock_statement)->willReturn([
532 'rcp_to' => 'phpunit'
533 ]);
534
535 $instance->persistToStage(
536 $usr_id,
537 $rcp_to,
538 $rcp_cc,
539 $rcp_bcc,
540 $subject,
541 $message,
542 $attachments,
543 $use_placeholders,
544 $context_id,
545 $params,
546 );
547 }
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 549 of file ilMailTest.php.

549 : void
550 {
551 $usr_id = 789;
552 $instance = $this->create(67, $usr_id);
553 $mock_statement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
554 $this->mock_database->expects($this->once())->method('queryF')->willReturnCallback($this->queryCallback($mock_statement, ['integer'], [$usr_id]));
555 $this->mock_database->expects($this->once())->method('fetchAssoc')->with($mock_statement)->willReturn([
556 'rcp_to' => 'phpunit'
557 ]);
558
559 $mail_data = $instance->retrieveFromStage();
560
561 $this->assertIsArray($mail_data);
562 $this->assertEquals('phpunit', $mail_data['rcp_to']);
563 }

References create(), and queryCallback().

+ Here is the call graph for this function:

◆ testSaveAttachments()

ilMailTest::testSaveAttachments ( )

Definition at line 626 of file ilMailTest.php.

626 : void
627 {
628 $usr_id = 89;
629 $attachments = new \ILIAS\ResourceStorage\Identification\ResourceCollectionIdentification('657497dc-5079-4f95-b19d-aecdaf81ff1a');
630 $instance = $this->create(789, $usr_id);
631
632 $this->mock_database->expects($this->once())->method('update')->with(
633 'mail_saved',
634 [
635 'attachments' => ['text', $attachments->serialize()],
636 ],
637 [
638 'user_id' => ['integer', $usr_id],
639 ]
640 );
641
642 $instance->saveAttachments($attachments);
643 }

References create().

+ Here is the call graph for this function:

◆ testUpdateDraft()

ilMailTest::testUpdateDraft ( )

Definition at line 444 of file ilMailTest.php.

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

References $params, and create().

+ Here is the call graph for this function:

◆ testValidateRecipients()

ilMailTest::testValidateRecipients (   $errors = [])

Definition at line 565 of file ilMailTest.php.

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

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 35 of file ilMailTest.php.

◆ $mock_database

MockObject& ilDBInterface ilMailTest::$mock_database
private

Definition at line 34 of file ilMailTest.php.

◆ $mock_language

MockObject& ilLanguage ilMailTest::$mock_language
private

Definition at line 38 of file ilMailTest.php.

◆ $mock_log

MockObject& ilLogger ilMailTest::$mock_log
private

Definition at line 36 of file ilMailTest.php.

◆ $mock_parser_factory

MockObject& ilMailRfc822AddressParserFactory ilMailTest::$mock_parser_factory
private

Definition at line 37 of file ilMailTest.php.


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