ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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)
 

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 int MAIL_SENDER_USER_ID = 4711
 
const int 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 28 of file ilMailAutoresponderServiceTest.php.

Member Function Documentation

◆ autoresponderProvider()

static ilMailAutoresponderServiceTest::autoresponderProvider ( )
static

Definition at line 128 of file ilMailAutoresponderServiceTest.php.

References null.

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

Referenced by testAutoresponderDeliveryWillBeHandledCorrectlyDependingOnLastSentTime().

120  : AutoresponderDto {
121  return new AutoresponderDto(
122  $auto_responder_sender_usr_id,
123  $auto_responder_receiver_id,
124  $sender_time
125  );
126  }
+ 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 97 of file ilMailAutoresponderServiceTest.php.

Referenced by testAutoresponderDeliveryWillBeHandledCorrectlyDependingOnLastSentTime().

102  return new AutoresponderServiceImpl(
103  $global_idle_time_interval,
104  true,
105  $auto_responder_repository,
106  $clock,
107  static function (
108  int $sender_id,
109  ilMailOptions $receiver_mail_options,
110  DateTimeImmutable $next_auto_responder_datetime
111  ): void {
112  }
113  );
114  }
+ 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 
)

Definition at line 34 of file ilMailAutoresponderServiceTest.php.

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

39  : void {
40  $clock = $this->createMock(ClockInterface::class);
41  $clock->method('now')->willReturn($faked_now);
42 
43  $repository = $this->createMock(AutoresponderRepository::class);
44 
45  if ($last_auto_responder_time === null) {
46  $repository->expects($this->once())->method('exists')->willReturn(false);
47  $repository->expects($this->never())->method('findBySenderIdAndReceiverId');
48 
49  $auto_responder_record = $this->createAutoresponderRecord(
50  self::MAIL_SENDER_USER_ID,
51  self::MAIL_RECEIVER_USER_ID,
52  $faked_now
53  );
54  } else {
55  $auto_responder_record = $this->createAutoresponderRecord(
56  self::MAIL_SENDER_USER_ID,
57  self::MAIL_RECEIVER_USER_ID,
58  $last_auto_responder_time
59  );
60 
61  $repository->expects($this->once())->method('exists')->willReturn(true);
62  $repository->expects($this->once())->method('findBySenderIdAndReceiverId')->willReturn($auto_responder_record);
63  }
64 
65  if ($expects_active_auto_responder) {
66  $repository->expects($this->once())->method('store')->with(
67  $this->callback(static fn(AutoresponderDto $actual): bool => (
68  // Compare by values, not identity (and ignore sent time)
69  $actual->getReceiverId() === $auto_responder_record->getReceiverId() &&
70  $actual->getSenderId() === $auto_responder_record->getSenderId()
71  ) && $faked_now->format('Y-m-d H:i:s') === $actual->getSentTime()->format('Y-m-d H:i:s'))
72  );
73  } else {
74  $repository->expects($this->never())->method('store');
75  }
76 
77  $mail_receiver_options = $this->getMockBuilder(ilMailOptions::class)->disableOriginalConstructor()->getMock();
78  $mail_receiver_options->method('getUsrId')->willReturn(self::MAIL_RECEIVER_USER_ID);
79  $mail_receiver_options->method('isAbsent')->willReturn(true);
80 
81  $mail_options = $this->getMockBuilder(ilMailOptions::class)->disableOriginalConstructor()->getMock();
82  $mail_options->method('getUsrId')->willReturn(self::MAIL_SENDER_USER_ID);
83  $mail_options->method('isAbsent')->willReturn(false);
84 
85 
86  $auto_responder_service = $this->createService(
87  $interval,
88  $repository,
89  $clock
90  );
91 
92  $auto_responder_service->enqueueAutoresponderIfEnabled(self::MAIL_SENDER_USER_ID, $mail_receiver_options, $mail_options);
93 
94  $auto_responder_service->handleAutoresponderMails(self::MAIL_RECEIVER_USER_ID);
95  }
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 int ilMailAutoresponderServiceTest::MAIL_RECEIVER_USER_ID = 4712
private

Definition at line 31 of file ilMailAutoresponderServiceTest.php.

◆ MAIL_SENDER_USER_ID

const int ilMailAutoresponderServiceTest::MAIL_SENDER_USER_ID = 4711
private

Definition at line 30 of file ilMailAutoresponderServiceTest.php.


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