@@ -17,72 +17,72 @@ |
||
17 | 17 | use Test\TestCase; |
18 | 18 | |
19 | 19 | class CalDAVSettingsTest extends TestCase { |
20 | - private IConfig&MockObject $config; |
|
21 | - private IInitialState&MockObject $initialState; |
|
22 | - private IURLGenerator&MockObject $urlGenerator; |
|
23 | - private IAppManager&MockObject $appManager; |
|
24 | - private CalDAVSettings $settings; |
|
20 | + private IConfig&MockObject $config; |
|
21 | + private IInitialState&MockObject $initialState; |
|
22 | + private IURLGenerator&MockObject $urlGenerator; |
|
23 | + private IAppManager&MockObject $appManager; |
|
24 | + private CalDAVSettings $settings; |
|
25 | 25 | |
26 | - protected function setUp(): void { |
|
27 | - parent::setUp(); |
|
26 | + protected function setUp(): void { |
|
27 | + parent::setUp(); |
|
28 | 28 | |
29 | - $this->config = $this->createMock(IConfig::class); |
|
30 | - $this->initialState = $this->createMock(IInitialState::class); |
|
31 | - $this->urlGenerator = $this->createMock(IURLGenerator::class); |
|
32 | - $this->appManager = $this->createMock(IAppManager::class); |
|
33 | - $this->settings = new CalDAVSettings($this->config, $this->initialState, $this->urlGenerator, $this->appManager); |
|
34 | - } |
|
29 | + $this->config = $this->createMock(IConfig::class); |
|
30 | + $this->initialState = $this->createMock(IInitialState::class); |
|
31 | + $this->urlGenerator = $this->createMock(IURLGenerator::class); |
|
32 | + $this->appManager = $this->createMock(IAppManager::class); |
|
33 | + $this->settings = new CalDAVSettings($this->config, $this->initialState, $this->urlGenerator, $this->appManager); |
|
34 | + } |
|
35 | 35 | |
36 | - public function testGetForm(): void { |
|
37 | - $this->config->method('getAppValue') |
|
38 | - ->willReturnMap([ |
|
39 | - ['dav', 'sendInvitations', 'yes', 'yes'], |
|
40 | - ['dav', 'generateBirthdayCalendar', 'yes', 'no'], |
|
41 | - ['dav', 'sendEventReminders', 'yes', 'yes'], |
|
42 | - ['dav', 'sendEventRemindersToSharedUsers', 'yes', 'yes'], |
|
43 | - ['dav', 'sendEventRemindersPush', 'yes', 'yes'], |
|
44 | - ]); |
|
45 | - $this->urlGenerator |
|
46 | - ->expects($this->once()) |
|
47 | - ->method('linkToDocs') |
|
48 | - ->with('user-sync-calendars') |
|
49 | - ->willReturn('Some docs URL'); |
|
36 | + public function testGetForm(): void { |
|
37 | + $this->config->method('getAppValue') |
|
38 | + ->willReturnMap([ |
|
39 | + ['dav', 'sendInvitations', 'yes', 'yes'], |
|
40 | + ['dav', 'generateBirthdayCalendar', 'yes', 'no'], |
|
41 | + ['dav', 'sendEventReminders', 'yes', 'yes'], |
|
42 | + ['dav', 'sendEventRemindersToSharedUsers', 'yes', 'yes'], |
|
43 | + ['dav', 'sendEventRemindersPush', 'yes', 'yes'], |
|
44 | + ]); |
|
45 | + $this->urlGenerator |
|
46 | + ->expects($this->once()) |
|
47 | + ->method('linkToDocs') |
|
48 | + ->with('user-sync-calendars') |
|
49 | + ->willReturn('Some docs URL'); |
|
50 | 50 | |
51 | - $calls = [ |
|
52 | - ['userSyncCalendarsDocUrl', 'Some docs URL'], |
|
53 | - ['sendInvitations', true], |
|
54 | - ['generateBirthdayCalendar', false], |
|
55 | - ['sendEventReminders', true], |
|
56 | - ['sendEventRemindersToSharedUsers', true], |
|
57 | - ['sendEventRemindersPush', true], |
|
58 | - ]; |
|
59 | - $this->initialState->method('provideInitialState') |
|
60 | - ->willReturnCallback(function () use (&$calls) { |
|
61 | - $expected = array_shift($calls); |
|
62 | - $this->assertEquals($expected, func_get_args()); |
|
63 | - }); |
|
64 | - $result = $this->settings->getForm(); |
|
51 | + $calls = [ |
|
52 | + ['userSyncCalendarsDocUrl', 'Some docs URL'], |
|
53 | + ['sendInvitations', true], |
|
54 | + ['generateBirthdayCalendar', false], |
|
55 | + ['sendEventReminders', true], |
|
56 | + ['sendEventRemindersToSharedUsers', true], |
|
57 | + ['sendEventRemindersPush', true], |
|
58 | + ]; |
|
59 | + $this->initialState->method('provideInitialState') |
|
60 | + ->willReturnCallback(function () use (&$calls) { |
|
61 | + $expected = array_shift($calls); |
|
62 | + $this->assertEquals($expected, func_get_args()); |
|
63 | + }); |
|
64 | + $result = $this->settings->getForm(); |
|
65 | 65 | |
66 | - $this->assertInstanceOf(TemplateResponse::class, $result); |
|
67 | - } |
|
66 | + $this->assertInstanceOf(TemplateResponse::class, $result); |
|
67 | + } |
|
68 | 68 | |
69 | - public function testGetSection(): void { |
|
70 | - $this->appManager->expects(self::once()) |
|
71 | - ->method('isBackendRequired') |
|
72 | - ->with(IAppManager::BACKEND_CALDAV) |
|
73 | - ->willReturn(true); |
|
74 | - $this->assertEquals('groupware', $this->settings->getSection()); |
|
75 | - } |
|
69 | + public function testGetSection(): void { |
|
70 | + $this->appManager->expects(self::once()) |
|
71 | + ->method('isBackendRequired') |
|
72 | + ->with(IAppManager::BACKEND_CALDAV) |
|
73 | + ->willReturn(true); |
|
74 | + $this->assertEquals('groupware', $this->settings->getSection()); |
|
75 | + } |
|
76 | 76 | |
77 | - public function testGetSectionWithoutCaldavBackend(): void { |
|
78 | - $this->appManager->expects(self::once()) |
|
79 | - ->method('isBackendRequired') |
|
80 | - ->with(IAppManager::BACKEND_CALDAV) |
|
81 | - ->willReturn(false); |
|
82 | - $this->assertEquals(null, $this->settings->getSection()); |
|
83 | - } |
|
77 | + public function testGetSectionWithoutCaldavBackend(): void { |
|
78 | + $this->appManager->expects(self::once()) |
|
79 | + ->method('isBackendRequired') |
|
80 | + ->with(IAppManager::BACKEND_CALDAV) |
|
81 | + ->willReturn(false); |
|
82 | + $this->assertEquals(null, $this->settings->getSection()); |
|
83 | + } |
|
84 | 84 | |
85 | - public function testGetPriority(): void { |
|
86 | - $this->assertEquals(10, $this->settings->getPriority()); |
|
87 | - } |
|
85 | + public function testGetPriority(): void { |
|
86 | + $this->assertEquals(10, $this->settings->getPriority()); |
|
87 | + } |
|
88 | 88 | } |
@@ -57,7 +57,7 @@ |
||
57 | 57 | ['sendEventRemindersPush', true], |
58 | 58 | ]; |
59 | 59 | $this->initialState->method('provideInitialState') |
60 | - ->willReturnCallback(function () use (&$calls) { |
|
60 | + ->willReturnCallback(function() use (&$calls) { |
|
61 | 61 | $expected = array_shift($calls); |
62 | 62 | $this->assertEquals($expected, func_get_args()); |
63 | 63 | }); |
@@ -18,142 +18,142 @@ |
||
18 | 18 | use PHPUnit\Framework\MockObject\MockObject; |
19 | 19 | |
20 | 20 | class SystemTagMappingNodeTest extends \Test\TestCase { |
21 | - private ISystemTagManager&MockObject $tagManager; |
|
22 | - private ISystemTagObjectMapper&MockObject $tagMapper; |
|
23 | - private IUser&MockObject $user; |
|
24 | - |
|
25 | - protected function setUp(): void { |
|
26 | - parent::setUp(); |
|
27 | - |
|
28 | - $this->tagManager = $this->createMock(ISystemTagManager::class); |
|
29 | - $this->tagMapper = $this->createMock(ISystemTagObjectMapper::class); |
|
30 | - $this->user = $this->createMock(IUser::class); |
|
31 | - } |
|
32 | - |
|
33 | - public function getMappingNode($tag = null, array $writableNodeIds = []) { |
|
34 | - if ($tag === null) { |
|
35 | - $tag = new SystemTag('1', 'Test', true, true); |
|
36 | - } |
|
37 | - return new SystemTagMappingNode( |
|
38 | - $tag, |
|
39 | - '123', |
|
40 | - 'files', |
|
41 | - $this->user, |
|
42 | - $this->tagManager, |
|
43 | - $this->tagMapper, |
|
44 | - fn ($id): bool => in_array($id, $writableNodeIds), |
|
45 | - ); |
|
46 | - } |
|
47 | - |
|
48 | - public function testGetters(): void { |
|
49 | - $tag = new SystemTag('1', 'Test', true, false); |
|
50 | - $node = $this->getMappingNode($tag); |
|
51 | - $this->assertEquals('1', $node->getName()); |
|
52 | - $this->assertEquals($tag, $node->getSystemTag()); |
|
53 | - $this->assertEquals(123, $node->getObjectId()); |
|
54 | - $this->assertEquals('files', $node->getObjectType()); |
|
55 | - } |
|
56 | - |
|
57 | - public function testDeleteTag(): void { |
|
58 | - $node = $this->getMappingNode(null, [123]); |
|
59 | - $this->tagManager->expects($this->once()) |
|
60 | - ->method('canUserSeeTag') |
|
61 | - ->with($node->getSystemTag()) |
|
62 | - ->willReturn(true); |
|
63 | - $this->tagManager->expects($this->once()) |
|
64 | - ->method('canUserAssignTag') |
|
65 | - ->with($node->getSystemTag()) |
|
66 | - ->willReturn(true); |
|
67 | - $this->tagManager->expects($this->never()) |
|
68 | - ->method('deleteTags'); |
|
69 | - $this->tagMapper->expects($this->once()) |
|
70 | - ->method('unassignTags') |
|
71 | - ->with(123, 'files', 1); |
|
72 | - |
|
73 | - $node->delete(); |
|
74 | - } |
|
75 | - |
|
76 | - public function testDeleteTagForbidden(): void { |
|
77 | - $node = $this->getMappingNode(); |
|
78 | - $this->tagManager->expects($this->once()) |
|
79 | - ->method('canUserSeeTag') |
|
80 | - ->with($node->getSystemTag()) |
|
81 | - ->willReturn(true); |
|
82 | - $this->tagManager->expects($this->once()) |
|
83 | - ->method('canUserAssignTag') |
|
84 | - ->with($node->getSystemTag()) |
|
85 | - ->willReturn(true); |
|
86 | - $this->tagManager->expects($this->never()) |
|
87 | - ->method('deleteTags'); |
|
88 | - $this->tagMapper->expects($this->never()) |
|
89 | - ->method('unassignTags'); |
|
90 | - |
|
91 | - $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
92 | - $node->delete(); |
|
93 | - } |
|
94 | - |
|
95 | - public static function tagNodeDeleteProviderPermissionException(): array { |
|
96 | - return [ |
|
97 | - [ |
|
98 | - // cannot unassign invisible tag |
|
99 | - new SystemTag('1', 'Original', false, true), |
|
100 | - 'Sabre\DAV\Exception\NotFound', |
|
101 | - ], |
|
102 | - [ |
|
103 | - // cannot unassign non-assignable tag |
|
104 | - new SystemTag('1', 'Original', true, false), |
|
105 | - 'Sabre\DAV\Exception\Forbidden', |
|
106 | - ], |
|
107 | - ]; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * @dataProvider tagNodeDeleteProviderPermissionException |
|
112 | - */ |
|
113 | - public function testDeleteTagExpectedException(ISystemTag $tag, $expectedException): void { |
|
114 | - $this->tagManager->expects($this->any()) |
|
115 | - ->method('canUserSeeTag') |
|
116 | - ->with($tag) |
|
117 | - ->willReturn($tag->isUserVisible()); |
|
118 | - $this->tagManager->expects($this->any()) |
|
119 | - ->method('canUserAssignTag') |
|
120 | - ->with($tag) |
|
121 | - ->willReturn($tag->isUserAssignable()); |
|
122 | - $this->tagManager->expects($this->never()) |
|
123 | - ->method('deleteTags'); |
|
124 | - $this->tagMapper->expects($this->never()) |
|
125 | - ->method('unassignTags'); |
|
126 | - |
|
127 | - $thrown = null; |
|
128 | - try { |
|
129 | - $this->getMappingNode($tag)->delete(); |
|
130 | - } catch (\Exception $e) { |
|
131 | - $thrown = $e; |
|
132 | - } |
|
133 | - |
|
134 | - $this->assertInstanceOf($expectedException, $thrown); |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - public function testDeleteTagNotFound(): void { |
|
139 | - $this->expectException(\Sabre\DAV\Exception\NotFound::class); |
|
140 | - |
|
141 | - // assuming the tag existed at the time the node was created, |
|
142 | - // but got deleted concurrently in the database |
|
143 | - $tag = new SystemTag('1', 'Test', true, true); |
|
144 | - $this->tagManager->expects($this->once()) |
|
145 | - ->method('canUserSeeTag') |
|
146 | - ->with($tag) |
|
147 | - ->willReturn($tag->isUserVisible()); |
|
148 | - $this->tagManager->expects($this->once()) |
|
149 | - ->method('canUserAssignTag') |
|
150 | - ->with($tag) |
|
151 | - ->willReturn($tag->isUserAssignable()); |
|
152 | - $this->tagMapper->expects($this->once()) |
|
153 | - ->method('unassignTags') |
|
154 | - ->with(123, 'files', 1) |
|
155 | - ->will($this->throwException(new TagNotFoundException())); |
|
156 | - |
|
157 | - $this->getMappingNode($tag, [123])->delete(); |
|
158 | - } |
|
21 | + private ISystemTagManager&MockObject $tagManager; |
|
22 | + private ISystemTagObjectMapper&MockObject $tagMapper; |
|
23 | + private IUser&MockObject $user; |
|
24 | + |
|
25 | + protected function setUp(): void { |
|
26 | + parent::setUp(); |
|
27 | + |
|
28 | + $this->tagManager = $this->createMock(ISystemTagManager::class); |
|
29 | + $this->tagMapper = $this->createMock(ISystemTagObjectMapper::class); |
|
30 | + $this->user = $this->createMock(IUser::class); |
|
31 | + } |
|
32 | + |
|
33 | + public function getMappingNode($tag = null, array $writableNodeIds = []) { |
|
34 | + if ($tag === null) { |
|
35 | + $tag = new SystemTag('1', 'Test', true, true); |
|
36 | + } |
|
37 | + return new SystemTagMappingNode( |
|
38 | + $tag, |
|
39 | + '123', |
|
40 | + 'files', |
|
41 | + $this->user, |
|
42 | + $this->tagManager, |
|
43 | + $this->tagMapper, |
|
44 | + fn ($id): bool => in_array($id, $writableNodeIds), |
|
45 | + ); |
|
46 | + } |
|
47 | + |
|
48 | + public function testGetters(): void { |
|
49 | + $tag = new SystemTag('1', 'Test', true, false); |
|
50 | + $node = $this->getMappingNode($tag); |
|
51 | + $this->assertEquals('1', $node->getName()); |
|
52 | + $this->assertEquals($tag, $node->getSystemTag()); |
|
53 | + $this->assertEquals(123, $node->getObjectId()); |
|
54 | + $this->assertEquals('files', $node->getObjectType()); |
|
55 | + } |
|
56 | + |
|
57 | + public function testDeleteTag(): void { |
|
58 | + $node = $this->getMappingNode(null, [123]); |
|
59 | + $this->tagManager->expects($this->once()) |
|
60 | + ->method('canUserSeeTag') |
|
61 | + ->with($node->getSystemTag()) |
|
62 | + ->willReturn(true); |
|
63 | + $this->tagManager->expects($this->once()) |
|
64 | + ->method('canUserAssignTag') |
|
65 | + ->with($node->getSystemTag()) |
|
66 | + ->willReturn(true); |
|
67 | + $this->tagManager->expects($this->never()) |
|
68 | + ->method('deleteTags'); |
|
69 | + $this->tagMapper->expects($this->once()) |
|
70 | + ->method('unassignTags') |
|
71 | + ->with(123, 'files', 1); |
|
72 | + |
|
73 | + $node->delete(); |
|
74 | + } |
|
75 | + |
|
76 | + public function testDeleteTagForbidden(): void { |
|
77 | + $node = $this->getMappingNode(); |
|
78 | + $this->tagManager->expects($this->once()) |
|
79 | + ->method('canUserSeeTag') |
|
80 | + ->with($node->getSystemTag()) |
|
81 | + ->willReturn(true); |
|
82 | + $this->tagManager->expects($this->once()) |
|
83 | + ->method('canUserAssignTag') |
|
84 | + ->with($node->getSystemTag()) |
|
85 | + ->willReturn(true); |
|
86 | + $this->tagManager->expects($this->never()) |
|
87 | + ->method('deleteTags'); |
|
88 | + $this->tagMapper->expects($this->never()) |
|
89 | + ->method('unassignTags'); |
|
90 | + |
|
91 | + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
92 | + $node->delete(); |
|
93 | + } |
|
94 | + |
|
95 | + public static function tagNodeDeleteProviderPermissionException(): array { |
|
96 | + return [ |
|
97 | + [ |
|
98 | + // cannot unassign invisible tag |
|
99 | + new SystemTag('1', 'Original', false, true), |
|
100 | + 'Sabre\DAV\Exception\NotFound', |
|
101 | + ], |
|
102 | + [ |
|
103 | + // cannot unassign non-assignable tag |
|
104 | + new SystemTag('1', 'Original', true, false), |
|
105 | + 'Sabre\DAV\Exception\Forbidden', |
|
106 | + ], |
|
107 | + ]; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * @dataProvider tagNodeDeleteProviderPermissionException |
|
112 | + */ |
|
113 | + public function testDeleteTagExpectedException(ISystemTag $tag, $expectedException): void { |
|
114 | + $this->tagManager->expects($this->any()) |
|
115 | + ->method('canUserSeeTag') |
|
116 | + ->with($tag) |
|
117 | + ->willReturn($tag->isUserVisible()); |
|
118 | + $this->tagManager->expects($this->any()) |
|
119 | + ->method('canUserAssignTag') |
|
120 | + ->with($tag) |
|
121 | + ->willReturn($tag->isUserAssignable()); |
|
122 | + $this->tagManager->expects($this->never()) |
|
123 | + ->method('deleteTags'); |
|
124 | + $this->tagMapper->expects($this->never()) |
|
125 | + ->method('unassignTags'); |
|
126 | + |
|
127 | + $thrown = null; |
|
128 | + try { |
|
129 | + $this->getMappingNode($tag)->delete(); |
|
130 | + } catch (\Exception $e) { |
|
131 | + $thrown = $e; |
|
132 | + } |
|
133 | + |
|
134 | + $this->assertInstanceOf($expectedException, $thrown); |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + public function testDeleteTagNotFound(): void { |
|
139 | + $this->expectException(\Sabre\DAV\Exception\NotFound::class); |
|
140 | + |
|
141 | + // assuming the tag existed at the time the node was created, |
|
142 | + // but got deleted concurrently in the database |
|
143 | + $tag = new SystemTag('1', 'Test', true, true); |
|
144 | + $this->tagManager->expects($this->once()) |
|
145 | + ->method('canUserSeeTag') |
|
146 | + ->with($tag) |
|
147 | + ->willReturn($tag->isUserVisible()); |
|
148 | + $this->tagManager->expects($this->once()) |
|
149 | + ->method('canUserAssignTag') |
|
150 | + ->with($tag) |
|
151 | + ->willReturn($tag->isUserAssignable()); |
|
152 | + $this->tagMapper->expects($this->once()) |
|
153 | + ->method('unassignTags') |
|
154 | + ->with(123, 'files', 1) |
|
155 | + ->will($this->throwException(new TagNotFoundException())); |
|
156 | + |
|
157 | + $this->getMappingNode($tag, [123])->delete(); |
|
158 | + } |
|
159 | 159 | } |
@@ -19,133 +19,133 @@ |
||
19 | 19 | use PHPUnit\Framework\MockObject\MockObject; |
20 | 20 | |
21 | 21 | class SystemTagsObjectTypeCollectionTest extends \Test\TestCase { |
22 | - private ISystemTagManager&MockObject $tagManager; |
|
23 | - private ISystemTagObjectMapper&MockObject $tagMapper; |
|
24 | - private Folder&MockObject $userFolder; |
|
25 | - private SystemTagsObjectTypeCollection $node; |
|
26 | - |
|
27 | - protected function setUp(): void { |
|
28 | - parent::setUp(); |
|
29 | - |
|
30 | - $this->tagManager = $this->createMock(ISystemTagManager::class); |
|
31 | - $this->tagMapper = $this->createMock(ISystemTagObjectMapper::class); |
|
32 | - |
|
33 | - $user = $this->createMock(IUser::class); |
|
34 | - $user->expects($this->any()) |
|
35 | - ->method('getUID') |
|
36 | - ->willReturn('testuser'); |
|
37 | - $userSession = $this->createMock(IUserSession::class); |
|
38 | - $userSession->expects($this->any()) |
|
39 | - ->method('getUser') |
|
40 | - ->willReturn($user); |
|
41 | - $groupManager = $this->createMock(IGroupManager::class); |
|
42 | - $groupManager->expects($this->any()) |
|
43 | - ->method('isAdmin') |
|
44 | - ->with('testuser') |
|
45 | - ->willReturn(true); |
|
46 | - |
|
47 | - $this->userFolder = $this->createMock(Folder::class); |
|
48 | - $userFolder = $this->userFolder; |
|
49 | - |
|
50 | - $closure = function ($name) use ($userFolder) { |
|
51 | - $node = $userFolder->getFirstNodeById((int)$name); |
|
52 | - return $node !== null; |
|
53 | - }; |
|
54 | - $writeAccessClosure = function ($name) use ($userFolder) { |
|
55 | - $nodes = $userFolder->getById((int)$name); |
|
56 | - foreach ($nodes as $node) { |
|
57 | - if (($node->getPermissions() & Constants::PERMISSION_UPDATE) === Constants::PERMISSION_UPDATE) { |
|
58 | - return true; |
|
59 | - } |
|
60 | - } |
|
61 | - return false; |
|
62 | - }; |
|
63 | - |
|
64 | - $this->node = new SystemTagsObjectTypeCollection( |
|
65 | - 'files', |
|
66 | - $this->tagManager, |
|
67 | - $this->tagMapper, |
|
68 | - $userSession, |
|
69 | - $groupManager, |
|
70 | - $closure, |
|
71 | - $writeAccessClosure, |
|
72 | - ); |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - public function testForbiddenCreateFile(): void { |
|
77 | - $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
78 | - |
|
79 | - $this->node->createFile('555'); |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - public function testForbiddenCreateDirectory(): void { |
|
84 | - $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
85 | - |
|
86 | - $this->node->createDirectory('789'); |
|
87 | - } |
|
88 | - |
|
89 | - public function testGetChild(): void { |
|
90 | - $this->userFolder->expects($this->once()) |
|
91 | - ->method('getFirstNodeById') |
|
92 | - ->with('555') |
|
93 | - ->willReturn($this->createMock(Node::class)); |
|
94 | - $childNode = $this->node->getChild('555'); |
|
95 | - |
|
96 | - $this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagsObjectMappingCollection', $childNode); |
|
97 | - $this->assertEquals('555', $childNode->getName()); |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - public function testGetChildWithoutAccess(): void { |
|
102 | - $this->expectException(\Sabre\DAV\Exception\NotFound::class); |
|
103 | - |
|
104 | - $this->userFolder->expects($this->once()) |
|
105 | - ->method('getFirstNodeById') |
|
106 | - ->with('555') |
|
107 | - ->willReturn(null); |
|
108 | - $this->node->getChild('555'); |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - public function testGetChildren(): void { |
|
113 | - $this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class); |
|
114 | - |
|
115 | - $this->node->getChildren(); |
|
116 | - } |
|
117 | - |
|
118 | - public function testChildExists(): void { |
|
119 | - $this->userFolder->expects($this->once()) |
|
120 | - ->method('getFirstNodeById') |
|
121 | - ->with('123') |
|
122 | - ->willReturn($this->createMock(Node::class)); |
|
123 | - $this->assertTrue($this->node->childExists('123')); |
|
124 | - } |
|
125 | - |
|
126 | - public function testChildExistsWithoutAccess(): void { |
|
127 | - $this->userFolder->expects($this->once()) |
|
128 | - ->method('getFirstNodeById') |
|
129 | - ->with('555') |
|
130 | - ->willReturn(null); |
|
131 | - $this->assertFalse($this->node->childExists('555')); |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - public function testDelete(): void { |
|
136 | - $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
137 | - |
|
138 | - $this->node->delete(); |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - public function testSetName(): void { |
|
143 | - $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
22 | + private ISystemTagManager&MockObject $tagManager; |
|
23 | + private ISystemTagObjectMapper&MockObject $tagMapper; |
|
24 | + private Folder&MockObject $userFolder; |
|
25 | + private SystemTagsObjectTypeCollection $node; |
|
26 | + |
|
27 | + protected function setUp(): void { |
|
28 | + parent::setUp(); |
|
29 | + |
|
30 | + $this->tagManager = $this->createMock(ISystemTagManager::class); |
|
31 | + $this->tagMapper = $this->createMock(ISystemTagObjectMapper::class); |
|
32 | + |
|
33 | + $user = $this->createMock(IUser::class); |
|
34 | + $user->expects($this->any()) |
|
35 | + ->method('getUID') |
|
36 | + ->willReturn('testuser'); |
|
37 | + $userSession = $this->createMock(IUserSession::class); |
|
38 | + $userSession->expects($this->any()) |
|
39 | + ->method('getUser') |
|
40 | + ->willReturn($user); |
|
41 | + $groupManager = $this->createMock(IGroupManager::class); |
|
42 | + $groupManager->expects($this->any()) |
|
43 | + ->method('isAdmin') |
|
44 | + ->with('testuser') |
|
45 | + ->willReturn(true); |
|
46 | + |
|
47 | + $this->userFolder = $this->createMock(Folder::class); |
|
48 | + $userFolder = $this->userFolder; |
|
49 | + |
|
50 | + $closure = function ($name) use ($userFolder) { |
|
51 | + $node = $userFolder->getFirstNodeById((int)$name); |
|
52 | + return $node !== null; |
|
53 | + }; |
|
54 | + $writeAccessClosure = function ($name) use ($userFolder) { |
|
55 | + $nodes = $userFolder->getById((int)$name); |
|
56 | + foreach ($nodes as $node) { |
|
57 | + if (($node->getPermissions() & Constants::PERMISSION_UPDATE) === Constants::PERMISSION_UPDATE) { |
|
58 | + return true; |
|
59 | + } |
|
60 | + } |
|
61 | + return false; |
|
62 | + }; |
|
63 | + |
|
64 | + $this->node = new SystemTagsObjectTypeCollection( |
|
65 | + 'files', |
|
66 | + $this->tagManager, |
|
67 | + $this->tagMapper, |
|
68 | + $userSession, |
|
69 | + $groupManager, |
|
70 | + $closure, |
|
71 | + $writeAccessClosure, |
|
72 | + ); |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + public function testForbiddenCreateFile(): void { |
|
77 | + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
78 | + |
|
79 | + $this->node->createFile('555'); |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + public function testForbiddenCreateDirectory(): void { |
|
84 | + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
85 | + |
|
86 | + $this->node->createDirectory('789'); |
|
87 | + } |
|
88 | + |
|
89 | + public function testGetChild(): void { |
|
90 | + $this->userFolder->expects($this->once()) |
|
91 | + ->method('getFirstNodeById') |
|
92 | + ->with('555') |
|
93 | + ->willReturn($this->createMock(Node::class)); |
|
94 | + $childNode = $this->node->getChild('555'); |
|
95 | + |
|
96 | + $this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagsObjectMappingCollection', $childNode); |
|
97 | + $this->assertEquals('555', $childNode->getName()); |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + public function testGetChildWithoutAccess(): void { |
|
102 | + $this->expectException(\Sabre\DAV\Exception\NotFound::class); |
|
103 | + |
|
104 | + $this->userFolder->expects($this->once()) |
|
105 | + ->method('getFirstNodeById') |
|
106 | + ->with('555') |
|
107 | + ->willReturn(null); |
|
108 | + $this->node->getChild('555'); |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + public function testGetChildren(): void { |
|
113 | + $this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class); |
|
114 | + |
|
115 | + $this->node->getChildren(); |
|
116 | + } |
|
117 | + |
|
118 | + public function testChildExists(): void { |
|
119 | + $this->userFolder->expects($this->once()) |
|
120 | + ->method('getFirstNodeById') |
|
121 | + ->with('123') |
|
122 | + ->willReturn($this->createMock(Node::class)); |
|
123 | + $this->assertTrue($this->node->childExists('123')); |
|
124 | + } |
|
125 | + |
|
126 | + public function testChildExistsWithoutAccess(): void { |
|
127 | + $this->userFolder->expects($this->once()) |
|
128 | + ->method('getFirstNodeById') |
|
129 | + ->with('555') |
|
130 | + ->willReturn(null); |
|
131 | + $this->assertFalse($this->node->childExists('555')); |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + public function testDelete(): void { |
|
136 | + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
137 | + |
|
138 | + $this->node->delete(); |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + public function testSetName(): void { |
|
143 | + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
144 | 144 | |
145 | - $this->node->setName('somethingelse'); |
|
146 | - } |
|
147 | - |
|
148 | - public function testGetName(): void { |
|
149 | - $this->assertEquals('files', $this->node->getName()); |
|
150 | - } |
|
145 | + $this->node->setName('somethingelse'); |
|
146 | + } |
|
147 | + |
|
148 | + public function testGetName(): void { |
|
149 | + $this->assertEquals('files', $this->node->getName()); |
|
150 | + } |
|
151 | 151 | } |
@@ -47,12 +47,12 @@ |
||
47 | 47 | $this->userFolder = $this->createMock(Folder::class); |
48 | 48 | $userFolder = $this->userFolder; |
49 | 49 | |
50 | - $closure = function ($name) use ($userFolder) { |
|
51 | - $node = $userFolder->getFirstNodeById((int)$name); |
|
50 | + $closure = function($name) use ($userFolder) { |
|
51 | + $node = $userFolder->getFirstNodeById((int) $name); |
|
52 | 52 | return $node !== null; |
53 | 53 | }; |
54 | - $writeAccessClosure = function ($name) use ($userFolder) { |
|
55 | - $nodes = $userFolder->getById((int)$name); |
|
54 | + $writeAccessClosure = function($name) use ($userFolder) { |
|
55 | + $nodes = $userFolder->getById((int) $name); |
|
56 | 56 | foreach ($nodes as $node) { |
57 | 57 | if (($node->getPermissions() & Constants::PERMISSION_UPDATE) === Constants::PERMISSION_UPDATE) { |
58 | 58 | return true; |
@@ -27,646 +27,646 @@ |
||
27 | 27 | use Sabre\HTTP\ResponseInterface; |
28 | 28 | |
29 | 29 | class SystemTagPluginTest extends \Test\TestCase { |
30 | - public const ID_PROPERTYNAME = SystemTagPlugin::ID_PROPERTYNAME; |
|
31 | - public const DISPLAYNAME_PROPERTYNAME = SystemTagPlugin::DISPLAYNAME_PROPERTYNAME; |
|
32 | - public const USERVISIBLE_PROPERTYNAME = SystemTagPlugin::USERVISIBLE_PROPERTYNAME; |
|
33 | - public const USERASSIGNABLE_PROPERTYNAME = SystemTagPlugin::USERASSIGNABLE_PROPERTYNAME; |
|
34 | - public const CANASSIGN_PROPERTYNAME = SystemTagPlugin::CANASSIGN_PROPERTYNAME; |
|
35 | - public const GROUPS_PROPERTYNAME = SystemTagPlugin::GROUPS_PROPERTYNAME; |
|
36 | - |
|
37 | - private \Sabre\DAV\Server $server; |
|
38 | - private \Sabre\DAV\Tree&MockObject $tree; |
|
39 | - private ISystemTagManager&MockObject $tagManager; |
|
40 | - private IGroupManager&MockObject $groupManager; |
|
41 | - private IUserSession&MockObject $userSession; |
|
42 | - private IRootFolder&MockObject $rootFolder; |
|
43 | - private IUser&MockObject $user; |
|
44 | - private ISystemTagObjectMapper&MockObject $tagMapper; |
|
45 | - private SystemTagPlugin $plugin; |
|
46 | - |
|
47 | - protected function setUp(): void { |
|
48 | - parent::setUp(); |
|
49 | - $this->tree = $this->createMock(Tree::class); |
|
50 | - |
|
51 | - $this->server = new \Sabre\DAV\Server($this->tree); |
|
52 | - |
|
53 | - $this->tagManager = $this->createMock(ISystemTagManager::class); |
|
54 | - $this->groupManager = $this->createMock(IGroupManager::class); |
|
55 | - $this->user = $this->createMock(IUser::class); |
|
56 | - $this->userSession = $this->createMock(IUserSession::class); |
|
57 | - $this->userSession |
|
58 | - ->expects($this->any()) |
|
59 | - ->method('getUser') |
|
60 | - ->willReturn($this->user); |
|
61 | - $this->userSession |
|
62 | - ->expects($this->any()) |
|
63 | - ->method('isLoggedIn') |
|
64 | - ->willReturn(true); |
|
65 | - |
|
66 | - $this->tagMapper = $this->createMock(ISystemTagObjectMapper::class); |
|
67 | - $this->rootFolder = $this->createMock(IRootFolder::class); |
|
68 | - |
|
69 | - $this->plugin = new SystemTagPlugin( |
|
70 | - $this->tagManager, |
|
71 | - $this->groupManager, |
|
72 | - $this->userSession, |
|
73 | - $this->rootFolder, |
|
74 | - $this->tagMapper |
|
75 | - ); |
|
76 | - $this->plugin->initialize($this->server); |
|
77 | - } |
|
78 | - |
|
79 | - public static function getPropertiesDataProvider(): array { |
|
80 | - return [ |
|
81 | - [ |
|
82 | - new SystemTag('1', 'Test', true, true), |
|
83 | - [], |
|
84 | - [ |
|
85 | - self::ID_PROPERTYNAME, |
|
86 | - self::DISPLAYNAME_PROPERTYNAME, |
|
87 | - self::USERVISIBLE_PROPERTYNAME, |
|
88 | - self::USERASSIGNABLE_PROPERTYNAME, |
|
89 | - self::CANASSIGN_PROPERTYNAME, |
|
90 | - ], |
|
91 | - [ |
|
92 | - self::ID_PROPERTYNAME => '1', |
|
93 | - self::DISPLAYNAME_PROPERTYNAME => 'Test', |
|
94 | - self::USERVISIBLE_PROPERTYNAME => 'true', |
|
95 | - self::USERASSIGNABLE_PROPERTYNAME => 'true', |
|
96 | - self::CANASSIGN_PROPERTYNAME => 'true', |
|
97 | - ] |
|
98 | - ], |
|
99 | - [ |
|
100 | - new SystemTag('1', 'Test', true, false), |
|
101 | - [], |
|
102 | - [ |
|
103 | - self::ID_PROPERTYNAME, |
|
104 | - self::DISPLAYNAME_PROPERTYNAME, |
|
105 | - self::USERVISIBLE_PROPERTYNAME, |
|
106 | - self::USERASSIGNABLE_PROPERTYNAME, |
|
107 | - self::CANASSIGN_PROPERTYNAME, |
|
108 | - ], |
|
109 | - [ |
|
110 | - self::ID_PROPERTYNAME => '1', |
|
111 | - self::DISPLAYNAME_PROPERTYNAME => 'Test', |
|
112 | - self::USERVISIBLE_PROPERTYNAME => 'true', |
|
113 | - self::USERASSIGNABLE_PROPERTYNAME => 'false', |
|
114 | - self::CANASSIGN_PROPERTYNAME => 'false', |
|
115 | - ] |
|
116 | - ], |
|
117 | - [ |
|
118 | - new SystemTag('1', 'Test', true, false), |
|
119 | - ['group1', 'group2'], |
|
120 | - [ |
|
121 | - self::ID_PROPERTYNAME, |
|
122 | - self::GROUPS_PROPERTYNAME, |
|
123 | - ], |
|
124 | - [ |
|
125 | - self::ID_PROPERTYNAME => '1', |
|
126 | - self::GROUPS_PROPERTYNAME => 'group1|group2', |
|
127 | - ] |
|
128 | - ], |
|
129 | - [ |
|
130 | - new SystemTag('1', 'Test', true, true), |
|
131 | - ['group1', 'group2'], |
|
132 | - [ |
|
133 | - self::ID_PROPERTYNAME, |
|
134 | - self::GROUPS_PROPERTYNAME, |
|
135 | - ], |
|
136 | - [ |
|
137 | - self::ID_PROPERTYNAME => '1', |
|
138 | - // groups only returned when userAssignable is false |
|
139 | - self::GROUPS_PROPERTYNAME => '', |
|
140 | - ] |
|
141 | - ], |
|
142 | - ]; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * @dataProvider getPropertiesDataProvider |
|
147 | - */ |
|
148 | - public function testGetProperties(ISystemTag $systemTag, array $groups, array $requestedProperties, array $expectedProperties): void { |
|
149 | - $this->user->expects($this->any()) |
|
150 | - ->method('getUID') |
|
151 | - ->willReturn('admin'); |
|
152 | - $this->groupManager |
|
153 | - ->expects($this->any()) |
|
154 | - ->method('isAdmin') |
|
155 | - ->with('admin') |
|
156 | - ->willReturn(true); |
|
157 | - |
|
158 | - $node = $this->getMockBuilder(SystemTagNode::class) |
|
159 | - ->disableOriginalConstructor() |
|
160 | - ->getMock(); |
|
161 | - $node->expects($this->any()) |
|
162 | - ->method('getSystemTag') |
|
163 | - ->willReturn($systemTag); |
|
164 | - |
|
165 | - $this->tagManager->expects($this->any()) |
|
166 | - ->method('canUserAssignTag') |
|
167 | - ->willReturn($systemTag->isUserAssignable()); |
|
168 | - |
|
169 | - $this->tagManager->expects($this->any()) |
|
170 | - ->method('getTagGroups') |
|
171 | - ->willReturn($groups); |
|
172 | - |
|
173 | - $this->tree->expects($this->any()) |
|
174 | - ->method('getNodeForPath') |
|
175 | - ->with('/systemtag/1') |
|
176 | - ->willReturn($node); |
|
177 | - |
|
178 | - $propFind = new \Sabre\DAV\PropFind( |
|
179 | - '/systemtag/1', |
|
180 | - $requestedProperties, |
|
181 | - 0 |
|
182 | - ); |
|
183 | - |
|
184 | - $this->plugin->handleGetProperties( |
|
185 | - $propFind, |
|
186 | - $node |
|
187 | - ); |
|
188 | - |
|
189 | - $result = $propFind->getResultForMultiStatus(); |
|
190 | - |
|
191 | - $this->assertEmpty($result[404]); |
|
192 | - $this->assertEquals($expectedProperties, $result[200]); |
|
193 | - } |
|
194 | - |
|
195 | - |
|
196 | - public function testGetPropertiesForbidden(): void { |
|
197 | - $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
198 | - |
|
199 | - $systemTag = new SystemTag('1', 'Test', true, false); |
|
200 | - $requestedProperties = [ |
|
201 | - self::ID_PROPERTYNAME, |
|
202 | - self::GROUPS_PROPERTYNAME, |
|
203 | - ]; |
|
204 | - $this->user->expects($this->once()) |
|
205 | - ->method('getUID') |
|
206 | - ->willReturn('admin'); |
|
207 | - $this->groupManager |
|
208 | - ->expects($this->once()) |
|
209 | - ->method('isAdmin') |
|
210 | - ->with('admin') |
|
211 | - ->willReturn(false); |
|
212 | - |
|
213 | - $node = $this->getMockBuilder(SystemTagNode::class) |
|
214 | - ->disableOriginalConstructor() |
|
215 | - ->getMock(); |
|
216 | - $node->expects($this->any()) |
|
217 | - ->method('getSystemTag') |
|
218 | - ->willReturn($systemTag); |
|
219 | - |
|
220 | - $this->tree->expects($this->any()) |
|
221 | - ->method('getNodeForPath') |
|
222 | - ->with('/systemtag/1') |
|
223 | - ->willReturn($node); |
|
224 | - |
|
225 | - $propFind = new \Sabre\DAV\PropFind( |
|
226 | - '/systemtag/1', |
|
227 | - $requestedProperties, |
|
228 | - 0 |
|
229 | - ); |
|
230 | - |
|
231 | - $this->plugin->handleGetProperties( |
|
232 | - $propFind, |
|
233 | - $node |
|
234 | - ); |
|
235 | - } |
|
236 | - |
|
237 | - public function testUpdatePropertiesAdmin(): void { |
|
238 | - $systemTag = new SystemTag('1', 'Test', true, false); |
|
239 | - $this->user->expects($this->any()) |
|
240 | - ->method('getUID') |
|
241 | - ->willReturn('admin'); |
|
242 | - $this->groupManager |
|
243 | - ->expects($this->any()) |
|
244 | - ->method('isAdmin') |
|
245 | - ->with('admin') |
|
246 | - ->willReturn(true); |
|
247 | - |
|
248 | - $node = $this->getMockBuilder(SystemTagNode::class) |
|
249 | - ->disableOriginalConstructor() |
|
250 | - ->getMock(); |
|
251 | - $node->expects($this->any()) |
|
252 | - ->method('getSystemTag') |
|
253 | - ->willReturn($systemTag); |
|
254 | - |
|
255 | - $this->tree->expects($this->any()) |
|
256 | - ->method('getNodeForPath') |
|
257 | - ->with('/systemtag/1') |
|
258 | - ->willReturn($node); |
|
259 | - |
|
260 | - $node->expects($this->once()) |
|
261 | - ->method('update') |
|
262 | - ->with('Test changed', false, true); |
|
263 | - |
|
264 | - $this->tagManager->expects($this->once()) |
|
265 | - ->method('setTagGroups') |
|
266 | - ->with($systemTag, ['group1', 'group2']); |
|
267 | - |
|
268 | - // properties to set |
|
269 | - $propPatch = new \Sabre\DAV\PropPatch([ |
|
270 | - self::DISPLAYNAME_PROPERTYNAME => 'Test changed', |
|
271 | - self::USERVISIBLE_PROPERTYNAME => 'false', |
|
272 | - self::USERASSIGNABLE_PROPERTYNAME => 'true', |
|
273 | - self::GROUPS_PROPERTYNAME => 'group1|group2', |
|
274 | - ]); |
|
275 | - |
|
276 | - $this->plugin->handleUpdateProperties( |
|
277 | - '/systemtag/1', |
|
278 | - $propPatch |
|
279 | - ); |
|
280 | - |
|
281 | - $propPatch->commit(); |
|
282 | - |
|
283 | - // all requested properties removed, as they were processed already |
|
284 | - $this->assertEmpty($propPatch->getRemainingMutations()); |
|
285 | - |
|
286 | - $result = $propPatch->getResult(); |
|
287 | - $this->assertEquals(200, $result[self::DISPLAYNAME_PROPERTYNAME]); |
|
288 | - $this->assertEquals(200, $result[self::USERASSIGNABLE_PROPERTYNAME]); |
|
289 | - $this->assertEquals(200, $result[self::USERVISIBLE_PROPERTYNAME]); |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - public function testUpdatePropertiesForbidden(): void { |
|
294 | - $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
295 | - |
|
296 | - $systemTag = new SystemTag('1', 'Test', true, false); |
|
297 | - $this->user->expects($this->any()) |
|
298 | - ->method('getUID') |
|
299 | - ->willReturn('admin'); |
|
300 | - $this->groupManager |
|
301 | - ->expects($this->any()) |
|
302 | - ->method('isAdmin') |
|
303 | - ->with('admin') |
|
304 | - ->willReturn(false); |
|
305 | - |
|
306 | - $node = $this->getMockBuilder(SystemTagNode::class) |
|
307 | - ->disableOriginalConstructor() |
|
308 | - ->getMock(); |
|
309 | - $node->expects($this->any()) |
|
310 | - ->method('getSystemTag') |
|
311 | - ->willReturn($systemTag); |
|
312 | - |
|
313 | - $this->tree->expects($this->any()) |
|
314 | - ->method('getNodeForPath') |
|
315 | - ->with('/systemtag/1') |
|
316 | - ->willReturn($node); |
|
317 | - |
|
318 | - $node->expects($this->never()) |
|
319 | - ->method('update'); |
|
320 | - |
|
321 | - $this->tagManager->expects($this->never()) |
|
322 | - ->method('setTagGroups'); |
|
323 | - |
|
324 | - // properties to set |
|
325 | - $propPatch = new \Sabre\DAV\PropPatch([ |
|
326 | - self::GROUPS_PROPERTYNAME => 'group1|group2', |
|
327 | - ]); |
|
328 | - |
|
329 | - $this->plugin->handleUpdateProperties( |
|
330 | - '/systemtag/1', |
|
331 | - $propPatch |
|
332 | - ); |
|
333 | - |
|
334 | - $propPatch->commit(); |
|
335 | - } |
|
336 | - |
|
337 | - public static function createTagInsufficientPermissionsProvider(): array { |
|
338 | - return [ |
|
339 | - [true, false, ''], |
|
340 | - [false, true, ''], |
|
341 | - [true, true, 'group1|group2'], |
|
342 | - ]; |
|
343 | - } |
|
344 | - /** |
|
345 | - * @dataProvider createTagInsufficientPermissionsProvider |
|
346 | - */ |
|
347 | - public function testCreateNotAssignableTagAsRegularUser(bool $userVisible, bool $userAssignable, string $groups): void { |
|
348 | - $this->expectException(\Sabre\DAV\Exception\BadRequest::class); |
|
349 | - $this->expectExceptionMessage('Not sufficient permissions'); |
|
350 | - |
|
351 | - $this->user->expects($this->once()) |
|
352 | - ->method('getUID') |
|
353 | - ->willReturn('admin'); |
|
354 | - $this->groupManager |
|
355 | - ->expects($this->once()) |
|
356 | - ->method('isAdmin') |
|
357 | - ->with('admin') |
|
358 | - ->willReturn(false); |
|
359 | - |
|
360 | - $requestData = [ |
|
361 | - 'name' => 'Test', |
|
362 | - 'userVisible' => $userVisible, |
|
363 | - 'userAssignable' => $userAssignable, |
|
364 | - ]; |
|
365 | - if (!empty($groups)) { |
|
366 | - $requestData['groups'] = $groups; |
|
367 | - } |
|
368 | - $requestData = json_encode($requestData); |
|
369 | - |
|
370 | - $node = $this->createMock(SystemTagsByIdCollection::class); |
|
371 | - $this->tagManager->expects($this->never()) |
|
372 | - ->method('createTag'); |
|
373 | - $this->tagManager->expects($this->never()) |
|
374 | - ->method('setTagGroups'); |
|
375 | - |
|
376 | - $this->tree->expects($this->any()) |
|
377 | - ->method('getNodeForPath') |
|
378 | - ->with('/systemtags') |
|
379 | - ->willReturn($node); |
|
380 | - |
|
381 | - $request = $this->createMock(RequestInterface::class); |
|
382 | - $response = $this->createMock(ResponseInterface::class); |
|
383 | - |
|
384 | - $request->expects($this->once()) |
|
385 | - ->method('getPath') |
|
386 | - ->willReturn('/systemtags'); |
|
387 | - |
|
388 | - $request->expects($this->once()) |
|
389 | - ->method('getBodyAsString') |
|
390 | - ->willReturn($requestData); |
|
391 | - |
|
392 | - $request->expects($this->once()) |
|
393 | - ->method('getHeader') |
|
394 | - ->with('Content-Type') |
|
395 | - ->willReturn('application/json'); |
|
396 | - |
|
397 | - $this->plugin->httpPost($request, $response); |
|
398 | - } |
|
399 | - |
|
400 | - public function testCreateTagInByIdCollectionAsRegularUser(): void { |
|
401 | - $systemTag = new SystemTag('1', 'Test', true, false); |
|
402 | - |
|
403 | - $requestData = json_encode([ |
|
404 | - 'name' => 'Test', |
|
405 | - 'userVisible' => true, |
|
406 | - 'userAssignable' => true, |
|
407 | - ]); |
|
408 | - |
|
409 | - $node = $this->createMock(SystemTagsByIdCollection::class); |
|
410 | - $this->tagManager->expects($this->once()) |
|
411 | - ->method('createTag') |
|
412 | - ->with('Test', true, true) |
|
413 | - ->willReturn($systemTag); |
|
414 | - |
|
415 | - $this->tree->expects($this->any()) |
|
416 | - ->method('getNodeForPath') |
|
417 | - ->with('/systemtags') |
|
418 | - ->willReturn($node); |
|
419 | - |
|
420 | - $request = $this->createMock(RequestInterface::class); |
|
421 | - $response = $this->createMock(ResponseInterface::class); |
|
422 | - |
|
423 | - $request->expects($this->once()) |
|
424 | - ->method('getPath') |
|
425 | - ->willReturn('/systemtags'); |
|
426 | - |
|
427 | - $request->expects($this->once()) |
|
428 | - ->method('getBodyAsString') |
|
429 | - ->willReturn($requestData); |
|
430 | - |
|
431 | - $request->expects($this->once()) |
|
432 | - ->method('getHeader') |
|
433 | - ->with('Content-Type') |
|
434 | - ->willReturn('application/json'); |
|
435 | - |
|
436 | - $request->expects($this->once()) |
|
437 | - ->method('getUrl') |
|
438 | - ->willReturn('http://example.com/dav/systemtags'); |
|
439 | - |
|
440 | - $response->expects($this->once()) |
|
441 | - ->method('setHeader') |
|
442 | - ->with('Content-Location', 'http://example.com/dav/systemtags/1'); |
|
443 | - |
|
444 | - $this->plugin->httpPost($request, $response); |
|
445 | - } |
|
446 | - |
|
447 | - public static function createTagProvider(): array { |
|
448 | - return [ |
|
449 | - [true, false, ''], |
|
450 | - [false, false, ''], |
|
451 | - [true, false, 'group1|group2'], |
|
452 | - ]; |
|
453 | - } |
|
454 | - |
|
455 | - /** |
|
456 | - * @dataProvider createTagProvider |
|
457 | - */ |
|
458 | - public function testCreateTagInByIdCollection(bool $userVisible, bool $userAssignable, string $groups): void { |
|
459 | - $this->user->expects($this->once()) |
|
460 | - ->method('getUID') |
|
461 | - ->willReturn('admin'); |
|
462 | - $this->groupManager |
|
463 | - ->expects($this->once()) |
|
464 | - ->method('isAdmin') |
|
465 | - ->with('admin') |
|
466 | - ->willReturn(true); |
|
467 | - |
|
468 | - $systemTag = new SystemTag('1', 'Test', true, false); |
|
469 | - |
|
470 | - $requestData = [ |
|
471 | - 'name' => 'Test', |
|
472 | - 'userVisible' => $userVisible, |
|
473 | - 'userAssignable' => $userAssignable, |
|
474 | - ]; |
|
475 | - if (!empty($groups)) { |
|
476 | - $requestData['groups'] = $groups; |
|
477 | - } |
|
478 | - $requestData = json_encode($requestData); |
|
479 | - |
|
480 | - $node = $this->createMock(SystemTagsByIdCollection::class); |
|
481 | - $this->tagManager->expects($this->once()) |
|
482 | - ->method('createTag') |
|
483 | - ->with('Test', $userVisible, $userAssignable) |
|
484 | - ->willReturn($systemTag); |
|
485 | - |
|
486 | - if (!empty($groups)) { |
|
487 | - $this->tagManager->expects($this->once()) |
|
488 | - ->method('setTagGroups') |
|
489 | - ->with($systemTag, explode('|', $groups)) |
|
490 | - ->willReturn($systemTag); |
|
491 | - } else { |
|
492 | - $this->tagManager->expects($this->never()) |
|
493 | - ->method('setTagGroups'); |
|
494 | - } |
|
495 | - |
|
496 | - $this->tree->expects($this->any()) |
|
497 | - ->method('getNodeForPath') |
|
498 | - ->with('/systemtags') |
|
499 | - ->willReturn($node); |
|
500 | - |
|
501 | - $request = $this->createMock(RequestInterface::class); |
|
502 | - $response = $this->createMock(ResponseInterface::class); |
|
503 | - |
|
504 | - $request->expects($this->once()) |
|
505 | - ->method('getPath') |
|
506 | - ->willReturn('/systemtags'); |
|
507 | - |
|
508 | - $request->expects($this->once()) |
|
509 | - ->method('getBodyAsString') |
|
510 | - ->willReturn($requestData); |
|
511 | - |
|
512 | - $request->expects($this->once()) |
|
513 | - ->method('getHeader') |
|
514 | - ->with('Content-Type') |
|
515 | - ->willReturn('application/json'); |
|
516 | - |
|
517 | - $request->expects($this->once()) |
|
518 | - ->method('getUrl') |
|
519 | - ->willReturn('http://example.com/dav/systemtags'); |
|
520 | - |
|
521 | - $response->expects($this->once()) |
|
522 | - ->method('setHeader') |
|
523 | - ->with('Content-Location', 'http://example.com/dav/systemtags/1'); |
|
524 | - |
|
525 | - $this->plugin->httpPost($request, $response); |
|
526 | - } |
|
527 | - |
|
528 | - public static function nodeClassProvider(): array { |
|
529 | - return [ |
|
530 | - ['\OCA\DAV\SystemTag\SystemTagsByIdCollection'], |
|
531 | - ['\OCA\DAV\SystemTag\SystemTagsObjectMappingCollection'], |
|
532 | - ]; |
|
533 | - } |
|
534 | - |
|
535 | - public function testCreateTagInMappingCollection(): void { |
|
536 | - $this->user->expects($this->once()) |
|
537 | - ->method('getUID') |
|
538 | - ->willReturn('admin'); |
|
539 | - $this->groupManager |
|
540 | - ->expects($this->once()) |
|
541 | - ->method('isAdmin') |
|
542 | - ->with('admin') |
|
543 | - ->willReturn(true); |
|
544 | - |
|
545 | - $systemTag = new SystemTag('1', 'Test', true, false); |
|
546 | - |
|
547 | - $requestData = json_encode([ |
|
548 | - 'name' => 'Test', |
|
549 | - 'userVisible' => true, |
|
550 | - 'userAssignable' => false, |
|
551 | - ]); |
|
552 | - |
|
553 | - $node = $this->createMock(SystemTagsObjectMappingCollection::class); |
|
554 | - |
|
555 | - $this->tagManager->expects($this->once()) |
|
556 | - ->method('createTag') |
|
557 | - ->with('Test', true, false) |
|
558 | - ->willReturn($systemTag); |
|
559 | - |
|
560 | - $this->tree->expects($this->any()) |
|
561 | - ->method('getNodeForPath') |
|
562 | - ->with('/systemtags-relations/files/12') |
|
563 | - ->willReturn($node); |
|
564 | - |
|
565 | - $node->expects($this->once()) |
|
566 | - ->method('createFile') |
|
567 | - ->with(1); |
|
568 | - |
|
569 | - $request = $this->createMock(RequestInterface::class); |
|
570 | - $response = $this->createMock(ResponseInterface::class); |
|
571 | - |
|
572 | - $request->expects($this->once()) |
|
573 | - ->method('getPath') |
|
574 | - ->willReturn('/systemtags-relations/files/12'); |
|
575 | - |
|
576 | - $request->expects($this->once()) |
|
577 | - ->method('getBodyAsString') |
|
578 | - ->willReturn($requestData); |
|
579 | - |
|
580 | - $request->expects($this->once()) |
|
581 | - ->method('getHeader') |
|
582 | - ->with('Content-Type') |
|
583 | - ->willReturn('application/json'); |
|
584 | - |
|
585 | - $request->expects($this->once()) |
|
586 | - ->method('getBaseUrl') |
|
587 | - ->willReturn('http://example.com/dav/'); |
|
588 | - |
|
589 | - $response->expects($this->once()) |
|
590 | - ->method('setHeader') |
|
591 | - ->with('Content-Location', 'http://example.com/dav/systemtags/1'); |
|
592 | - |
|
593 | - $this->plugin->httpPost($request, $response); |
|
594 | - } |
|
595 | - |
|
596 | - |
|
597 | - public function testCreateTagToUnknownNode(): void { |
|
598 | - $this->expectException(\Sabre\DAV\Exception\NotFound::class); |
|
599 | - |
|
600 | - $node = $this->createMock(SystemTagsObjectMappingCollection::class); |
|
601 | - |
|
602 | - $this->tree->expects($this->any()) |
|
603 | - ->method('getNodeForPath') |
|
604 | - ->will($this->throwException(new \Sabre\DAV\Exception\NotFound())); |
|
605 | - |
|
606 | - $this->tagManager->expects($this->never()) |
|
607 | - ->method('createTag'); |
|
608 | - |
|
609 | - $node->expects($this->never()) |
|
610 | - ->method('createFile'); |
|
611 | - |
|
612 | - $request = $this->createMock(RequestInterface::class); |
|
613 | - $response = $this->createMock(ResponseInterface::class); |
|
614 | - |
|
615 | - $request->expects($this->once()) |
|
616 | - ->method('getPath') |
|
617 | - ->willReturn('/systemtags-relations/files/12'); |
|
618 | - |
|
619 | - $this->plugin->httpPost($request, $response); |
|
620 | - } |
|
621 | - |
|
622 | - /** |
|
623 | - * @dataProvider nodeClassProvider |
|
624 | - */ |
|
625 | - public function testCreateTagConflict(string $nodeClass): void { |
|
626 | - $this->expectException(\Sabre\DAV\Exception\Conflict::class); |
|
627 | - |
|
628 | - $this->user->expects($this->once()) |
|
629 | - ->method('getUID') |
|
630 | - ->willReturn('admin'); |
|
631 | - $this->groupManager |
|
632 | - ->expects($this->once()) |
|
633 | - ->method('isAdmin') |
|
634 | - ->with('admin') |
|
635 | - ->willReturn(true); |
|
636 | - |
|
637 | - $requestData = json_encode([ |
|
638 | - 'name' => 'Test', |
|
639 | - 'userVisible' => true, |
|
640 | - 'userAssignable' => false, |
|
641 | - ]); |
|
30 | + public const ID_PROPERTYNAME = SystemTagPlugin::ID_PROPERTYNAME; |
|
31 | + public const DISPLAYNAME_PROPERTYNAME = SystemTagPlugin::DISPLAYNAME_PROPERTYNAME; |
|
32 | + public const USERVISIBLE_PROPERTYNAME = SystemTagPlugin::USERVISIBLE_PROPERTYNAME; |
|
33 | + public const USERASSIGNABLE_PROPERTYNAME = SystemTagPlugin::USERASSIGNABLE_PROPERTYNAME; |
|
34 | + public const CANASSIGN_PROPERTYNAME = SystemTagPlugin::CANASSIGN_PROPERTYNAME; |
|
35 | + public const GROUPS_PROPERTYNAME = SystemTagPlugin::GROUPS_PROPERTYNAME; |
|
36 | + |
|
37 | + private \Sabre\DAV\Server $server; |
|
38 | + private \Sabre\DAV\Tree&MockObject $tree; |
|
39 | + private ISystemTagManager&MockObject $tagManager; |
|
40 | + private IGroupManager&MockObject $groupManager; |
|
41 | + private IUserSession&MockObject $userSession; |
|
42 | + private IRootFolder&MockObject $rootFolder; |
|
43 | + private IUser&MockObject $user; |
|
44 | + private ISystemTagObjectMapper&MockObject $tagMapper; |
|
45 | + private SystemTagPlugin $plugin; |
|
46 | + |
|
47 | + protected function setUp(): void { |
|
48 | + parent::setUp(); |
|
49 | + $this->tree = $this->createMock(Tree::class); |
|
50 | + |
|
51 | + $this->server = new \Sabre\DAV\Server($this->tree); |
|
52 | + |
|
53 | + $this->tagManager = $this->createMock(ISystemTagManager::class); |
|
54 | + $this->groupManager = $this->createMock(IGroupManager::class); |
|
55 | + $this->user = $this->createMock(IUser::class); |
|
56 | + $this->userSession = $this->createMock(IUserSession::class); |
|
57 | + $this->userSession |
|
58 | + ->expects($this->any()) |
|
59 | + ->method('getUser') |
|
60 | + ->willReturn($this->user); |
|
61 | + $this->userSession |
|
62 | + ->expects($this->any()) |
|
63 | + ->method('isLoggedIn') |
|
64 | + ->willReturn(true); |
|
65 | + |
|
66 | + $this->tagMapper = $this->createMock(ISystemTagObjectMapper::class); |
|
67 | + $this->rootFolder = $this->createMock(IRootFolder::class); |
|
68 | + |
|
69 | + $this->plugin = new SystemTagPlugin( |
|
70 | + $this->tagManager, |
|
71 | + $this->groupManager, |
|
72 | + $this->userSession, |
|
73 | + $this->rootFolder, |
|
74 | + $this->tagMapper |
|
75 | + ); |
|
76 | + $this->plugin->initialize($this->server); |
|
77 | + } |
|
78 | + |
|
79 | + public static function getPropertiesDataProvider(): array { |
|
80 | + return [ |
|
81 | + [ |
|
82 | + new SystemTag('1', 'Test', true, true), |
|
83 | + [], |
|
84 | + [ |
|
85 | + self::ID_PROPERTYNAME, |
|
86 | + self::DISPLAYNAME_PROPERTYNAME, |
|
87 | + self::USERVISIBLE_PROPERTYNAME, |
|
88 | + self::USERASSIGNABLE_PROPERTYNAME, |
|
89 | + self::CANASSIGN_PROPERTYNAME, |
|
90 | + ], |
|
91 | + [ |
|
92 | + self::ID_PROPERTYNAME => '1', |
|
93 | + self::DISPLAYNAME_PROPERTYNAME => 'Test', |
|
94 | + self::USERVISIBLE_PROPERTYNAME => 'true', |
|
95 | + self::USERASSIGNABLE_PROPERTYNAME => 'true', |
|
96 | + self::CANASSIGN_PROPERTYNAME => 'true', |
|
97 | + ] |
|
98 | + ], |
|
99 | + [ |
|
100 | + new SystemTag('1', 'Test', true, false), |
|
101 | + [], |
|
102 | + [ |
|
103 | + self::ID_PROPERTYNAME, |
|
104 | + self::DISPLAYNAME_PROPERTYNAME, |
|
105 | + self::USERVISIBLE_PROPERTYNAME, |
|
106 | + self::USERASSIGNABLE_PROPERTYNAME, |
|
107 | + self::CANASSIGN_PROPERTYNAME, |
|
108 | + ], |
|
109 | + [ |
|
110 | + self::ID_PROPERTYNAME => '1', |
|
111 | + self::DISPLAYNAME_PROPERTYNAME => 'Test', |
|
112 | + self::USERVISIBLE_PROPERTYNAME => 'true', |
|
113 | + self::USERASSIGNABLE_PROPERTYNAME => 'false', |
|
114 | + self::CANASSIGN_PROPERTYNAME => 'false', |
|
115 | + ] |
|
116 | + ], |
|
117 | + [ |
|
118 | + new SystemTag('1', 'Test', true, false), |
|
119 | + ['group1', 'group2'], |
|
120 | + [ |
|
121 | + self::ID_PROPERTYNAME, |
|
122 | + self::GROUPS_PROPERTYNAME, |
|
123 | + ], |
|
124 | + [ |
|
125 | + self::ID_PROPERTYNAME => '1', |
|
126 | + self::GROUPS_PROPERTYNAME => 'group1|group2', |
|
127 | + ] |
|
128 | + ], |
|
129 | + [ |
|
130 | + new SystemTag('1', 'Test', true, true), |
|
131 | + ['group1', 'group2'], |
|
132 | + [ |
|
133 | + self::ID_PROPERTYNAME, |
|
134 | + self::GROUPS_PROPERTYNAME, |
|
135 | + ], |
|
136 | + [ |
|
137 | + self::ID_PROPERTYNAME => '1', |
|
138 | + // groups only returned when userAssignable is false |
|
139 | + self::GROUPS_PROPERTYNAME => '', |
|
140 | + ] |
|
141 | + ], |
|
142 | + ]; |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * @dataProvider getPropertiesDataProvider |
|
147 | + */ |
|
148 | + public function testGetProperties(ISystemTag $systemTag, array $groups, array $requestedProperties, array $expectedProperties): void { |
|
149 | + $this->user->expects($this->any()) |
|
150 | + ->method('getUID') |
|
151 | + ->willReturn('admin'); |
|
152 | + $this->groupManager |
|
153 | + ->expects($this->any()) |
|
154 | + ->method('isAdmin') |
|
155 | + ->with('admin') |
|
156 | + ->willReturn(true); |
|
157 | + |
|
158 | + $node = $this->getMockBuilder(SystemTagNode::class) |
|
159 | + ->disableOriginalConstructor() |
|
160 | + ->getMock(); |
|
161 | + $node->expects($this->any()) |
|
162 | + ->method('getSystemTag') |
|
163 | + ->willReturn($systemTag); |
|
164 | + |
|
165 | + $this->tagManager->expects($this->any()) |
|
166 | + ->method('canUserAssignTag') |
|
167 | + ->willReturn($systemTag->isUserAssignable()); |
|
168 | + |
|
169 | + $this->tagManager->expects($this->any()) |
|
170 | + ->method('getTagGroups') |
|
171 | + ->willReturn($groups); |
|
172 | + |
|
173 | + $this->tree->expects($this->any()) |
|
174 | + ->method('getNodeForPath') |
|
175 | + ->with('/systemtag/1') |
|
176 | + ->willReturn($node); |
|
177 | + |
|
178 | + $propFind = new \Sabre\DAV\PropFind( |
|
179 | + '/systemtag/1', |
|
180 | + $requestedProperties, |
|
181 | + 0 |
|
182 | + ); |
|
183 | + |
|
184 | + $this->plugin->handleGetProperties( |
|
185 | + $propFind, |
|
186 | + $node |
|
187 | + ); |
|
188 | + |
|
189 | + $result = $propFind->getResultForMultiStatus(); |
|
190 | + |
|
191 | + $this->assertEmpty($result[404]); |
|
192 | + $this->assertEquals($expectedProperties, $result[200]); |
|
193 | + } |
|
194 | + |
|
195 | + |
|
196 | + public function testGetPropertiesForbidden(): void { |
|
197 | + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
198 | + |
|
199 | + $systemTag = new SystemTag('1', 'Test', true, false); |
|
200 | + $requestedProperties = [ |
|
201 | + self::ID_PROPERTYNAME, |
|
202 | + self::GROUPS_PROPERTYNAME, |
|
203 | + ]; |
|
204 | + $this->user->expects($this->once()) |
|
205 | + ->method('getUID') |
|
206 | + ->willReturn('admin'); |
|
207 | + $this->groupManager |
|
208 | + ->expects($this->once()) |
|
209 | + ->method('isAdmin') |
|
210 | + ->with('admin') |
|
211 | + ->willReturn(false); |
|
212 | + |
|
213 | + $node = $this->getMockBuilder(SystemTagNode::class) |
|
214 | + ->disableOriginalConstructor() |
|
215 | + ->getMock(); |
|
216 | + $node->expects($this->any()) |
|
217 | + ->method('getSystemTag') |
|
218 | + ->willReturn($systemTag); |
|
219 | + |
|
220 | + $this->tree->expects($this->any()) |
|
221 | + ->method('getNodeForPath') |
|
222 | + ->with('/systemtag/1') |
|
223 | + ->willReturn($node); |
|
224 | + |
|
225 | + $propFind = new \Sabre\DAV\PropFind( |
|
226 | + '/systemtag/1', |
|
227 | + $requestedProperties, |
|
228 | + 0 |
|
229 | + ); |
|
230 | + |
|
231 | + $this->plugin->handleGetProperties( |
|
232 | + $propFind, |
|
233 | + $node |
|
234 | + ); |
|
235 | + } |
|
236 | + |
|
237 | + public function testUpdatePropertiesAdmin(): void { |
|
238 | + $systemTag = new SystemTag('1', 'Test', true, false); |
|
239 | + $this->user->expects($this->any()) |
|
240 | + ->method('getUID') |
|
241 | + ->willReturn('admin'); |
|
242 | + $this->groupManager |
|
243 | + ->expects($this->any()) |
|
244 | + ->method('isAdmin') |
|
245 | + ->with('admin') |
|
246 | + ->willReturn(true); |
|
247 | + |
|
248 | + $node = $this->getMockBuilder(SystemTagNode::class) |
|
249 | + ->disableOriginalConstructor() |
|
250 | + ->getMock(); |
|
251 | + $node->expects($this->any()) |
|
252 | + ->method('getSystemTag') |
|
253 | + ->willReturn($systemTag); |
|
254 | + |
|
255 | + $this->tree->expects($this->any()) |
|
256 | + ->method('getNodeForPath') |
|
257 | + ->with('/systemtag/1') |
|
258 | + ->willReturn($node); |
|
259 | + |
|
260 | + $node->expects($this->once()) |
|
261 | + ->method('update') |
|
262 | + ->with('Test changed', false, true); |
|
263 | + |
|
264 | + $this->tagManager->expects($this->once()) |
|
265 | + ->method('setTagGroups') |
|
266 | + ->with($systemTag, ['group1', 'group2']); |
|
267 | + |
|
268 | + // properties to set |
|
269 | + $propPatch = new \Sabre\DAV\PropPatch([ |
|
270 | + self::DISPLAYNAME_PROPERTYNAME => 'Test changed', |
|
271 | + self::USERVISIBLE_PROPERTYNAME => 'false', |
|
272 | + self::USERASSIGNABLE_PROPERTYNAME => 'true', |
|
273 | + self::GROUPS_PROPERTYNAME => 'group1|group2', |
|
274 | + ]); |
|
275 | + |
|
276 | + $this->plugin->handleUpdateProperties( |
|
277 | + '/systemtag/1', |
|
278 | + $propPatch |
|
279 | + ); |
|
280 | + |
|
281 | + $propPatch->commit(); |
|
282 | + |
|
283 | + // all requested properties removed, as they were processed already |
|
284 | + $this->assertEmpty($propPatch->getRemainingMutations()); |
|
285 | + |
|
286 | + $result = $propPatch->getResult(); |
|
287 | + $this->assertEquals(200, $result[self::DISPLAYNAME_PROPERTYNAME]); |
|
288 | + $this->assertEquals(200, $result[self::USERASSIGNABLE_PROPERTYNAME]); |
|
289 | + $this->assertEquals(200, $result[self::USERVISIBLE_PROPERTYNAME]); |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + public function testUpdatePropertiesForbidden(): void { |
|
294 | + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
295 | + |
|
296 | + $systemTag = new SystemTag('1', 'Test', true, false); |
|
297 | + $this->user->expects($this->any()) |
|
298 | + ->method('getUID') |
|
299 | + ->willReturn('admin'); |
|
300 | + $this->groupManager |
|
301 | + ->expects($this->any()) |
|
302 | + ->method('isAdmin') |
|
303 | + ->with('admin') |
|
304 | + ->willReturn(false); |
|
305 | + |
|
306 | + $node = $this->getMockBuilder(SystemTagNode::class) |
|
307 | + ->disableOriginalConstructor() |
|
308 | + ->getMock(); |
|
309 | + $node->expects($this->any()) |
|
310 | + ->method('getSystemTag') |
|
311 | + ->willReturn($systemTag); |
|
312 | + |
|
313 | + $this->tree->expects($this->any()) |
|
314 | + ->method('getNodeForPath') |
|
315 | + ->with('/systemtag/1') |
|
316 | + ->willReturn($node); |
|
317 | + |
|
318 | + $node->expects($this->never()) |
|
319 | + ->method('update'); |
|
320 | + |
|
321 | + $this->tagManager->expects($this->never()) |
|
322 | + ->method('setTagGroups'); |
|
323 | + |
|
324 | + // properties to set |
|
325 | + $propPatch = new \Sabre\DAV\PropPatch([ |
|
326 | + self::GROUPS_PROPERTYNAME => 'group1|group2', |
|
327 | + ]); |
|
328 | + |
|
329 | + $this->plugin->handleUpdateProperties( |
|
330 | + '/systemtag/1', |
|
331 | + $propPatch |
|
332 | + ); |
|
333 | + |
|
334 | + $propPatch->commit(); |
|
335 | + } |
|
336 | + |
|
337 | + public static function createTagInsufficientPermissionsProvider(): array { |
|
338 | + return [ |
|
339 | + [true, false, ''], |
|
340 | + [false, true, ''], |
|
341 | + [true, true, 'group1|group2'], |
|
342 | + ]; |
|
343 | + } |
|
344 | + /** |
|
345 | + * @dataProvider createTagInsufficientPermissionsProvider |
|
346 | + */ |
|
347 | + public function testCreateNotAssignableTagAsRegularUser(bool $userVisible, bool $userAssignable, string $groups): void { |
|
348 | + $this->expectException(\Sabre\DAV\Exception\BadRequest::class); |
|
349 | + $this->expectExceptionMessage('Not sufficient permissions'); |
|
350 | + |
|
351 | + $this->user->expects($this->once()) |
|
352 | + ->method('getUID') |
|
353 | + ->willReturn('admin'); |
|
354 | + $this->groupManager |
|
355 | + ->expects($this->once()) |
|
356 | + ->method('isAdmin') |
|
357 | + ->with('admin') |
|
358 | + ->willReturn(false); |
|
359 | + |
|
360 | + $requestData = [ |
|
361 | + 'name' => 'Test', |
|
362 | + 'userVisible' => $userVisible, |
|
363 | + 'userAssignable' => $userAssignable, |
|
364 | + ]; |
|
365 | + if (!empty($groups)) { |
|
366 | + $requestData['groups'] = $groups; |
|
367 | + } |
|
368 | + $requestData = json_encode($requestData); |
|
369 | + |
|
370 | + $node = $this->createMock(SystemTagsByIdCollection::class); |
|
371 | + $this->tagManager->expects($this->never()) |
|
372 | + ->method('createTag'); |
|
373 | + $this->tagManager->expects($this->never()) |
|
374 | + ->method('setTagGroups'); |
|
375 | + |
|
376 | + $this->tree->expects($this->any()) |
|
377 | + ->method('getNodeForPath') |
|
378 | + ->with('/systemtags') |
|
379 | + ->willReturn($node); |
|
380 | + |
|
381 | + $request = $this->createMock(RequestInterface::class); |
|
382 | + $response = $this->createMock(ResponseInterface::class); |
|
383 | + |
|
384 | + $request->expects($this->once()) |
|
385 | + ->method('getPath') |
|
386 | + ->willReturn('/systemtags'); |
|
387 | + |
|
388 | + $request->expects($this->once()) |
|
389 | + ->method('getBodyAsString') |
|
390 | + ->willReturn($requestData); |
|
391 | + |
|
392 | + $request->expects($this->once()) |
|
393 | + ->method('getHeader') |
|
394 | + ->with('Content-Type') |
|
395 | + ->willReturn('application/json'); |
|
396 | + |
|
397 | + $this->plugin->httpPost($request, $response); |
|
398 | + } |
|
399 | + |
|
400 | + public function testCreateTagInByIdCollectionAsRegularUser(): void { |
|
401 | + $systemTag = new SystemTag('1', 'Test', true, false); |
|
402 | + |
|
403 | + $requestData = json_encode([ |
|
404 | + 'name' => 'Test', |
|
405 | + 'userVisible' => true, |
|
406 | + 'userAssignable' => true, |
|
407 | + ]); |
|
408 | + |
|
409 | + $node = $this->createMock(SystemTagsByIdCollection::class); |
|
410 | + $this->tagManager->expects($this->once()) |
|
411 | + ->method('createTag') |
|
412 | + ->with('Test', true, true) |
|
413 | + ->willReturn($systemTag); |
|
414 | + |
|
415 | + $this->tree->expects($this->any()) |
|
416 | + ->method('getNodeForPath') |
|
417 | + ->with('/systemtags') |
|
418 | + ->willReturn($node); |
|
419 | + |
|
420 | + $request = $this->createMock(RequestInterface::class); |
|
421 | + $response = $this->createMock(ResponseInterface::class); |
|
422 | + |
|
423 | + $request->expects($this->once()) |
|
424 | + ->method('getPath') |
|
425 | + ->willReturn('/systemtags'); |
|
426 | + |
|
427 | + $request->expects($this->once()) |
|
428 | + ->method('getBodyAsString') |
|
429 | + ->willReturn($requestData); |
|
430 | + |
|
431 | + $request->expects($this->once()) |
|
432 | + ->method('getHeader') |
|
433 | + ->with('Content-Type') |
|
434 | + ->willReturn('application/json'); |
|
435 | + |
|
436 | + $request->expects($this->once()) |
|
437 | + ->method('getUrl') |
|
438 | + ->willReturn('http://example.com/dav/systemtags'); |
|
439 | + |
|
440 | + $response->expects($this->once()) |
|
441 | + ->method('setHeader') |
|
442 | + ->with('Content-Location', 'http://example.com/dav/systemtags/1'); |
|
443 | + |
|
444 | + $this->plugin->httpPost($request, $response); |
|
445 | + } |
|
446 | + |
|
447 | + public static function createTagProvider(): array { |
|
448 | + return [ |
|
449 | + [true, false, ''], |
|
450 | + [false, false, ''], |
|
451 | + [true, false, 'group1|group2'], |
|
452 | + ]; |
|
453 | + } |
|
454 | + |
|
455 | + /** |
|
456 | + * @dataProvider createTagProvider |
|
457 | + */ |
|
458 | + public function testCreateTagInByIdCollection(bool $userVisible, bool $userAssignable, string $groups): void { |
|
459 | + $this->user->expects($this->once()) |
|
460 | + ->method('getUID') |
|
461 | + ->willReturn('admin'); |
|
462 | + $this->groupManager |
|
463 | + ->expects($this->once()) |
|
464 | + ->method('isAdmin') |
|
465 | + ->with('admin') |
|
466 | + ->willReturn(true); |
|
467 | + |
|
468 | + $systemTag = new SystemTag('1', 'Test', true, false); |
|
469 | + |
|
470 | + $requestData = [ |
|
471 | + 'name' => 'Test', |
|
472 | + 'userVisible' => $userVisible, |
|
473 | + 'userAssignable' => $userAssignable, |
|
474 | + ]; |
|
475 | + if (!empty($groups)) { |
|
476 | + $requestData['groups'] = $groups; |
|
477 | + } |
|
478 | + $requestData = json_encode($requestData); |
|
479 | + |
|
480 | + $node = $this->createMock(SystemTagsByIdCollection::class); |
|
481 | + $this->tagManager->expects($this->once()) |
|
482 | + ->method('createTag') |
|
483 | + ->with('Test', $userVisible, $userAssignable) |
|
484 | + ->willReturn($systemTag); |
|
485 | + |
|
486 | + if (!empty($groups)) { |
|
487 | + $this->tagManager->expects($this->once()) |
|
488 | + ->method('setTagGroups') |
|
489 | + ->with($systemTag, explode('|', $groups)) |
|
490 | + ->willReturn($systemTag); |
|
491 | + } else { |
|
492 | + $this->tagManager->expects($this->never()) |
|
493 | + ->method('setTagGroups'); |
|
494 | + } |
|
495 | + |
|
496 | + $this->tree->expects($this->any()) |
|
497 | + ->method('getNodeForPath') |
|
498 | + ->with('/systemtags') |
|
499 | + ->willReturn($node); |
|
500 | + |
|
501 | + $request = $this->createMock(RequestInterface::class); |
|
502 | + $response = $this->createMock(ResponseInterface::class); |
|
503 | + |
|
504 | + $request->expects($this->once()) |
|
505 | + ->method('getPath') |
|
506 | + ->willReturn('/systemtags'); |
|
507 | + |
|
508 | + $request->expects($this->once()) |
|
509 | + ->method('getBodyAsString') |
|
510 | + ->willReturn($requestData); |
|
511 | + |
|
512 | + $request->expects($this->once()) |
|
513 | + ->method('getHeader') |
|
514 | + ->with('Content-Type') |
|
515 | + ->willReturn('application/json'); |
|
516 | + |
|
517 | + $request->expects($this->once()) |
|
518 | + ->method('getUrl') |
|
519 | + ->willReturn('http://example.com/dav/systemtags'); |
|
520 | + |
|
521 | + $response->expects($this->once()) |
|
522 | + ->method('setHeader') |
|
523 | + ->with('Content-Location', 'http://example.com/dav/systemtags/1'); |
|
524 | + |
|
525 | + $this->plugin->httpPost($request, $response); |
|
526 | + } |
|
527 | + |
|
528 | + public static function nodeClassProvider(): array { |
|
529 | + return [ |
|
530 | + ['\OCA\DAV\SystemTag\SystemTagsByIdCollection'], |
|
531 | + ['\OCA\DAV\SystemTag\SystemTagsObjectMappingCollection'], |
|
532 | + ]; |
|
533 | + } |
|
534 | + |
|
535 | + public function testCreateTagInMappingCollection(): void { |
|
536 | + $this->user->expects($this->once()) |
|
537 | + ->method('getUID') |
|
538 | + ->willReturn('admin'); |
|
539 | + $this->groupManager |
|
540 | + ->expects($this->once()) |
|
541 | + ->method('isAdmin') |
|
542 | + ->with('admin') |
|
543 | + ->willReturn(true); |
|
544 | + |
|
545 | + $systemTag = new SystemTag('1', 'Test', true, false); |
|
546 | + |
|
547 | + $requestData = json_encode([ |
|
548 | + 'name' => 'Test', |
|
549 | + 'userVisible' => true, |
|
550 | + 'userAssignable' => false, |
|
551 | + ]); |
|
552 | + |
|
553 | + $node = $this->createMock(SystemTagsObjectMappingCollection::class); |
|
554 | + |
|
555 | + $this->tagManager->expects($this->once()) |
|
556 | + ->method('createTag') |
|
557 | + ->with('Test', true, false) |
|
558 | + ->willReturn($systemTag); |
|
559 | + |
|
560 | + $this->tree->expects($this->any()) |
|
561 | + ->method('getNodeForPath') |
|
562 | + ->with('/systemtags-relations/files/12') |
|
563 | + ->willReturn($node); |
|
564 | + |
|
565 | + $node->expects($this->once()) |
|
566 | + ->method('createFile') |
|
567 | + ->with(1); |
|
568 | + |
|
569 | + $request = $this->createMock(RequestInterface::class); |
|
570 | + $response = $this->createMock(ResponseInterface::class); |
|
571 | + |
|
572 | + $request->expects($this->once()) |
|
573 | + ->method('getPath') |
|
574 | + ->willReturn('/systemtags-relations/files/12'); |
|
575 | + |
|
576 | + $request->expects($this->once()) |
|
577 | + ->method('getBodyAsString') |
|
578 | + ->willReturn($requestData); |
|
579 | + |
|
580 | + $request->expects($this->once()) |
|
581 | + ->method('getHeader') |
|
582 | + ->with('Content-Type') |
|
583 | + ->willReturn('application/json'); |
|
584 | + |
|
585 | + $request->expects($this->once()) |
|
586 | + ->method('getBaseUrl') |
|
587 | + ->willReturn('http://example.com/dav/'); |
|
588 | + |
|
589 | + $response->expects($this->once()) |
|
590 | + ->method('setHeader') |
|
591 | + ->with('Content-Location', 'http://example.com/dav/systemtags/1'); |
|
592 | + |
|
593 | + $this->plugin->httpPost($request, $response); |
|
594 | + } |
|
595 | + |
|
596 | + |
|
597 | + public function testCreateTagToUnknownNode(): void { |
|
598 | + $this->expectException(\Sabre\DAV\Exception\NotFound::class); |
|
599 | + |
|
600 | + $node = $this->createMock(SystemTagsObjectMappingCollection::class); |
|
601 | + |
|
602 | + $this->tree->expects($this->any()) |
|
603 | + ->method('getNodeForPath') |
|
604 | + ->will($this->throwException(new \Sabre\DAV\Exception\NotFound())); |
|
605 | + |
|
606 | + $this->tagManager->expects($this->never()) |
|
607 | + ->method('createTag'); |
|
608 | + |
|
609 | + $node->expects($this->never()) |
|
610 | + ->method('createFile'); |
|
611 | + |
|
612 | + $request = $this->createMock(RequestInterface::class); |
|
613 | + $response = $this->createMock(ResponseInterface::class); |
|
614 | + |
|
615 | + $request->expects($this->once()) |
|
616 | + ->method('getPath') |
|
617 | + ->willReturn('/systemtags-relations/files/12'); |
|
618 | + |
|
619 | + $this->plugin->httpPost($request, $response); |
|
620 | + } |
|
621 | + |
|
622 | + /** |
|
623 | + * @dataProvider nodeClassProvider |
|
624 | + */ |
|
625 | + public function testCreateTagConflict(string $nodeClass): void { |
|
626 | + $this->expectException(\Sabre\DAV\Exception\Conflict::class); |
|
627 | + |
|
628 | + $this->user->expects($this->once()) |
|
629 | + ->method('getUID') |
|
630 | + ->willReturn('admin'); |
|
631 | + $this->groupManager |
|
632 | + ->expects($this->once()) |
|
633 | + ->method('isAdmin') |
|
634 | + ->with('admin') |
|
635 | + ->willReturn(true); |
|
636 | + |
|
637 | + $requestData = json_encode([ |
|
638 | + 'name' => 'Test', |
|
639 | + 'userVisible' => true, |
|
640 | + 'userAssignable' => false, |
|
641 | + ]); |
|
642 | 642 | |
643 | - $node = $this->createMock($nodeClass); |
|
644 | - $this->tagManager->expects($this->once()) |
|
645 | - ->method('createTag') |
|
646 | - ->with('Test', true, false) |
|
647 | - ->will($this->throwException(new TagAlreadyExistsException('Tag already exists'))); |
|
648 | - |
|
649 | - $this->tree->expects($this->any()) |
|
650 | - ->method('getNodeForPath') |
|
651 | - ->with('/systemtags') |
|
652 | - ->willReturn($node); |
|
643 | + $node = $this->createMock($nodeClass); |
|
644 | + $this->tagManager->expects($this->once()) |
|
645 | + ->method('createTag') |
|
646 | + ->with('Test', true, false) |
|
647 | + ->will($this->throwException(new TagAlreadyExistsException('Tag already exists'))); |
|
648 | + |
|
649 | + $this->tree->expects($this->any()) |
|
650 | + ->method('getNodeForPath') |
|
651 | + ->with('/systemtags') |
|
652 | + ->willReturn($node); |
|
653 | 653 | |
654 | - $request = $this->createMock(RequestInterface::class); |
|
655 | - $response = $this->createMock(ResponseInterface::class); |
|
656 | - |
|
657 | - $request->expects($this->once()) |
|
658 | - ->method('getPath') |
|
659 | - ->willReturn('/systemtags'); |
|
660 | - |
|
661 | - $request->expects($this->once()) |
|
662 | - ->method('getBodyAsString') |
|
663 | - ->willReturn($requestData); |
|
654 | + $request = $this->createMock(RequestInterface::class); |
|
655 | + $response = $this->createMock(ResponseInterface::class); |
|
656 | + |
|
657 | + $request->expects($this->once()) |
|
658 | + ->method('getPath') |
|
659 | + ->willReturn('/systemtags'); |
|
660 | + |
|
661 | + $request->expects($this->once()) |
|
662 | + ->method('getBodyAsString') |
|
663 | + ->willReturn($requestData); |
|
664 | 664 | |
665 | - $request->expects($this->once()) |
|
666 | - ->method('getHeader') |
|
667 | - ->with('Content-Type') |
|
668 | - ->willReturn('application/json'); |
|
665 | + $request->expects($this->once()) |
|
666 | + ->method('getHeader') |
|
667 | + ->with('Content-Type') |
|
668 | + ->willReturn('application/json'); |
|
669 | 669 | |
670 | - $this->plugin->httpPost($request, $response); |
|
671 | - } |
|
670 | + $this->plugin->httpPost($request, $response); |
|
671 | + } |
|
672 | 672 | } |
@@ -20,263 +20,263 @@ |
||
20 | 20 | use Sabre\DAV\Exception\Forbidden; |
21 | 21 | |
22 | 22 | class SystemTagNodeTest extends \Test\TestCase { |
23 | - private ISystemTagManager&MockObject $tagManager; |
|
24 | - private ISystemTagObjectMapper&MockObject $tagMapper; |
|
25 | - private IUser&MockObject $user; |
|
23 | + private ISystemTagManager&MockObject $tagManager; |
|
24 | + private ISystemTagObjectMapper&MockObject $tagMapper; |
|
25 | + private IUser&MockObject $user; |
|
26 | 26 | |
27 | - protected function setUp(): void { |
|
28 | - parent::setUp(); |
|
27 | + protected function setUp(): void { |
|
28 | + parent::setUp(); |
|
29 | 29 | |
30 | - $this->tagManager = $this->createMock(ISystemTagManager::class); |
|
31 | - $this->tagMapper = $this->createMock(ISystemTagObjectMapper::class); |
|
32 | - $this->user = $this->createMock(IUser::class); |
|
33 | - } |
|
30 | + $this->tagManager = $this->createMock(ISystemTagManager::class); |
|
31 | + $this->tagMapper = $this->createMock(ISystemTagObjectMapper::class); |
|
32 | + $this->user = $this->createMock(IUser::class); |
|
33 | + } |
|
34 | 34 | |
35 | - protected function getTagNode($isAdmin = true, $tag = null) { |
|
36 | - if ($tag === null) { |
|
37 | - $tag = new SystemTag('1', 'Test', true, true); |
|
38 | - } |
|
39 | - return new SystemTagNode( |
|
40 | - $tag, |
|
41 | - $this->user, |
|
42 | - $isAdmin, |
|
43 | - $this->tagManager, |
|
44 | - $this->tagMapper, |
|
45 | - ); |
|
46 | - } |
|
35 | + protected function getTagNode($isAdmin = true, $tag = null) { |
|
36 | + if ($tag === null) { |
|
37 | + $tag = new SystemTag('1', 'Test', true, true); |
|
38 | + } |
|
39 | + return new SystemTagNode( |
|
40 | + $tag, |
|
41 | + $this->user, |
|
42 | + $isAdmin, |
|
43 | + $this->tagManager, |
|
44 | + $this->tagMapper, |
|
45 | + ); |
|
46 | + } |
|
47 | 47 | |
48 | - public static function adminFlagProvider(): array { |
|
49 | - return [[true], [false]]; |
|
50 | - } |
|
48 | + public static function adminFlagProvider(): array { |
|
49 | + return [[true], [false]]; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @dataProvider adminFlagProvider |
|
54 | - */ |
|
55 | - public function testGetters(bool $isAdmin): void { |
|
56 | - $tag = new SystemTag('1', 'Test', true, true); |
|
57 | - $node = $this->getTagNode($isAdmin, $tag); |
|
58 | - $this->assertEquals('1', $node->getName()); |
|
59 | - $this->assertEquals($tag, $node->getSystemTag()); |
|
60 | - } |
|
52 | + /** |
|
53 | + * @dataProvider adminFlagProvider |
|
54 | + */ |
|
55 | + public function testGetters(bool $isAdmin): void { |
|
56 | + $tag = new SystemTag('1', 'Test', true, true); |
|
57 | + $node = $this->getTagNode($isAdmin, $tag); |
|
58 | + $this->assertEquals('1', $node->getName()); |
|
59 | + $this->assertEquals($tag, $node->getSystemTag()); |
|
60 | + } |
|
61 | 61 | |
62 | 62 | |
63 | - public function testSetName(): void { |
|
64 | - $this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class); |
|
63 | + public function testSetName(): void { |
|
64 | + $this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class); |
|
65 | 65 | |
66 | - $this->getTagNode()->setName('2'); |
|
67 | - } |
|
66 | + $this->getTagNode()->setName('2'); |
|
67 | + } |
|
68 | 68 | |
69 | - public static function tagNodeProvider(): array { |
|
70 | - return [ |
|
71 | - // admin |
|
72 | - [ |
|
73 | - true, |
|
74 | - new SystemTag('1', 'Original', true, true), |
|
75 | - ['Renamed', true, true, null] |
|
76 | - ], |
|
77 | - [ |
|
78 | - true, |
|
79 | - new SystemTag('1', 'Original', true, true), |
|
80 | - ['Original', false, false, null] |
|
81 | - ], |
|
82 | - // non-admin |
|
83 | - [ |
|
84 | - // renaming allowed |
|
85 | - false, |
|
86 | - new SystemTag('1', 'Original', true, true), |
|
87 | - ['Rename', true, true, '0082c9'] |
|
88 | - ], |
|
89 | - ]; |
|
90 | - } |
|
69 | + public static function tagNodeProvider(): array { |
|
70 | + return [ |
|
71 | + // admin |
|
72 | + [ |
|
73 | + true, |
|
74 | + new SystemTag('1', 'Original', true, true), |
|
75 | + ['Renamed', true, true, null] |
|
76 | + ], |
|
77 | + [ |
|
78 | + true, |
|
79 | + new SystemTag('1', 'Original', true, true), |
|
80 | + ['Original', false, false, null] |
|
81 | + ], |
|
82 | + // non-admin |
|
83 | + [ |
|
84 | + // renaming allowed |
|
85 | + false, |
|
86 | + new SystemTag('1', 'Original', true, true), |
|
87 | + ['Rename', true, true, '0082c9'] |
|
88 | + ], |
|
89 | + ]; |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * @dataProvider tagNodeProvider |
|
94 | - */ |
|
95 | - public function testUpdateTag(bool $isAdmin, ISystemTag $originalTag, array $changedArgs): void { |
|
96 | - $this->tagManager->expects($this->once()) |
|
97 | - ->method('canUserSeeTag') |
|
98 | - ->with($originalTag) |
|
99 | - ->willReturn($originalTag->isUserVisible() || $isAdmin); |
|
100 | - $this->tagManager->expects($this->once()) |
|
101 | - ->method('canUserAssignTag') |
|
102 | - ->with($originalTag) |
|
103 | - ->willReturn($originalTag->isUserAssignable() || $isAdmin); |
|
104 | - $this->tagManager->expects($this->once()) |
|
105 | - ->method('updateTag') |
|
106 | - ->with(1, $changedArgs[0], $changedArgs[1], $changedArgs[2], $changedArgs[3]); |
|
107 | - $this->getTagNode($isAdmin, $originalTag) |
|
108 | - ->update($changedArgs[0], $changedArgs[1], $changedArgs[2], $changedArgs[3]); |
|
109 | - } |
|
92 | + /** |
|
93 | + * @dataProvider tagNodeProvider |
|
94 | + */ |
|
95 | + public function testUpdateTag(bool $isAdmin, ISystemTag $originalTag, array $changedArgs): void { |
|
96 | + $this->tagManager->expects($this->once()) |
|
97 | + ->method('canUserSeeTag') |
|
98 | + ->with($originalTag) |
|
99 | + ->willReturn($originalTag->isUserVisible() || $isAdmin); |
|
100 | + $this->tagManager->expects($this->once()) |
|
101 | + ->method('canUserAssignTag') |
|
102 | + ->with($originalTag) |
|
103 | + ->willReturn($originalTag->isUserAssignable() || $isAdmin); |
|
104 | + $this->tagManager->expects($this->once()) |
|
105 | + ->method('updateTag') |
|
106 | + ->with(1, $changedArgs[0], $changedArgs[1], $changedArgs[2], $changedArgs[3]); |
|
107 | + $this->getTagNode($isAdmin, $originalTag) |
|
108 | + ->update($changedArgs[0], $changedArgs[1], $changedArgs[2], $changedArgs[3]); |
|
109 | + } |
|
110 | 110 | |
111 | - public static function tagNodeProviderPermissionException(): array { |
|
112 | - return [ |
|
113 | - [ |
|
114 | - // changing permissions not allowed |
|
115 | - new SystemTag('1', 'Original', true, true), |
|
116 | - ['Original', false, true, ''], |
|
117 | - 'Sabre\DAV\Exception\Forbidden', |
|
118 | - ], |
|
119 | - [ |
|
120 | - // changing permissions not allowed |
|
121 | - new SystemTag('1', 'Original', true, true), |
|
122 | - ['Original', true, false, ''], |
|
123 | - 'Sabre\DAV\Exception\Forbidden', |
|
124 | - ], |
|
125 | - [ |
|
126 | - // changing permissions not allowed |
|
127 | - new SystemTag('1', 'Original', true, true), |
|
128 | - ['Original', false, false, ''], |
|
129 | - 'Sabre\DAV\Exception\Forbidden', |
|
130 | - ], |
|
131 | - [ |
|
132 | - // changing non-assignable not allowed |
|
133 | - new SystemTag('1', 'Original', true, false), |
|
134 | - ['Rename', true, false, ''], |
|
135 | - 'Sabre\DAV\Exception\Forbidden', |
|
136 | - ], |
|
137 | - [ |
|
138 | - // changing non-assignable not allowed |
|
139 | - new SystemTag('1', 'Original', true, false), |
|
140 | - ['Original', true, true, ''], |
|
141 | - 'Sabre\DAV\Exception\Forbidden', |
|
142 | - ], |
|
143 | - [ |
|
144 | - // invisible tag does not exist |
|
145 | - new SystemTag('1', 'Original', false, false), |
|
146 | - ['Rename', false, false, ''], |
|
147 | - 'Sabre\DAV\Exception\NotFound', |
|
148 | - ], |
|
149 | - ]; |
|
150 | - } |
|
111 | + public static function tagNodeProviderPermissionException(): array { |
|
112 | + return [ |
|
113 | + [ |
|
114 | + // changing permissions not allowed |
|
115 | + new SystemTag('1', 'Original', true, true), |
|
116 | + ['Original', false, true, ''], |
|
117 | + 'Sabre\DAV\Exception\Forbidden', |
|
118 | + ], |
|
119 | + [ |
|
120 | + // changing permissions not allowed |
|
121 | + new SystemTag('1', 'Original', true, true), |
|
122 | + ['Original', true, false, ''], |
|
123 | + 'Sabre\DAV\Exception\Forbidden', |
|
124 | + ], |
|
125 | + [ |
|
126 | + // changing permissions not allowed |
|
127 | + new SystemTag('1', 'Original', true, true), |
|
128 | + ['Original', false, false, ''], |
|
129 | + 'Sabre\DAV\Exception\Forbidden', |
|
130 | + ], |
|
131 | + [ |
|
132 | + // changing non-assignable not allowed |
|
133 | + new SystemTag('1', 'Original', true, false), |
|
134 | + ['Rename', true, false, ''], |
|
135 | + 'Sabre\DAV\Exception\Forbidden', |
|
136 | + ], |
|
137 | + [ |
|
138 | + // changing non-assignable not allowed |
|
139 | + new SystemTag('1', 'Original', true, false), |
|
140 | + ['Original', true, true, ''], |
|
141 | + 'Sabre\DAV\Exception\Forbidden', |
|
142 | + ], |
|
143 | + [ |
|
144 | + // invisible tag does not exist |
|
145 | + new SystemTag('1', 'Original', false, false), |
|
146 | + ['Rename', false, false, ''], |
|
147 | + 'Sabre\DAV\Exception\NotFound', |
|
148 | + ], |
|
149 | + ]; |
|
150 | + } |
|
151 | 151 | |
152 | - /** |
|
153 | - * @dataProvider tagNodeProviderPermissionException |
|
154 | - */ |
|
155 | - public function testUpdateTagPermissionException(ISystemTag $originalTag, array $changedArgs, string $expectedException): void { |
|
156 | - $this->tagManager->expects($this->any()) |
|
157 | - ->method('canUserSeeTag') |
|
158 | - ->with($originalTag) |
|
159 | - ->willReturn($originalTag->isUserVisible()); |
|
160 | - $this->tagManager->expects($this->any()) |
|
161 | - ->method('canUserAssignTag') |
|
162 | - ->with($originalTag) |
|
163 | - ->willReturn($originalTag->isUserAssignable()); |
|
164 | - $this->tagManager->expects($this->never()) |
|
165 | - ->method('updateTag'); |
|
152 | + /** |
|
153 | + * @dataProvider tagNodeProviderPermissionException |
|
154 | + */ |
|
155 | + public function testUpdateTagPermissionException(ISystemTag $originalTag, array $changedArgs, string $expectedException): void { |
|
156 | + $this->tagManager->expects($this->any()) |
|
157 | + ->method('canUserSeeTag') |
|
158 | + ->with($originalTag) |
|
159 | + ->willReturn($originalTag->isUserVisible()); |
|
160 | + $this->tagManager->expects($this->any()) |
|
161 | + ->method('canUserAssignTag') |
|
162 | + ->with($originalTag) |
|
163 | + ->willReturn($originalTag->isUserAssignable()); |
|
164 | + $this->tagManager->expects($this->never()) |
|
165 | + ->method('updateTag'); |
|
166 | 166 | |
167 | - $thrown = null; |
|
167 | + $thrown = null; |
|
168 | 168 | |
169 | - try { |
|
170 | - $this->getTagNode(false, $originalTag) |
|
171 | - ->update($changedArgs[0], $changedArgs[1], $changedArgs[2], $changedArgs[3]); |
|
172 | - } catch (\Exception $e) { |
|
173 | - $thrown = $e; |
|
174 | - } |
|
169 | + try { |
|
170 | + $this->getTagNode(false, $originalTag) |
|
171 | + ->update($changedArgs[0], $changedArgs[1], $changedArgs[2], $changedArgs[3]); |
|
172 | + } catch (\Exception $e) { |
|
173 | + $thrown = $e; |
|
174 | + } |
|
175 | 175 | |
176 | - $this->assertInstanceOf($expectedException, $thrown); |
|
177 | - } |
|
176 | + $this->assertInstanceOf($expectedException, $thrown); |
|
177 | + } |
|
178 | 178 | |
179 | 179 | |
180 | - public function testUpdateTagAlreadyExists(): void { |
|
181 | - $this->expectException(\Sabre\DAV\Exception\Conflict::class); |
|
180 | + public function testUpdateTagAlreadyExists(): void { |
|
181 | + $this->expectException(\Sabre\DAV\Exception\Conflict::class); |
|
182 | 182 | |
183 | - $tag = new SystemTag('1', 'tag1', true, true); |
|
184 | - $this->tagManager->expects($this->any()) |
|
185 | - ->method('canUserSeeTag') |
|
186 | - ->with($tag) |
|
187 | - ->willReturn(true); |
|
188 | - $this->tagManager->expects($this->any()) |
|
189 | - ->method('canUserAssignTag') |
|
190 | - ->with($tag) |
|
191 | - ->willReturn(true); |
|
192 | - $this->tagManager->expects($this->once()) |
|
193 | - ->method('updateTag') |
|
194 | - ->with(1, 'Renamed', true, true) |
|
195 | - ->will($this->throwException(new TagAlreadyExistsException())); |
|
196 | - $this->getTagNode(false, $tag)->update('Renamed', true, true, null); |
|
197 | - } |
|
183 | + $tag = new SystemTag('1', 'tag1', true, true); |
|
184 | + $this->tagManager->expects($this->any()) |
|
185 | + ->method('canUserSeeTag') |
|
186 | + ->with($tag) |
|
187 | + ->willReturn(true); |
|
188 | + $this->tagManager->expects($this->any()) |
|
189 | + ->method('canUserAssignTag') |
|
190 | + ->with($tag) |
|
191 | + ->willReturn(true); |
|
192 | + $this->tagManager->expects($this->once()) |
|
193 | + ->method('updateTag') |
|
194 | + ->with(1, 'Renamed', true, true) |
|
195 | + ->will($this->throwException(new TagAlreadyExistsException())); |
|
196 | + $this->getTagNode(false, $tag)->update('Renamed', true, true, null); |
|
197 | + } |
|
198 | 198 | |
199 | 199 | |
200 | - public function testUpdateTagNotFound(): void { |
|
201 | - $this->expectException(\Sabre\DAV\Exception\NotFound::class); |
|
200 | + public function testUpdateTagNotFound(): void { |
|
201 | + $this->expectException(\Sabre\DAV\Exception\NotFound::class); |
|
202 | 202 | |
203 | - $tag = new SystemTag('1', 'tag1', true, true); |
|
204 | - $this->tagManager->expects($this->any()) |
|
205 | - ->method('canUserSeeTag') |
|
206 | - ->with($tag) |
|
207 | - ->willReturn(true); |
|
208 | - $this->tagManager->expects($this->any()) |
|
209 | - ->method('canUserAssignTag') |
|
210 | - ->with($tag) |
|
211 | - ->willReturn(true); |
|
212 | - $this->tagManager->expects($this->once()) |
|
213 | - ->method('updateTag') |
|
214 | - ->with(1, 'Renamed', true, true) |
|
215 | - ->will($this->throwException(new TagNotFoundException())); |
|
216 | - $this->getTagNode(false, $tag)->update('Renamed', true, true, null); |
|
217 | - } |
|
203 | + $tag = new SystemTag('1', 'tag1', true, true); |
|
204 | + $this->tagManager->expects($this->any()) |
|
205 | + ->method('canUserSeeTag') |
|
206 | + ->with($tag) |
|
207 | + ->willReturn(true); |
|
208 | + $this->tagManager->expects($this->any()) |
|
209 | + ->method('canUserAssignTag') |
|
210 | + ->with($tag) |
|
211 | + ->willReturn(true); |
|
212 | + $this->tagManager->expects($this->once()) |
|
213 | + ->method('updateTag') |
|
214 | + ->with(1, 'Renamed', true, true) |
|
215 | + ->will($this->throwException(new TagNotFoundException())); |
|
216 | + $this->getTagNode(false, $tag)->update('Renamed', true, true, null); |
|
217 | + } |
|
218 | 218 | |
219 | - /** |
|
220 | - * @dataProvider adminFlagProvider |
|
221 | - */ |
|
222 | - public function testDeleteTag(bool $isAdmin): void { |
|
223 | - $tag = new SystemTag('1', 'tag1', true, true); |
|
224 | - $this->tagManager->expects($isAdmin ? $this->once() : $this->never()) |
|
225 | - ->method('canUserSeeTag') |
|
226 | - ->with($tag) |
|
227 | - ->willReturn(true); |
|
228 | - $this->tagManager->expects($isAdmin ? $this->once() : $this->never()) |
|
229 | - ->method('deleteTags') |
|
230 | - ->with('1'); |
|
231 | - if (!$isAdmin) { |
|
232 | - $this->expectException(Forbidden::class); |
|
233 | - } |
|
234 | - $this->getTagNode($isAdmin, $tag)->delete(); |
|
235 | - } |
|
219 | + /** |
|
220 | + * @dataProvider adminFlagProvider |
|
221 | + */ |
|
222 | + public function testDeleteTag(bool $isAdmin): void { |
|
223 | + $tag = new SystemTag('1', 'tag1', true, true); |
|
224 | + $this->tagManager->expects($isAdmin ? $this->once() : $this->never()) |
|
225 | + ->method('canUserSeeTag') |
|
226 | + ->with($tag) |
|
227 | + ->willReturn(true); |
|
228 | + $this->tagManager->expects($isAdmin ? $this->once() : $this->never()) |
|
229 | + ->method('deleteTags') |
|
230 | + ->with('1'); |
|
231 | + if (!$isAdmin) { |
|
232 | + $this->expectException(Forbidden::class); |
|
233 | + } |
|
234 | + $this->getTagNode($isAdmin, $tag)->delete(); |
|
235 | + } |
|
236 | 236 | |
237 | - public static function tagNodeDeleteProviderPermissionException(): array { |
|
238 | - return [ |
|
239 | - [ |
|
240 | - // cannot delete invisible tag |
|
241 | - new SystemTag('1', 'Original', false, true), |
|
242 | - 'Sabre\DAV\Exception\Forbidden', |
|
243 | - ], |
|
244 | - [ |
|
245 | - // cannot delete non-assignable tag |
|
246 | - new SystemTag('1', 'Original', true, false), |
|
247 | - 'Sabre\DAV\Exception\Forbidden', |
|
248 | - ], |
|
249 | - ]; |
|
250 | - } |
|
237 | + public static function tagNodeDeleteProviderPermissionException(): array { |
|
238 | + return [ |
|
239 | + [ |
|
240 | + // cannot delete invisible tag |
|
241 | + new SystemTag('1', 'Original', false, true), |
|
242 | + 'Sabre\DAV\Exception\Forbidden', |
|
243 | + ], |
|
244 | + [ |
|
245 | + // cannot delete non-assignable tag |
|
246 | + new SystemTag('1', 'Original', true, false), |
|
247 | + 'Sabre\DAV\Exception\Forbidden', |
|
248 | + ], |
|
249 | + ]; |
|
250 | + } |
|
251 | 251 | |
252 | - /** |
|
253 | - * @dataProvider tagNodeDeleteProviderPermissionException |
|
254 | - */ |
|
255 | - public function testDeleteTagPermissionException(ISystemTag $tag, string $expectedException): void { |
|
256 | - $this->tagManager->expects($this->any()) |
|
257 | - ->method('canUserSeeTag') |
|
258 | - ->with($tag) |
|
259 | - ->willReturn($tag->isUserVisible()); |
|
260 | - $this->tagManager->expects($this->never()) |
|
261 | - ->method('deleteTags'); |
|
252 | + /** |
|
253 | + * @dataProvider tagNodeDeleteProviderPermissionException |
|
254 | + */ |
|
255 | + public function testDeleteTagPermissionException(ISystemTag $tag, string $expectedException): void { |
|
256 | + $this->tagManager->expects($this->any()) |
|
257 | + ->method('canUserSeeTag') |
|
258 | + ->with($tag) |
|
259 | + ->willReturn($tag->isUserVisible()); |
|
260 | + $this->tagManager->expects($this->never()) |
|
261 | + ->method('deleteTags'); |
|
262 | 262 | |
263 | - $this->expectException($expectedException); |
|
264 | - $this->getTagNode(false, $tag)->delete(); |
|
265 | - } |
|
263 | + $this->expectException($expectedException); |
|
264 | + $this->getTagNode(false, $tag)->delete(); |
|
265 | + } |
|
266 | 266 | |
267 | 267 | |
268 | - public function testDeleteTagNotFound(): void { |
|
269 | - $this->expectException(\Sabre\DAV\Exception\NotFound::class); |
|
268 | + public function testDeleteTagNotFound(): void { |
|
269 | + $this->expectException(\Sabre\DAV\Exception\NotFound::class); |
|
270 | 270 | |
271 | - $tag = new SystemTag('1', 'tag1', true, true); |
|
272 | - $this->tagManager->expects($this->any()) |
|
273 | - ->method('canUserSeeTag') |
|
274 | - ->with($tag) |
|
275 | - ->willReturn($tag->isUserVisible()); |
|
276 | - $this->tagManager->expects($this->once()) |
|
277 | - ->method('deleteTags') |
|
278 | - ->with('1') |
|
279 | - ->will($this->throwException(new TagNotFoundException())); |
|
280 | - $this->getTagNode(true, $tag)->delete(); |
|
281 | - } |
|
271 | + $tag = new SystemTag('1', 'tag1', true, true); |
|
272 | + $this->tagManager->expects($this->any()) |
|
273 | + ->method('canUserSeeTag') |
|
274 | + ->with($tag) |
|
275 | + ->willReturn($tag->isUserVisible()); |
|
276 | + $this->tagManager->expects($this->once()) |
|
277 | + ->method('deleteTags') |
|
278 | + ->with('1') |
|
279 | + ->will($this->throwException(new TagNotFoundException())); |
|
280 | + $this->getTagNode(true, $tag)->delete(); |
|
281 | + } |
|
282 | 282 | } |
@@ -17,333 +17,333 @@ |
||
17 | 17 | use PHPUnit\Framework\MockObject\MockObject; |
18 | 18 | |
19 | 19 | class SystemTagsObjectMappingCollectionTest extends \Test\TestCase { |
20 | - private ISystemTagManager&MockObject $tagManager; |
|
21 | - private ISystemTagObjectMapper&MockObject $tagMapper; |
|
22 | - private IUser&MockObject $user; |
|
23 | - |
|
24 | - protected function setUp(): void { |
|
25 | - parent::setUp(); |
|
26 | - |
|
27 | - $this->tagManager = $this->createMock(ISystemTagManager::class); |
|
28 | - $this->tagMapper = $this->createMock(ISystemTagObjectMapper::class); |
|
29 | - $this->user = $this->createMock(IUser::class); |
|
30 | - } |
|
31 | - |
|
32 | - public function getNode(array $writableNodeIds = []): SystemTagsObjectMappingCollection { |
|
33 | - return new SystemTagsObjectMappingCollection( |
|
34 | - '111', |
|
35 | - 'files', |
|
36 | - $this->user, |
|
37 | - $this->tagManager, |
|
38 | - $this->tagMapper, |
|
39 | - fn ($id): bool => in_array($id, $writableNodeIds), |
|
40 | - ); |
|
41 | - } |
|
42 | - |
|
43 | - public function testAssignTag(): void { |
|
44 | - $tag = new SystemTag('1', 'Test', true, true); |
|
45 | - $this->tagManager->expects($this->once()) |
|
46 | - ->method('canUserSeeTag') |
|
47 | - ->with($tag) |
|
48 | - ->willReturn(true); |
|
49 | - $this->tagManager->expects($this->once()) |
|
50 | - ->method('canUserAssignTag') |
|
51 | - ->with($tag) |
|
52 | - ->willReturn(true); |
|
53 | - |
|
54 | - $this->tagManager->expects($this->once()) |
|
55 | - ->method('getTagsByIds') |
|
56 | - ->with(['555']) |
|
57 | - ->willReturn([$tag]); |
|
58 | - $this->tagMapper->expects($this->once()) |
|
59 | - ->method('assignTags') |
|
60 | - ->with(111, 'files', '555'); |
|
61 | - |
|
62 | - $this->getNode([111])->createFile('555'); |
|
63 | - } |
|
64 | - |
|
65 | - public function testAssignTagForbidden(): void { |
|
66 | - $tag = new SystemTag('1', 'Test', true, true); |
|
67 | - $this->tagManager->expects($this->once()) |
|
68 | - ->method('canUserSeeTag') |
|
69 | - ->with($tag) |
|
70 | - ->willReturn(true); |
|
71 | - $this->tagManager->expects($this->once()) |
|
72 | - ->method('canUserAssignTag') |
|
73 | - ->with($tag) |
|
74 | - ->willReturn(true); |
|
75 | - |
|
76 | - $this->tagManager->expects($this->once()) |
|
77 | - ->method('getTagsByIds') |
|
78 | - ->with(['555']) |
|
79 | - ->willReturn([$tag]); |
|
80 | - $this->tagMapper->expects($this->never()) |
|
81 | - ->method('assignTags'); |
|
82 | - |
|
83 | - $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
84 | - $this->getNode()->createFile('555'); |
|
85 | - } |
|
86 | - |
|
87 | - public static function permissionsProvider(): array { |
|
88 | - return [ |
|
89 | - // invisible, tag does not exist for user |
|
90 | - [false, true, '\Sabre\DAV\Exception\PreconditionFailed'], |
|
91 | - // visible but static, cannot assign tag |
|
92 | - [true, false, '\Sabre\DAV\Exception\Forbidden'], |
|
93 | - ]; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * @dataProvider permissionsProvider |
|
98 | - */ |
|
99 | - public function testAssignTagNoPermission(bool $userVisible, bool $userAssignable, string $expectedException): void { |
|
100 | - $tag = new SystemTag('1', 'Test', $userVisible, $userAssignable); |
|
101 | - $this->tagManager->expects($this->once()) |
|
102 | - ->method('canUserSeeTag') |
|
103 | - ->with($tag) |
|
104 | - ->willReturn($userVisible); |
|
105 | - $this->tagManager->expects($this->any()) |
|
106 | - ->method('canUserAssignTag') |
|
107 | - ->with($tag) |
|
108 | - ->willReturn($userAssignable); |
|
109 | - |
|
110 | - $this->tagManager->expects($this->once()) |
|
111 | - ->method('getTagsByIds') |
|
112 | - ->with(['555']) |
|
113 | - ->willReturn([$tag]); |
|
114 | - $this->tagMapper->expects($this->never()) |
|
115 | - ->method('assignTags'); |
|
116 | - |
|
117 | - $thrown = null; |
|
118 | - try { |
|
119 | - $this->getNode()->createFile('555'); |
|
120 | - } catch (\Exception $e) { |
|
121 | - $thrown = $e; |
|
122 | - } |
|
123 | - |
|
124 | - $this->assertInstanceOf($expectedException, $thrown); |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - public function testAssignTagNotFound(): void { |
|
129 | - $this->expectException(\Sabre\DAV\Exception\PreconditionFailed::class); |
|
130 | - |
|
131 | - $this->tagManager->expects($this->once()) |
|
132 | - ->method('getTagsByIds') |
|
133 | - ->with(['555']) |
|
134 | - ->will($this->throwException(new TagNotFoundException())); |
|
135 | - |
|
136 | - $this->getNode()->createFile('555'); |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - public function testForbiddenCreateDirectory(): void { |
|
141 | - $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
142 | - |
|
143 | - $this->getNode()->createDirectory('789'); |
|
144 | - } |
|
145 | - |
|
146 | - public function testGetChild(): void { |
|
147 | - $tag = new SystemTag('555', 'TheTag', true, false); |
|
148 | - $this->tagManager->expects($this->once()) |
|
149 | - ->method('canUserSeeTag') |
|
150 | - ->with($tag) |
|
151 | - ->willReturn(true); |
|
152 | - |
|
153 | - $this->tagMapper->expects($this->once()) |
|
154 | - ->method('haveTag') |
|
155 | - ->with([111], 'files', '555', true) |
|
156 | - ->willReturn(true); |
|
157 | - |
|
158 | - $this->tagManager->expects($this->once()) |
|
159 | - ->method('getTagsByIds') |
|
160 | - ->with(['555']) |
|
161 | - ->willReturn(['555' => $tag]); |
|
162 | - |
|
163 | - $childNode = $this->getNode()->getChild('555'); |
|
164 | - |
|
165 | - $this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagMappingNode', $childNode); |
|
166 | - $this->assertEquals('555', $childNode->getName()); |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - public function testGetChildNonVisible(): void { |
|
171 | - $this->expectException(\Sabre\DAV\Exception\NotFound::class); |
|
172 | - |
|
173 | - $tag = new SystemTag('555', 'TheTag', false, false); |
|
174 | - $this->tagManager->expects($this->once()) |
|
175 | - ->method('canUserSeeTag') |
|
176 | - ->with($tag) |
|
177 | - ->willReturn(false); |
|
178 | - |
|
179 | - $this->tagMapper->expects($this->once()) |
|
180 | - ->method('haveTag') |
|
181 | - ->with([111], 'files', '555', true) |
|
182 | - ->willReturn(true); |
|
183 | - |
|
184 | - $this->tagManager->expects($this->once()) |
|
185 | - ->method('getTagsByIds') |
|
186 | - ->with(['555']) |
|
187 | - ->willReturn(['555' => $tag]); |
|
20 | + private ISystemTagManager&MockObject $tagManager; |
|
21 | + private ISystemTagObjectMapper&MockObject $tagMapper; |
|
22 | + private IUser&MockObject $user; |
|
23 | + |
|
24 | + protected function setUp(): void { |
|
25 | + parent::setUp(); |
|
26 | + |
|
27 | + $this->tagManager = $this->createMock(ISystemTagManager::class); |
|
28 | + $this->tagMapper = $this->createMock(ISystemTagObjectMapper::class); |
|
29 | + $this->user = $this->createMock(IUser::class); |
|
30 | + } |
|
31 | + |
|
32 | + public function getNode(array $writableNodeIds = []): SystemTagsObjectMappingCollection { |
|
33 | + return new SystemTagsObjectMappingCollection( |
|
34 | + '111', |
|
35 | + 'files', |
|
36 | + $this->user, |
|
37 | + $this->tagManager, |
|
38 | + $this->tagMapper, |
|
39 | + fn ($id): bool => in_array($id, $writableNodeIds), |
|
40 | + ); |
|
41 | + } |
|
42 | + |
|
43 | + public function testAssignTag(): void { |
|
44 | + $tag = new SystemTag('1', 'Test', true, true); |
|
45 | + $this->tagManager->expects($this->once()) |
|
46 | + ->method('canUserSeeTag') |
|
47 | + ->with($tag) |
|
48 | + ->willReturn(true); |
|
49 | + $this->tagManager->expects($this->once()) |
|
50 | + ->method('canUserAssignTag') |
|
51 | + ->with($tag) |
|
52 | + ->willReturn(true); |
|
53 | + |
|
54 | + $this->tagManager->expects($this->once()) |
|
55 | + ->method('getTagsByIds') |
|
56 | + ->with(['555']) |
|
57 | + ->willReturn([$tag]); |
|
58 | + $this->tagMapper->expects($this->once()) |
|
59 | + ->method('assignTags') |
|
60 | + ->with(111, 'files', '555'); |
|
61 | + |
|
62 | + $this->getNode([111])->createFile('555'); |
|
63 | + } |
|
64 | + |
|
65 | + public function testAssignTagForbidden(): void { |
|
66 | + $tag = new SystemTag('1', 'Test', true, true); |
|
67 | + $this->tagManager->expects($this->once()) |
|
68 | + ->method('canUserSeeTag') |
|
69 | + ->with($tag) |
|
70 | + ->willReturn(true); |
|
71 | + $this->tagManager->expects($this->once()) |
|
72 | + ->method('canUserAssignTag') |
|
73 | + ->with($tag) |
|
74 | + ->willReturn(true); |
|
75 | + |
|
76 | + $this->tagManager->expects($this->once()) |
|
77 | + ->method('getTagsByIds') |
|
78 | + ->with(['555']) |
|
79 | + ->willReturn([$tag]); |
|
80 | + $this->tagMapper->expects($this->never()) |
|
81 | + ->method('assignTags'); |
|
82 | + |
|
83 | + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
84 | + $this->getNode()->createFile('555'); |
|
85 | + } |
|
86 | + |
|
87 | + public static function permissionsProvider(): array { |
|
88 | + return [ |
|
89 | + // invisible, tag does not exist for user |
|
90 | + [false, true, '\Sabre\DAV\Exception\PreconditionFailed'], |
|
91 | + // visible but static, cannot assign tag |
|
92 | + [true, false, '\Sabre\DAV\Exception\Forbidden'], |
|
93 | + ]; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * @dataProvider permissionsProvider |
|
98 | + */ |
|
99 | + public function testAssignTagNoPermission(bool $userVisible, bool $userAssignable, string $expectedException): void { |
|
100 | + $tag = new SystemTag('1', 'Test', $userVisible, $userAssignable); |
|
101 | + $this->tagManager->expects($this->once()) |
|
102 | + ->method('canUserSeeTag') |
|
103 | + ->with($tag) |
|
104 | + ->willReturn($userVisible); |
|
105 | + $this->tagManager->expects($this->any()) |
|
106 | + ->method('canUserAssignTag') |
|
107 | + ->with($tag) |
|
108 | + ->willReturn($userAssignable); |
|
109 | + |
|
110 | + $this->tagManager->expects($this->once()) |
|
111 | + ->method('getTagsByIds') |
|
112 | + ->with(['555']) |
|
113 | + ->willReturn([$tag]); |
|
114 | + $this->tagMapper->expects($this->never()) |
|
115 | + ->method('assignTags'); |
|
116 | + |
|
117 | + $thrown = null; |
|
118 | + try { |
|
119 | + $this->getNode()->createFile('555'); |
|
120 | + } catch (\Exception $e) { |
|
121 | + $thrown = $e; |
|
122 | + } |
|
123 | + |
|
124 | + $this->assertInstanceOf($expectedException, $thrown); |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + public function testAssignTagNotFound(): void { |
|
129 | + $this->expectException(\Sabre\DAV\Exception\PreconditionFailed::class); |
|
130 | + |
|
131 | + $this->tagManager->expects($this->once()) |
|
132 | + ->method('getTagsByIds') |
|
133 | + ->with(['555']) |
|
134 | + ->will($this->throwException(new TagNotFoundException())); |
|
135 | + |
|
136 | + $this->getNode()->createFile('555'); |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + public function testForbiddenCreateDirectory(): void { |
|
141 | + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
142 | + |
|
143 | + $this->getNode()->createDirectory('789'); |
|
144 | + } |
|
145 | + |
|
146 | + public function testGetChild(): void { |
|
147 | + $tag = new SystemTag('555', 'TheTag', true, false); |
|
148 | + $this->tagManager->expects($this->once()) |
|
149 | + ->method('canUserSeeTag') |
|
150 | + ->with($tag) |
|
151 | + ->willReturn(true); |
|
152 | + |
|
153 | + $this->tagMapper->expects($this->once()) |
|
154 | + ->method('haveTag') |
|
155 | + ->with([111], 'files', '555', true) |
|
156 | + ->willReturn(true); |
|
157 | + |
|
158 | + $this->tagManager->expects($this->once()) |
|
159 | + ->method('getTagsByIds') |
|
160 | + ->with(['555']) |
|
161 | + ->willReturn(['555' => $tag]); |
|
162 | + |
|
163 | + $childNode = $this->getNode()->getChild('555'); |
|
164 | + |
|
165 | + $this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagMappingNode', $childNode); |
|
166 | + $this->assertEquals('555', $childNode->getName()); |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + public function testGetChildNonVisible(): void { |
|
171 | + $this->expectException(\Sabre\DAV\Exception\NotFound::class); |
|
172 | + |
|
173 | + $tag = new SystemTag('555', 'TheTag', false, false); |
|
174 | + $this->tagManager->expects($this->once()) |
|
175 | + ->method('canUserSeeTag') |
|
176 | + ->with($tag) |
|
177 | + ->willReturn(false); |
|
178 | + |
|
179 | + $this->tagMapper->expects($this->once()) |
|
180 | + ->method('haveTag') |
|
181 | + ->with([111], 'files', '555', true) |
|
182 | + ->willReturn(true); |
|
183 | + |
|
184 | + $this->tagManager->expects($this->once()) |
|
185 | + ->method('getTagsByIds') |
|
186 | + ->with(['555']) |
|
187 | + ->willReturn(['555' => $tag]); |
|
188 | 188 | |
189 | - $this->getNode()->getChild('555'); |
|
190 | - } |
|
189 | + $this->getNode()->getChild('555'); |
|
190 | + } |
|
191 | 191 | |
192 | 192 | |
193 | - public function testGetChildRelationNotFound(): void { |
|
194 | - $this->expectException(\Sabre\DAV\Exception\NotFound::class); |
|
193 | + public function testGetChildRelationNotFound(): void { |
|
194 | + $this->expectException(\Sabre\DAV\Exception\NotFound::class); |
|
195 | 195 | |
196 | - $this->tagMapper->expects($this->once()) |
|
197 | - ->method('haveTag') |
|
198 | - ->with([111], 'files', '777') |
|
199 | - ->willReturn(false); |
|
196 | + $this->tagMapper->expects($this->once()) |
|
197 | + ->method('haveTag') |
|
198 | + ->with([111], 'files', '777') |
|
199 | + ->willReturn(false); |
|
200 | 200 | |
201 | - $this->getNode()->getChild('777'); |
|
202 | - } |
|
201 | + $this->getNode()->getChild('777'); |
|
202 | + } |
|
203 | 203 | |
204 | 204 | |
205 | - public function testGetChildInvalidId(): void { |
|
206 | - $this->expectException(\Sabre\DAV\Exception\BadRequest::class); |
|
205 | + public function testGetChildInvalidId(): void { |
|
206 | + $this->expectException(\Sabre\DAV\Exception\BadRequest::class); |
|
207 | 207 | |
208 | - $this->tagMapper->expects($this->once()) |
|
209 | - ->method('haveTag') |
|
210 | - ->with([111], 'files', 'badid') |
|
211 | - ->will($this->throwException(new \InvalidArgumentException())); |
|
208 | + $this->tagMapper->expects($this->once()) |
|
209 | + ->method('haveTag') |
|
210 | + ->with([111], 'files', 'badid') |
|
211 | + ->will($this->throwException(new \InvalidArgumentException())); |
|
212 | 212 | |
213 | - $this->getNode()->getChild('badid'); |
|
214 | - } |
|
213 | + $this->getNode()->getChild('badid'); |
|
214 | + } |
|
215 | 215 | |
216 | 216 | |
217 | - public function testGetChildTagDoesNotExist(): void { |
|
218 | - $this->expectException(\Sabre\DAV\Exception\NotFound::class); |
|
217 | + public function testGetChildTagDoesNotExist(): void { |
|
218 | + $this->expectException(\Sabre\DAV\Exception\NotFound::class); |
|
219 | 219 | |
220 | - $this->tagMapper->expects($this->once()) |
|
221 | - ->method('haveTag') |
|
222 | - ->with([111], 'files', '777') |
|
223 | - ->will($this->throwException(new TagNotFoundException())); |
|
220 | + $this->tagMapper->expects($this->once()) |
|
221 | + ->method('haveTag') |
|
222 | + ->with([111], 'files', '777') |
|
223 | + ->will($this->throwException(new TagNotFoundException())); |
|
224 | 224 | |
225 | - $this->getNode()->getChild('777'); |
|
226 | - } |
|
225 | + $this->getNode()->getChild('777'); |
|
226 | + } |
|
227 | 227 | |
228 | - public function testGetChildren(): void { |
|
229 | - $tag1 = new SystemTag('555', 'TagOne', true, false); |
|
230 | - $tag2 = new SystemTag('556', 'TagTwo', true, true); |
|
231 | - $tag3 = new SystemTag('557', 'InvisibleTag', false, true); |
|
228 | + public function testGetChildren(): void { |
|
229 | + $tag1 = new SystemTag('555', 'TagOne', true, false); |
|
230 | + $tag2 = new SystemTag('556', 'TagTwo', true, true); |
|
231 | + $tag3 = new SystemTag('557', 'InvisibleTag', false, true); |
|
232 | 232 | |
233 | - $this->tagMapper->expects($this->once()) |
|
234 | - ->method('getTagIdsForObjects') |
|
235 | - ->with([111], 'files') |
|
236 | - ->willReturn(['111' => ['555', '556', '557']]); |
|
233 | + $this->tagMapper->expects($this->once()) |
|
234 | + ->method('getTagIdsForObjects') |
|
235 | + ->with([111], 'files') |
|
236 | + ->willReturn(['111' => ['555', '556', '557']]); |
|
237 | 237 | |
238 | - $this->tagManager->expects($this->once()) |
|
239 | - ->method('getTagsByIds') |
|
240 | - ->with(['555', '556', '557']) |
|
241 | - ->willReturn(['555' => $tag1, '556' => $tag2, '557' => $tag3]); |
|
238 | + $this->tagManager->expects($this->once()) |
|
239 | + ->method('getTagsByIds') |
|
240 | + ->with(['555', '556', '557']) |
|
241 | + ->willReturn(['555' => $tag1, '556' => $tag2, '557' => $tag3]); |
|
242 | 242 | |
243 | - $this->tagManager->expects($this->exactly(3)) |
|
244 | - ->method('canUserSeeTag') |
|
245 | - ->willReturnCallback(function ($tag) { |
|
246 | - return $tag->isUserVisible(); |
|
247 | - }); |
|
243 | + $this->tagManager->expects($this->exactly(3)) |
|
244 | + ->method('canUserSeeTag') |
|
245 | + ->willReturnCallback(function ($tag) { |
|
246 | + return $tag->isUserVisible(); |
|
247 | + }); |
|
248 | 248 | |
249 | - $children = $this->getNode()->getChildren(); |
|
249 | + $children = $this->getNode()->getChildren(); |
|
250 | 250 | |
251 | - $this->assertCount(2, $children); |
|
251 | + $this->assertCount(2, $children); |
|
252 | 252 | |
253 | - $this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagMappingNode', $children[0]); |
|
254 | - $this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagMappingNode', $children[1]); |
|
253 | + $this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagMappingNode', $children[0]); |
|
254 | + $this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagMappingNode', $children[1]); |
|
255 | 255 | |
256 | - $this->assertEquals(111, $children[0]->getObjectId()); |
|
257 | - $this->assertEquals('files', $children[0]->getObjectType()); |
|
258 | - $this->assertEquals($tag1, $children[0]->getSystemTag()); |
|
256 | + $this->assertEquals(111, $children[0]->getObjectId()); |
|
257 | + $this->assertEquals('files', $children[0]->getObjectType()); |
|
258 | + $this->assertEquals($tag1, $children[0]->getSystemTag()); |
|
259 | 259 | |
260 | - $this->assertEquals(111, $children[1]->getObjectId()); |
|
261 | - $this->assertEquals('files', $children[1]->getObjectType()); |
|
262 | - $this->assertEquals($tag2, $children[1]->getSystemTag()); |
|
263 | - } |
|
260 | + $this->assertEquals(111, $children[1]->getObjectId()); |
|
261 | + $this->assertEquals('files', $children[1]->getObjectType()); |
|
262 | + $this->assertEquals($tag2, $children[1]->getSystemTag()); |
|
263 | + } |
|
264 | 264 | |
265 | - public function testChildExistsWithVisibleTag(): void { |
|
266 | - $tag = new SystemTag('555', 'TagOne', true, false); |
|
265 | + public function testChildExistsWithVisibleTag(): void { |
|
266 | + $tag = new SystemTag('555', 'TagOne', true, false); |
|
267 | 267 | |
268 | - $this->tagMapper->expects($this->once()) |
|
269 | - ->method('haveTag') |
|
270 | - ->with([111], 'files', '555') |
|
271 | - ->willReturn(true); |
|
268 | + $this->tagMapper->expects($this->once()) |
|
269 | + ->method('haveTag') |
|
270 | + ->with([111], 'files', '555') |
|
271 | + ->willReturn(true); |
|
272 | 272 | |
273 | - $this->tagManager->expects($this->once()) |
|
274 | - ->method('canUserSeeTag') |
|
275 | - ->with($tag) |
|
276 | - ->willReturn(true); |
|
273 | + $this->tagManager->expects($this->once()) |
|
274 | + ->method('canUserSeeTag') |
|
275 | + ->with($tag) |
|
276 | + ->willReturn(true); |
|
277 | 277 | |
278 | - $this->tagManager->expects($this->once()) |
|
279 | - ->method('getTagsByIds') |
|
280 | - ->with(['555']) |
|
281 | - ->willReturn([$tag]); |
|
278 | + $this->tagManager->expects($this->once()) |
|
279 | + ->method('getTagsByIds') |
|
280 | + ->with(['555']) |
|
281 | + ->willReturn([$tag]); |
|
282 | 282 | |
283 | - $this->assertTrue($this->getNode()->childExists('555')); |
|
284 | - } |
|
283 | + $this->assertTrue($this->getNode()->childExists('555')); |
|
284 | + } |
|
285 | 285 | |
286 | - public function testChildExistsWithInvisibleTag(): void { |
|
287 | - $tag = new SystemTag('555', 'TagOne', false, false); |
|
286 | + public function testChildExistsWithInvisibleTag(): void { |
|
287 | + $tag = new SystemTag('555', 'TagOne', false, false); |
|
288 | 288 | |
289 | - $this->tagMapper->expects($this->once()) |
|
290 | - ->method('haveTag') |
|
291 | - ->with([111], 'files', '555') |
|
292 | - ->willReturn(true); |
|
289 | + $this->tagMapper->expects($this->once()) |
|
290 | + ->method('haveTag') |
|
291 | + ->with([111], 'files', '555') |
|
292 | + ->willReturn(true); |
|
293 | 293 | |
294 | - $this->tagManager->expects($this->once()) |
|
295 | - ->method('getTagsByIds') |
|
296 | - ->with(['555']) |
|
297 | - ->willReturn([$tag]); |
|
294 | + $this->tagManager->expects($this->once()) |
|
295 | + ->method('getTagsByIds') |
|
296 | + ->with(['555']) |
|
297 | + ->willReturn([$tag]); |
|
298 | 298 | |
299 | - $this->assertFalse($this->getNode()->childExists('555')); |
|
300 | - } |
|
299 | + $this->assertFalse($this->getNode()->childExists('555')); |
|
300 | + } |
|
301 | 301 | |
302 | - public function testChildExistsNotFound(): void { |
|
303 | - $this->tagMapper->expects($this->once()) |
|
304 | - ->method('haveTag') |
|
305 | - ->with([111], 'files', '555') |
|
306 | - ->willReturn(false); |
|
302 | + public function testChildExistsNotFound(): void { |
|
303 | + $this->tagMapper->expects($this->once()) |
|
304 | + ->method('haveTag') |
|
305 | + ->with([111], 'files', '555') |
|
306 | + ->willReturn(false); |
|
307 | 307 | |
308 | - $this->assertFalse($this->getNode()->childExists('555')); |
|
309 | - } |
|
308 | + $this->assertFalse($this->getNode()->childExists('555')); |
|
309 | + } |
|
310 | 310 | |
311 | - public function testChildExistsTagNotFound(): void { |
|
312 | - $this->tagMapper->expects($this->once()) |
|
313 | - ->method('haveTag') |
|
314 | - ->with([111], 'files', '555') |
|
315 | - ->will($this->throwException(new TagNotFoundException())); |
|
311 | + public function testChildExistsTagNotFound(): void { |
|
312 | + $this->tagMapper->expects($this->once()) |
|
313 | + ->method('haveTag') |
|
314 | + ->with([111], 'files', '555') |
|
315 | + ->will($this->throwException(new TagNotFoundException())); |
|
316 | 316 | |
317 | - $this->assertFalse($this->getNode()->childExists('555')); |
|
318 | - } |
|
317 | + $this->assertFalse($this->getNode()->childExists('555')); |
|
318 | + } |
|
319 | 319 | |
320 | 320 | |
321 | - public function testChildExistsInvalidId(): void { |
|
322 | - $this->expectException(\Sabre\DAV\Exception\BadRequest::class); |
|
321 | + public function testChildExistsInvalidId(): void { |
|
322 | + $this->expectException(\Sabre\DAV\Exception\BadRequest::class); |
|
323 | 323 | |
324 | - $this->tagMapper->expects($this->once()) |
|
325 | - ->method('haveTag') |
|
326 | - ->with([111], 'files', '555') |
|
327 | - ->will($this->throwException(new \InvalidArgumentException())); |
|
324 | + $this->tagMapper->expects($this->once()) |
|
325 | + ->method('haveTag') |
|
326 | + ->with([111], 'files', '555') |
|
327 | + ->will($this->throwException(new \InvalidArgumentException())); |
|
328 | 328 | |
329 | - $this->getNode()->childExists('555'); |
|
330 | - } |
|
329 | + $this->getNode()->childExists('555'); |
|
330 | + } |
|
331 | 331 | |
332 | 332 | |
333 | - public function testDelete(): void { |
|
334 | - $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
333 | + public function testDelete(): void { |
|
334 | + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
335 | 335 | |
336 | - $this->getNode()->delete(); |
|
337 | - } |
|
336 | + $this->getNode()->delete(); |
|
337 | + } |
|
338 | 338 | |
339 | 339 | |
340 | - public function testSetName(): void { |
|
341 | - $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
340 | + public function testSetName(): void { |
|
341 | + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
342 | 342 | |
343 | - $this->getNode()->setName('somethingelse'); |
|
344 | - } |
|
343 | + $this->getNode()->setName('somethingelse'); |
|
344 | + } |
|
345 | 345 | |
346 | - public function testGetName(): void { |
|
347 | - $this->assertEquals('111', $this->getNode()->getName()); |
|
348 | - } |
|
346 | + public function testGetName(): void { |
|
347 | + $this->assertEquals('111', $this->getNode()->getName()); |
|
348 | + } |
|
349 | 349 | } |
@@ -19,208 +19,208 @@ |
||
19 | 19 | use PHPUnit\Framework\MockObject\MockObject; |
20 | 20 | |
21 | 21 | class SystemTagsByIdCollectionTest extends \Test\TestCase { |
22 | - private ISystemTagManager&MockObject $tagManager; |
|
23 | - private IUser&MockObject $user; |
|
22 | + private ISystemTagManager&MockObject $tagManager; |
|
23 | + private IUser&MockObject $user; |
|
24 | 24 | |
25 | - protected function setUp(): void { |
|
26 | - parent::setUp(); |
|
25 | + protected function setUp(): void { |
|
26 | + parent::setUp(); |
|
27 | 27 | |
28 | - $this->tagManager = $this->createMock(ISystemTagManager::class); |
|
29 | - } |
|
28 | + $this->tagManager = $this->createMock(ISystemTagManager::class); |
|
29 | + } |
|
30 | 30 | |
31 | - public function getNode(bool $isAdmin = true) { |
|
32 | - $this->user = $this->createMock(IUser::class); |
|
33 | - $this->user->expects($this->any()) |
|
34 | - ->method('getUID') |
|
35 | - ->willReturn('testuser'); |
|
31 | + public function getNode(bool $isAdmin = true) { |
|
32 | + $this->user = $this->createMock(IUser::class); |
|
33 | + $this->user->expects($this->any()) |
|
34 | + ->method('getUID') |
|
35 | + ->willReturn('testuser'); |
|
36 | 36 | |
37 | - /** @var IUserSession&MockObject */ |
|
38 | - $userSession = $this->createMock(IUserSession::class); |
|
39 | - $userSession->expects($this->any()) |
|
40 | - ->method('getUser') |
|
41 | - ->willReturn($this->user); |
|
37 | + /** @var IUserSession&MockObject */ |
|
38 | + $userSession = $this->createMock(IUserSession::class); |
|
39 | + $userSession->expects($this->any()) |
|
40 | + ->method('getUser') |
|
41 | + ->willReturn($this->user); |
|
42 | 42 | |
43 | - /** @var IGroupManager&MockObject */ |
|
44 | - $groupManager = $this->createMock(IGroupManager::class); |
|
45 | - $groupManager->expects($this->any()) |
|
46 | - ->method('isAdmin') |
|
47 | - ->with('testuser') |
|
48 | - ->willReturn($isAdmin); |
|
43 | + /** @var IGroupManager&MockObject */ |
|
44 | + $groupManager = $this->createMock(IGroupManager::class); |
|
45 | + $groupManager->expects($this->any()) |
|
46 | + ->method('isAdmin') |
|
47 | + ->with('testuser') |
|
48 | + ->willReturn($isAdmin); |
|
49 | 49 | |
50 | - /** @var ISystemTagObjectMapper&MockObject */ |
|
51 | - $tagMapper = $this->createMock(ISystemTagObjectMapper::class); |
|
52 | - return new SystemTagsByIdCollection( |
|
53 | - $this->tagManager, |
|
54 | - $userSession, |
|
55 | - $groupManager, |
|
56 | - $tagMapper, |
|
57 | - ); |
|
58 | - } |
|
50 | + /** @var ISystemTagObjectMapper&MockObject */ |
|
51 | + $tagMapper = $this->createMock(ISystemTagObjectMapper::class); |
|
52 | + return new SystemTagsByIdCollection( |
|
53 | + $this->tagManager, |
|
54 | + $userSession, |
|
55 | + $groupManager, |
|
56 | + $tagMapper, |
|
57 | + ); |
|
58 | + } |
|
59 | 59 | |
60 | - public static function adminFlagProvider(): array { |
|
61 | - return [[true], [false]]; |
|
62 | - } |
|
60 | + public static function adminFlagProvider(): array { |
|
61 | + return [[true], [false]]; |
|
62 | + } |
|
63 | 63 | |
64 | 64 | |
65 | - public function testForbiddenCreateFile(): void { |
|
66 | - $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
65 | + public function testForbiddenCreateFile(): void { |
|
66 | + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
67 | 67 | |
68 | - $this->getNode()->createFile('555'); |
|
69 | - } |
|
68 | + $this->getNode()->createFile('555'); |
|
69 | + } |
|
70 | 70 | |
71 | 71 | |
72 | - public function testForbiddenCreateDirectory(): void { |
|
73 | - $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
72 | + public function testForbiddenCreateDirectory(): void { |
|
73 | + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
74 | 74 | |
75 | - $this->getNode()->createDirectory('789'); |
|
76 | - } |
|
75 | + $this->getNode()->createDirectory('789'); |
|
76 | + } |
|
77 | 77 | |
78 | - public function testGetChild(): void { |
|
79 | - $tag = new SystemTag('123', 'Test', true, false); |
|
80 | - $this->tagManager->expects($this->once()) |
|
81 | - ->method('canUserSeeTag') |
|
82 | - ->with($tag) |
|
83 | - ->willReturn(true); |
|
78 | + public function testGetChild(): void { |
|
79 | + $tag = new SystemTag('123', 'Test', true, false); |
|
80 | + $this->tagManager->expects($this->once()) |
|
81 | + ->method('canUserSeeTag') |
|
82 | + ->with($tag) |
|
83 | + ->willReturn(true); |
|
84 | 84 | |
85 | - $this->tagManager->expects($this->once()) |
|
86 | - ->method('getTagsByIds') |
|
87 | - ->with(['123']) |
|
88 | - ->willReturn([$tag]); |
|
85 | + $this->tagManager->expects($this->once()) |
|
86 | + ->method('getTagsByIds') |
|
87 | + ->with(['123']) |
|
88 | + ->willReturn([$tag]); |
|
89 | 89 | |
90 | - $childNode = $this->getNode()->getChild('123'); |
|
90 | + $childNode = $this->getNode()->getChild('123'); |
|
91 | 91 | |
92 | - $this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagNode', $childNode); |
|
93 | - $this->assertEquals('123', $childNode->getName()); |
|
94 | - $this->assertEquals($tag, $childNode->getSystemTag()); |
|
95 | - } |
|
92 | + $this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagNode', $childNode); |
|
93 | + $this->assertEquals('123', $childNode->getName()); |
|
94 | + $this->assertEquals($tag, $childNode->getSystemTag()); |
|
95 | + } |
|
96 | 96 | |
97 | 97 | |
98 | - public function testGetChildInvalidName(): void { |
|
99 | - $this->expectException(\Sabre\DAV\Exception\BadRequest::class); |
|
98 | + public function testGetChildInvalidName(): void { |
|
99 | + $this->expectException(\Sabre\DAV\Exception\BadRequest::class); |
|
100 | 100 | |
101 | - $this->tagManager->expects($this->once()) |
|
102 | - ->method('getTagsByIds') |
|
103 | - ->with(['invalid']) |
|
104 | - ->will($this->throwException(new \InvalidArgumentException())); |
|
101 | + $this->tagManager->expects($this->once()) |
|
102 | + ->method('getTagsByIds') |
|
103 | + ->with(['invalid']) |
|
104 | + ->will($this->throwException(new \InvalidArgumentException())); |
|
105 | 105 | |
106 | - $this->getNode()->getChild('invalid'); |
|
107 | - } |
|
106 | + $this->getNode()->getChild('invalid'); |
|
107 | + } |
|
108 | 108 | |
109 | 109 | |
110 | - public function testGetChildNotFound(): void { |
|
111 | - $this->expectException(\Sabre\DAV\Exception\NotFound::class); |
|
112 | - |
|
113 | - $this->tagManager->expects($this->once()) |
|
114 | - ->method('getTagsByIds') |
|
115 | - ->with(['444']) |
|
116 | - ->will($this->throwException(new TagNotFoundException())); |
|
110 | + public function testGetChildNotFound(): void { |
|
111 | + $this->expectException(\Sabre\DAV\Exception\NotFound::class); |
|
112 | + |
|
113 | + $this->tagManager->expects($this->once()) |
|
114 | + ->method('getTagsByIds') |
|
115 | + ->with(['444']) |
|
116 | + ->will($this->throwException(new TagNotFoundException())); |
|
117 | 117 | |
118 | - $this->getNode()->getChild('444'); |
|
119 | - } |
|
118 | + $this->getNode()->getChild('444'); |
|
119 | + } |
|
120 | 120 | |
121 | 121 | |
122 | - public function testGetChildUserNotVisible(): void { |
|
123 | - $this->expectException(\Sabre\DAV\Exception\NotFound::class); |
|
122 | + public function testGetChildUserNotVisible(): void { |
|
123 | + $this->expectException(\Sabre\DAV\Exception\NotFound::class); |
|
124 | 124 | |
125 | - $tag = new SystemTag('123', 'Test', false, false); |
|
125 | + $tag = new SystemTag('123', 'Test', false, false); |
|
126 | 126 | |
127 | - $this->tagManager->expects($this->once()) |
|
128 | - ->method('getTagsByIds') |
|
129 | - ->with(['123']) |
|
130 | - ->willReturn([$tag]); |
|
127 | + $this->tagManager->expects($this->once()) |
|
128 | + ->method('getTagsByIds') |
|
129 | + ->with(['123']) |
|
130 | + ->willReturn([$tag]); |
|
131 | 131 | |
132 | - $this->getNode(false)->getChild('123'); |
|
133 | - } |
|
132 | + $this->getNode(false)->getChild('123'); |
|
133 | + } |
|
134 | 134 | |
135 | - public function testGetChildrenAdmin(): void { |
|
136 | - $tag1 = new SystemTag('123', 'One', true, false); |
|
137 | - $tag2 = new SystemTag('456', 'Two', true, true); |
|
135 | + public function testGetChildrenAdmin(): void { |
|
136 | + $tag1 = new SystemTag('123', 'One', true, false); |
|
137 | + $tag2 = new SystemTag('456', 'Two', true, true); |
|
138 | 138 | |
139 | - $this->tagManager->expects($this->once()) |
|
140 | - ->method('getAllTags') |
|
141 | - ->with(null) |
|
142 | - ->willReturn([$tag1, $tag2]); |
|
139 | + $this->tagManager->expects($this->once()) |
|
140 | + ->method('getAllTags') |
|
141 | + ->with(null) |
|
142 | + ->willReturn([$tag1, $tag2]); |
|
143 | 143 | |
144 | - $children = $this->getNode(true)->getChildren(); |
|
144 | + $children = $this->getNode(true)->getChildren(); |
|
145 | 145 | |
146 | - $this->assertCount(2, $children); |
|
146 | + $this->assertCount(2, $children); |
|
147 | 147 | |
148 | - $this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagNode', $children[0]); |
|
149 | - $this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagNode', $children[1]); |
|
150 | - $this->assertEquals($tag1, $children[0]->getSystemTag()); |
|
151 | - $this->assertEquals($tag2, $children[1]->getSystemTag()); |
|
152 | - } |
|
148 | + $this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagNode', $children[0]); |
|
149 | + $this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagNode', $children[1]); |
|
150 | + $this->assertEquals($tag1, $children[0]->getSystemTag()); |
|
151 | + $this->assertEquals($tag2, $children[1]->getSystemTag()); |
|
152 | + } |
|
153 | 153 | |
154 | - public function testGetChildrenNonAdmin(): void { |
|
155 | - $tag1 = new SystemTag('123', 'One', true, false); |
|
156 | - $tag2 = new SystemTag('456', 'Two', true, true); |
|
154 | + public function testGetChildrenNonAdmin(): void { |
|
155 | + $tag1 = new SystemTag('123', 'One', true, false); |
|
156 | + $tag2 = new SystemTag('456', 'Two', true, true); |
|
157 | 157 | |
158 | - $this->tagManager->expects($this->once()) |
|
159 | - ->method('getAllTags') |
|
160 | - ->with(true) |
|
161 | - ->willReturn([$tag1, $tag2]); |
|
158 | + $this->tagManager->expects($this->once()) |
|
159 | + ->method('getAllTags') |
|
160 | + ->with(true) |
|
161 | + ->willReturn([$tag1, $tag2]); |
|
162 | 162 | |
163 | - $children = $this->getNode(false)->getChildren(); |
|
163 | + $children = $this->getNode(false)->getChildren(); |
|
164 | 164 | |
165 | - $this->assertCount(2, $children); |
|
165 | + $this->assertCount(2, $children); |
|
166 | 166 | |
167 | - $this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagNode', $children[0]); |
|
168 | - $this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagNode', $children[1]); |
|
169 | - $this->assertEquals($tag1, $children[0]->getSystemTag()); |
|
170 | - $this->assertEquals($tag2, $children[1]->getSystemTag()); |
|
171 | - } |
|
167 | + $this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagNode', $children[0]); |
|
168 | + $this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagNode', $children[1]); |
|
169 | + $this->assertEquals($tag1, $children[0]->getSystemTag()); |
|
170 | + $this->assertEquals($tag2, $children[1]->getSystemTag()); |
|
171 | + } |
|
172 | 172 | |
173 | - public function testGetChildrenEmpty(): void { |
|
174 | - $this->tagManager->expects($this->once()) |
|
175 | - ->method('getAllTags') |
|
176 | - ->with(null) |
|
177 | - ->willReturn([]); |
|
178 | - $this->assertCount(0, $this->getNode()->getChildren()); |
|
179 | - } |
|
173 | + public function testGetChildrenEmpty(): void { |
|
174 | + $this->tagManager->expects($this->once()) |
|
175 | + ->method('getAllTags') |
|
176 | + ->with(null) |
|
177 | + ->willReturn([]); |
|
178 | + $this->assertCount(0, $this->getNode()->getChildren()); |
|
179 | + } |
|
180 | 180 | |
181 | - public static function childExistsProvider(): array { |
|
182 | - return [ |
|
183 | - [true, true], |
|
184 | - [false, false], |
|
185 | - ]; |
|
186 | - } |
|
181 | + public static function childExistsProvider(): array { |
|
182 | + return [ |
|
183 | + [true, true], |
|
184 | + [false, false], |
|
185 | + ]; |
|
186 | + } |
|
187 | 187 | |
188 | - /** |
|
189 | - * @dataProvider childExistsProvider |
|
190 | - */ |
|
191 | - public function testChildExists(bool $userVisible, bool $expectedResult): void { |
|
192 | - $tag = new SystemTag('123', 'One', $userVisible, false); |
|
193 | - $this->tagManager->expects($this->once()) |
|
194 | - ->method('canUserSeeTag') |
|
195 | - ->with($tag) |
|
196 | - ->willReturn($userVisible); |
|
188 | + /** |
|
189 | + * @dataProvider childExistsProvider |
|
190 | + */ |
|
191 | + public function testChildExists(bool $userVisible, bool $expectedResult): void { |
|
192 | + $tag = new SystemTag('123', 'One', $userVisible, false); |
|
193 | + $this->tagManager->expects($this->once()) |
|
194 | + ->method('canUserSeeTag') |
|
195 | + ->with($tag) |
|
196 | + ->willReturn($userVisible); |
|
197 | 197 | |
198 | - $this->tagManager->expects($this->once()) |
|
199 | - ->method('getTagsByIds') |
|
200 | - ->with(['123']) |
|
201 | - ->willReturn([$tag]); |
|
198 | + $this->tagManager->expects($this->once()) |
|
199 | + ->method('getTagsByIds') |
|
200 | + ->with(['123']) |
|
201 | + ->willReturn([$tag]); |
|
202 | 202 | |
203 | - $this->assertEquals($expectedResult, $this->getNode()->childExists('123')); |
|
204 | - } |
|
203 | + $this->assertEquals($expectedResult, $this->getNode()->childExists('123')); |
|
204 | + } |
|
205 | 205 | |
206 | - public function testChildExistsNotFound(): void { |
|
207 | - $this->tagManager->expects($this->once()) |
|
208 | - ->method('getTagsByIds') |
|
209 | - ->with(['123']) |
|
210 | - ->will($this->throwException(new TagNotFoundException())); |
|
211 | - |
|
212 | - $this->assertFalse($this->getNode()->childExists('123')); |
|
213 | - } |
|
206 | + public function testChildExistsNotFound(): void { |
|
207 | + $this->tagManager->expects($this->once()) |
|
208 | + ->method('getTagsByIds') |
|
209 | + ->with(['123']) |
|
210 | + ->will($this->throwException(new TagNotFoundException())); |
|
211 | + |
|
212 | + $this->assertFalse($this->getNode()->childExists('123')); |
|
213 | + } |
|
214 | 214 | |
215 | 215 | |
216 | - public function testChildExistsBadRequest(): void { |
|
217 | - $this->expectException(\Sabre\DAV\Exception\BadRequest::class); |
|
218 | - |
|
219 | - $this->tagManager->expects($this->once()) |
|
220 | - ->method('getTagsByIds') |
|
221 | - ->with(['invalid']) |
|
222 | - ->will($this->throwException(new \InvalidArgumentException())); |
|
223 | - |
|
224 | - $this->getNode()->childExists('invalid'); |
|
225 | - } |
|
216 | + public function testChildExistsBadRequest(): void { |
|
217 | + $this->expectException(\Sabre\DAV\Exception\BadRequest::class); |
|
218 | + |
|
219 | + $this->tagManager->expects($this->once()) |
|
220 | + ->method('getTagsByIds') |
|
221 | + ->with(['invalid']) |
|
222 | + ->will($this->throwException(new \InvalidArgumentException())); |
|
223 | + |
|
224 | + $this->getNode()->childExists('invalid'); |
|
225 | + } |
|
226 | 226 | } |
@@ -20,25 +20,25 @@ |
||
20 | 20 | */ |
21 | 21 | class ServerTest extends \Test\TestCase { |
22 | 22 | |
23 | - /** |
|
24 | - * @dataProvider providesUris |
|
25 | - */ |
|
26 | - public function test(string $uri, array $plugins): void { |
|
27 | - /** @var IRequest | \PHPUnit\Framework\MockObject\MockObject $r */ |
|
28 | - $r = $this->createMock(IRequest::class); |
|
29 | - $r->expects($this->any())->method('getRequestUri')->willReturn($uri); |
|
30 | - $this->loginAsUser('admin'); |
|
31 | - $s = new Server($r, '/'); |
|
32 | - $this->assertNotNull($s->server); |
|
33 | - foreach ($plugins as $plugin) { |
|
34 | - $this->assertNotNull($s->server->getPlugin($plugin)); |
|
35 | - } |
|
36 | - } |
|
37 | - public static function providesUris(): array { |
|
38 | - return [ |
|
39 | - 'principals' => ['principals/users/admin', ['caldav', 'oc-resource-sharing', 'carddav']], |
|
40 | - 'calendars' => ['calendars/admin', ['caldav', 'oc-resource-sharing']], |
|
41 | - 'addressbooks' => ['addressbooks/admin', ['carddav', 'oc-resource-sharing']], |
|
42 | - ]; |
|
43 | - } |
|
23 | + /** |
|
24 | + * @dataProvider providesUris |
|
25 | + */ |
|
26 | + public function test(string $uri, array $plugins): void { |
|
27 | + /** @var IRequest | \PHPUnit\Framework\MockObject\MockObject $r */ |
|
28 | + $r = $this->createMock(IRequest::class); |
|
29 | + $r->expects($this->any())->method('getRequestUri')->willReturn($uri); |
|
30 | + $this->loginAsUser('admin'); |
|
31 | + $s = new Server($r, '/'); |
|
32 | + $this->assertNotNull($s->server); |
|
33 | + foreach ($plugins as $plugin) { |
|
34 | + $this->assertNotNull($s->server->getPlugin($plugin)); |
|
35 | + } |
|
36 | + } |
|
37 | + public static function providesUris(): array { |
|
38 | + return [ |
|
39 | + 'principals' => ['principals/users/admin', ['caldav', 'oc-resource-sharing', 'carddav']], |
|
40 | + 'calendars' => ['calendars/admin', ['caldav', 'oc-resource-sharing']], |
|
41 | + 'addressbooks' => ['addressbooks/admin', ['carddav', 'oc-resource-sharing']], |
|
42 | + ]; |
|
43 | + } |
|
44 | 44 | } |
@@ -12,84 +12,84 @@ |
||
12 | 12 | use OCA\DAV\Upload\FutureFile; |
13 | 13 | |
14 | 14 | class FutureFileTest extends \Test\TestCase { |
15 | - public function testGetContentType(): void { |
|
16 | - $f = $this->mockFutureFile(); |
|
17 | - $this->assertEquals('application/octet-stream', $f->getContentType()); |
|
18 | - } |
|
19 | - |
|
20 | - public function testGetETag(): void { |
|
21 | - $f = $this->mockFutureFile(); |
|
22 | - $this->assertEquals('1234567890', $f->getETag()); |
|
23 | - } |
|
24 | - |
|
25 | - public function testGetName(): void { |
|
26 | - $f = $this->mockFutureFile(); |
|
27 | - $this->assertEquals('foo.txt', $f->getName()); |
|
28 | - } |
|
29 | - |
|
30 | - public function testGetLastModified(): void { |
|
31 | - $f = $this->mockFutureFile(); |
|
32 | - $this->assertEquals(12121212, $f->getLastModified()); |
|
33 | - } |
|
34 | - |
|
35 | - public function testGetSize(): void { |
|
36 | - $f = $this->mockFutureFile(); |
|
37 | - $this->assertEquals(0, $f->getSize()); |
|
38 | - } |
|
39 | - |
|
40 | - public function testGet(): void { |
|
41 | - $f = $this->mockFutureFile(); |
|
42 | - $stream = $f->get(); |
|
43 | - $this->assertTrue(is_resource($stream)); |
|
44 | - } |
|
45 | - |
|
46 | - public function testDelete(): void { |
|
47 | - $d = $this->getMockBuilder(Directory::class) |
|
48 | - ->disableOriginalConstructor() |
|
49 | - ->onlyMethods(['delete']) |
|
50 | - ->getMock(); |
|
51 | - |
|
52 | - $d->expects($this->once()) |
|
53 | - ->method('delete'); |
|
54 | - |
|
55 | - $f = new FutureFile($d, 'foo.txt'); |
|
56 | - $f->delete(); |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - public function testPut(): void { |
|
61 | - $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
62 | - |
|
63 | - $f = $this->mockFutureFile(); |
|
64 | - $f->put(''); |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - public function testSetName(): void { |
|
69 | - $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
70 | - |
|
71 | - $f = $this->mockFutureFile(); |
|
72 | - $f->setName(''); |
|
73 | - } |
|
74 | - |
|
75 | - private function mockFutureFile(): FutureFile { |
|
76 | - $d = $this->getMockBuilder(Directory::class) |
|
77 | - ->disableOriginalConstructor() |
|
78 | - ->onlyMethods(['getETag', 'getLastModified', 'getChildren']) |
|
79 | - ->getMock(); |
|
80 | - |
|
81 | - $d->expects($this->any()) |
|
82 | - ->method('getETag') |
|
83 | - ->willReturn('1234567890'); |
|
84 | - |
|
85 | - $d->expects($this->any()) |
|
86 | - ->method('getLastModified') |
|
87 | - ->willReturn(12121212); |
|
88 | - |
|
89 | - $d->expects($this->any()) |
|
90 | - ->method('getChildren') |
|
91 | - ->willReturn([]); |
|
92 | - |
|
93 | - return new FutureFile($d, 'foo.txt'); |
|
94 | - } |
|
15 | + public function testGetContentType(): void { |
|
16 | + $f = $this->mockFutureFile(); |
|
17 | + $this->assertEquals('application/octet-stream', $f->getContentType()); |
|
18 | + } |
|
19 | + |
|
20 | + public function testGetETag(): void { |
|
21 | + $f = $this->mockFutureFile(); |
|
22 | + $this->assertEquals('1234567890', $f->getETag()); |
|
23 | + } |
|
24 | + |
|
25 | + public function testGetName(): void { |
|
26 | + $f = $this->mockFutureFile(); |
|
27 | + $this->assertEquals('foo.txt', $f->getName()); |
|
28 | + } |
|
29 | + |
|
30 | + public function testGetLastModified(): void { |
|
31 | + $f = $this->mockFutureFile(); |
|
32 | + $this->assertEquals(12121212, $f->getLastModified()); |
|
33 | + } |
|
34 | + |
|
35 | + public function testGetSize(): void { |
|
36 | + $f = $this->mockFutureFile(); |
|
37 | + $this->assertEquals(0, $f->getSize()); |
|
38 | + } |
|
39 | + |
|
40 | + public function testGet(): void { |
|
41 | + $f = $this->mockFutureFile(); |
|
42 | + $stream = $f->get(); |
|
43 | + $this->assertTrue(is_resource($stream)); |
|
44 | + } |
|
45 | + |
|
46 | + public function testDelete(): void { |
|
47 | + $d = $this->getMockBuilder(Directory::class) |
|
48 | + ->disableOriginalConstructor() |
|
49 | + ->onlyMethods(['delete']) |
|
50 | + ->getMock(); |
|
51 | + |
|
52 | + $d->expects($this->once()) |
|
53 | + ->method('delete'); |
|
54 | + |
|
55 | + $f = new FutureFile($d, 'foo.txt'); |
|
56 | + $f->delete(); |
|
57 | + } |
|
58 | + |
|
59 | + |
|
60 | + public function testPut(): void { |
|
61 | + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
62 | + |
|
63 | + $f = $this->mockFutureFile(); |
|
64 | + $f->put(''); |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + public function testSetName(): void { |
|
69 | + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
70 | + |
|
71 | + $f = $this->mockFutureFile(); |
|
72 | + $f->setName(''); |
|
73 | + } |
|
74 | + |
|
75 | + private function mockFutureFile(): FutureFile { |
|
76 | + $d = $this->getMockBuilder(Directory::class) |
|
77 | + ->disableOriginalConstructor() |
|
78 | + ->onlyMethods(['getETag', 'getLastModified', 'getChildren']) |
|
79 | + ->getMock(); |
|
80 | + |
|
81 | + $d->expects($this->any()) |
|
82 | + ->method('getETag') |
|
83 | + ->willReturn('1234567890'); |
|
84 | + |
|
85 | + $d->expects($this->any()) |
|
86 | + ->method('getLastModified') |
|
87 | + ->willReturn(12121212); |
|
88 | + |
|
89 | + $d->expects($this->any()) |
|
90 | + ->method('getChildren') |
|
91 | + ->willReturn([]); |
|
92 | + |
|
93 | + return new FutureFile($d, 'foo.txt'); |
|
94 | + } |
|
95 | 95 | } |