ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
ilMailOptionsGUITest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
26 
28 {
29  protected function getMailOptionsGUI(
30  GlobalHttpState $http_state,
31  ilCtrlInterface $ctrl,
32  ilMailOptions $mail_options
33  ): ilMailOptionsGUI {
34  $tpl = $this->getMockBuilder(ilGlobalTemplateInterface::class)->disableOriginalConstructor()->getMock();
35  $lng = $this->getMockBuilder(ilLanguage::class)->disableOriginalConstructor()->getMock();
36  $user = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->getMock();
37 
38  return new ilMailOptionsGUI(
39  $tpl,
40  $ctrl,
41  $lng,
42  $user,
43  $http_state,
44  new Factory(new \ILIAS\Data\Factory(), $lng),
45  $mail_options
46  );
47  }
48 
49  #[DoesNotPerformAssertions]
51  {
52  $ctrl = $this->getMockBuilder(ilCtrl::class)->disableOriginalConstructor()->getMock();
53  $form = $this->getMockBuilder(ilMailOptionsFormGUI::class)->disableOriginalConstructor()->getMock();
54 
55  $ctrl->method('getCmd')->willReturn('showOptions');
56 
57  $request = $this->getMockBuilder(ServerRequestInterface::class)->disableOriginalConstructor()->getMock();
58  $request->method('getQueryParams')->willReturn([]);
59  $wrapper = new WrapperFactory($request);
60 
61  $http = $this->getMockBuilder(GlobalHttpState::class)->getMock();
62  $http->method('wrapper')->willReturn($wrapper);
63 
64  $settings = $this->getMockBuilder(ilSetting::class)->disableOriginalConstructor()->onlyMethods(['get'])->getMock();
65  $settings->method('get')->willReturnCallback(static function (string $key, ?string $default = null) {
66  if ($key === 'show_mail_settings') {
67  return '1';
68  }
69 
70  return $default;
71  });
72 
73  $options = new ilMailOptions(
74  0,
75  null,
76  $this->createMock(\ILIAS\Data\Clock\ClockInterface::class),
77  $settings,
78  $this->createMock(ilDBInterface::class)
79  );
80 
81  $gui = $this->getMailOptionsGUI($http, $ctrl, $options);
82  $gui->setForm($form);
83  $gui->executeCommand();
84  }
85 
87  {
88  $ctrl = $this->getMockBuilder(ilCtrl::class)->disableOriginalConstructor()->getMock();
89  $form = $this->getMockBuilder(ilMailOptionsFormGUI::class)->disableOriginalConstructor()->getMock();
90 
91  $ctrl->method('getCmd')->willReturn('showOptions');
92 
93  $request = $this->getMockBuilder(ServerRequestInterface::class)->disableOriginalConstructor()->getMock();
94  $request->method('getQueryParams')->willReturn([]);
95  $wrapper = new WrapperFactory($request);
96 
97  $http = $this->getMockBuilder(GlobalHttpState::class)->getMock();
98  $http->method('wrapper')->willReturn($wrapper);
99 
100  $ctrl->expects($this->once())->method('redirectByClass')->with(ilMailGUI::class);
101 
102  $settings = $this->getMockBuilder(ilSetting::class)->disableOriginalConstructor()->onlyMethods(['get'])->getMock();
103  $settings->method('get')->willReturnCallback(static function (string $key, ?string $default = null) {
104  if ($key === 'show_mail_settings') {
105  return '0';
106  }
107 
108  return $default;
109  });
110 
111  $options = new ilMailOptions(
112  0,
113  null,
114  $this->createMock(\ILIAS\Data\Clock\ClockInterface::class),
115  $settings,
116  $this->createMock(ilDBInterface::class)
117  );
118 
119  $gui = $this->getMailOptionsGUI($http, $ctrl, $options);
120  $gui->setForm($form);
121  $gui->executeCommand();
122  }
123 
125  {
126  $this->expectException(ilCtrlException::class);
127 
128  $request = $this->getMockBuilder(ServerRequestInterface::class)->disableOriginalConstructor()->getMock();
129  $ctrl = $this->createMock(ilCtrlInterface::class);
130  $form = $this->getMockBuilder(ilMailOptionsFormGUI::class)->disableOriginalConstructor()->getMock();
131 
132  $ctrl->method('getCmd')->willReturn('showOptions');
133 
134  $ctrl->expects($this->once())->method('redirectByClass')->with(ilPersonalSettingsGUI::class)->willThrowException(
135  new ilCtrlException('Script terminated')
136  );
137 
138  $settings = $this->getMockBuilder(ilSetting::class)->disableOriginalConstructor()->onlyMethods(['get'])->getMock();
139  $settings->method('get')->willReturnCallback(static function (string $key, ?string $default = null) {
140  if ($key === 'show_mail_settings') {
141  return '0';
142  }
143 
144  return $default;
145  });
146 
147  $request = $this->getMockBuilder(ServerRequestInterface::class)->disableOriginalConstructor()->getMock();
148  $request->method('getQueryParams')->willReturn([
149  'referrer' => ilPersonalSettingsGUI::class,
150  ]);
151  $wrapper = new WrapperFactory($request);
152 
153  $http = $this->getMockBuilder(GlobalHttpState::class)->getMock();
154  $http->method('wrapper')->willReturn($wrapper);
155 
156  $options = new ilMailOptions(
157  0,
158  null,
159  $this->createMock(\ILIAS\Data\Clock\ClockInterface::class),
160  $settings,
161  $this->createMock(ilDBInterface::class)
162  );
163 
164  $gui = $this->getMailOptionsGUI($http, $ctrl, $options);
165  $gui->setForm($form);
166  $gui->executeCommand();
167  }
168 }
testMailOptionsAreNotAccessibleIfGlobalAccessIsDeniedAndUserWillBeRedirectedToPersonalSettings()
Interface Observer Contains several chained tasks and infos about them.
$http
Definition: deliver.php:30
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getMailOptionsGUI(GlobalHttpState $http_state, ilCtrlInterface $ctrl, ilMailOptions $mail_options)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $lng
Definition: privfeed.php:31
testMailOptionsAreNotAccessibleIfGlobalAccessIsDeniedAndUserWillBeRedirectedToMailSystem()