ILIAS  trunk Revision v11.0_alpha-1769-g99a433fe2dc
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilMailAutoresponderServiceTest Class Reference
+ Inheritance diagram for ilMailAutoresponderServiceTest:
+ Collaboration diagram for ilMailAutoresponderServiceTest:

Public Member Functions

 testAutoresponderDeliveryWillBeHandledCorrectlyDependingOnLastSentTime (?DateTimeImmutable $last_auto_responder_time, DateTimeImmutable $faked_now, int $interval, bool $expects_active_auto_responder)
 autoresponderProvider More...
 

Static Public Member Functions

static autoresponderProvider ()
 

Private Member Functions

 createService (int $global_idle_time_interval, AutoresponderRepository $auto_responder_repository, ClockInterface $clock)
 
 createAutoresponderRecord (int $auto_responder_sender_usr_id, int $auto_responder_receiver_id, DateTimeImmutable $sender_time)
 

Private Attributes

const MAIL_SENDER_USER_ID = 4711
 
const MAIL_RECEIVER_USER_ID = 4712
 

Additional Inherited Members

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

Detailed Description

Definition at line 27 of file ilMailAutoresponderServiceTest.php.

Member Function Documentation

◆ autoresponderProvider()

static ilMailAutoresponderServiceTest::autoresponderProvider ( )
static

Definition at line 131 of file ilMailAutoresponderServiceTest.php.

References null.

131  : Generator
132  {
133  $now = new DateTimeImmutable('now', new DateTimeZone('UTC'));
134 
135  yield 'Last Sent Date is 1 Second in Future with Disabled Idle Time Interval' => [
136  $now->modify('+1 seconds'),
137  $now,
138  0,
139  false,
140  ];
141 
142  yield 'Last Sent Date is -1 Day in Past with Disabled Idle Time Interval' => [
143  $now->sub(new DateInterval('P1D')),
144  $now,
145  0,
146  true,
147  ];
148 
149  yield 'Last Sent Date is -1 Day + 1 Second in Past with Idle Time Interval being 1 Day' => [
150  $now->sub(new DateInterval('P1D'))->modify('+1 second'),
151  $now,
152  1,
153  false,
154  ];
155 
156  yield 'Last Sent Date is -1 Day in Past with Idle Time Interval being 1 Day' => [
157  $now->sub(new DateInterval('P1D')),
158  $now,
159  1,
160  true,
161  ];
162 
163  yield 'Last Sent Date is -1 Day in Past with an Added Idle Time Interval Exceeding Now' => [
164  $now->sub(new DateInterval('P1D')),
165  $now,
166  2,
167  false,
168  ];
169 
170  yield 'No autoresponder sent, yet' => [
171  null,
172  $now,
173  1,
174  true,
175  ];
176  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null

◆ createAutoresponderRecord()

ilMailAutoresponderServiceTest::createAutoresponderRecord ( int  $auto_responder_sender_usr_id,
int  $auto_responder_receiver_id,
DateTimeImmutable  $sender_time 
)
private

Definition at line 119 of file ilMailAutoresponderServiceTest.php.

Referenced by testAutoresponderDeliveryWillBeHandledCorrectlyDependingOnLastSentTime().

123  : AutoresponderDto {
124  return new AutoresponderDto(
125  $auto_responder_sender_usr_id,
126  $auto_responder_receiver_id,
127  $sender_time
128  );
129  }
+ Here is the caller graph for this function:

◆ createService()

ilMailAutoresponderServiceTest::createService ( int  $global_idle_time_interval,
AutoresponderRepository  $auto_responder_repository,
ClockInterface  $clock 
)
private

Definition at line 100 of file ilMailAutoresponderServiceTest.php.

Referenced by testAutoresponderDeliveryWillBeHandledCorrectlyDependingOnLastSentTime().

105  return new AutoresponderServiceImpl(
106  $global_idle_time_interval,
107  true,
108  $auto_responder_repository,
109  $clock,
110  static function (
111  int $sender_id,
112  ilMailOptions $receiver_mail_options,
113  DateTimeImmutable $next_auto_responder_datetime
114  ): void {
115  }
116  );
117  }
+ Here is the caller graph for this function:

◆ testAutoresponderDeliveryWillBeHandledCorrectlyDependingOnLastSentTime()

ilMailAutoresponderServiceTest::testAutoresponderDeliveryWillBeHandledCorrectlyDependingOnLastSentTime ( ?DateTimeImmutable  $last_auto_responder_time,
DateTimeImmutable  $faked_now,
int  $interval,
bool  $expects_active_auto_responder 
)

autoresponderProvider

Definition at line 35 of file ilMailAutoresponderServiceTest.php.

References createAutoresponderRecord(), createService(), ILIAS\Mail\Autoresponder\AutoresponderDto\getReceiverId(), ILIAS\Mail\Autoresponder\AutoresponderDto\getSenderId(), ILIAS\Mail\Autoresponder\AutoresponderDto\getSentTime(), and null.

40  : void {
41  $clock = $this->createMock(ClockInterface::class);
42  $clock->method('now')->willReturn($faked_now);
43 
44  $repository = $this->createMock(AutoresponderRepository::class);
45 
46  if ($last_auto_responder_time === null) {
47  $repository->expects($this->once())->method('exists')->willReturn(false);
48  $repository->expects($this->never())->method('findBySenderIdAndReceiverId');
49 
50  $auto_responder_record = $this->createAutoresponderRecord(
51  self::MAIL_SENDER_USER_ID,
52  self::MAIL_RECEIVER_USER_ID,
53  $faked_now
54  );
55  } else {
56  $auto_responder_record = $this->createAutoresponderRecord(
57  self::MAIL_SENDER_USER_ID,
58  self::MAIL_RECEIVER_USER_ID,
59  $last_auto_responder_time
60  );
61 
62  $repository->expects($this->once())->method('exists')->willReturn(true);
63  $repository->expects($this->once())->method('findBySenderIdAndReceiverId')->willReturn($auto_responder_record);
64  }
65 
66  if ($expects_active_auto_responder) {
67  $repository->expects($this->once())->method('store')->with(
68  $this->callback(static function (AutoresponderDto $actual) use ($faked_now, $auto_responder_record): bool {
69  return (
70  // Compare by values, not identity (and ignore sent time)
71  $actual->getReceiverId() === $auto_responder_record->getReceiverId() &&
72  $actual->getSenderId() === $auto_responder_record->getSenderId()
73  ) && $faked_now->format('Y-m-d H:i:s') === $actual->getSentTime()->format('Y-m-d H:i:s');
74  })
75  );
76  } else {
77  $repository->expects($this->never())->method('store');
78  }
79 
80  $mail_receiver_options = $this->getMockBuilder(ilMailOptions::class)->disableOriginalConstructor()->getMock();
81  $mail_receiver_options->method('getUsrId')->willReturn(self::MAIL_RECEIVER_USER_ID);
82  $mail_receiver_options->method('isAbsent')->willReturn(true);
83 
84  $mail_options = $this->getMockBuilder(ilMailOptions::class)->disableOriginalConstructor()->getMock();
85  $mail_options->method('getUsrId')->willReturn(self::MAIL_SENDER_USER_ID);
86  $mail_options->method('isAbsent')->willReturn(false);
87 
88 
89  $auto_responder_service = $this->createService(
90  $interval,
91  $repository,
92  $clock
93  );
94 
95  $auto_responder_service->enqueueAutoresponderIfEnabled(self::MAIL_SENDER_USER_ID, $mail_receiver_options, $mail_options);
96 
97  $auto_responder_service->handleAutoresponderMails(self::MAIL_RECEIVER_USER_ID);
98  }
createAutoresponderRecord(int $auto_responder_sender_usr_id, int $auto_responder_receiver_id, DateTimeImmutable $sender_time)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
createService(int $global_idle_time_interval, AutoresponderRepository $auto_responder_repository, ClockInterface $clock)
+ Here is the call graph for this function:

Field Documentation

◆ MAIL_RECEIVER_USER_ID

const ilMailAutoresponderServiceTest::MAIL_RECEIVER_USER_ID = 4712
private

Definition at line 30 of file ilMailAutoresponderServiceTest.php.

◆ MAIL_SENDER_USER_ID

const ilMailAutoresponderServiceTest::MAIL_SENDER_USER_ID = 4711
private

Definition at line 29 of file ilMailAutoresponderServiceTest.php.


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