ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
ilMailOptionsTest Class Reference
+ Inheritance diagram for ilMailOptionsTest:
+ Collaboration diagram for ilMailOptionsTest:

Public Member Functions

 testConstructor ()
 
 testConstructorWithUserSettings ()
 
 testIsAbsent (bool $absence_status, int $absent_from, int $absent_until, bool $result)
 

Static Public Member Functions

static provideMailOptionsData ()
 

Protected Member Functions

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

Protected Attributes

stdClass $object
 
MockObject &ilDBInterface $database
 
MockObject &ilSetting $settings
 

Detailed Description

Definition at line 25 of file ilMailOptionsTest.php.

Member Function Documentation

◆ provideMailOptionsData()

static ilMailOptionsTest::provideMailOptionsData ( )
static

Definition at line 163 of file ilMailOptionsTest.php.

163  : Generator
164  {
165  yield 'correct configuration' => [
166  'absence_status' => true,
167  'absent_from' => 100,
168  'absent_until' => 100,
169  'result' => true,
170  ];
171 
172  yield 'not absent' => [
173  'absence_status' => false,
174  'absent_from' => 100,
175  'absent_until' => 100,
176  'result' => false,
177  ];
178 
179  yield 'absent, absent_from is in the future' => [
180  'absence_status' => true,
181  'absent_from' => 100 + 1,
182  'absent_until' => 100,
183  'result' => false,
184  ];
185 
186  yield 'absent, absent_until is in the past' => [
187  'absence_status' => true,
188  'absent_from' => 100,
189  'absent_until' => 100 - 1,
190  'result' => false,
191  ];
192 
193  yield 'absent, absent_from is in the past, absent_until is in the future' => [
194  'absence_status' => true,
195  'absent_from' => 100 - 1,
196  'absent_until' => 100 + 1,
197  'result' => true,
198  ];
199  }

◆ setUp()

ilMailOptionsTest::setUp ( )
protected

Definition at line 31 of file ilMailOptionsTest.php.

References ILIAS\Repository\database(), and ilMailBaseTestCase\setGlobalVariable().

31  : void
32  {
33  parent::setUp();
34 
35  $this->database = $this->getMockBuilder(ilDBInterface::class)
36  ->getMock();
37  $query_mock = $this->getMockBuilder(ilDBStatement::class)
38  ->getMock();
39 
40  $this->object = new stdClass();
41  $this->object->cronjob_notification = false;
42  $this->object->signature = 'smth';
43  $this->object->incoming_type = 1;
44  $this->object->mail_address_option = 0;
45  $this->object->email = 'test@test.com';
46  $this->object->second_email = 'ilias@ilias.com';
47  $this->object->absence_status = false;
48  $this->object->absent_from = time();
49  $this->object->absent_until = time();
50  $this->object->absence_ar_subject = 'subject';
51  $this->object->absence_ar_body = 'body';
52 
53 
54  $this->database->expects($this->once())->method('queryF')->willReturn($query_mock);
55  $this->database->expects($this->once())->method('fetchObject')->willReturn($this->object);
56  $this->database->method('replace')->willReturn(0);
57  $this->setGlobalVariable('ilDB', $this->database);
58  }
setGlobalVariable(string $name, $value)
+ Here is the call graph for this function:

◆ testConstructor()

ilMailOptionsTest::testConstructor ( )

Definition at line 60 of file ilMailOptionsTest.php.

References ilMailOptions\INCOMING_LOCAL, and null.

60  : void
61  {
62  $settings = $this->getMockBuilder(ilSetting::class)->disableOriginalConstructor()->onlyMethods(['get'])->getMock();
63  $settings->method('get')->willReturnCallback(static function (string $key, ?string $default = null) {
64  if ($key === 'mail_incoming_mail' || $key === 'mail_address_option') {
65  return $default;
66  }
67 
68  if ($key === 'show_mail_settings') {
69  return '0';
70  }
71 
72  return $default;
73  });
74 
75  $mail_options = new ilMailOptions(
76  1,
77  null,
78  $this->createMock(ClockInterface::class),
79  $settings
80  );
81 
82  $this->assertSame('', $mail_options->getSignature());
83  $this->assertSame(ilMailOptions::INCOMING_LOCAL, $mail_options->getIncomingType());
84  $this->assertFalse($mail_options->isCronJobNotificationEnabled());
85  }
MockObject &ilSetting $settings
final const int INCOMING_LOCAL
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null

◆ testConstructorWithUserSettings()

ilMailOptionsTest::testConstructorWithUserSettings ( )

Definition at line 87 of file ilMailOptionsTest.php.

References null, and ILIAS\Repository\object().

87  : void
88  {
89  $settings = $this->getMockBuilder(ilSetting::class)->disableOriginalConstructor()->onlyMethods(['get'])->getMock();
90  $settings->method('get')->willReturnCallback(static function (string $key, ?string $default = null) {
91  if ($key === 'mail_incoming_mail' || $key === 'mail_address_option') {
92  return $default;
93  }
94 
95  if ($key === 'show_mail_settings') {
96  return '1';
97  }
98 
99  if ($key === 'usr_settings_disable_mail_incoming_mail') {
100  return '0';
101  }
102 
103  return $default;
104  });
105 
106  $mail_options = new ilMailOptions(
107  1,
108  null,
109  $this->createMock(ClockInterface::class),
110  $settings
111  );
112 
113  $this->assertSame($this->object->signature, $mail_options->getSignature());
114  $this->assertSame($this->object->incoming_type, $mail_options->getIncomingType());
115  $this->assertSame($this->object->cronjob_notification, $mail_options->isCronJobNotificationEnabled());
116  $this->assertSame($this->object->absence_status, $mail_options->getAbsenceStatus());
117  $this->assertSame($this->object->absent_from, $mail_options->getAbsentFrom());
118  $this->assertSame($this->object->absent_until, $mail_options->getAbsentUntil());
119  $this->assertSame($this->object->absence_ar_subject, $mail_options->getAbsenceAutoresponderSubject());
120  $this->assertSame($this->object->absence_ar_body, $mail_options->getAbsenceAutoresponderBody());
121  }
MockObject &ilSetting $settings
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the call graph for this function:

◆ testIsAbsent()

ilMailOptionsTest::testIsAbsent ( bool  $absence_status,
int  $absent_from,
int  $absent_until,
bool  $result 
)

Definition at line 124 of file ilMailOptionsTest.php.

References null.

124  : void
125  {
126  $usr_id = 1;
127  $this->object->absence_status = $absence_status;
128  $this->object->absent_from = $absent_from;
129  $this->object->absent_until = $absent_until;
130  $this->object->absence_ar_subject = 'subject';
131  $this->object->absence_ar_body = 'body';
132 
133  $cloc_service = $this->createMock(ClockInterface::class);
134  $cloc_service->method('now')->willReturn((new DateTimeImmutable())->setTimestamp(100));
135 
136  $settings = $this->getMockBuilder(ilSetting::class)->disableOriginalConstructor()->onlyMethods(['get'])->getMock();
137  $settings->method('get')->willReturnCallback(static function (string $key, ?string $default = null) {
138  if ($key === 'mail_incoming_mail' || $key === 'mail_address_option') {
139  return $default;
140  }
141 
142  if ($key === 'show_mail_settings') {
143  return '1';
144  }
145 
146  if ($key === 'usr_settings_disable_mail_incoming_mail') {
147  return '0';
148  }
149 
150  return $default;
151  });
152 
153  $mail_options = new ilMailOptions(
154  $usr_id,
155  null,
156  $cloc_service,
157  $settings
158  );
159 
160  $this->assertEquals($result, $mail_options->isAbsent());
161  }
MockObject &ilSetting $settings
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null

Field Documentation

◆ $database

MockObject& ilDBInterface ilMailOptionsTest::$database
protected

Definition at line 28 of file ilMailOptionsTest.php.

◆ $object

stdClass ilMailOptionsTest::$object
protected

Definition at line 27 of file ilMailOptionsTest.php.

◆ $settings

MockObject& ilSetting ilMailOptionsTest::$settings
protected

Definition at line 29 of file ilMailOptionsTest.php.


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