Skip to content

Commit d2dda2b

Browse files
committed
adjust tests
Signed-off-by: Christian Hartmann <chris-hartmann@gmx.de>
1 parent 88d94e3 commit d2dda2b

4 files changed

Lines changed: 18 additions & 405 deletions

File tree

tests/Integration/Api/ApiV3Test.php

Lines changed: 0 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
class ApiV3Test extends IntegrationBase {
2020
/** @var GuzzleHttp\Client */
2121
private $http;
22-
/** @var GuzzleHttp\Client */
23-
private $httpUser1;
2422

2523
protected array $users = [
2624
'test' => 'Test user',
@@ -43,7 +41,6 @@ private function setTestForms() {
4341
'state' => 0,
4442
'is_anonymous' => false,
4543
'submit_multiple' => false,
46-
'allow_edit' => true,
4744
'show_expiration' => false,
4845
'last_updated' => 123456789,
4946
'submission_message' => 'Back to website',
@@ -167,7 +164,6 @@ private function setTestForms() {
167164
'state' => 0,
168165
'is_anonymous' => false,
169166
'submit_multiple' => false,
170-
'allow_edit' => true,
171167
'show_expiration' => false,
172168
'last_updated' => 123456789,
173169
'submission_message' => '',
@@ -205,7 +201,6 @@ private function setTestForms() {
205201
'state' => 0,
206202
'is_anonymous' => false,
207203
'submit_multiple' => false,
208-
'allow_edit' => true,
209204
'show_expiration' => false,
210205
'last_updated' => 123456789,
211206
'submission_message' => '',
@@ -257,16 +252,6 @@ public function setUp(): void {
257252
'Accept' => 'application/json'
258253
],
259254
]);
260-
261-
// Set up http Client for user user1
262-
$this->httpUser1 = new Client([
263-
'base_uri' => 'http://localhost:8080/ocs/v2.php/apps/forms/',
264-
'auth' => ['user1', 'user1'],
265-
'headers' => [
266-
'OCS-ApiRequest' => 'true',
267-
'Accept' => 'application/json'
268-
],
269-
]);
270255
}
271256

272257
public function tearDown(): void {
@@ -381,7 +366,6 @@ public function dataGetNewForm() {
381366
'state' => 0,
382367
'isAnonymous' => false,
383368
'submitMultiple' => false,
384-
'allowEdit' => false,
385369
'showExpiration' => false,
386370
// 'lastUpdated' => time() can not be checked exactly
387371
'canSubmit' => true,
@@ -441,7 +425,6 @@ public function dataGetFullForm() {
441425
'state' => 0,
442426
'isAnonymous' => false,
443427
'submitMultiple' => false,
444-
'allowEdit' => false,
445428
'showExpiration' => false,
446429
'lastUpdated' => 123456789,
447430
'canSubmit' => true,
@@ -1364,93 +1347,6 @@ public function testNewSubmission() {
13641347
], $data['submissions'][0]);
13651348
}
13661349

1367-
/**
1368-
* @dataProvider dataNewSubmission
1369-
*/
1370-
public function testUpdateSubmission() {
1371-
1372-
$resp = $this->http->request('PATCH', "api/v3/forms/{$this->testForms[0]['id']}", [
1373-
'json' => [
1374-
'keyValuePairs' => [
1375-
'AllowEdit' => true,
1376-
]
1377-
]
1378-
]);
1379-
1380-
$uploadedFileResponse = $this->httpUser1->request('POST',
1381-
"api/v3/forms/{$this->testForms[0]['id']}/submissions/files/{$this->testForms[0]['questions'][2]['id']}",
1382-
[
1383-
'multipart' => [
1384-
[
1385-
'name' => 'files[]',
1386-
'contents' => 'hello world2',
1387-
'filename' => 'test2.txt'
1388-
]
1389-
]
1390-
]);
1391-
1392-
$data = $this->OcsResponse2Data($uploadedFileResponse);
1393-
$uploadedFileId = $data[0]['uploadedFileId'];
1394-
1395-
$resp = $this->httpUser1->request('PUT', "api/v3/forms/{$this->testForms[0]['id']}/submissions/{$this->testForms[0]['submissions'][0]['id']}", [
1396-
'json' => [
1397-
'answers' => [
1398-
$this->testForms[0]['questions'][0]['id'] => ['ShortAnswer2!'],
1399-
$this->testForms[0]['questions'][1]['id'] => [
1400-
$this->testForms[0]['questions'][1]['options'][1]['id']
1401-
],
1402-
$this->testForms[0]['questions'][2]['id'] => [['uploadedFileId' => $uploadedFileId]]
1403-
]
1404-
]
1405-
]);
1406-
$data = $this->OcsResponse2Data($resp);
1407-
1408-
$this->assertEquals(200, $resp->getStatusCode());
1409-
1410-
// Check stored submissions
1411-
$resp = $this->http->request('GET', "api/v3/forms/{$this->testForms[0]['id']}/submissions");
1412-
$data = $this->OcsResponse2Data($resp);
1413-
1414-
// Check Ids
1415-
foreach ($data['submissions'][0]['answers'] as $aIndex => $answer) {
1416-
$this->assertEquals($data['submissions'][0]['id'], $answer['submissionId']);
1417-
unset($data['submissions'][0]['answers'][$aIndex]['id']);
1418-
unset($data['submissions'][0]['answers'][$aIndex]['submissionId']);
1419-
1420-
if (isset($answer['fileId'])) {
1421-
$this->assertIsNumeric($answer['fileId'], 'fileId should be numeric.');
1422-
$this->assertGreaterThan(0, $answer['fileId'], 'fileId should be greater than 0.');
1423-
unset($data['submissions'][0]['answers'][$aIndex]['fileId']);
1424-
}
1425-
}
1426-
unset($data['submissions'][0]['id']);
1427-
// Check general behaviour of timestamp (Insert in the last 10 seconds)
1428-
$this->assertTrue(time() - $data['submissions'][0]['timestamp'] < 10);
1429-
unset($data['submissions'][0]['timestamp']);
1430-
1431-
$this->assertEquals([
1432-
'userId' => 'user1',
1433-
'userDisplayName' => 'User No. 1',
1434-
'formId' => $this->testForms[0]['id'],
1435-
'answers' => [
1436-
[
1437-
'questionId' => $this->testForms[0]['questions'][0]['id'],
1438-
'text' => 'ShortAnswer2!',
1439-
'fileId' => null,
1440-
],
1441-
[
1442-
'questionId' => $this->testForms[0]['questions'][1]['id'],
1443-
'text' => 'Option 2',
1444-
'fileId' => null,
1445-
],
1446-
[
1447-
'questionId' => $this->testForms[0]['questions'][2]['id'],
1448-
'text' => 'test2.txt',
1449-
],
1450-
]
1451-
], $data['submissions'][0]);
1452-
}
1453-
14541350
public function dataDeleteSingleSubmission() {
14551351
$submissionsExpected = $this->dataGetSubmissions()['getSubmissions']['expected'];
14561352
array_splice($submissionsExpected['submissions'], 0, 1);

tests/Integration/Api/RespectAdminSettingsTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ private static function sharedTestForms(): array {
131131
],
132132
'canSubmit' => true,
133133
'submissionCount' => 0,
134-
'allowEdit' => false,
135134
],
136135
];
137136
}

tests/Unit/Controller/ApiControllerTest.php

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -394,13 +394,11 @@ public function dataTestCreateNewForm() {
394394
'expires' => 0,
395395
'isAnonymous' => false,
396396
'submitMultiple' => false,
397-
'allowEdit' => false,
398397
'showExpiration' => false,
399398
'lastUpdated' => 123456789,
400399
'submissionMessage' => null,
401400
'fileId' => null,
402401
'fileFormat' => null,
403-
'allowEdit' => null,
404402
]]
405403
];
406404
}
@@ -487,7 +485,6 @@ public function dataCloneForm() {
487485
'expires' => 0,
488486
'isAnonymous' => false,
489487
'submitMultiple' => false,
490-
'allowEdit' => false,
491488
'showExpiration' => false
492489
],
493490
'new' => [
@@ -503,7 +500,6 @@ public function dataCloneForm() {
503500
'expires' => 0,
504501
'isAnonymous' => false,
505502
'submitMultiple' => false,
506-
'allowEdit' => false,
507503
'showExpiration' => false
508504
]
509505
]
@@ -634,10 +630,7 @@ public function testUploadFiles() {
634630
$this->apiController->uploadFiles(1, 10, '');
635631
}
636632

637-
/**
638-
* Values for the mock objects for the following methods: testNewSubmission_answers, testUpdateSubmission_answers.
639-
*/
640-
public function dataForSubmission_answers() {
633+
public function testNewSubmission_answers() {
641634
$form = new Form();
642635
$form->setId(1);
643636
$form->setHash('hash');
@@ -685,16 +678,6 @@ public function dataForSubmission_answers() {
685678
5 => ['ignore unknown question'],
686679
];
687680

688-
return [
689-
'test' => [$form, $questions, $answers],
690-
];
691-
}
692-
693-
/**
694-
* @dataProvider dataForSubmission_answers()
695-
*/
696-
public function testNewSubmission_answers($form, $questions, $answers) {
697-
698681
$this->formMapper->expects($this->once())
699682
->method('findById')
700683
->with(1)
@@ -842,61 +825,6 @@ public function testNewSubmission_validateSubmission() {
842825
$this->apiController->newSubmission(1, [], '');
843826
}
844827

845-
/**
846-
* @dataProvider dataForSubmission_answers()
847-
*/
848-
public function testUpdateSubmission_answers($form, $questions, $answers) {
849-
850-
$form->setAllowEdit(true);
851-
$submission = new Submission();
852-
$submission->setId(12);
853-
854-
$this->formMapper->expects($this->once())
855-
->method('findById')
856-
->with(1)
857-
->willReturn($form);
858-
859-
$this->formsService->expects($this->once())
860-
->method('getQuestions')
861-
->with(1)
862-
->willReturn($questions);
863-
864-
$this->formAccess();
865-
866-
$this->submissionService
867-
->method('validateSubmission')
868-
->willReturn(true);
869-
870-
$this->submissionMapper->expects($this->once())
871-
->method('findByFormAndUser')
872-
->with(1, 'currentUser')
873-
->willReturn($submission);
874-
875-
$userFolder = $this->createMock(Folder::class);
876-
$userFolder->expects($this->once())
877-
->method('nodeExists')
878-
->willReturn(true);
879-
880-
$file = $this->createMock(File::class);
881-
882-
$userFolder->expects($this->once())
883-
->method('getById')
884-
->willReturn([$file]);
885-
886-
$folder = $this->createMock(Folder::class);
887-
888-
$userFolder->expects($this->once())
889-
->method('get')
890-
->willReturn($folder);
891-
892-
$this->storage->expects($this->once())
893-
->method('getUserFolder')
894-
->with('admin')
895-
->willReturn($userFolder);
896-
897-
$this->apiController->updateSubmission(1, 12, $answers, '');
898-
}
899-
900828
public function testDeleteSubmissionNotFound() {
901829
$exception = $this->createMock(MapperException::class);
902830

@@ -1002,7 +930,6 @@ public function dataTestDeletePermission() {
1002930
'expires' => 0,
1003931
'isAnonymous' => false,
1004932
'submitMultiple' => false,
1005-
'allowEdit' => false,
1006933
'showExpiration' => false
1007934
],
1008935
]

0 commit comments

Comments
 (0)