131 : void
132 {
133 $document = $this
134 ->getMockBuilder(ilTermsOfServiceDocument::class)
135 ->disableOriginalConstructor()
136 ->onlyMethods(['fetchAllCriterionAssignments'])
137 ->addMethods(['getId'])
138 ->getMock();
139
140 $document
141 ->method('fetchAllCriterionAssignments');
142
143 $purifier = $this
144 ->getMockBuilder(ilHtmlPurifierInterface::class)
145 ->getMock();
146
148 'phpunit',
149 1024,
150 'text/xml',
151 $this->getMockBuilder(ImmutableStringMap::class)->getMock(),
153 '/tmp'
154 );
155
156 $user = $this
157 ->getMockBuilder(ilObjUser::class)
158 ->disableOriginalConstructor()
159 ->onlyMethods(['getId'])
160 ->getMock();
161
162 $user
163 ->expects($this->exactly(2))
164 ->method('getId')
165 ->willReturn(6);
166
167 $fs = $this
168 ->getMockBuilder(Filesystem::class)
169 ->getMock();
170
171 $fs
172 ->expects($this->exactly(2))
173 ->method('has')
174 ->with('/agreements/' . $uploadResult->getName())
175 ->willReturn(true);
176
177 $fs
178 ->expects($this->exactly(2))
179 ->method('read')
180 ->with('/agreements/' . $uploadResult->getName())
181 ->willReturn('phpunit');
182
183 $purifier
184 ->expects($this->atLeast(1))
185 ->method('purify')
186 ->with('phpunit')
187 ->willReturnArgument(0);
188
189 $fs
190 ->expects($this->exactly(2))
191 ->method('delete')
192 ->with('/agreements/' . $uploadResult->getName());
193
194 $fu = $this
195 ->getMockBuilder(FileUpload::class)
196 ->onlyMethods([
197 'moveFilesTo',
198 'uploadSizeLimit',
199 'register',
200 'hasBeenProcessed',
201 'hasUploads',
202 'process',
203 'getResults',
204 'moveOneFileTo'
205 ])
206 ->getMock();
207
208 $fu
209 ->method('hasUploads')
210 ->willReturn(true);
211
212 $fu
213 ->expects($this->exactly(2))
214 ->method('hasBeenProcessed')
215 ->willReturn(false);
216
217 $fu
218 ->expects($this->exactly(2))
219 ->method('process');
220
221 $fu
222 ->expects($this->exactly(2))
223 ->method('getResults')
224 ->willReturn([
225 0 => $uploadResult
226 ]);
227
228 $fu
229 ->expects($this->exactly(2))
230 ->method('moveOneFileTo')
231 ->with(
232 $uploadResult,
233 '/agreements',
234 Location::TEMPORARY,
235 $this->isEmpty(),
236 $this->isTrue()
237 );
238
240
241 $documentConnector = $this->getMockBuilder(arConnector::class)->getMock();
242 $criterionConnector = $this->getMockBuilder(arConnector::class)->getMock();
243
244 $expectedSortingValueExistingDocuments = 10;
245
246 $documentConnector
247 ->expects($this->once())
248 ->method('readSet')
249 ->willReturnCallback(function () use ($expectedSortingValueExistingDocuments) {
250 return [
251 [
252 'id' => 666,
253 'title' => 'another',
254 'sorting' => $expectedSortingValueExistingDocuments - 1,
255 ]
256 ];
257 });
258 $documentConnector->method('affectedRows')->willReturn(1);
259
260 $criterionConnector
261 ->expects($this->once())
262 ->method('readSet')
263 ->willReturn([]);
264
268
269 $form = $this->getMockBuilder(ilTermsOfServiceDocumentFormGUI::class)
270 ->setConstructorArgs([
271 $document,
272 $purifier,
273 $user,
274 $fs,
275 $fu,
276 'action',
277 'save',
278 'cancel',
279 true
280 ])
281 ->onlyMethods(['checkInput'])
282 ->getMock();
283
284 $form
285 ->expects($this->once())
286 ->method('checkInput')
287 ->willReturn(true);
288
289 $_FILES['document'] = [];
290
291 $form->setCheckInputCalled(true);
292
293 $this->assertTrue($form->saveObject());
294 $this->assertFalse($form->hasTranslatedError());
295 $this->assertEmpty($form->getTranslatedError());
296 $this->assertSame(
297 $expectedSortingValueExistingDocuments,
298 $document->getSorting(),
299 'Failed asserting that the sorting of the new document equals the maximum incremented by one when other documents exist'
300 );
301
302 $documentConnector = $this->getMockBuilder(arConnector::class)->getMock();
303
304 $documentConnector
305 ->expects($this->once())
306 ->method('readSet')
307 ->willReturnCallback(function () {
308 return [];
309 });
310
312
313 $form = $this->getMockBuilder(ilTermsOfServiceDocumentFormGUI::class)
314 ->setConstructorArgs([
315 $document,
316 $purifier,
317 $user,
318 $fs,
319 $fu,
320 'action',
321 'save',
322 'cancel',
323 true
324 ])
325 ->onlyMethods(['checkInput'])
326 ->getMock();
327
328 $form
329 ->expects($this->once())
330 ->method('checkInput')
331 ->willReturn(true);
332
333 $form->setCheckInputCalled(true);
334
335 $this->assertTrue($form->saveObject());
336 $this->assertFalse($form->hasTranslatedError());
337 $this->assertEmpty($form->getTranslatedError());
338 $this->assertSame(
339 1,
340 $document->getSorting(),
341 'Failed asserting that the sorting of the new document equals 1 when no other document exists'
342 );
343 }
Class ilTermsOfServiceDocumentCriterionAssignment.