ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilMailOptionsGUITest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 
31 {
35  protected function getMailOptionsGUI(
36  GlobalHttpState $httpState,
37  ilCtrlInterface $ctrl,
38  ilMailOptions $mail_options
39  ): ilMailOptionsGUI {
40  $tpl = $this->getMockBuilder(ilGlobalTemplateInterface::class)->disableOriginalConstructor()->getMock();
41  $lng = $this->getMockBuilder(ilLanguage::class)->disableOriginalConstructor()->getMock();
42  $user = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->getMock();
43 
44  return new ilMailOptionsGUI(
45  $tpl,
46  $ctrl,
47  $lng,
48  $user,
49  $httpState,
50  new Factory(new \ILIAS\Data\Factory(), $lng),
51  $mail_options
52  );
53  }
54 
60  {
61  $ctrl = $this->getMockBuilder(ilCtrl::class)->disableOriginalConstructor()->getMock();
62  $form = $this->getMockBuilder(ilMailOptionsFormGUI::class)->disableOriginalConstructor()->getMock();
63 
64  $ctrl->method('getCmd')->willReturn('showOptions');
65 
66  $request = $this->getMockBuilder(ServerRequestInterface::class)->disableOriginalConstructor()->getMock();
67  $request->method('getQueryParams')->willReturn([]);
68  $wrapper = new WrapperFactory($request);
69 
70  $http = $this->getMockBuilder(GlobalHttpState::class)->getMock();
71  $http->method('wrapper')->willReturn($wrapper);
72 
73  $settings = $this->getMockBuilder(ilSetting::class)->disableOriginalConstructor()->onlyMethods(['get'])->getMock();
74  $settings->method('get')->willReturnCallback(static function (string $key, ?string $default = null) {
75  if ($key === 'show_mail_settings') {
76  return '1';
77  }
78 
79  return $default;
80  });
81 
82  $options = new ilMailOptions(
83  0,
84  null,
85  $settings,
86  $this->createMock(ilDBInterface::class)
87  );
88 
89  $gui = $this->getMailOptionsGUI($http, $ctrl, $options);
90  $gui->setForm($form);
91  $gui->executeCommand();
92  }
93 
98  {
99  $ctrl = $this->getMockBuilder(ilCtrl::class)->disableOriginalConstructor()->getMock();
100  $form = $this->getMockBuilder(ilMailOptionsFormGUI::class)->disableOriginalConstructor()->getMock();
101 
102  $ctrl->method('getCmd')->willReturn('showOptions');
103 
104  $request = $this->getMockBuilder(ServerRequestInterface::class)->disableOriginalConstructor()->getMock();
105  $request->method('getQueryParams')->willReturn([]);
106  $wrapper = new WrapperFactory($request);
107 
108  $http = $this->getMockBuilder(GlobalHttpState::class)->getMock();
109  $http->method('wrapper')->willReturn($wrapper);
110 
111  $ctrl->expects($this->once())->method('redirectByClass')->with(ilMailGUI::class);
112 
113  $settings = $this->getMockBuilder(ilSetting::class)->disableOriginalConstructor()->onlyMethods(['get'])->getMock();
114  $settings->method('get')->willReturnCallback(static function (string $key, ?string $default = null) {
115  if ($key === 'show_mail_settings') {
116  return '0';
117  }
118 
119  return $default;
120  });
121 
122  $options = new ilMailOptions(
123  0,
124  null,
125  $settings,
126  $this->createMock(ilDBInterface::class)
127  );
128 
129  $gui = $this->getMailOptionsGUI($http, $ctrl, $options);
130  $gui->setForm($form);
131  $gui->executeCommand();
132  }
133 
138  {
139  $this->expectException(ilCtrlException::class);
140 
141  $request = $this->getMockBuilder(ServerRequestInterface::class)->disableOriginalConstructor()->getMock();
142  $ctrl = $this->createMock(ilCtrlInterface::class);
143  $form = $this->getMockBuilder(ilMailOptionsFormGUI::class)->disableOriginalConstructor()->getMock();
144 
145  $ctrl->method('getCmd')->willReturn('showOptions');
146 
147  $ctrl->expects($this->once())->method('redirectByClass')->with(ilPersonalSettingsGUI::class)->willThrowException(
148  new ilCtrlException('Script terminated')
149  );
150 
151  $settings = $this->getMockBuilder(ilSetting::class)->disableOriginalConstructor()->onlyMethods(['get'])->getMock();
152  $settings->method('get')->willReturnCallback(static function (string $key, ?string $default = null) {
153  if ($key === 'show_mail_settings') {
154  return '0';
155  }
156 
157  return $default;
158  });
159 
160  $request = $this->getMockBuilder(ServerRequestInterface::class)->disableOriginalConstructor()->getMock();
161  $request->method('getQueryParams')->willReturn([
162  'referrer' => ilPersonalSettingsGUI::class,
163  ]);
164  $wrapper = new WrapperFactory($request);
165 
166  $http = $this->getMockBuilder(GlobalHttpState::class)->getMock();
167  $http->method('wrapper')->willReturn($wrapper);
168 
169  $options = new ilMailOptions(
170  0,
171  null,
172  $settings,
173  $this->createMock(ilDBInterface::class)
174  );
175 
176  $gui = $this->getMailOptionsGUI($http, $ctrl, $options);
177  $gui->setForm($form);
178  $gui->executeCommand();
179  }
180 }
Interface GlobalHttpState.
Class ilMailOptions this class handles user mails.
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
testMailOptionsAreNotAccessibleIfGlobalAccessIsDeniedAndUserWillBeRedirectedToPersonalSettings()
$lng
Class ChatMainBarProvider .
Class ilMailOptionsGUITest.
Class ilMailBaseTest.
string $key
Consumer key/client ID value.
Definition: System.php:193
$http
Definition: raiseError.php:7
ilCtrl exceptions
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getMailOptionsGUI(GlobalHttpState $httpState, ilCtrlInterface $ctrl, ilMailOptions $mail_options)
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
testMailOptionsAreNotAccessibleIfGlobalAccessIsDeniedAndUserWillBeRedirectedToMailSystem()