ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilMailTest Class Reference

Class ilMailMimeTest. More...

+ Inheritance diagram for ilMailTest:
+ Collaboration diagram for ilMailTest:

Public Member Functions

 testExternalMailDeliveryToLocalRecipientsWorksAsExpected ()
 
 testGetMailObjectReferenceId ()
 
 testFormatNamesForOutput ()
 
 testGetPreviousMail (array $rowData)
 provideGetPreviousMail More...
 
 provideGetPreviousMail ()
 
 testGetNextMail ()
 
 testGetMailsOfFolder ()
 
 testCountMailsOfFolder ()
 
 testGetMail ()
 
 testMarkRead ()
 
 testMarkUnread ()
 
 testMoveMailsToFolder ()
 
 testMoveMailsToFolderFalse ()
 
 testGetNewDraftId ()
 
 testUpdateDraft ()
 
 testPersistingToStage ()
 
 testRetrievalFromStage ()
 
 testValidateRecipients ($errors=[])
 
 provideValidateRecipients ()
 
 testGetIliasMailerName ()
 
 testSaveAttachments ()
 

Private Member Functions

 queryCallback ($returnValue, array $expectedTypes, array $expectedValues)
 
 createAndExpectDatabaseCall (int $someMailId, array $rowData)
 
 create (int $refId=234, int $userId=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 ilMailBaseTest
 brutallyTrimHTML (string $html)
 
 setUp ()
 
 tearDown ()
 
 setGlobalVariable (string $name, $value)
 

Detailed Description

Class ilMailMimeTest.

Author
Michael Jansen mjans.nosp@m.en@d.nosp@m.ataba.nosp@m.y.de

Definition at line 33 of file ilMailTest.php.

Member Function Documentation

◆ create()

ilMailTest::create ( int  $refId = 234,
int  $userId = 123 
)
private

Definition at line 570 of file ilMailTest.php.

References $refId.

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

570  : ilMail
571  {
572  return new ilMail(
573  $userId,
574  ($this->mock_address_type_factory = $this->getMockBuilder(ilMailAddressTypeFactory::class)->disableOriginalConstructor()->getMock()),
575  ($this->mock_parser_factory = $this->getMockBuilder(ilMailRfc822AddressParserFactory::class)->disableOriginalConstructor()->getMock()),
576  $this->getMockBuilder(ilAppEventHandler::class)->disableOriginalConstructor()->getMock(),
577  ($this->mock_log = $this->getMockBuilder(ilLogger::class)->disableOriginalConstructor()->getMock()),
578  ($this->mock_database = $this->getMockBuilder(ilDBInterface::class)->disableOriginalConstructor()->getMock()),
579  ($this->mock_language = $this->getMockBuilder(ilLanguage::class)->disableOriginalConstructor()->getMock()),
580  $this->getMockBuilder(ilFileDataMail::class)->disableOriginalConstructor()->getMock(),
581  $this->getMockBuilder(ilMailOptions::class)->disableOriginalConstructor()->getMock(),
582  $this->getMockBuilder(ilMailbox::class)->disableOriginalConstructor()->getMock(),
583  $this->getMockBuilder(ilMailMimeSenderFactory::class)->disableOriginalConstructor()->getMock(),
584  static function (string $login): int {
585  return 780;
586  },
587  $this->createMock(AutoresponderService::class),
588  0,
589  $refId,
590  $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->getMock(),
591  $this->getMockBuilder(ilMailTemplatePlaceholderResolver::class)->disableOriginalConstructor()->getMock()
592  );
593  }
$refId
Definition: xapitoken.php:58
+ Here is the caller graph for this function:

◆ createAndExpectDatabaseCall()

ilMailTest::createAndExpectDatabaseCall ( int  $someMailId,
array  $rowData 
)
private

Definition at line 559 of file ilMailTest.php.

References create(), and queryCallback().

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

559  : ilMail
560  {
561  $userId = 900;
562  $instance = $this->create(234, $userId);
563  $mockStatement = $this->getMockBuilder(ilDBStatement::class)->getMock();
564  $this->mock_database->expects(self::once())->method('fetchAssoc')->with($mockStatement)->willReturn($rowData);
565  $this->mock_database->expects(self::once())->method('queryF')->willReturnCallback($this->queryCallback($mockStatement, ['integer', 'integer'], [$userId, $someMailId]));
566 
567  return $instance;
568  }
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:570
queryCallback($returnValue, array $expectedTypes, array $expectedValues)
Definition: ilMailTest.php:549
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ provideGetPreviousMail()

ilMailTest::provideGetPreviousMail ( )

Definition at line 240 of file ilMailTest.php.

240  : array
241  {
242  return [
243  [[]],
244  [[
245  'attachments' => '',
246  'folder_id' => '',
247  'mail_id' => '',
248  'sender_id' => '',
249  'tpl_ctx_params' => '[]',
250  'use_placeholders' => '',
251  'user_id' => ''
252  ]],
253  [[
254  'folder_id' => '',
255  'mail_id' => '',
256  'sender_id' => '',
257  'use_placeholders' => '',
258  'user_id' => ''
259  ]],
260  ];
261  }

◆ provideValidateRecipients()

ilMailTest::provideValidateRecipients ( )

Definition at line 511 of file ilMailTest.php.

511  : array
512  {
513  return [
514  [[]],
515  [['some error']]
516  ];
517  }

◆ queryCallback()

ilMailTest::queryCallback (   $returnValue,
array  $expectedTypes,
array  $expectedValues 
)
private

Definition at line 549 of file ilMailTest.php.

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

549  : Closure
550  {
551  return function (string $query, array $types, array $values) use ($expectedTypes, $expectedValues, $returnValue) {
552  $this->assertEquals($expectedTypes, $types);
553  $this->assertEquals($expectedValues, $values);
554 
555  return $returnValue;
556  };
557  }
+ Here is the caller graph for this function:

◆ testCountMailsOfFolder()

ilMailTest::testCountMailsOfFolder ( )

Definition at line 298 of file ilMailTest.php.

References create(), and queryCallback().

298  : void
299  {
300  $userId = 46;
301  $folderId = 68;
302  $numRows = 89;
303  $instance = $this->create(345, $userId);
304  $mockStatement = $this->getMockBuilder(ilDBStatement::class)->getMock();
305  $this->mock_database->expects(self::once())->method('queryF')->willReturnCallback($this->queryCallback($mockStatement, ['integer', 'integer'], [$userId, $folderId]));
306  $this->mock_database->expects(self::once())->method('numRows')->with($mockStatement)->willReturn($numRows);
307 
308  $this->assertSame($numRows, $instance->countMailsOfFolder($folderId));
309  }
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:570
queryCallback($returnValue, array $expectedTypes, array $expectedValues)
Definition: ilMailTest.php:549
+ Here is the call graph for this function:

◆ testExternalMailDeliveryToLocalRecipientsWorksAsExpected()

ilMailTest::testExternalMailDeliveryToLocalRecipientsWorksAsExpected ( )
Exceptions
ReflectionException

Definition at line 44 of file ilMailTest.php.

References $lng, ILIAS\LTI\ToolProvider\$settings, ILIAS\MetaData\Repository\Validation\Data\__construct(), ilMailMimeSenderUserById\addUserToCache(), ilMimeMail\getBcc(), ilMimeMail\getDefaultTransport(), ilMailOptions\INCOMING_EMAIL, ilMimeMail\setDefaultTransport(), and ilMailBaseTest\setGlobalVariable().

44  : void
45  {
46  $refineryMock = $this->getMockBuilder(Factory::class)->disableOriginalConstructor()->getMock();
47  $this->setGlobalVariable('refinery', $refineryMock);
48 
49  $legal_documents = $this->createMock(Conductor::class);
50  $this->setGlobalVariable('legalDocuments', $legal_documents);
51 
52  $senderUsrId = 666;
53  $loginToIdMap = [
54  'phpunit1' => 1,
55  'phpunit2' => 2,
56  'phpunit3' => 3,
57  'phpunit4' => 4,
58  'phpunit5' => 5,
59  'phpunit6' => 6,
60  'phpunit7' => 7,
61  ];
62 
63  $transformation = $this->createMock(Transformation::class);
64  $transformation->expects(self::exactly(count($loginToIdMap)))->method('applyTo')->willReturn(new Ok(null));
65  $legal_documents->expects(self::exactly(count($loginToIdMap)))->method('userCanReadInternalMail')->willReturn($transformation);
66 
67  $userInstanceById = [];
68  $mailOptionsById = [];
69  foreach ($loginToIdMap as $usrId) {
70  $user = $this
71  ->getMockBuilder(ilObjUser::class)
72  ->disableOriginalConstructor()
73  ->onlyMethods(['getId', 'checkTimeLimit', 'getActive'])
74  ->getMock();
75  $user->method('getId')->willReturn($usrId);
76  $user->method('getActive')->willReturn(true);
77  $user->method('checkTimeLimit')->willReturn(true);
78  $userInstanceById[$usrId] = $user;
79 
80  $mailOptions = $this
81  ->getMockBuilder(ilMailOptions::class)
82  ->disableOriginalConstructor()
83  ->onlyMethods(['getExternalEmailAddresses', 'getIncomingType'])
84  ->getMock();
85  $mailOptions->method('getExternalEmailAddresses')->willReturn([
86  'phpunit' . $usrId . '@ilias.de',
87  ]);
88  $mailOptions->method('getIncomingType')->willReturn(ilMailOptions::INCOMING_EMAIL);
89  $mailOptionsById[$usrId] = $mailOptions;
90  }
91 
92  $user = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->getMock();
93  ilMailMimeSenderUserById::addUserToCache($senderUsrId, $user);
94 
95  $addressTypeFactory = $this
96  ->getMockBuilder(ilMailAddressTypeFactory::class)
97  ->disableOriginalConstructor()
98  ->onlyMethods(['getByPrefix'])
99  ->getMock();
100  $addressTypeFactory
101  ->method('getByPrefix')
102  ->willReturnCallback(function ($arg) use ($loginToIdMap): object {
103  return new class ($arg, $loginToIdMap) implements ilMailAddressType {
104  protected array $loginToIdMap = [];
105 
106  public function __construct(protected ilMailAddress $address, $loginToIdMap)
107  {
108  $this->loginToIdMap = array_map(static function (int $usrId): array {
109  return [$usrId];
110  }, $loginToIdMap);
111  }
112 
113  public function resolve(): array
114  {
115  return $this->loginToIdMap[$this->address->getMailbox()] ?? [];
116  }
117 
118  public function validate(int $senderId): bool
119  {
120  return true;
121  }
122 
123  public function getErrors(): array
124  {
125  return [];
126  }
127 
128  public function getAddress(): ilMailAddress
129  {
130  return $this->address;
131  }
132  };
133  });
134 
135  $db = $this->getMockBuilder(ilDBInterface::class)->getMock();
136  $nextId = 0;
137  $db->method('nextId')->willReturnCallback(function () use (&$nextId): int {
138  ++$nextId;
139 
140  return $nextId;
141  });
142 
143  $eventHandler = $this->getMockBuilder(ilAppEventHandler::class)->disableOriginalConstructor()->getMock();
144  $logger = $this->getMockBuilder(ilLogger::class)->disableOriginalConstructor()->getMock();
145  $lng = $this->getMockBuilder(ilLanguage::class)->disableOriginalConstructor()->getMock();
146  $settings = $this->getMockBuilder(ilSetting::class)->disableOriginalConstructor()->getMock();
147  $this->setGlobalVariable('ilSetting', $settings);
148 
149  $mailFileData = $this->getMockBuilder(ilFileDataMail::class)->disableOriginalConstructor()->getMock();
150  $mailOptions = $this->getMockBuilder(ilMailOptions::class)->disableOriginalConstructor()->getMock();
151  $mailBox = $this->getMockBuilder(ilMailbox::class)->disableOriginalConstructor()->getMock();
152  $actor = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->getMock();
153  $mustache_factory = $this->getMockBuilder(ilMustacheFactory::class)->getMock();
154 
155  $mailService = new ilMail(
156  $senderUsrId,
157  $addressTypeFactory,
159  $eventHandler,
160  $logger,
161  $db,
162  $lng,
163  $mailFileData,
164  $mailOptions,
165  $mailBox,
166  new ilMailMimeSenderFactory($settings, $mustache_factory),
167  static function (string $login) use ($loginToIdMap): int {
168  return $loginToIdMap[$login] ?? 0;
169  },
170  $this->createMock(AutoresponderService::class),
171  0,
172  4711,
173  $actor,
174  new ilMailTemplatePlaceholderResolver(new Mustache_Engine())
175  );
176 
177  $oldTransport = ilMimeMail::getDefaultTransport();
178 
179  $mailTransport = $this
180  ->getMockBuilder(ilMailMimeTransport::class)
181  ->getMock();
182  $mailTransport->expects($this->once())->method('send')->with($this->callback(function (
183  ilMimeMail $mailer
184  ) use ($loginToIdMap): bool {
185  $totalBcc = [];
186  foreach ($mailer->getBcc() as $bcc) {
187  $totalBcc = array_filter(array_map('trim', explode(',', $bcc))) + $totalBcc;
188  }
189 
190  return count($totalBcc) === count($loginToIdMap);
191  }))->willReturn(true);
192  ilMimeMail::setDefaultTransport($mailTransport);
193 
194  $mailService->setUserInstanceById($userInstanceById);
195  $mailService->setMailOptionsByUserIdMap($mailOptionsById);
196 
197  $mail_data = new MailDeliveryData(
198  implode(',', array_slice(array_keys($loginToIdMap), 0, 3)),
199  implode(',', array_slice(array_keys($loginToIdMap), 3, 2)),
200  implode(',', array_slice(array_keys($loginToIdMap), 5, 2)),
201  'Subject',
202  'Message',
203  [],
204  false
205  );
206  $mailService->sendMail($mail_data);
207 
208  ilMimeMail::setDefaultTransport($oldTransport);
209  }
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
static addUserToCache(int $usrId, ilObjUser $user)
static setDefaultTransport(?ilMailMimeTransport $transport)
static getDefaultTransport()
Interface ilMailAddressType.
Class ilMailRfc822AddressParserFactory.
final const INCOMING_EMAIL
setGlobalVariable(string $name, $value)
__construct(VocabulariesInterface $vocabularies)
$lng
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:16
Class ilMailTemplatePlaceholderResolver.
Class ilMailAddress.
+ Here is the call graph for this function:

◆ testFormatNamesForOutput()

ilMailTest::testFormatNamesForOutput ( )

Definition at line 219 of file ilMailTest.php.

References create().

219  : void
220  {
221  $instance = $this->create();
222 
223  $this->mock_language->expects(self::once())->method('txt')->with('not_available')->willReturn('not_available');
224 
225  $this->assertSame('not_available', $instance->formatNamesForOutput(''));
226  $this->assertSame('', $instance->formatNamesForOutput(','));
227  }
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:570
+ Here is the call graph for this function:

◆ testGetIliasMailerName()

ilMailTest::testGetIliasMailerName ( )

Definition at line 519 of file ilMailTest.php.

References ILIAS\LTI\ToolProvider\$settings, ilMail\_getIliasMailerName(), and ilMailBaseTest\setGlobalVariable().

519  : void
520  {
521  $expected = 'Phasellus lacus';
522  $settings = $this->getMockBuilder(ilSetting::class)->disableOriginalConstructor()->getMock();
523  $settings->method('get')->with('mail_system_sys_from_name')->willReturn($expected);
524  $this->setGlobalVariable('ilSetting', $settings);
525 
526 
527  $this->assertSame($expected, ilMail::_getIliasMailerName());
528  }
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
static _getIliasMailerName()
setGlobalVariable(string $name, $value)
+ Here is the call graph for this function:

◆ testGetMail()

ilMailTest::testGetMail ( )

Definition at line 311 of file ilMailTest.php.

References createAndExpectDatabaseCall().

311  : void
312  {
313  $mailId = 7890;
314  $instance = $this->createAndExpectDatabaseCall($mailId, []);
315  $instance->getMail($mailId);
316  }
createAndExpectDatabaseCall(int $someMailId, array $rowData)
Definition: ilMailTest.php:559
+ Here is the call graph for this function:

◆ testGetMailObjectReferenceId()

ilMailTest::testGetMailObjectReferenceId ( )

Definition at line 211 of file ilMailTest.php.

References $refId, and create().

211  : void
212  {
213  $refId = 364;
214  $instance = $this->create($refId);
215 
216  $this->assertSame($refId, $instance->getMailObjectReferenceId());
217  }
$refId
Definition: xapitoken.php:58
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:570
+ Here is the call graph for this function:

◆ testGetMailsOfFolder()

ilMailTest::testGetMailsOfFolder ( )

Definition at line 271 of file ilMailTest.php.

References create(), and queryCallback().

271  : void
272  {
273  $filter = ['status' => 'yes'];
274  $rowData = ['mail_id' => 8908];
275  $one = $rowData + [
276  'attachments' => [],
277  'tpl_ctx_params' => [],
278  'm_subject' => '',
279  'm_message' => '',
280  'rcp_to' => '',
281  'rcp_cc' => '',
282  'rcp_bcc' => '',
283  ];
284  $expected = [$one, $one];
285  $folderId = 89;
286  $userId = 901;
287  $instance = $this->create(234, $userId);
288  $mockStatement = $this->getMockBuilder(ilDBStatement::class)->getMock();
289  $this->mock_database->expects(self::never())->method('setLimit');
290  $this->mock_database->expects(self::exactly(3))->method('fetchAssoc')->with($mockStatement)->willReturnOnConsecutiveCalls($rowData, $rowData, null);
291  $this->mock_database->expects(self::once())->method('queryF')->willReturnCallback($this->queryCallback($mockStatement, ['integer', 'integer'], [$userId, $folderId]));
292 
293  $this->mock_database->expects(self::once())->method('quote')->with($filter['status'], 'text')->willReturn($filter['status']);
294 
295  $this->assertEquals($expected, $instance->getMailsOfFolder($folderId, $filter));
296  }
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:570
queryCallback($returnValue, array $expectedTypes, array $expectedValues)
Definition: ilMailTest.php:549
+ Here is the call graph for this function:

◆ testGetNewDraftId()

ilMailTest::testGetNewDraftId ( )

Definition at line 364 of file ilMailTest.php.

References create().

364  : void
365  {
366  $nextId = 789;
367  $userId = 5678;
368  $folderId = 47;
369  $instance = $this->create(4749, $userId);
370 
371  $this->mock_database->expects(self::once())->method('nextId')->with('mail')->willReturn($nextId);
372  $this->mock_database->expects(self::once())->method('insert')->with('mail', [
373  'mail_id' => ['integer', $nextId],
374  'user_id' => ['integer', $userId],
375  'folder_id' => ['integer', $folderId],
376  'sender_id' => ['integer', $userId],
377  ]);
378 
379  $this->assertSame($nextId, $instance->getNewDraftId($folderId));
380  }
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:570
+ Here is the call graph for this function:

◆ testGetNextMail()

ilMailTest::testGetNextMail ( )

Definition at line 263 of file ilMailTest.php.

References createAndExpectDatabaseCall().

263  : void
264  {
265  $mailId = 8484;
266  $instance = $this->createAndExpectDatabaseCall($mailId, []);
267  $this->mock_database->expects(self::once())->method('setLimit')->with(1, 0);
268  $instance->getNextMail($mailId);
269  }
createAndExpectDatabaseCall(int $someMailId, array $rowData)
Definition: ilMailTest.php:559
+ Here is the call graph for this function:

◆ testGetPreviousMail()

ilMailTest::testGetPreviousMail ( array  $rowData)

provideGetPreviousMail

Definition at line 232 of file ilMailTest.php.

References createAndExpectDatabaseCall().

232  : void
233  {
234  $mailId = 3454;
235  $instance = $this->createAndExpectDatabaseCall($mailId, $rowData);
236  $this->mock_database->expects(self::once())->method('setLimit')->with(1, 0);
237  $instance->getPreviousMail($mailId);
238  }
createAndExpectDatabaseCall(int $someMailId, array $rowData)
Definition: ilMailTest.php:559
+ Here is the call graph for this function:

◆ testMarkRead()

ilMailTest::testMarkRead ( )

Definition at line 318 of file ilMailTest.php.

References create(), and queryCallback().

318  : void
319  {
320  $mailIds = [1, 2, 3, 4, 5, 6];
321  $userId = 987;
322  $instance = $this->create(567, $userId);
323  $this->getMockBuilder(ilDBStatement::class)->getMock();
324  $this->mock_database->expects(self::once())->method('in')->with('mail_id', $mailIds, false, 'integer')->willReturn('');
325  $this->mock_database->expects(self::once())->method('manipulateF')->willReturnCallback($this->queryCallback(0, ['text', 'integer'], ['read', $userId]));
326 
327  $instance->markRead($mailIds);
328  }
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:570
queryCallback($returnValue, array $expectedTypes, array $expectedValues)
Definition: ilMailTest.php:549
+ Here is the call graph for this function:

◆ testMarkUnread()

ilMailTest::testMarkUnread ( )

Definition at line 330 of file ilMailTest.php.

References create(), and queryCallback().

330  : void
331  {
332  $mailIds = [1, 2, 3, 4, 5, 6];
333  $userId = 987;
334  $instance = $this->create(567, $userId);
335  $this->getMockBuilder(ilDBStatement::class)->getMock();
336  $this->mock_database->expects(self::once())->method('in')->with('mail_id', $mailIds, false, 'integer')->willReturn('');
337  $this->mock_database->expects(self::once())->method('manipulateF')->willReturnCallback($this->queryCallback(0, ['text', 'integer'], ['unread', $userId]));
338 
339  $instance->markUnread($mailIds);
340  }
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:570
queryCallback($returnValue, array $expectedTypes, array $expectedValues)
Definition: ilMailTest.php:549
+ Here is the call graph for this function:

◆ testMoveMailsToFolder()

ilMailTest::testMoveMailsToFolder ( )

Definition at line 342 of file ilMailTest.php.

References create(), and queryCallback().

342  : void
343  {
344  $mailIds = [1, 2, 3, 4, 5, 6];
345  $folderId = 890;
346  $userId = 987;
347  $instance = $this->create(567, $userId);
348  $this->mock_database->expects(self::once())->method('in')->with('mail_id', $mailIds, false, 'integer')->willReturn('');
349  $this->mock_database->expects(self::once())->method('manipulateF')->willReturnCallback($this->queryCallback(1, ['integer', 'integer', 'integer'], [$folderId, $userId, $userId]));
350 
351  $this->assertTrue($instance->moveMailsToFolder($mailIds, $folderId));
352  }
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:570
queryCallback($returnValue, array $expectedTypes, array $expectedValues)
Definition: ilMailTest.php:549
+ Here is the call graph for this function:

◆ testMoveMailsToFolderFalse()

ilMailTest::testMoveMailsToFolderFalse ( )

Definition at line 354 of file ilMailTest.php.

References create().

354  : void
355  {
356  $mailIds = [];
357  $instance = $this->create();
358  $this->mock_database->expects(self::never())->method('in');
359  $this->mock_database->expects(self::never())->method('manipulateF');
360 
361  $this->assertFalse($instance->moveMailsToFolder($mailIds, 892));
362  }
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:570
+ Here is the call graph for this function:

◆ testPersistingToStage()

ilMailTest::testPersistingToStage ( )

Definition at line 416 of file ilMailTest.php.

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

416  : void
417  {
418  $userId = 897;
419  $attachments = [];
420  $rcpTo = 'jlh';
421  $rcpCc = 'jhkjh';
422  $rcpBcc = 'ououi';
423  $subject = 'hbansn';
424  $message = 'message';
425  $usePlaceholders = false;
426  $contextId = '9080';
427  $params = [];
428 
429  $instance = $this->create(789, $userId);
430 
431  $this->mock_database->expects(self::once())->method('replace')->with('mail_saved', [
432  'user_id' => ['integer', $userId],
433  ], [
434  'attachments' => ['clob', serialize($attachments)],
435  'rcp_to' => ['clob', $rcpTo],
436  'rcp_cc' => ['clob', $rcpCc],
437  'rcp_bcc' => ['clob', $rcpBcc],
438  'm_subject' => ['text', $subject],
439  'm_message' => ['clob', $message],
440  'use_placeholders' => ['integer', (int) $usePlaceholders],
441  'tpl_ctx_id' => ['text', $contextId],
442  'tpl_ctx_params' => ['blob', json_encode($params, JSON_THROW_ON_ERROR)],
443  ]);
444 
445  $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
446  $this->mock_database->expects(self::once())->method('queryF')->willReturnCallback($this->queryCallback($mockStatement, ['integer'], [$userId]));
447  $this->mock_database->expects(self::once())->method('fetchAssoc')->with($mockStatement)->willReturn([
448  'rcp_to' => 'phpunit'
449  ]);
450 
451  $instance->persistToStage(
452  78_979_078,
453  $attachments,
454  $rcpTo,
455  $rcpCc,
456  $rcpBcc,
457  $subject,
458  $message,
459  $usePlaceholders,
460  $contextId,
461  $params,
462  );
463  }
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:33
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:570
queryCallback($returnValue, array $expectedTypes, array $expectedValues)
Definition: ilMailTest.php:549
$message
Definition: xapiexit.php:32
+ Here is the call graph for this function:

◆ testRetrievalFromStage()

ilMailTest::testRetrievalFromStage ( )

Definition at line 465 of file ilMailTest.php.

References create(), and queryCallback().

465  : void
466  {
467  $userId = 789;
468  $instance = $this->create(67, $userId);
469  $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
470  $this->mock_database->expects(self::once())->method('queryF')->willReturnCallback($this->queryCallback($mockStatement, ['integer'], [$userId]));
471  $this->mock_database->expects(self::once())->method('fetchAssoc')->with($mockStatement)->willReturn([
472  'rcp_to' => 'phpunit'
473  ]);
474 
475  $mail_data = $instance->retrieveFromStage();
476 
477  $this->assertIsArray($mail_data);
478  $this->assertEquals('phpunit', $mail_data['rcp_to']);
479  }
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:570
queryCallback($returnValue, array $expectedTypes, array $expectedValues)
Definition: ilMailTest.php:549
+ Here is the call graph for this function:

◆ testSaveAttachments()

ilMailTest::testSaveAttachments ( )

Definition at line 530 of file ilMailTest.php.

References create().

530  : void
531  {
532  $userId = 89;
533  $attachments = ['aaa', 'bb', 'cc', 'rrr'];
534  $instance = $this->create(789, $userId);
535 
536  $this->mock_database->expects(self::once())->method('update')->with(
537  'mail_saved',
538  [
539  'attachments' => ['clob', serialize($attachments)],
540  ],
541  [
542  'user_id' => ['integer', $userId],
543  ]
544  );
545 
546  $instance->saveAttachments($attachments);
547  }
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:570
+ Here is the call graph for this function:

◆ testUpdateDraft()

ilMailTest::testUpdateDraft ( )

Definition at line 382 of file ilMailTest.php.

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

382  : void
383  {
384  $folderId = 7890;
385  $instance = $this->create();
386  $to = 'abc';
387  $cc = 'bcde';
388  $bcc = 'jkl';
389  $subject = 'jlh';
390  $message = 'some message';
391  $usePlaceholders = true;
392  $contextId = '87';
393  $params = [];
394  $draftId = 78;
395 
396  $this->mock_database->expects(self::once())->method('update')->with('mail', [
397  'folder_id' => ['integer', $folderId],
398  'attachments' => ['clob', serialize([])],
399  'send_time' => ['timestamp', date('Y-m-d H:i:s')],
400  'rcp_to' => ['clob', $to],
401  'rcp_cc' => ['clob', $cc],
402  'rcp_bcc' => ['clob', $bcc],
403  'm_status' => ['text', 'read'],
404  'm_subject' => ['text', $subject],
405  'm_message' => ['clob', $message],
406  'use_placeholders' => ['integer', (int) $usePlaceholders],
407  'tpl_ctx_id' => ['text', $contextId],
408  'tpl_ctx_params' => ['blob', json_encode($params, JSON_THROW_ON_ERROR)],
409  ], [
410  'mail_id' => ['integer', $draftId],
411  ]);
412 
413  $this->assertSame($draftId, $instance->updateDraft($folderId, [], $to, $cc, $bcc, $subject, $message, $draftId, $usePlaceholders, $contextId, $params));
414  }
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:33
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:570
$message
Definition: xapiexit.php:32
+ Here is the call graph for this function:

◆ testValidateRecipients()

ilMailTest::testValidateRecipients (   $errors = [])

Definition at line 481 of file ilMailTest.php.

References create().

481  : void
482  {
483  $to = 'jkhk';
484  $cc = 'hjhjkl';
485  $bcc = 'jklhjk';
486 
487  $instance = $this->create();
488  $this->mock_log->expects(self::exactly(6))->method('debug')->withConsecutive(
489  ['Started parsing of recipient string: ' . $to],
490  ['Parsed addresses: hello'],
491  ['Started parsing of recipient string: ' . $cc],
492  ['Parsed addresses: hello'],
493  ['Started parsing of recipient string: ' . $bcc],
494  ['Parsed addresses: hello']
495  );
496 
497  $mockAddress = $this->getMockBuilder(ilMailAddress::class)->disableOriginalConstructor()->getMock();
498  $mockAddress->expects(self::exactly(3))->method('__toString')->willReturn('hello');
499  $mockParser = $this->getMockBuilder(ilMailRecipientParser::class)->disableOriginalConstructor()->getMock();
500  $mockParser->expects(self::exactly(3))->method('parse')->willReturn([$mockAddress]);
501  $this->mock_parser_factory->expects(self::exactly(3))->method('getParser')->withConsecutive([$to], [$cc], [$bcc])->willReturn($mockParser);
502 
503  $mockAddressType = $this->getMockBuilder(ilMailAddressType::class)->disableOriginalConstructor()->getMock();
504  $mockAddressType->expects(self::exactly(3))->method('validate')->willReturn(empty($errors));
505  $mockAddressType->expects(self::exactly(empty($errors) ? 0 : 3))->method('getErrors')->willReturn($errors);
506  $this->mock_address_type_factory->expects(self::exactly(3))->method('getByPrefix')->with($mockAddress)->willReturn($mockAddressType);
507 
508  $this->assertSame([], $instance->validateRecipients($to, $cc, $bcc));
509  }
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:570
+ 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 36 of file ilMailTest.php.

◆ $mock_database

MockObject& ilDBInterface ilMailTest::$mock_database
private

Definition at line 35 of file ilMailTest.php.

◆ $mock_language

MockObject& ilLanguage ilMailTest::$mock_language
private

Definition at line 39 of file ilMailTest.php.

◆ $mock_log

MockObject& ilLogger ilMailTest::$mock_log
private

Definition at line 37 of file ilMailTest.php.

◆ $mock_parser_factory

MockObject& ilMailRfc822AddressParserFactory ilMailTest::$mock_parser_factory
private

Definition at line 38 of file ilMailTest.php.


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