Skip to content

Commit

Permalink
test: fix ShareAPIControllerTest.php
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Sep 19, 2024
1 parent 3224554 commit bf904b3
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,8 @@ public function dataGetShare() {

$parentFolder = $this->getMockBuilder(Folder::class)->getMock();
$parentFolder->method('getId')->willReturn(3);
$mountPoint = $this->createMock(IMountPoint::class);
$mountPoint->method('getMountType')->willReturn('');

$file = $this->getMockBuilder('OCP\Files\File')->getMock();
$file->method('getId')->willReturn(1);
Expand All @@ -543,6 +545,7 @@ public function dataGetShare() {
$file->method('getSize')->willReturn(123465);
$file->method('getMTime')->willReturn(1234567890);
$file->method('getMimeType')->willReturn('myMimeType');
$file->method('getMountPoint')->willReturn($mountPoint);

$folder = $this->getMockBuilder(Folder::class)->getMock();
$folder->method('getId')->willReturn(2);
Expand All @@ -552,6 +555,7 @@ public function dataGetShare() {
$folder->method('getSize')->willReturn(123465);
$folder->method('getMTime')->willReturn(1234567890);
$folder->method('getMimeType')->willReturn('myFolderMimeType');
$folder->method('getMountPoint')->willReturn($mountPoint);

[$shareAttributes, $shareAttributesReturnJson] = $this->mockShareAttributes();

Expand Down Expand Up @@ -607,6 +611,9 @@ public function dataGetShare() {
'item_size' => 123465,
'item_mtime' => 1234567890,
'attributes' => null,
'item_permissions' => 4,
'is-mount-root' => false,
'mount-type' => '',
];
$data[] = [$share, $expected];

Expand Down Expand Up @@ -661,6 +668,9 @@ public function dataGetShare() {
'item_size' => 123465,
'item_mtime' => 1234567890,
'attributes' => null,
'item_permissions' => 4,
'is-mount-root' => false,
'mount-type' => '',
];
$data[] = [$share, $expected];

Expand Down Expand Up @@ -721,6 +731,9 @@ public function dataGetShare() {
'item_size' => 123465,
'item_mtime' => 1234567890,
'attributes' => null,
'item_permissions' => 4,
'is-mount-root' => false,
'mount-type' => '',
];
$data[] = [$share, $expected];

Expand Down Expand Up @@ -3740,6 +3753,12 @@ public function dataFormatShare() {
$folder->method('getMimeType')->willReturn('myFolderMimeType');
$fileWithPreview->method('getMimeType')->willReturn('mimeWithPreview');

$mountPoint = $this->createMock(IMountPoint::class);
$mountPoint->method('getMountType')->willReturn('');
$file->method('getMountPoint')->willReturn($mountPoint);
$folder->method('getMountPoint')->willReturn($mountPoint);
$fileWithPreview->method('getMountPoint')->willReturn($mountPoint);

$file->method('getPath')->willReturn('file');
$folder->method('getPath')->willReturn('folder');
$fileWithPreview->method('getPath')->willReturn('fileWithPreview');
Expand Down Expand Up @@ -3839,6 +3858,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => '[{"scope":"permissions","key":"download","value":true}]',
'item_permissions' => 1,
], $share, [], false
];
// User backend up
Expand Down Expand Up @@ -3880,6 +3900,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => '[{"scope":"permissions","key":"download","value":true}]',
'item_permissions' => 1,
], $share, [
['owner', $owner],
['initiator', $initiator],
Expand Down Expand Up @@ -3937,6 +3958,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
'item_permissions' => 1,
], $share, [], false
];

Expand Down Expand Up @@ -3990,6 +4012,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
'item_permissions' => 11,
], $share, [], false
];

Expand Down Expand Up @@ -4044,6 +4067,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
'item_permissions' => 1,
], $share, [], false
];

Expand Down Expand Up @@ -4095,6 +4119,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
'item_permissions' => 1,
], $share, [], false
];

Expand Down Expand Up @@ -4153,6 +4178,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
'item_permissions' => 1,
], $share, [], false
];

Expand Down Expand Up @@ -4211,6 +4237,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
'item_permissions' => 1,
], $share, [], false
];

Expand Down Expand Up @@ -4263,6 +4290,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
'item_permissions' => 1,
], $share, [], false
];

Expand Down Expand Up @@ -4315,6 +4343,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
'item_permissions' => 1,
], $share, [], false
];

Expand Down Expand Up @@ -4370,6 +4399,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
'item_permissions' => 1,
], $share, [], false
];

Expand Down Expand Up @@ -4422,6 +4452,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
'item_permissions' => 1,
], $share, [], false
];

Expand Down Expand Up @@ -4474,6 +4505,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
'item_permissions' => 1,
], $share, [], false
];

Expand Down Expand Up @@ -4543,6 +4575,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
'item_permissions' => 1,
], $share, [], false
];

Expand Down Expand Up @@ -4598,6 +4631,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
'item_permissions' => 1,
], $share, [], false
];

Expand Down Expand Up @@ -4651,6 +4685,7 @@ public function dataFormatShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
'item_permissions' => 11,
], $share, [], false
];

Expand Down Expand Up @@ -4815,6 +4850,7 @@ public function dataFormatRoomShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
'item_permissions' => 1,
], $share, false, []
];

Expand Down Expand Up @@ -4866,6 +4902,7 @@ public function dataFormatRoomShare() {
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
'item_permissions' => 9,
], $share, true, [
'share_with_displayname' => 'recipientRoomName'
]
Expand Down Expand Up @@ -4905,11 +4942,14 @@ public function testFormatRoomShare(array $expects, \OCP\Share\IShare $share, bo
->willReturn(true);

$helper = $this->getMockBuilder('\OCA\Talk\Share\Helper\ShareAPIController')
->setMethods(['formatShare'])
->setMethods(['formatShare', 'canAccessShare'])
->getMock();
$helper->method('formatShare')
->with($share)
->willReturn($formatShareByHelper);
$helper->method('canAccessShare')
->with($share)
->willReturn(true);

$this->serverContainer->method('get')
->with('\OCA\Talk\Share\Helper\ShareAPIController')
Expand Down

0 comments on commit bf904b3

Please sign in to comment.