ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator 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...
 
 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 ($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 ilMailBaseTestCase
 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 592 of file ilMailTest.php.

References $refId, and null.

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

592  : ilMail
593  {
594  return new ilMail(
595  $userId,
596  ($this->mock_address_type_factory = $this->getMockBuilder(ilMailAddressTypeFactory::class)->disableOriginalConstructor()->getMock()),
597  ($this->mock_parser_factory = $this->getMockBuilder(ilMailRfc822AddressParserFactory::class)->disableOriginalConstructor()->getMock()),
598  $this->getMockBuilder(ilAppEventHandler::class)->disableOriginalConstructor()->getMock(),
599  ($this->mock_log = $this->getMockBuilder(ilLogger::class)->disableOriginalConstructor()->getMock()),
600  ($this->mock_database = $this->getMockBuilder(ilDBInterface::class)->disableOriginalConstructor()->getMock()),
601  ($this->mock_language = $this->getMockBuilder(ilLanguage::class)->disableOriginalConstructor()->getMock()),
602  $this->getMockBuilder(ilFileDataMail::class)->disableOriginalConstructor()->getMock(),
603  $this->getMockBuilder(ilMailOptions::class)->disableOriginalConstructor()->getMock(),
604  $this->getMockBuilder(ilMailbox::class)->disableOriginalConstructor()->getMock(),
605  $this->getMockBuilder(ilMailMimeSenderFactory::class)->disableOriginalConstructor()->getMock(),
606  static function (string $login): int {
607  return 780;
608  },
609  $this->createMock(AutoresponderService::class),
610  0,
611  $refId,
612  $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->getMock(),
613  $this->getMockBuilder(ilMailTemplatePlaceholderResolver::class)->disableOriginalConstructor()->getMock(),
614  null,
615  null,
616  $this->getMockBuilder(MailSignatureService::class)->disableOriginalConstructor()->getMock(),
617  );
618  }
$refId
Definition: xapitoken.php:58
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the caller graph for this function:

◆ createAndExpectDatabaseCall()

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

Definition at line 581 of file ilMailTest.php.

References create(), and queryCallback().

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

581  : ilMail
582  {
583  $userId = 900;
584  $instance = $this->create(234, $userId);
585  $mockStatement = $this->getMockBuilder(ilDBStatement::class)->getMock();
586  $this->mock_database->expects(self::once())->method('fetchAssoc')->with($mockStatement)->willReturn($rowData);
587  $this->mock_database->expects(self::once())->method('queryF')->willReturnCallback($this->queryCallback($mockStatement, ['integer', 'integer'], [$userId, $someMailId]));
588 
589  return $instance;
590  }
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:592
queryCallback($returnValue, array $expectedTypes, array $expectedValues)
Definition: ilMailTest.php:571
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ provideGetPreviousMail()

static ilMailTest::provideGetPreviousMail ( )
static

Definition at line 250 of file ilMailTest.php.

250  : array
251  {
252  return [
253  [[]],
254  [[
255  'attachments' => '',
256  'folder_id' => '',
257  'mail_id' => '',
258  'sender_id' => '',
259  'tpl_ctx_params' => '[]',
260  'use_placeholders' => '',
261  'user_id' => ''
262  ]],
263  [[
264  'folder_id' => '',
265  'mail_id' => '',
266  'sender_id' => '',
267  'use_placeholders' => '',
268  'user_id' => ''
269  ]],
270  ];
271  }

◆ provideValidateRecipients()

ilMailTest::provideValidateRecipients ( )

Definition at line 533 of file ilMailTest.php.

533  : array
534  {
535  return [
536  [[]],
537  [['some error']]
538  ];
539  }

◆ queryCallback()

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

Definition at line 571 of file ilMailTest.php.

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

571  : Closure
572  {
573  return function (string $query, array $types, array $values) use ($expectedTypes, $expectedValues, $returnValue) {
574  $this->assertEquals($expectedTypes, $types);
575  $this->assertEquals($expectedValues, $values);
576 
577  return $returnValue;
578  };
579  }
+ Here is the caller graph for this function:

◆ testCountMailsOfFolder()

ilMailTest::testCountMailsOfFolder ( )

Definition at line 308 of file ilMailTest.php.

References create(), and queryCallback().

308  : void
309  {
310  $userId = 46;
311  $folderId = 68;
312  $numRows = 89;
313  $instance = $this->create(345, $userId);
314  $mockStatement = $this->getMockBuilder(ilDBStatement::class)->getMock();
315  $this->mock_database->expects(self::once())->method('queryF')->willReturnCallback($this->queryCallback($mockStatement, ['integer', 'integer'], [$userId, $folderId]));
316  $this->mock_database->expects(self::once())->method('numRows')->with($mockStatement)->willReturn($numRows);
317 
318  $this->assertSame($numRows, $instance->countMailsOfFolder($folderId));
319  }
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:592
queryCallback($returnValue, array $expectedTypes, array $expectedValues)
Definition: ilMailTest.php:571
+ Here is the call graph for this function:

◆ testExternalMailDeliveryToLocalRecipientsWorksAsExpected()

ilMailTest::testExternalMailDeliveryToLocalRecipientsWorksAsExpected ( )
Exceptions
ReflectionException

Definition at line 44 of file ilMailTest.php.

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

◆ testFormatNamesForOutput()

ilMailTest::testFormatNamesForOutput ( )

Definition at line 229 of file ilMailTest.php.

References create().

229  : void
230  {
231  $instance = $this->create();
232 
233  $this->mock_language->expects(self::once())->method('txt')->with('not_available')->willReturn('not_available');
234 
235  $this->assertSame('not_available', $instance->formatNamesForOutput(''));
236  $this->assertSame('', $instance->formatNamesForOutput(','));
237  }
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:592
+ Here is the call graph for this function:

◆ testGetIliasMailerName()

ilMailTest::testGetIliasMailerName ( )

Definition at line 541 of file ilMailTest.php.

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

541  : void
542  {
543  $expected = 'Phasellus lacus';
544  $settings = $this->getMockBuilder(ilSetting::class)->disableOriginalConstructor()->getMock();
545  $settings->method('get')->with('mail_system_sys_from_name')->willReturn($expected);
546  $this->setGlobalVariable('ilSetting', $settings);
547 
548 
549  $this->assertSame($expected, ilMail::_getIliasMailerName());
550  }
static _getIliasMailerName()
setGlobalVariable(string $name, $value)
+ Here is the call graph for this function:

◆ testGetMail()

ilMailTest::testGetMail ( )

Definition at line 321 of file ilMailTest.php.

References createAndExpectDatabaseCall().

321  : void
322  {
323  $mailId = 7890;
324  $instance = $this->createAndExpectDatabaseCall($mailId, []);
325  $instance->getMail($mailId);
326  }
createAndExpectDatabaseCall(int $someMailId, array $rowData)
Definition: ilMailTest.php:581
+ Here is the call graph for this function:

◆ testGetMailObjectReferenceId()

ilMailTest::testGetMailObjectReferenceId ( )

Definition at line 221 of file ilMailTest.php.

References $refId, and create().

221  : void
222  {
223  $refId = 364;
224  $instance = $this->create($refId);
225 
226  $this->assertSame($refId, $instance->getMailObjectReferenceId());
227  }
$refId
Definition: xapitoken.php:58
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:592
+ Here is the call graph for this function:

◆ testGetMailsOfFolder()

ilMailTest::testGetMailsOfFolder ( )

Definition at line 281 of file ilMailTest.php.

References create(), null, and queryCallback().

281  : void
282  {
283  $filter = ['status' => 'yes'];
284  $rowData = ['mail_id' => 8908];
285  $one = $rowData + [
286  'attachments' => [],
287  'tpl_ctx_params' => [],
288  'm_subject' => '',
289  'm_message' => '',
290  'rcp_to' => '',
291  'rcp_cc' => '',
292  'rcp_bcc' => '',
293  ];
294  $expected = [$one, $one];
295  $folderId = 89;
296  $userId = 901;
297  $instance = $this->create(234, $userId);
298  $mockStatement = $this->getMockBuilder(ilDBStatement::class)->getMock();
299  $this->mock_database->expects(self::never())->method('setLimit');
300  $this->mock_database->expects(self::exactly(3))->method('fetchAssoc')->with($mockStatement)->willReturnOnConsecutiveCalls($rowData, $rowData, null);
301  $this->mock_database->expects(self::once())->method('queryF')->willReturnCallback($this->queryCallback($mockStatement, ['integer', 'integer'], [$userId, $folderId]));
302 
303  $this->mock_database->expects(self::once())->method('quote')->with($filter['status'], 'text')->willReturn($filter['status']);
304 
305  $this->assertEquals($expected, $instance->getMailsOfFolder($folderId, $filter));
306  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:592
queryCallback($returnValue, array $expectedTypes, array $expectedValues)
Definition: ilMailTest.php:571
+ Here is the call graph for this function:

◆ testGetNewDraftId()

ilMailTest::testGetNewDraftId ( )

Definition at line 374 of file ilMailTest.php.

References create().

374  : void
375  {
376  $nextId = 789;
377  $userId = 5678;
378  $folderId = 47;
379  $instance = $this->create(4749, $userId);
380 
381  $this->mock_database->expects(self::once())->method('nextId')->with('mail')->willReturn($nextId);
382  $this->mock_database->expects(self::once())->method('insert')->with('mail', [
383  'mail_id' => ['integer', $nextId],
384  'user_id' => ['integer', $userId],
385  'folder_id' => ['integer', $folderId],
386  'sender_id' => ['integer', $userId],
387  ]);
388 
389  $this->assertSame($nextId, $instance->getNewDraftId($folderId));
390  }
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:592
+ Here is the call graph for this function:

◆ testGetNextMail()

ilMailTest::testGetNextMail ( )

Definition at line 273 of file ilMailTest.php.

References createAndExpectDatabaseCall().

273  : void
274  {
275  $mailId = 8484;
276  $instance = $this->createAndExpectDatabaseCall($mailId, []);
277  $this->mock_database->expects(self::once())->method('setLimit')->with(1, 0);
278  $instance->getNextMail($mailId);
279  }
createAndExpectDatabaseCall(int $someMailId, array $rowData)
Definition: ilMailTest.php:581
+ Here is the call graph for this function:

◆ testGetPreviousMail()

ilMailTest::testGetPreviousMail ( array  $rowData)

provideGetPreviousMail

Definition at line 242 of file ilMailTest.php.

References createAndExpectDatabaseCall().

242  : void
243  {
244  $mailId = 3454;
245  $instance = $this->createAndExpectDatabaseCall($mailId, $rowData);
246  $this->mock_database->expects(self::once())->method('setLimit')->with(1, 0);
247  $instance->getPreviousMail($mailId);
248  }
createAndExpectDatabaseCall(int $someMailId, array $rowData)
Definition: ilMailTest.php:581
+ Here is the call graph for this function:

◆ testMarkRead()

ilMailTest::testMarkRead ( )

Definition at line 328 of file ilMailTest.php.

References create(), and queryCallback().

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

◆ testMarkUnread()

ilMailTest::testMarkUnread ( )

Definition at line 340 of file ilMailTest.php.

References create(), and queryCallback().

340  : void
341  {
342  $mailIds = [1, 2, 3, 4, 5, 6];
343  $userId = 987;
344  $instance = $this->create(567, $userId);
345  $this->getMockBuilder(ilDBStatement::class)->getMock();
346  $this->mock_database->expects(self::once())->method('in')->with('mail_id', $mailIds, false, 'integer')->willReturn('');
347  $this->mock_database->expects(self::once())->method('manipulateF')->willReturnCallback($this->queryCallback(0, ['text', 'integer'], ['unread', $userId]));
348 
349  $instance->markUnread($mailIds);
350  }
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:592
queryCallback($returnValue, array $expectedTypes, array $expectedValues)
Definition: ilMailTest.php:571
+ Here is the call graph for this function:

◆ testMoveMailsToFolder()

ilMailTest::testMoveMailsToFolder ( )

Definition at line 352 of file ilMailTest.php.

References create(), and queryCallback().

352  : void
353  {
354  $mailIds = [1, 2, 3, 4, 5, 6];
355  $folderId = 890;
356  $userId = 987;
357  $instance = $this->create(567, $userId);
358  $this->mock_database->expects(self::once())->method('in')->with('mail_id', $mailIds, false, 'integer')->willReturn('');
359  $this->mock_database->expects(self::once())->method('manipulateF')->willReturnCallback($this->queryCallback(1, ['integer', 'integer', 'integer'], [$folderId, $userId, $userId]));
360 
361  $this->assertTrue($instance->moveMailsToFolder($mailIds, $folderId));
362  }
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:592
queryCallback($returnValue, array $expectedTypes, array $expectedValues)
Definition: ilMailTest.php:571
+ Here is the call graph for this function:

◆ testMoveMailsToFolderFalse()

ilMailTest::testMoveMailsToFolderFalse ( )

Definition at line 364 of file ilMailTest.php.

References create().

364  : void
365  {
366  $mailIds = [];
367  $instance = $this->create();
368  $this->mock_database->expects(self::never())->method('in');
369  $this->mock_database->expects(self::never())->method('manipulateF');
370 
371  $this->assertFalse($instance->moveMailsToFolder($mailIds, 892));
372  }
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:592
+ Here is the call graph for this function:

◆ testPersistingToStage()

ilMailTest::testPersistingToStage ( )

Definition at line 426 of file ilMailTest.php.

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

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

◆ testRetrievalFromStage()

ilMailTest::testRetrievalFromStage ( )

Definition at line 475 of file ilMailTest.php.

References create(), and queryCallback().

475  : void
476  {
477  $userId = 789;
478  $instance = $this->create(67, $userId);
479  $mockStatement = $this->getMockBuilder(ilDBStatement::class)->disableOriginalConstructor()->getMock();
480  $this->mock_database->expects(self::once())->method('queryF')->willReturnCallback($this->queryCallback($mockStatement, ['integer'], [$userId]));
481  $this->mock_database->expects(self::once())->method('fetchAssoc')->with($mockStatement)->willReturn([
482  'rcp_to' => 'phpunit'
483  ]);
484 
485  $mail_data = $instance->retrieveFromStage();
486 
487  $this->assertIsArray($mail_data);
488  $this->assertEquals('phpunit', $mail_data['rcp_to']);
489  }
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:592
queryCallback($returnValue, array $expectedTypes, array $expectedValues)
Definition: ilMailTest.php:571
+ Here is the call graph for this function:

◆ testSaveAttachments()

ilMailTest::testSaveAttachments ( )

Definition at line 552 of file ilMailTest.php.

References create().

552  : void
553  {
554  $userId = 89;
555  $attachments = ['aaa', 'bb', 'cc', 'rrr'];
556  $instance = $this->create(789, $userId);
557 
558  $this->mock_database->expects(self::once())->method('update')->with(
559  'mail_saved',
560  [
561  'attachments' => ['clob', serialize($attachments)],
562  ],
563  [
564  'user_id' => ['integer', $userId],
565  ]
566  );
567 
568  $instance->saveAttachments($attachments);
569  }
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:592
+ Here is the call graph for this function:

◆ testUpdateDraft()

ilMailTest::testUpdateDraft ( )

Definition at line 392 of file ilMailTest.php.

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

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

◆ testValidateRecipients()

ilMailTest::testValidateRecipients (   $errors = [])

Definition at line 491 of file ilMailTest.php.

References create().

491  : void
492  {
493  $to = 'jkhk';
494  $cc = 'hjhjkl';
495  $bcc = 'jklhjk';
496 
497  $instance = $this->create();
498  $consecutive_debug = [
499  'Started parsing of recipient string: ' . $to,
500  'Parsed addresses: hello',
501  'Started parsing of recipient string: ' . $cc,
502  'Parsed addresses: hello',
503  'Started parsing of recipient string: ' . $bcc,
504  'Parsed addresses: hello'
505  ];
506  $this->mock_log->expects(self::exactly(6))->method('debug')->with(
507  $this->callback(function ($value) use (&$consecutive_debug) {
508  $this->assertSame(array_shift($consecutive_debug), $value);
509  return true;
510  }),
511  );
512 
513  $mockAddress = $this->getMockBuilder(ilMailAddress::class)->disableOriginalConstructor()->getMock();
514  $mockAddress->expects(self::exactly(3))->method('__toString')->willReturn('hello');
515  $mockParser = $this->getMockBuilder(ilMailRecipientParser::class)->disableOriginalConstructor()->getMock();
516  $mockParser->expects(self::exactly(3))->method('parse')->willReturn([$mockAddress]);
517  $consecutive_get = [$to, $cc, $bcc];
518  $this->mock_parser_factory->expects(self::exactly(3))->method('getParser')->with(
519  $this->callback(function ($value) use (&$consecutive_get) {
520  $this->assertSame(array_shift($consecutive_get), $value);
521  return true;
522  }),
523  )->willReturn($mockParser);
524 
525  $mockAddressType = $this->getMockBuilder(ilMailAddressType::class)->disableOriginalConstructor()->getMock();
526  $mockAddressType->expects(self::exactly(3))->method('validate')->willReturn(empty($errors));
527  $mockAddressType->expects(self::exactly(empty($errors) ? 0 : 3))->method('getErrors')->willReturn($errors);
528  $this->mock_address_type_factory->expects(self::exactly(3))->method('getByPrefix')->with($mockAddress)->willReturn($mockAddressType);
529 
530  $this->assertSame([], $instance->validateRecipients($to, $cc, $bcc));
531  }
create(int $refId=234, int $userId=123)
Definition: ilMailTest.php:592
+ 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: