86 {
87 $document = $this
88 ->getMockBuilder(\ilTermsOfServiceDocument::class)
89 ->disableOriginalConstructor()
90 ->setMethods(['getId', 'fetchAllCriterionAssignments'])
91 ->getMock();
92
93 $document
94 ->expects($this->any())
95 ->method('fetchAllCriterionAssignments');
96
97 $purifier = $this
98 ->getMockBuilder(\ilHtmlPurifierInterface::class)
99 ->getMock();
100
102 'phpunit',
103 1024,
104 'text/xml',
105 $this->getMockBuilder(ImmutableStringMap::class)->getMock(),
107 '/tmp'
108 );
109
111 ->getMockBuilder(\ilObjUser::class)
112 ->disableOriginalConstructor()
113 ->setMethods(['getId'])
114 ->getMock();
115
117 ->expects($this->exactly(2))
118 ->method('getId')
119 ->willReturn(6);
120
121 $fs = $this
122 ->getMockBuilder(Filesystem::class)
123 ->getMock();
124
125 $fs
126 ->expects($this->exactly(2))
127 ->method('has')
128 ->with('/agreements/' . $uploadResult->getName())
129 ->willReturn(true);
130
131 $fs
132 ->expects($this->exactly(2))
133 ->method('read')
134 ->with('/agreements/' . $uploadResult->getName())
135 ->willReturn('phpunit');
136
137 $purifier
138 ->expects($this->atLeast(1))
139 ->method('purify')
140 ->with('phpunit')
141 ->willReturnArgument(0);
142
143 $fs
144 ->expects($this->exactly(2))
145 ->method('delete')
146 ->with('/agreements/' . $uploadResult->getName());
147
148 $fu = $this
149 ->getMockBuilder(FileUpload::class)
150 ->setMethods(['moveFilesTo', 'uploadSizeLimit', 'register', 'hasBeenProcessed', 'hasUploads', 'process', 'getResults', 'moveOneFileTo'])
151 ->getMock();
152
153 $fu
154 ->expects($this->any())
155 ->method('hasUploads')
156 ->willReturn(true);
157
158 $fu
159 ->expects($this->exactly(2))
160 ->method('hasBeenProcessed')
161 ->willReturn(false);
162
163 $fu
164 ->expects($this->exactly(2))
165 ->method('process');
166
167 $fu
168 ->expects($this->exactly(2))
169 ->method('getResults')
170 ->willReturn([
171 0 => $uploadResult
172 ]);
173
174 $fu
175 ->expects($this->exactly(2))
176 ->method('moveOneFileTo')
177 ->with(
178 $uploadResult,
179 '/agreements',
180 Location::TEMPORARY,
181 $this->isEmpty(),
182 $this->isTrue()
183 );
184
186
187 $documentConnector = $this->getMockBuilder(\arConnector::class)->getMock();
188 $criterionConnector = $this->getMockBuilder(\arConnector::class)->getMock();
189
190 $expectedSortingValueExistingDocuments = 10;
191
192 $documentConnector
193 ->expects($this->
once())
194 ->method('readSet')
195 ->willReturnCallback(function () use ($expectedSortingValueExistingDocuments) {
196 return [[
197 'id' => 666,
198 'title' => 'another',
199 'sorting' => $expectedSortingValueExistingDocuments - 1,
200 ]];
201 });
202
203 $criterionConnector
204 ->expects($this->
once())
205 ->method('readSet')
206 ->willReturn([]);
207
211
212 $form = $this->getMockBuilder(\ilTermsOfServiceDocumentFormGUI::class)
213 ->setConstructorArgs([
214 $document, $purifier,
$user, $fs, $fu,
215 'action', 'save', 'cancel',
216 true
217 ])
218 ->setMethods(['checkInput'])
219 ->getMock();
220
222 ->expects($this->
once())
223 ->method('checkInput')
224 ->willReturn(true);
225
226 $_FILES['document'] = [];
228 'title' => 'phpunit',
229 'document' => '',
230 '' => ''
231 ];
232 $form->setCheckInputCalled(
true);
233
234 $this->assertTrue(
$form->saveObject());
235 $this->assertFalse(
$form->hasTranslatedError());
236 $this->assertEmpty(
$form->getTranslatedError());
237 $this->assertEquals(
238 $expectedSortingValueExistingDocuments,
239 $document->getSorting(),
240 'Failed asserting that the sorting of the new document equals the maximum incremented by one when other documents exist'
241 );
242
243 $documentConnector = $this->getMockBuilder(\arConnector::class)->getMock();
244
245 $documentConnector
246 ->expects($this->
once())
247 ->method('readSet')
248 ->willReturnCallback(function () {
249 return [];
250 });
251
253
254 $form = $this->getMockBuilder(\ilTermsOfServiceDocumentFormGUI::class)
255 ->setConstructorArgs([
256 $document, $purifier,
$user, $fs, $fu,
257 'action', 'save', 'cancel',
258 true
259 ])
260 ->setMethods(['checkInput'])
261 ->getMock();
262
264 ->expects($this->
once())
265 ->method('checkInput')
266 ->willReturn(true);
267
268 $form->setCheckInputCalled(
true);
269
270 $this->assertTrue(
$form->saveObject());
271 $this->assertFalse(
$form->hasTranslatedError());
272 $this->assertEmpty(
$form->getTranslatedError());
273 $this->assertEquals(
274 1,
275 $document->getSorting(),
276 'Failed asserting that the sorting of the new document equals 1 when no other document exists'
277 );
278 }
Class ilTermsOfServiceDocumentCriterionAssignment.