Skip to content

Commit 3d88bc6

Browse files
committed
test: update form tests to include lockedBy and lockedUntil fields
Signed-off-by: Christian Hartmann <chris-hartmann@gmx.de>
1 parent 972f86b commit 3d88bc6

5 files changed

Lines changed: 67 additions & 8 deletions

File tree

tests/Integration/Api/ApiV3Test.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ private function setTestForms() {
3939
'created' => 12345,
4040
'expires' => 0,
4141
'state' => 0,
42+
'lockedBy' => null,
43+
'lockedUntil' => null,
4244
'is_anonymous' => false,
4345
'submit_multiple' => false,
4446
'allowEditSubmissions' => false,
@@ -163,6 +165,8 @@ private function setTestForms() {
163165
'created' => 12345,
164166
'expires' => 0,
165167
'state' => 0,
168+
'lockedBy' => null,
169+
'lockedUntil' => null,
166170
'is_anonymous' => false,
167171
'submit_multiple' => false,
168172
'allowEditSubmissions' => false,
@@ -201,6 +205,8 @@ private function setTestForms() {
201205
'created' => 12345,
202206
'expires' => 0,
203207
'state' => 0,
208+
'lockedBy' => null,
209+
'lockedUntil' => null,
204210
'is_anonymous' => false,
205211
'submit_multiple' => false,
206212
'allowEditSubmissions' => false,
@@ -288,6 +294,8 @@ public function dataGetForms() {
288294
'permissions' => Constants::PERMISSION_ALL,
289295
'partial' => true,
290296
'submissionCount' => 3,
297+
'lockedBy' => null,
298+
'lockedUntil' => null,
291299
],
292300
[
293301
'hash' => 'zyxwvutsrq654321',
@@ -298,6 +306,8 @@ public function dataGetForms() {
298306
'permissions' => Constants::PERMISSION_ALL,
299307
'partial' => true,
300308
'submissionCount' => 0,
309+
'lockedBy' => null,
310+
'lockedUntil' => null,
301311
]
302312
]
303313
]
@@ -331,7 +341,9 @@ public function dataGetSharedForms() {
331341
'permissions' => [
332342
'submit'
333343
],
334-
'partial' => true
344+
'partial' => true,
345+
'lockedBy' => null,
346+
'lockedUntil' => null,
335347
],
336348
]
337349
]
@@ -367,6 +379,8 @@ public function dataGetNewForm() {
367379
],
368380
'expires' => 0,
369381
'state' => 0,
382+
'lockedBy' => null,
383+
'lockedUntil' => null,
370384
'isAnonymous' => false,
371385
'submitMultiple' => false,
372386
'allowEditSubmissions' => false,
@@ -427,6 +441,8 @@ public function dataGetFullForm() {
427441
],
428442
'expires' => 0,
429443
'state' => 0,
444+
'lockedBy' => null,
445+
'lockedUntil' => null,
430446
'isAnonymous' => false,
431447
'submitMultiple' => false,
432448
'allowEditSubmissions' => false,
@@ -651,6 +667,8 @@ public function testUpdateFormProperties(array $expected): void {
651667
$this->assertEquals($this->testForms[0]['id'], $data);
652668

653669
$expected['lastUpdated'] = time();
670+
$expected['lockedBy'] = 'test';
671+
$expected['lockedUntil'] = time() + 900;
654672

655673
// Check if form equals updated form.
656674
$this->testGetFullForm($expected);
@@ -763,6 +781,8 @@ public function testUpdateQuestionProperties(array $fullFormExpected): void {
763781
$this->assertEquals($this->testForms[0]['questions'][0]['id'], $data);
764782

765783
$fullFormExpected['lastUpdated'] = time();
784+
$fullFormExpected['lockedBy'] = 'test';
785+
$fullFormExpected['lockedUntil'] = time() + 900;
766786

767787
// Check if form equals updated form.
768788
$this->testGetFullForm($fullFormExpected);
@@ -809,6 +829,8 @@ public function testReorderQuestions(array $fullFormExpected): void {
809829
], $data);
810830

811831
$fullFormExpected['lastUpdated'] = time();
832+
$fullFormExpected['lockedBy'] = 'test';
833+
$fullFormExpected['lockedUntil'] = time() + 900;
812834

813835
// Check if form equals updated form.
814836
$this->testGetFullForm($fullFormExpected);
@@ -839,6 +861,8 @@ public function testDeleteQuestion(array $fullFormExpected) {
839861
$this->assertEquals($this->testForms[0]['questions'][0]['id'], $data);
840862

841863
$fullFormExpected['lastUpdated'] = time();
864+
$fullFormExpected['lockedBy'] = 'test';
865+
$fullFormExpected['lockedUntil'] = time() + 900;
842866

843867
$this->testGetFullForm($fullFormExpected);
844868
}
@@ -924,6 +948,8 @@ public function testUpdateOptionProperties(array $fullFormExpected): void {
924948
$this->assertEquals($this->testForms[0]['questions'][1]['options'][0]['id'], $data);
925949

926950
$fullFormExpected['lastUpdated'] = time();
951+
$fullFormExpected['lockedBy'] = 'test';
952+
$fullFormExpected['lockedUntil'] = time() + 900;
927953

928954
// Check if form equals updated form.
929955
$this->testGetFullForm($fullFormExpected);
@@ -952,6 +978,8 @@ public function testDeleteOption(array $fullFormExpected) {
952978
$this->assertEquals($this->testForms[0]['questions'][1]['options'][0]['id'], $data);
953979

954980
$fullFormExpected['lastUpdated'] = time();
981+
$fullFormExpected['lockedBy'] = 'test';
982+
$fullFormExpected['lockedUntil'] = time() + 900;
955983
$fullFormExpected['questions'][1]['options'][0]['order'] = 1;
956984
$fullFormExpected['questions'][1]['options'][1]['order'] = 2;
957985

tests/Integration/Api/RespectAdminSettingsTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ private function setTestForms() {
4040
'created' => 12345,
4141
'expires' => 0,
4242
'state' => 0,
43+
'lockedBy' => null,
44+
'lockedUntil' => null,
4345
'is_anonymous' => false,
4446
'submit_multiple' => false,
4547
'allowEditSubmissions' => false,
@@ -61,6 +63,8 @@ private function setTestForms() {
6163
'created' => 12345,
6264
'expires' => 0,
6365
'state' => 0,
66+
'lockedBy' => null,
67+
'lockedUntil' => null,
6468
'is_anonymous' => false,
6569
'submit_multiple' => false,
6670
'allowEditSubmissions' => false,
@@ -82,6 +86,8 @@ private function setTestForms() {
8286
'created' => 12345,
8387
'expires' => 0,
8488
'state' => 0,
89+
'lockedBy' => null,
90+
'lockedUntil' => null,
8591
'is_anonymous' => false,
8692
'submit_multiple' => false,
8793
'allowEditSubmissions' => false,
@@ -112,6 +118,8 @@ private static function sharedTestForms(): array {
112118
'created' => 12345,
113119
'expires' => 0,
114120
'state' => 0,
121+
'lockedBy' => null,
122+
'lockedUntil' => null,
115123
'questions' => [],
116124
'shares' => [],
117125
'ownerId' => 'test',
@@ -196,9 +204,11 @@ public function testAllowUpdate(): void {
196204
// we do not know the ID and the update time is flaky
197205
unset($data['id']);
198206
unset($data['lastUpdated']);
207+
$data['lockedUntil'] = null;
199208

200209
$expected = self::sharedTestForms()[0];
201210
$expected['access'] = ['permitAllUsers' => true, 'showToAllUsers' => true];
211+
$expected['lockedBy'] = 'test';
202212

203213
$this->assertEquals(200, $resp->getStatusCode());
204214
$this->assertEquals($expected, $data);
@@ -235,6 +245,7 @@ public function testForbidUpdate(array $accessValue, array $adminConfigKeys): vo
235245
// we do not know the ID or the update
236246
unset($data['id']);
237247
unset($data['lastUpdated']);
248+
$data['lockedUntil'] = null;
238249

239250
$this->assertEquals(200, $resp->getStatusCode());
240251
$this->assertEquals(self::sharedTestForms()[0], $data);

tests/Unit/Controller/ApiControllerTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,9 @@ public function dataTestCreateNewForm() {
407407
'submissionMessage' => null,
408408
'fileId' => null,
409409
'fileFormat' => null,
410-
'allowEditSubmissions' => false
410+
'allowEditSubmissions' => false,
411+
'lockedBy' => null,
412+
'lockedUntil' => null,
411413
]]
412414
];
413415
}
@@ -977,6 +979,11 @@ public function testTransferNewOwnerNotFound() {
977979
->with(1)
978980
->willReturn($form);
979981

982+
$this->formsService
983+
->method('canEditForm')
984+
->with($form)
985+
->willReturn(true);
986+
980987
$this->userManager->expects($this->once())
981988
->method('get')
982989
->with('newOwner')
@@ -997,6 +1004,11 @@ public function testTransferOwner() {
9971004
->with(1)
9981005
->willReturn($form);
9991006

1007+
$this->formsService
1008+
->method('canEditForm')
1009+
->with($form)
1010+
->willReturn(true);
1011+
10001012
$newOwner = $this->createMock(IUser::class);
10011013
$this->userManager->expects($this->once())
10021014
->method('get')

tests/Unit/FormsMigratorTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@
99

1010
use OCA\Forms\Db\AnswerMapper;
1111

12-
// use OCA\Forms\Db\Answer;
1312
use OCA\Forms\Db\Form;
1413
use OCA\Forms\Db\FormMapper;
1514
use OCA\Forms\Db\OptionMapper;
16-
// use OCA\Forms\Db\Option;
1715
use OCA\Forms\Db\QuestionMapper;
18-
// use OCA\Forms\Db\Question;
1916
use OCA\Forms\Db\SubmissionMapper;
20-
// use OCA\Forms\Db\Submission;
2117
use OCA\Forms\FormsMigrator;
2218
use OCA\Forms\Service\FormsService;
2319
use OCA\Forms\Service\SubmissionService;
@@ -106,6 +102,8 @@ public function dataExport() {
106102
},
107103
"expires": 0,
108104
"state": 0,
105+
"lockedBy": null,
106+
"lockedUntil": null,
109107
"isAnonymous": false,
110108
"submitMultiple": false,
111109
"allowEditSubmissions": false,
@@ -168,6 +166,8 @@ public function testExport(string $expectedJson) {
168166
$form = new Form();
169167
$form->setId(42);
170168
$form->setState(0);
169+
$form->setLockedBy(null);
170+
$form->setLockedBy(null);
171171
$form->setHash('abcdefg');
172172
$form->setTitle('Link');
173173
$form->setDescription('');
@@ -253,7 +253,7 @@ public function testExport(string $expectedJson) {
253253
public function dataImport() {
254254
return [
255255
'exactlyOneOfEach' => [
256-
'$inputJson' => '[{"title":"Link","description":"","created":1646251830,"access":{"permitAllUsers":false,"showToAllUsers":false},"expires":0,"state":0,"isAnonymous":false,"submitMultiple":false,"allowEditSubmissions":false,"showExpiration":false,"lastUpdated":123456789,"questions":[{"id":14,"order":2,"type":"multiple","isRequired":false,"text":"checkbox","description":"huhu","extraSettings":{},"options":[{"text":"ans1"}]}],"submissions":[{"userId":"anyUser@localhost","timestamp":1651354059,"answers":[{"questionId":14,"text":"ans1"}]}]}]'
256+
'$inputJson' => '[{"title":"Link","description":"","created":1646251830,"access":{"permitAllUsers":false,"showToAllUsers":false},"expires":0,"state":0,"lockedBy":null,"lockedUntil":null,"isAnonymous":false,"submitMultiple":false,"allowEditSubmissions":false,"showExpiration":false,"lastUpdated":123456789,"questions":[{"id":14,"order":2,"type":"multiple","isRequired":false,"text":"checkbox","description":"huhu","extraSettings":{},"options":[{"text":"ans1"}]}],"submissions":[{"userId":"anyUser@localhost","timestamp":1651354059,"answers":[{"questionId":14,"text":"ans1"}]}]}]'
257257
]
258258
];
259259
}

tests/Unit/Service/FormsServiceTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,9 @@ public function dataGetForm() {
244244
'fileId' => null,
245245
'fileFormat' => null,
246246
'permissions' => Constants::PERMISSION_ALL,
247-
'allowEditSubmissions' => false
247+
'allowEditSubmissions' => false,
248+
'lockedBy' => null,
249+
'lockedUntil' => null,
248250
]]
249251
];
250252
}
@@ -358,6 +360,8 @@ public function dataGetPartialForm() {
358360
'permissions' => Constants::PERMISSION_ALL,
359361
'submissionCount' => 123,
360362
'partial' => true,
363+
'lockedBy' => null,
364+
'lockedUntil' => null,
361365
]]
362366
];
363367
}
@@ -397,6 +401,8 @@ public function dataGetPartialFormShared() {
397401
'submissionCount' => 123,
398402
'state' => 0,
399403
'partial' => true,
404+
'lockedBy' => null,
405+
'lockedUntil' => null,
400406
]]
401407
];
402408
}
@@ -458,6 +464,8 @@ public function dataGetPublicForm() {
458464
],
459465
'submissionMessage' => null,
460466
'allowEditSubmissions' => false,
467+
'lockedBy' => null,
468+
'lockedUntil' => null,
461469
]]
462470
];
463471
}

0 commit comments

Comments
 (0)