ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
ilTermsOfServiceSettingsFormGUITest.php
Go to the documentation of this file.
1 <?php declare(strict_types=1);
2 /* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
9 {
13  public function testFormCanBeProperlyBuilt() : void
14  {
15  $tos = $this->getMockBuilder(ilObjTermsOfService::class)->disableOriginalConstructor()->getMock();
16 
17  $tos
18  ->expects($this->any())
19  ->method('getStatus')
20  ->willReturn(true);
21 
23  $tos,
24  '',
25  'save',
26  true
27  );
28 
29  $this->assertCount(1, $form->getCommandButtons(), 'Failed asserting save button is given if form is editable');
30  $this->assertArrayHasKey(
31  0,
32  $form->getCommandButtons(),
33  'Failed asserting save button ist given if form is editable'
34  );
35  $this->assertEquals(
36  'save',
37  $form->getCommandButtons()[0]['cmd'],
38  'Failed asserting save button ist given if form is editable'
39  );
40 
42  $tos,
43  '',
44  'save',
45  false
46  );
47 
48  $this->assertCount(
49  0,
50  $form->getCommandButtons(),
51  'Failed asserting no button is given if form is not editable'
52  );
53  }
54 
58  public function testFormCanBeSavedWithDisabledService() : void
59  {
60  $tos = $this->getMockBuilder(ilObjTermsOfService::class)->disableOriginalConstructor()->getMock();
61 
62  $tos
63  ->expects($this->any())
64  ->method('getStatus')
65  ->willReturn(false);
66 
67  $tos
68  ->expects($this->once())
69  ->method('saveStatus')
70  ->with(false);
71 
72  $form = $this->getMockBuilder(ilTermsOfServiceSettingsFormGUI::class)
73  ->setConstructorArgs([
74  $tos,
75  '',
76  'save',
77  true
78  ])
79  ->setMethods(['checkInput', 'getInput'])
80  ->getMock();
81 
82  $form
83  ->expects($this->once())
84  ->method('checkInput')
85  ->willReturn(true);
86 
87  $form
88  ->expects($this->exactly(2))
89  ->method('getInput')
90  ->willReturn(0);
91 
92  $_POST = [
93  'tos_status' => 1
94  ];
95 
96  $form->setCheckInputCalled(true);
97 
98  $this->assertTrue($form->saveObject());
99  $this->assertFalse($form->hasTranslatedError());
100  $this->assertEmpty($form->getTranslatedError());
101  }
102 
107  {
108  $tos = $this->getMockBuilder(ilObjTermsOfService::class)->disableOriginalConstructor()->getMock();
109 
110  $tos
111  ->expects($this->any())
112  ->method('getStatus')
113  ->willReturn(false);
114 
115  $tos
116  ->expects($this->once())
117  ->method('saveStatus')
118  ->with(true);
119 
120  $form = $this->getMockBuilder(ilTermsOfServiceSettingsFormGUI::class)
121  ->setConstructorArgs([
122  $tos,
123  '',
124  'save',
125  true
126  ])
127  ->setMethods(['checkInput', 'getInput'])
128  ->getMock();
129 
130  $form
131  ->expects($this->once())
132  ->method('checkInput')
133  ->willReturn(true);
134 
135  $form
136  ->expects($this->exactly(2))
137  ->method('getInput')
138  ->willReturn(1);
139 
140  $_POST = [
141  'tos_status' => 1
142  ];
143 
144  $form->setCheckInputCalled(true);
145 
146  $documentConnector = $this->getMockBuilder(arConnector::class)->getMock();#
147 
148  $documentConnector
149  ->expects($this->once())
150  ->method('affectedRows')
151  ->willReturn(2);
152 
153  arConnectorMap::register(new ilTermsOfServiceDocument(), $documentConnector);
154 
155  $this->assertTrue($form->saveObject());
156  $this->assertFalse($form->hasTranslatedError());
157  $this->assertEmpty($form->getTranslatedError());
158  }
159 
164  {
165  $lng = $this->getLanguageMock();
166 
167  $lng
168  ->expects($this->any())
169  ->method('txt')
170  ->willReturn('translation');
171 
172  $this->setGlobalVariable('lng', $lng);
173 
174  $tos = $this->getMockBuilder(ilObjTermsOfService::class)->disableOriginalConstructor()->getMock();
175 
176  $tos
177  ->expects($this->any())
178  ->method('getStatus')
179  ->willReturn(false);
180 
181  $tos
182  ->expects($this->never())
183  ->method('saveStatus');
184 
185  $form = $this->getMockBuilder(ilTermsOfServiceSettingsFormGUI::class)
186  ->setConstructorArgs([
187  $tos,
188  '',
189  'save',
190  true
191  ])
192  ->setMethods(['checkInput', 'getInput'])
193  ->getMock();
194 
195  $form
196  ->expects($this->once())
197  ->method('checkInput')
198  ->willReturn(true);
199 
200  $form
201  ->expects($this->once())
202  ->method('getInput')
203  ->willReturn(1);
204 
205  $_POST = [
206  'tos_status' => 1
207  ];
208 
209  $form->setCheckInputCalled(true);
210 
211  $documentConnector = $this->getMockBuilder(arConnector::class)->getMock();#
212 
213  $documentConnector
214  ->expects($this->once())
215  ->method('affectedRows')
216  ->willReturn(0);
217 
218  arConnectorMap::register(new ilTermsOfServiceDocument(), $documentConnector);
219 
220  $this->assertFalse($form->saveObject());
221  $this->assertTrue($form->hasTranslatedError());
222  $this->assertNotEmpty($form->getTranslatedError());
223  }
224 
229  {
230  $tos = $this->getMockBuilder(ilObjTermsOfService::class)->disableOriginalConstructor()->getMock();
231 
232  $tos
233  ->expects($this->any())
234  ->method('getStatus')
235  ->willReturn(true);
236 
237  $tos
238  ->expects($this->once())
239  ->method('saveStatus');
240 
241  $form = $this->getMockBuilder(ilTermsOfServiceSettingsFormGUI::class)
242  ->setConstructorArgs([
243  $tos,
244  '',
245  'save',
246  true
247  ])
248  ->setMethods(['checkInput', 'getInput'])
249  ->getMock();
250 
251  $form
252  ->expects($this->once())
253  ->method('checkInput')
254  ->willReturn(true);
255 
256  $form
257  ->expects($this->exactly(2))
258  ->method('getInput')
259  ->willReturn(1);
260 
261  $_POST = [
262  'tos_status' => 1
263  ];
264 
265  $form->setCheckInputCalled(true);
266 
267  $documentConnector = $this->getMockBuilder(arConnector::class)->getMock();#
268 
269  $documentConnector
270  ->expects($this->once())
271  ->method('affectedRows')
272  ->willReturn(0);
273 
274  arConnectorMap::register(new ilTermsOfServiceDocument(), $documentConnector);
275 
276  $this->assertTrue($form->saveObject());
277  $this->assertFalse($form->hasTranslatedError());
278  $this->assertEmpty($form->getTranslatedError());
279  }
280 }
setGlobalVariable(string $name, $value)
static register(ActiveRecord $ar, arConnector $connector)
Class ilTermsOfServiceSettingsFormGUITest.
Class ilTermsOfServiceBaseTest.
Class ilTermsOfServiceDocument.
$lng
$_POST["username"]
Class ilTermsOfServiceSettingsFormGUI.