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