ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 176 of file ilMailOptionsTest.php.

176 : Generator
177 {
178 yield 'correct configuration' => [
179 'absence_status' => true,
180 'absent_from' => 100,
181 'absent_until' => 100,
182 'result' => true,
183 ];
184
185 yield 'not absent' => [
186 'absence_status' => false,
187 'absent_from' => 100,
188 'absent_until' => 100,
189 'result' => false,
190 ];
191
192 yield 'absent, absent_from is in the future' => [
193 'absence_status' => true,
194 'absent_from' => 100 + 1,
195 'absent_until' => 100,
196 'result' => false,
197 ];
198
199 yield 'absent, absent_until is in the past' => [
200 'absence_status' => true,
201 'absent_from' => 100,
202 'absent_until' => 100 - 1,
203 'result' => false,
204 ];
205
206 yield 'absent, absent_from is in the past, absent_until is in the future' => [
207 'absence_status' => true,
208 'absent_from' => 100 - 1,
209 'absent_until' => 100 + 1,
210 'result' => true,
211 ];
212 }

◆ setUp()

ilMailOptionsTest::setUp ( )
protected

Reimplemented from ilMailBaseTestCase.

Definition at line 31 of file ilMailOptionsTest.php.

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 }

References ILIAS\Repository\database().

+ Here is the call graph for this function:

◆ testConstructor()

ilMailOptionsTest::testConstructor ( )

Definition at line 59 of file ilMailOptionsTest.php.

59 : void
60 {
61 $settings = $this->getMockBuilder(ilSetting::class)->disableOriginalConstructor()->onlyMethods(['get'])->getMock();
62 $settings->method('get')->willReturnCallback(static function (string $key, ?string $default = null) {
63 if ($key === 'mail_incoming_mail' || $key === 'mail_address_option') {
64 return $default;
65 }
66
67 if ($key === 'show_mail_settings') {
68 return '0';
69 }
70
71 return $default;
72 });
73
74 $user_settings = $this->getMockBuilder(ILIAS\User\Settings\Settings::class)->disableOriginalConstructor()
75 ->getMock();
76
77 $mail_options = new ilMailOptions(
78 1,
79 null,
80 $this->createMock(ClockInterface::class),
82 $this->database,
83 $user_settings,
84 $this->database,
85 $user_settings
86 );
87
88 $this->assertSame('', $mail_options->getSignature());
89 $this->assertSame(ilMailOptions::INCOMING_LOCAL, $mail_options->getIncomingType());
90 $this->assertFalse($mail_options->isCronJobNotificationEnabled());
91 }
MockObject &ilSetting $settings
final const int INCOMING_LOCAL
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.

References $settings, ILIAS\Repository\database(), and ilMailOptions\INCOMING_LOCAL.

+ Here is the call graph for this function:

◆ testConstructorWithUserSettings()

ilMailOptionsTest::testConstructorWithUserSettings ( )

Definition at line 93 of file ilMailOptionsTest.php.

93 : void
94 {
95 $settings = $this->getMockBuilder(ilSetting::class)->disableOriginalConstructor()->onlyMethods(['get'])->getMock();
96 $settings->method('get')->willReturnCallback(static function (string $key, ?string $default = null) {
97 if ($key === 'mail_incoming_mail' || $key === 'mail_address_option') {
98 return $default;
99 }
100
101 if ($key === 'show_mail_settings') {
102 return '1';
103 }
104
105 return $default;
106 });
107
108 $user_settings = $this->getMockBuilder(ILIAS\User\Settings\Settings::class)->disableOriginalConstructor()
109 ->getMock();
110 $user_settings->method('settingAvailableToUser')->willReturn(true);
111
112 $mail_options = new ilMailOptions(
113 1,
114 null,
115 $this->createMock(ClockInterface::class),
116 $settings,
117 $this->database,
118 $user_settings
119 );
120
121 $this->assertSame($this->object->signature, $mail_options->getSignature());
122 $this->assertSame($this->object->incoming_type, $mail_options->getIncomingType());
123 $this->assertSame($this->object->cronjob_notification, $mail_options->isCronJobNotificationEnabled());
124 $this->assertSame($this->object->absence_status, $mail_options->getAbsenceStatus());
125 $this->assertSame($this->object->absent_from, $mail_options->getAbsentFrom());
126 $this->assertSame($this->object->absent_until, $mail_options->getAbsentUntil());
127 $this->assertSame($this->object->absence_ar_subject, $mail_options->getAbsenceAutoresponderSubject());
128 $this->assertSame($this->object->absence_ar_body, $mail_options->getAbsenceAutoresponderBody());
129 }

References $settings, ILIAS\Repository\database(), and ILIAS\Repository\object().

+ 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 132 of file ilMailOptionsTest.php.

132 : void
133 {
134 $usr_id = 1;
135 $this->object->absence_status = $absence_status;
136 $this->object->absent_from = $absent_from;
137 $this->object->absent_until = $absent_until;
138 $this->object->absence_ar_subject = 'subject';
139 $this->object->absence_ar_body = 'body';
140
141 $cloc_service = $this->createMock(ClockInterface::class);
142 $cloc_service->method('now')->willReturn((new DateTimeImmutable())->setTimestamp(100));
143
144 $settings = $this->getMockBuilder(ilSetting::class)->disableOriginalConstructor()->onlyMethods(['get'])->getMock();
145 $settings->method('get')->willReturnCallback(static function (string $key, ?string $default = null) {
146 if ($key === 'mail_incoming_mail' || $key === 'mail_address_option') {
147 return $default;
148 }
149
150 if ($key === 'show_mail_settings') {
151 return '1';
152 }
153
154 if ($key === 'usr_settings_disable_mail_incoming_mail') {
155 return '0';
156 }
157
158 return $default;
159 });
160
161 $user_settings = $this->getMockBuilder(ILIAS\User\Settings\Settings::class)->disableOriginalConstructor()
162 ->getMock();
163
164 $mail_options = new ilMailOptions(
165 $usr_id,
166 null,
167 $cloc_service,
168 $settings,
169 $this->database,
170 $user_settings
171 );
172
173 $this->assertEquals($result, $mail_options->isAbsent());
174 }

References $settings, and ILIAS\Repository\database().

+ Here is the call graph for this function:

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

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