Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions tests/Integration/Api/ApiV2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1491,4 +1491,22 @@ public function testDeleteSingleSubmission(array $submissionsExpected) {

$this->testGetSubmissions($submissionsExpected);
}

/**
* Test transfer owner endpoint for form
*
* Keep this test at the end as it might break other tests
*/
public function testTransferOwner() {
$resp = $this->http->request('POST', "api/v2.4/form/transfer", [
'json' => [
'formId' => $this->testForms[0]['id'],
'uid' => 'user1'
],
]);
$data = $this->OcsResponse2Data($resp);

$this->assertEquals(200, $resp->getStatusCode());
$this->assertEquals('user1', $data);
}
};
43 changes: 43 additions & 0 deletions tests/Unit/Controller/ApiControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -904,4 +904,47 @@ public function dataTestDeletePermission() {
]
];
}

public function testTransferOwnerNotOwner() {
$form = new Form();
$form->setId(1);
$form->setHash('hash');
$form->setOwnerId('otherUser');

$this->formMapper
->method('findById')
->with(1)
->willReturn($form);

$newOwner = $this->createMock(IUser::class);
$this->userManager->expects($this->once())
->method('get')
->with('newOwner')
->willReturn($newOwner);

$this->expectException(OCSForbiddenException::class);
$this->expectExceptionMessage('This form is not owned by the current user');
$this->apiController->transferOwner(1, 'newOwner');
}

public function testTransferOwner() {
$form = new Form();
$form->setId(1);
$form->setHash('hash');
$form->setOwnerId('currentUser');

$this->formMapper
->method('findById')
->with(1)
->willReturn($form);

$newOwner = $this->createMock(IUser::class);
$this->userManager->expects($this->once())
->method('get')
->with('newOwner')
->willReturn($newOwner);

$this->assertEquals(new DataResponse('newOwner'), $this->apiController->transferOwner(1, 'newOwner'));
$this->assertEquals('newOwner', $form->getOwnerId());
}
}