ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ilMailOptionsTest.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2017 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 declare(strict_types=1);
6 
11 {
13  protected $setting;
15  protected $object;
16 
17  protected function setUp() : void
18  {
19  parent::setUp();
20 
21  $this->database = $this->getMockBuilder(ilDBInterface::class)
22  ->getMock();
23  $queryMock = $this->getMockBuilder(ilDBStatement::class)
24  ->getMock();
25 
26  $this->object = new stdClass();
27  $this->object->cronjob_notification = false;
28  $this->object->signature = 'smth';
29  $this->object->linebreak = 0;
30  $this->object->incoming_type = 1;
31  $this->object->mail_address_option = 0;
32  $this->object->email = 'test@test.com';
33  $this->object->second_email = 'ilias@ilias.com';
34 
35  $this->database->expects($this->once())->method('queryF')->willReturn($queryMock);
36  $this->database->expects($this->once())->method('fetchObject')->willReturn($this->object);
37  $this->database->method('replace')->willReturn(0);
38  $this->setGlobalVariable('ilDB', $this->database);
39  }
40 
41  public function testConstructor() : void
42  {
43  $settings = $this->getMockBuilder(ilSetting::class)->disableOriginalConstructor()->onlyMethods(['get'])->getMock();
44  $settings->method('get')->willReturnCallback(static function (string $key, $default = false) {
45  if ($key === 'mail_incoming_mail' || $key === 'mail_address_option') {
46  return $default;
47  }
48 
49  if ($key === 'show_mail_settings') {
50  return '0';
51  }
52 
53  return $default;
54  });
55 
56  $mailOptions = new ilMailOptions(
57  1,
58  null,
59  $settings
60  );
61 
62  $this->assertSame('', $mailOptions->getSignature());
63  $this->assertSame(ilMailOptions::INCOMING_LOCAL, $mailOptions->getIncomingType());
64  $this->assertSame(ilMailOptions::DEFAULT_LINE_BREAK, $mailOptions->getLinebreak());
65  $this->assertFalse($mailOptions->isCronJobNotificationEnabled());
66  }
67 
68  public function testConstructorWithUserSettings() : void
69  {
70  $settings = $this->getMockBuilder(ilSetting::class)->disableOriginalConstructor()->onlyMethods(['get'])->getMock();
71  $settings->method('get')->willReturnCallback(static function (string $key, $default = false) {
72  if ($key === 'mail_incoming_mail' || $key === 'mail_address_option') {
73  return $default;
74  }
75 
76  if ($key === 'show_mail_settings') {
77  return '1';
78  }
79 
80  if ($key === 'usr_settings_disable_mail_incoming_mail') {
81  return '0';
82  }
83 
84  return $default;
85  });
86 
87  $mailOptions = new ilMailOptions(
88  1,
89  null,
90  $settings
91  );
92 
93  $this->assertSame($this->object->signature, $mailOptions->getSignature());
94  $this->assertSame($this->object->incoming_type, $mailOptions->getIncomingType());
95  $this->assertSame($this->object->linebreak, $mailOptions->getLinebreak());
96  $this->assertSame($this->object->cronjob_notification, $mailOptions->isCronJobNotificationEnabled());
97  }
98 }
Class ilMailOptions this class handles user mails.
Class ilMailBaseTest.
setGlobalVariable(string $name, $value)