Skip to content

Commit 0524520

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

5 files changed

Lines changed: 25 additions & 404 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: 2 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

@@ -1002,7 +931,6 @@ public function dataTestDeletePermission() {
1002931
'expires' => 0,
1003932
'isAnonymous' => false,
1004933
'submitMultiple' => false,
1005-
'allowEdit' => false,
1006934
'showExpiration' => false
1007935
],
1008936
]

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)