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