Skip to content

Commit 4442248

Browse files
committed
adjust tests
Signed-off-by: Christian Hartmann <chris-hartmann@gmx.de>
1 parent 0f0e79a commit 4442248

5 files changed

Lines changed: 38 additions & 401 deletions

File tree

tests/Integration/Api/ApiV3Test.php

Lines changed: 3 additions & 102 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,7 @@ private function setTestForms() {
4341
'state' => 0,
4442
'is_anonymous' => false,
4543
'submit_multiple' => false,
46-
'allow_edit' => true,
44+
'allowEdit' => false,
4745
'show_expiration' => false,
4846
'last_updated' => 123456789,
4947
'submission_message' => 'Back to website',
@@ -167,7 +165,7 @@ private function setTestForms() {
167165
'state' => 0,
168166
'is_anonymous' => false,
169167
'submit_multiple' => false,
170-
'allow_edit' => true,
168+
'allowEdit' => false,
171169
'show_expiration' => false,
172170
'last_updated' => 123456789,
173171
'submission_message' => '',
@@ -205,7 +203,7 @@ private function setTestForms() {
205203
'state' => 0,
206204
'is_anonymous' => false,
207205
'submit_multiple' => false,
208-
'allow_edit' => true,
206+
'allowEdit' => false,
209207
'show_expiration' => false,
210208
'last_updated' => 123456789,
211209
'submission_message' => '',
@@ -257,16 +255,6 @@ public function setUp(): void {
257255
'Accept' => 'application/json'
258256
],
259257
]);
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-
]);
270258
}
271259

272260
public function tearDown(): void {
@@ -1364,93 +1352,6 @@ public function testNewSubmission() {
13641352
], $data['submissions'][0]);
13651353
}
13661354

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-
14541355
public function dataDeleteSingleSubmission() {
14551356
$submissionsExpected = $this->dataGetSubmissions()['getSubmissions']['expected'];
14561357
array_splice($submissionsExpected['submissions'], 0, 1);

tests/Integration/Api/RespectAdminSettingsTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ private function setTestForms() {
4242
'state' => 0,
4343
'is_anonymous' => false,
4444
'submit_multiple' => false,
45+
'allowEdit' => false,
4546
'show_expiration' => false,
4647
'last_updated' => 123456789,
4748
'submission_message' => '',
@@ -62,6 +63,7 @@ private function setTestForms() {
6263
'state' => 0,
6364
'is_anonymous' => false,
6465
'submit_multiple' => false,
66+
'allowEdit' => false,
6567
'show_expiration' => false,
6668
'last_updated' => 123456789,
6769
'submission_message' => '',
@@ -82,6 +84,7 @@ private function setTestForms() {
8284
'state' => 0,
8385
'is_anonymous' => false,
8486
'submit_multiple' => false,
87+
'allowEdit' => false,
8588
'show_expiration' => false,
8689
'last_updated' => 123456789,
8790
'submission_message' => '',
@@ -120,6 +123,7 @@ private static function sharedTestForms(): array {
120123
],
121124
'isAnonymous' => false,
122125
'submitMultiple' => false,
126+
'allowEdit' => false,
123127
'showExpiration' => false,
124128
'submissionMessage' => '',
125129
'permissions' => [
@@ -131,7 +135,6 @@ private static function sharedTestForms(): array {
131135
],
132136
'canSubmit' => true,
133137
'submissionCount' => 0,
134-
'allowEdit' => false,
135138
],
136139
];
137140
}

tests/Unit/Controller/ApiControllerTest.php

Lines changed: 8 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -394,13 +394,12 @@ 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,
402+
'allowEdit' => false
404403
]]
405404
];
406405
}
@@ -487,7 +486,6 @@ public function dataCloneForm() {
487486
'expires' => 0,
488487
'isAnonymous' => false,
489488
'submitMultiple' => false,
490-
'allowEdit' => false,
491489
'showExpiration' => false
492490
],
493491
'new' => [
@@ -503,7 +501,6 @@ public function dataCloneForm() {
503501
'expires' => 0,
504502
'isAnonymous' => false,
505503
'submitMultiple' => false,
506-
'allowEdit' => false,
507504
'showExpiration' => false
508505
]
509506
]
@@ -634,10 +631,7 @@ public function testUploadFiles() {
634631
$this->apiController->uploadFiles(1, 10, '');
635632
}
636633

637-
/**
638-
* Values for the mock objects for the following methods: testNewSubmission_answers, testUpdateSubmission_answers.
639-
*/
640-
public function dataForSubmission_answers() {
634+
public function testNewSubmission_answers() {
641635
$form = new Form();
642636
$form->setId(1);
643637
$form->setHash('hash');
@@ -685,16 +679,6 @@ public function dataForSubmission_answers() {
685679
5 => ['ignore unknown question'],
686680
];
687681

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-
698682
$this->formMapper->expects($this->once())
699683
->method('findById')
700684
->with(1)
@@ -842,61 +826,6 @@ public function testNewSubmission_validateSubmission() {
842826
$this->apiController->newSubmission(1, [], '');
843827
}
844828

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-
900829
public function testDeleteSubmissionNotFound() {
901830
$exception = $this->createMock(MapperException::class);
902831

@@ -975,6 +904,12 @@ public function testDeleteSubmission($submissionData, $formData) {
975904
->with($form)
976905
->willReturn(true);
977906

907+
$this->formsService
908+
->expects($this->once())
909+
->method('getPermissions')
910+
->with($form)
911+
->willReturn(Constants::PERMISSION_ALL);
912+
978913
$this->submissionMapper
979914
->expects($this->once())
980915
->method('deleteById')
@@ -1002,7 +937,6 @@ public function dataTestDeletePermission() {
1002937
'expires' => 0,
1003938
'isAnonymous' => false,
1004939
'submitMultiple' => false,
1005-
'allowEdit' => false,
1006940
'showExpiration' => false
1007941
],
1008942
]

tests/Unit/Controller/PageControllerTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use OCA\Forms\Controller\PageController;
1111
use OCA\Forms\Db\FormMapper;
1212
use OCA\Forms\Db\ShareMapper;
13+
use OCA\Forms\Db\SubmissionMapper;
1314
use OCA\Forms\Service\ConfigService;
1415
use OCA\Forms\Service\FormsService;
1516
use OCP\Accounts\IAccountManager;
@@ -39,6 +40,9 @@ class PageControllerTest extends TestCase {
3940
/** @var ShareMapper|MockObject */
4041
private $shareMapper;
4142

43+
/** @var SubmissionMapper|MockObject */
44+
private $submissionMapper;
45+
4246
/** @var ConfigService|MockObject */
4347
private $configService;
4448

@@ -69,6 +73,7 @@ public function setUp(): void {
6973
$this->request = $this->createMock(IRequest::class);
7074
$this->formMapper = $this->createMock(FormMapper::class);
7175
$this->shareMapper = $this->createMock(ShareMapper::class);
76+
$this->submissionMapper = $this->createMock(SubmissionMapper::class);
7277
$this->configService = $this->createMock(ConfigService::class);
7378
$this->formsService = $this->createMock(FormsService::class);
7479
$this->accountManager = $this->createMock(IAccountManager::class);
@@ -83,6 +88,7 @@ public function setUp(): void {
8388
$this->request,
8489
$this->formMapper,
8590
$this->shareMapper,
91+
$this->submissionMapper,
8692
$this->configService,
8793
$this->formsService,
8894
$this->accountManager,

0 commit comments

Comments
 (0)