ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilTermsOfServiceSettingsFormGUITest.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
9 {
13  public function testFormCanBeProperlyBuilt()
14  {
15  $tos = $this->getMockBuilder(\ilObjTermsOfService::class)->disableOriginalConstructor()->getMock();
16 
17  $tos
18  ->expects($this->any())
19  ->method('getStatus')
20  ->willReturn(true);
21 
22  $form = new \ilTermsOfServiceSettingsFormGUI(
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(0, $form->getCommandButtons(), 'Failed asserting save button ist given if form is editable');
31  $this->assertEquals('save', $form->getCommandButtons()[0]['cmd'], 'Failed asserting save button ist given if form is editable');
32 
33  $form = new \ilTermsOfServiceSettingsFormGUI(
34  $tos,
35  '',
36  'save',
37  false
38  );
39 
40  $this->assertCount(0, $form->getCommandButtons(), 'Failed asserting no button is given if form is not editable');
41  }
42 
47  {
48  $tos = $this->getMockBuilder(\ilObjTermsOfService::class)->disableOriginalConstructor()->getMock();
49 
50  $tos
51  ->expects($this->any())
52  ->method('getStatus')
53  ->willReturn(false);
54 
55  $tos
56  ->expects($this->once())
57  ->method('saveStatus')
58  ->with(false);
59 
60  $form = $this->getMockBuilder(\ilTermsOfServiceSettingsFormGUI::class)
61  ->setConstructorArgs([
62  $tos,
63  '', 'save', true
64  ])
65  ->setMethods(['checkInput', 'getInput'])
66  ->getMock();
67 
68  $form
69  ->expects($this->once())
70  ->method('checkInput')
71  ->willReturn(true);
72 
73  $form
74  ->expects($this->exactly(2))
75  ->method('getInput')
76  ->willReturn(0);
77 
78  $_POST = [
79  'tos_status' => 1
80  ];
81 
82  $form->setCheckInputCalled(true);
83 
84  $this->assertTrue($form->saveObject());
85  $this->assertFalse($form->hasTranslatedError());
86  $this->assertEmpty($form->getTranslatedError());
87  }
88 
93  {
94  $tos = $this->getMockBuilder(\ilObjTermsOfService::class)->disableOriginalConstructor()->getMock();
95 
96  $tos
97  ->expects($this->any())
98  ->method('getStatus')
99  ->willReturn(false);
100 
101  $tos
102  ->expects($this->once())
103  ->method('saveStatus')
104  ->with(true);
105 
106  $form = $this->getMockBuilder(\ilTermsOfServiceSettingsFormGUI::class)
107  ->setConstructorArgs([
108  $tos,
109  '', 'save', true
110  ])
111  ->setMethods(['checkInput', 'getInput'])
112  ->getMock();
113 
114  $form
115  ->expects($this->once())
116  ->method('checkInput')
117  ->willReturn(true);
118 
119  $form
120  ->expects($this->exactly(2))
121  ->method('getInput')
122  ->willReturn(1);
123 
124  $_POST = [
125  'tos_status' => 1
126  ];
127 
128  $form->setCheckInputCalled(true);
129 
130  $documentConnector = $this->getMockBuilder(\arConnector::class)->getMock();#
131 
132  $documentConnector
133  ->expects($this->once())
134  ->method('affectedRows')
135  ->willReturn(2);
136 
137  \arConnectorMap::register(new \ilTermsOfServiceDocument(), $documentConnector);
138 
139  $this->assertTrue($form->saveObject());
140  $this->assertFalse($form->hasTranslatedError());
141  $this->assertEmpty($form->getTranslatedError());
142  }
143 
148  {
149  $lng = $this->getLanguageMock();
150 
151  $lng
152  ->expects($this->any())
153  ->method('txt')
154  ->willReturn('translation');
155 
156  $this->setGlobalVariable('lng', $lng);
157 
158  $tos = $this->getMockBuilder(\ilObjTermsOfService::class)->disableOriginalConstructor()->getMock();
159 
160  $tos
161  ->expects($this->any())
162  ->method('getStatus')
163  ->willReturn(false);
164 
165  $tos
166  ->expects($this->never())
167  ->method('saveStatus');
168 
169  $form = $this->getMockBuilder(\ilTermsOfServiceSettingsFormGUI::class)
170  ->setConstructorArgs([
171  $tos,
172  '', 'save', true
173  ])
174  ->setMethods(['checkInput', 'getInput'])
175  ->getMock();
176 
177  $form
178  ->expects($this->once())
179  ->method('checkInput')
180  ->willReturn(true);
181 
182  $form
183  ->expects($this->once())
184  ->method('getInput')
185  ->willReturn(1);
186 
187  $_POST = [
188  'tos_status' => 1
189  ];
190 
191  $form->setCheckInputCalled(true);
192 
193  $documentConnector = $this->getMockBuilder(\arConnector::class)->getMock();#
194 
195  $documentConnector
196  ->expects($this->once())
197  ->method('affectedRows')
198  ->willReturn(0);
199 
200  \arConnectorMap::register(new \ilTermsOfServiceDocument(), $documentConnector);
201 
202  $this->assertFalse($form->saveObject());
203  $this->assertTrue($form->hasTranslatedError());
204  $this->assertNotEmpty($form->getTranslatedError());
205  }
206 
211  {
212  $tos = $this->getMockBuilder(\ilObjTermsOfService::class)->disableOriginalConstructor()->getMock();
213 
214  $tos
215  ->expects($this->any())
216  ->method('getStatus')
217  ->willReturn(true);
218 
219  $tos
220  ->expects($this->once())
221  ->method('saveStatus');
222 
223  $form = $this->getMockBuilder(\ilTermsOfServiceSettingsFormGUI::class)
224  ->setConstructorArgs([
225  $tos,
226  '', 'save', true
227  ])
228  ->setMethods(['checkInput', 'getInput'])
229  ->getMock();
230 
231  $form
232  ->expects($this->once())
233  ->method('checkInput')
234  ->willReturn(true);
235 
236  $form
237  ->expects($this->exactly(2))
238  ->method('getInput')
239  ->willReturn(1);
240 
241  $_POST = [
242  'tos_status' => 1
243  ];
244 
245  $form->setCheckInputCalled(true);
246 
247  $documentConnector = $this->getMockBuilder(\arConnector::class)->getMock();#
248 
249  $documentConnector
250  ->expects($this->once())
251  ->method('affectedRows')
252  ->willReturn(0);
253 
254  \arConnectorMap::register(new \ilTermsOfServiceDocument(), $documentConnector);
255 
256  $this->assertTrue($form->saveObject());
257  $this->assertFalse($form->hasTranslatedError());
258  $this->assertEmpty($form->getTranslatedError());
259  }
260 }
setGlobalVariable(string $name, $value)
static register(ActiveRecord $ar, arConnector $connector)
Class ilTermsOfServiceSettingsFormGUITest.
Class ilTermsOfServiceBaseTest.
if(isset($_POST['submit'])) $form
Class ilTermsOfServiceDocument.
$lng
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
$_POST["username"]