ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
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

ilDBInterface $mockDatabase
 
 $mockAddressTypeFactory
 
 $mockLog
 
 $mockParserFactory
 
 $mockLanguage
 

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

Member Function Documentation

◆ create()

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

Definition at line 561 of file ilMailTest.php.

References $refId.

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

561  : ilMail
562  {
563  $instance = new ilMail(
564  $userId,
565  ($this->mockAddressTypeFactory = $this->getMockBuilder(ilMailAddressTypeFactory::class)->disableOriginalConstructor()->getMock()),
566  ($this->mockParserFactory = $this->getMockBuilder(ilMailRfc822AddressParserFactory::class)->disableOriginalConstructor()->getMock()),
567  $this->getMockBuilder(ilAppEventHandler::class)->disableOriginalConstructor()->getMock(),
568  ($this->mockLog = $this->getMockBuilder(ilLogger::class)->disableOriginalConstructor()->getMock()),
569  ($this->mockDatabase = $this->getMockBuilder(ilDBInterface::class)->disableOriginalConstructor()->getMock()),
570  ($this->mockLanguage = $this->getMockBuilder(ilLanguage::class)->disableOriginalConstructor()->getMock()),
571  $this->getMockBuilder(ilFileDataMail::class)->disableOriginalConstructor()->getMock(),
572  $this->getMockBuilder(ilMailOptions::class)->disableOriginalConstructor()->getMock(),
573  $this->getMockBuilder(ilMailbox::class)->disableOriginalConstructor()->getMock(),
574  $this->getMockBuilder(ilMailMimeSenderFactory::class)->disableOriginalConstructor()->getMock(),
575  static function (string $login): int {
576  return 780;
577  },
578  $refId,
579  $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->getMock()
580  );
581 
582  return $instance;
583  }
$refId
Definition: xapitoken.php:58
+ Here is the caller graph for this function:

◆ createAndExpectDatabaseCall()

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

Definition at line 550 of file ilMailTest.php.

References create(), and queryCallback().

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

550  : ilMail
551  {
552  $userId = 900;
553  $instance = $this->create(234, $userId);
554  $mockStatement = $this->getMockBuilder(ilDBStatement::class)->getMock();
555  $this->mockDatabase->expects(self::once())->method('fetchAssoc')->with($mockStatement)->willReturn($rowData);
556  $this->mockDatabase->expects(self::once())->method('queryF')->willReturnCallback($this->queryCallback($mockStatement, ['integer', 'integer'], [$userId, $someMailId]));
557 
558  return $instance;
559  }
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:561
queryCallback($returnValue, array $expectedTypes, array $expectedValues)
Definition: ilMailTest.php:540
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ provideGetPreviousMail()

ilMailTest::provideGetPreviousMail ( )

Definition at line 230 of file ilMailTest.php.

230  : array
231  {
232  return [
233  [[]],
234  [[
235  'attachments' => '',
236  'folder_id' => '',
237  'mail_id' => '',
238  'sender_id' => '',
239  'tpl_ctx_params' => '[]',
240  'use_placeholders' => '',
241  'user_id' => ''
242  ]],
243  [[
244  'folder_id' => '',
245  'mail_id' => '',
246  'sender_id' => '',
247  'use_placeholders' => '',
248  'user_id' => ''
249  ]],
250  ];
251  }

◆ provideValidateRecipients()

ilMailTest::provideValidateRecipients ( )

Definition at line 501 of file ilMailTest.php.

501  : array
502  {
503  return [
504  [[]],
505  [['some error']]
506  ];
507  }

◆ queryCallback()

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

Definition at line 540 of file ilMailTest.php.

References $query.

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

540  : Closure
541  {
542  return function (string $query, array $types, array $values) use ($expectedTypes, $expectedValues, $returnValue) {
543  $this->assertEquals($expectedTypes, $types);
544  $this->assertEquals($expectedValues, $values);
545 
546  return $returnValue;
547  };
548  }
$query
+ Here is the caller graph for this function:

◆ testCountMailsOfFolder()

ilMailTest::testCountMailsOfFolder ( )

Definition at line 288 of file ilMailTest.php.

References create(), and queryCallback().

288  : void
289  {
290  $userId = 46;
291  $folderId = 68;
292  $numRows = 89;
293  $instance = $this->create(345, $userId);
294  $mockStatement = $this->getMockBuilder(ilDBStatement::class)->getMock();
295  $this->mockDatabase->expects(self::once())->method('queryF')->willReturnCallback($this->queryCallback($mockStatement, ['integer', 'integer'], [$userId, $folderId]));
296  $this->mockDatabase->expects(self::once())->method('numRows')->with($mockStatement)->willReturn($numRows);
297 
298  $this->assertSame($numRows, $instance->countMailsOfFolder($folderId));
299  }
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:561
queryCallback($returnValue, array $expectedTypes, array $expectedValues)
Definition: ilMailTest.php:540
+ 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\GlobalScreen\Provider\__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  $senderUsrId = 666;
50  $loginToIdMap = [
51  'phpunit1' => 1,
52  'phpunit2' => 2,
53  'phpunit3' => 3,
54  'phpunit4' => 4,
55  'phpunit5' => 5,
56  'phpunit6' => 6,
57  'phpunit7' => 7,
58  ];
59  $userInstanceById = [];
60  $mailOptionsById = [];
61  foreach ($loginToIdMap as $login => $usrId) {
62  $user = $this
63  ->getMockBuilder(ilObjUser::class)
64  ->disableOriginalConstructor()
65  ->onlyMethods(['getId', 'hasToAcceptTermsOfService', 'checkTimeLimit', 'getActive'])
66  ->getMock();
67  $user->method('getId')->willReturn($usrId);
68  $user->method('getActive')->willReturn(true);
69  $user->method('hasToAcceptTermsOfService')->willReturn(false);
70  $user->method('checkTimeLimit')->willReturn(true);
71  $userInstanceById[$usrId] = $user;
72 
73  $mailOptions = $this
74  ->getMockBuilder(ilMailOptions::class)
75  ->disableOriginalConstructor()
76  ->onlyMethods(['getExternalEmailAddresses', 'getIncomingType'])
77  ->getMock();
78  $mailOptions->method('getExternalEmailAddresses')->willReturn([
79  'phpunit' . $usrId . '@ilias.de',
80  ]);
81  $mailOptions->method('getIncomingType')->willReturn(ilMailOptions::INCOMING_EMAIL);
82  $mailOptionsById[$usrId] = $mailOptions;
83  }
84 
85  $user = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->getMock();
86  ilMailMimeSenderUserById::addUserToCache($senderUsrId, $user);
87 
88  $addressTypeFactory = $this
89  ->getMockBuilder(ilMailAddressTypeFactory::class)
90  ->disableOriginalConstructor()
91  ->onlyMethods(['getByPrefix'])
92  ->getMock();
93  $addressTypeFactory
94  ->method('getByPrefix')
95  ->willReturnCallback(function ($arg) use ($loginToIdMap) {
96  return new class ($arg, $loginToIdMap) implements ilMailAddressType {
97  protected array $loginToIdMap = [];
98  protected ilMailAddress $address;
99 
100  public function __construct(ilMailAddress $address, $loginToIdMap)
101  {
102  $this->address = $address;
103  $this->loginToIdMap = array_map(static function (int $usrId): array {
104  return [$usrId];
105  }, $loginToIdMap);
106  }
107 
108  public function resolve(): array
109  {
110  return $this->loginToIdMap[$this->address->getMailbox()] ?? [];
111  }
112 
113  public function validate(int $senderId): bool
114  {
115  return true;
116  }
117 
118  public function getErrors(): array
119  {
120  return [];
121  }
122 
123  public function getAddress(): ilMailAddress
124  {
125  return $this->address;
126  }
127  };
128  });
129 
130  $db = $this->getMockBuilder(ilDBInterface::class)->getMock();
131  $nextId = 0;
132  $db->method('nextId')->willReturnCallback(function () use (&$nextId): int {
133  ++$nextId;
134 
135  return $nextId;
136  });
137 
138  $eventHandler = $this->getMockBuilder(ilAppEventHandler::class)->disableOriginalConstructor()->getMock();
139  $logger = $this->getMockBuilder(ilLogger::class)->disableOriginalConstructor()->getMock();
140  $lng = $this->getMockBuilder(ilLanguage::class)->disableOriginalConstructor()->getMock();
141  $settings = $this->getMockBuilder(ilSetting::class)->disableOriginalConstructor()->getMock();
142  $this->setGlobalVariable('ilSetting', $settings);
143 
144  $mailFileData = $this->getMockBuilder(ilFileDataMail::class)->disableOriginalConstructor()->getMock();
145  $mailOptions = $this->getMockBuilder(ilMailOptions::class)->disableOriginalConstructor()->getMock();
146  $mailBox = $this->getMockBuilder(ilMailbox::class)->disableOriginalConstructor()->getMock();
147  $actor = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->getMock();
148 
149  $mailService = new ilMail(
150  $senderUsrId,
151  $addressTypeFactory,
153  $eventHandler,
154  $logger,
155  $db,
156  $lng,
157  $mailFileData,
158  $mailOptions,
159  $mailBox,
161  static function (string $login) use ($loginToIdMap): int {
162  return $loginToIdMap[$login] ?? 0;
163  },
164  4711,
165  $actor
166  );
167 
168  $oldTransport = ilMimeMail::getDefaultTransport();
169 
170  $mailTransport = $this
171  ->getMockBuilder(ilMailMimeTransport::class)
172  ->getMock();
173  $mailTransport->expects($this->once())->method('send')->with($this->callback(function (
174  ilMimeMail $mailer
175  ) use ($loginToIdMap): bool {
176  $totalBcc = [];
177  foreach ($mailer->getBcc() as $bcc) {
178  $totalBcc = array_filter(array_map('trim', explode(',', $bcc))) + $totalBcc;
179  }
180 
181  return count($totalBcc) === count($loginToIdMap);
182  }))->willReturn(true);
183  ilMimeMail::setDefaultTransport($mailTransport);
184 
185  $mailService->setUserInstanceById($userInstanceById);
186  $mailService->setMailOptionsByUserIdMap($mailOptionsById);
187 
188  $mailService->sendMail(
189  implode(',', array_slice(array_keys($loginToIdMap), 0, 3)),
190  implode(',', array_slice(array_keys($loginToIdMap), 3, 2)),
191  implode(',', array_slice(array_keys($loginToIdMap), 5, 2)),
192  'Subject',
193  'Message',
194  [],
195  false
196  );
197 
198  ilMimeMail::setDefaultTransport($oldTransport);
199  }
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
static addUserToCache(int $usrId, ilObjUser $user)
Class ilMailMimeSenderFactory.
$lng
static setDefaultTransport(?ilMailMimeTransport $transport)
static getDefaultTransport()
Interface ilMailAddressType.
Class ilMailRfc822AddressParserFactory.
setGlobalVariable(string $name, $value)
__construct(Container $dic, ilPlugin $plugin)
Class ilMailAddress.
+ Here is the call graph for this function:

◆ testFormatNamesForOutput()

ilMailTest::testFormatNamesForOutput ( )

Definition at line 209 of file ilMailTest.php.

References create().

209  : void
210  {
211  $instance = $this->create();
212 
213  $this->mockLanguage->expects(self::once())->method('txt')->with('not_available')->willReturn('not_available');
214 
215  $this->assertSame('not_available', $instance->formatNamesForOutput(''));
216  $this->assertSame('', $instance->formatNamesForOutput(','));
217  }
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:561
+ Here is the call graph for this function:

◆ testGetIliasMailerName()

ilMailTest::testGetIliasMailerName ( )

Definition at line 509 of file ilMailTest.php.

References ilMailBaseTest\setGlobalVariable().

509  : void
510  {
511  $expected = 'Phasellus lacus';
512  $mockSystem = $this->getMockBuilder(ilMailMimeSenderSystem::class)->disableOriginalConstructor()->getMock();
513  $mockSystem->expects(self::once())->method('getFromName')->willReturn($expected);
514  $mockFactory = $this->getMockBuilder(ilMailMimeSenderFactory::class)->disableOriginalConstructor()->getMock();
515  $mockFactory->expects(self::once())->method('system')->willReturn($mockSystem);
516  $this->setGlobalVariable('mail.mime.sender.factory', $mockFactory);
517 
518  $this->assertSame($expected, ilMail::_getIliasMailerName());
519  }
setGlobalVariable(string $name, $value)
+ Here is the call graph for this function:

◆ testGetMail()

ilMailTest::testGetMail ( )

Definition at line 301 of file ilMailTest.php.

References createAndExpectDatabaseCall().

301  : void
302  {
303  $mailId = 7890;
304  $instance = $this->createAndExpectDatabaseCall($mailId, []);
305  $instance->getMail($mailId);
306  }
createAndExpectDatabaseCall(int $someMailId, array $rowData)
Definition: ilMailTest.php:550
+ Here is the call graph for this function:

◆ testGetMailObjectReferenceId()

ilMailTest::testGetMailObjectReferenceId ( )

Definition at line 201 of file ilMailTest.php.

References $refId, and create().

201  : void
202  {
203  $refId = 364;
204  $instance = $this->create($refId);
205 
206  $this->assertSame($refId, $instance->getMailObjectReferenceId());
207  }
$refId
Definition: xapitoken.php:58
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:561
+ Here is the call graph for this function:

◆ testGetMailsOfFolder()

ilMailTest::testGetMailsOfFolder ( )

Definition at line 261 of file ilMailTest.php.

References create(), and queryCallback().

261  : void
262  {
263  $filter = ['status' => 'yes'];
264  $rowData = ['mail_id' => 8908];
265  $one = $rowData + [
266  'attachments' => [],
267  'tpl_ctx_params' => [],
268  'm_subject' => '',
269  'm_message' => '',
270  'rcp_to' => '',
271  'rcp_cc' => '',
272  'rcp_bcc' => '',
273  ];
274  $expected = [$one, $one];
275  $folderId = 89;
276  $userId = 901;
277  $instance = $this->create(234, $userId);
278  $mockStatement = $this->getMockBuilder(ilDBStatement::class)->getMock();
279  $this->mockDatabase->expects(self::never())->method('setLimit');
280  $this->mockDatabase->expects(self::exactly(3))->method('fetchAssoc')->with($mockStatement)->willReturnOnConsecutiveCalls($rowData, $rowData, null);
281  $this->mockDatabase->expects(self::once())->method('queryF')->willReturnCallback($this->queryCallback($mockStatement, ['integer', 'integer'], [$userId, $folderId]));
282 
283  $this->mockDatabase->expects(self::once())->method('quote')->with($filter['status'], 'text')->willReturn($filter['status']);
284 
285  $this->assertEquals($expected, $instance->getMailsOfFolder($folderId, $filter));
286  }
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:561
queryCallback($returnValue, array $expectedTypes, array $expectedValues)
Definition: ilMailTest.php:540
+ Here is the call graph for this function:

◆ testGetNewDraftId()

ilMailTest::testGetNewDraftId ( )

Definition at line 354 of file ilMailTest.php.

References create().

354  : void
355  {
356  $nextId = 789;
357  $userId = 5678;
358  $folderId = 47;
359  $instance = $this->create(4749, $userId);
360 
361  $this->mockDatabase->expects(self::once())->method('nextId')->with('mail')->willReturn($nextId);
362  $this->mockDatabase->expects(self::once())->method('insert')->with('mail', [
363  'mail_id' => ['integer', $nextId],
364  'user_id' => ['integer', $userId],
365  'folder_id' => ['integer', $folderId],
366  'sender_id' => ['integer', $userId],
367  ]);
368 
369  $this->assertSame($nextId, $instance->getNewDraftId($folderId));
370  }
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:561
+ Here is the call graph for this function:

◆ testGetNextMail()

ilMailTest::testGetNextMail ( )

Definition at line 253 of file ilMailTest.php.

References createAndExpectDatabaseCall().

253  : void
254  {
255  $mailId = 8484;
256  $instance = $this->createAndExpectDatabaseCall($mailId, []);
257  $this->mockDatabase->expects(self::once())->method('setLimit')->with(1, 0);
258  $instance->getNextMail($mailId);
259  }
createAndExpectDatabaseCall(int $someMailId, array $rowData)
Definition: ilMailTest.php:550
+ Here is the call graph for this function:

◆ testGetPreviousMail()

ilMailTest::testGetPreviousMail ( array  $rowData)

provideGetPreviousMail

Definition at line 222 of file ilMailTest.php.

References createAndExpectDatabaseCall().

222  : void
223  {
224  $mailId = 3454;
225  $instance = $this->createAndExpectDatabaseCall($mailId, $rowData);
226  $this->mockDatabase->expects(self::once())->method('setLimit')->with(1, 0);
227  $instance->getPreviousMail($mailId);
228  }
createAndExpectDatabaseCall(int $someMailId, array $rowData)
Definition: ilMailTest.php:550
+ Here is the call graph for this function:

◆ testMarkRead()

ilMailTest::testMarkRead ( )

Definition at line 308 of file ilMailTest.php.

References create(), and queryCallback().

308  : void
309  {
310  $mailIds = [1, 2, 3, 4, 5, 6];
311  $userId = 987;
312  $instance = $this->create(567, $userId);
313  $mockStatement = $this->getMockBuilder(ilDBStatement::class)->getMock();
314  $this->mockDatabase->expects(self::once())->method('in')->with('mail_id', $mailIds, false, 'integer')->willReturn('');
315  $this->mockDatabase->expects(self::once())->method('manipulateF')->willReturnCallback($this->queryCallback(0, ['text', 'integer'], ['read', $userId]));
316 
317  $instance->markRead($mailIds);
318  }
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:561
queryCallback($returnValue, array $expectedTypes, array $expectedValues)
Definition: ilMailTest.php:540
+ Here is the call graph for this function:

◆ testMarkUnread()

ilMailTest::testMarkUnread ( )

Definition at line 320 of file ilMailTest.php.

References create(), and queryCallback().

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

◆ testMoveMailsToFolder()

ilMailTest::testMoveMailsToFolder ( )

Definition at line 332 of file ilMailTest.php.

References create(), and queryCallback().

332  : void
333  {
334  $mailIds = [1, 2, 3, 4, 5, 6];
335  $folderId = 890;
336  $userId = 987;
337  $instance = $this->create(567, $userId);
338  $this->mockDatabase->expects(self::once())->method('in')->with('mail_id', $mailIds, false, 'integer')->willReturn('');
339  $this->mockDatabase->expects(self::once())->method('manipulateF')->willReturnCallback($this->queryCallback(1, ['integer', 'integer', 'integer'], [$folderId, $userId, $userId]));
340 
341  $this->assertTrue($instance->moveMailsToFolder($mailIds, $folderId));
342  }
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:561
queryCallback($returnValue, array $expectedTypes, array $expectedValues)
Definition: ilMailTest.php:540
+ Here is the call graph for this function:

◆ testMoveMailsToFolderFalse()

ilMailTest::testMoveMailsToFolderFalse ( )

Definition at line 344 of file ilMailTest.php.

References create().

344  : void
345  {
346  $mailIds = [];
347  $instance = $this->create();
348  $this->mockDatabase->expects(self::never())->method('in');
349  $this->mockDatabase->expects(self::never())->method('manipulateF');
350 
351  $this->assertFalse($instance->moveMailsToFolder($mailIds, 892));
352  }
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:561
+ Here is the call graph for this function:

◆ testPersistingToStage()

ilMailTest::testPersistingToStage ( )

Definition at line 406 of file ilMailTest.php.

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

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

◆ testRetrievalFromStage()

ilMailTest::testRetrievalFromStage ( )

Definition at line 455 of file ilMailTest.php.

References create(), and queryCallback().

455  : void
456  {
457  $userId = 789;
458  $instance = $this->create(67, $userId);
459  $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
460  $this->mockDatabase->expects(self::once())->method('queryF')->willReturnCallback($this->queryCallback($mockStatement, ['integer'], [$userId]));
461  $this->mockDatabase->expects(self::once())->method('fetchAssoc')->with($mockStatement)->willReturn([
462  'rcp_to' => 'phpunit'
463  ]);
464 
465  $mail_data = $instance->retrieveFromStage();
466 
467  $this->assertIsArray($mail_data);
468  $this->assertEquals('phpunit', $mail_data['rcp_to']);
469  }
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:561
queryCallback($returnValue, array $expectedTypes, array $expectedValues)
Definition: ilMailTest.php:540
+ Here is the call graph for this function:

◆ testSaveAttachments()

ilMailTest::testSaveAttachments ( )

Definition at line 521 of file ilMailTest.php.

References create().

521  : void
522  {
523  $userId = 89;
524  $attachments = ['aaa', 'bb', 'cc', 'rrr'];
525  $instance = $this->create(789, $userId);
526 
527  $this->mockDatabase->expects(self::once())->method('update')->with(
528  'mail_saved',
529  [
530  'attachments' => ['clob', serialize($attachments)],
531  ],
532  [
533  'user_id' => ['integer', $userId],
534  ]
535  );
536 
537  $instance->saveAttachments($attachments);
538  }
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:561
+ Here is the call graph for this function:

◆ testUpdateDraft()

ilMailTest::testUpdateDraft ( )

Definition at line 372 of file ilMailTest.php.

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

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

◆ testValidateRecipients()

ilMailTest::testValidateRecipients (   $errors = [])

Definition at line 471 of file ilMailTest.php.

References $errors, and create().

471  : void
472  {
473  $to = 'jkhk';
474  $cc = 'hjhjkl';
475  $bcc = 'jklhjk';
476 
477  $instance = $this->create();
478  $this->mockLog->expects(self::exactly(6))->method('debug')->withConsecutive(
479  ['Started parsing of recipient string: ' . $to],
480  ['Parsed addresses: hello'],
481  ['Started parsing of recipient string: ' . $cc],
482  ['Parsed addresses: hello'],
483  ['Started parsing of recipient string: ' . $bcc],
484  ['Parsed addresses: hello']
485  );
486 
487  $mockAddress = $this->getMockBuilder(ilMailAddress::class)->disableOriginalConstructor()->getMock();
488  $mockAddress->expects(self::exactly(3))->method('__toString')->willReturn('hello');
489  $mockParser = $this->getMockBuilder(ilMailRecipientParser::class)->disableOriginalConstructor()->getMock();
490  $mockParser->expects(self::exactly(3))->method('parse')->willReturn([$mockAddress]);
491  $this->mockParserFactory->expects(self::exactly(3))->method('getParser')->withConsecutive([$to], [$cc], [$bcc])->willReturn($mockParser);
492 
493  $mockAddressType = $this->getMockBuilder(ilMailAddressType::class)->disableOriginalConstructor()->getMock();
494  $mockAddressType->expects(self::exactly(3))->method('validate')->willReturn(empty($errors));
495  $mockAddressType->expects(self::exactly(empty($errors) ? 0 : 3))->method('getErrors')->willReturn($errors);
496  $this->mockAddressTypeFactory->expects(self::exactly(3))->method('getByPrefix')->with($mockAddress)->willReturn($mockAddressType);
497 
498  $this->assertSame([], $instance->validateRecipients($to, $cc, $bcc));
499  }
$errors
Definition: imgupload.php:65
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:561
+ Here is the call graph for this function:

Field Documentation

◆ $mockAddressTypeFactory

ilMailTest::$mockAddressTypeFactory
private

Definition at line 33 of file ilMailTest.php.

◆ $mockDatabase

ilDBInterface ilMailTest::$mockDatabase
private

Definition at line 31 of file ilMailTest.php.

◆ $mockLanguage

ilMailTest::$mockLanguage
private

Definition at line 39 of file ilMailTest.php.

◆ $mockLog

ilMailTest::$mockLog
private

Definition at line 35 of file ilMailTest.php.

◆ $mockParserFactory

ilMailTest::$mockParserFactory
private

Definition at line 37 of file ilMailTest.php.


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