@@ -14,84 +14,84 @@ |
||
14 | 14 | use Test\TestCase; |
15 | 15 | |
16 | 16 | class InfoTest extends TestCase { |
17 | - /** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
18 | - private $groupManager; |
|
19 | - |
|
20 | - /** @var Info|\PHPUnit\Framework\MockObject\MockObject */ |
|
21 | - private $command; |
|
22 | - |
|
23 | - /** @var InputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
24 | - private $input; |
|
25 | - |
|
26 | - /** @var OutputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
27 | - private $output; |
|
28 | - |
|
29 | - protected function setUp(): void { |
|
30 | - parent::setUp(); |
|
31 | - |
|
32 | - $this->groupManager = $this->createMock(IGroupManager::class); |
|
33 | - $this->command = $this->getMockBuilder(Info::class) |
|
34 | - ->setConstructorArgs([$this->groupManager]) |
|
35 | - ->onlyMethods(['writeArrayInOutputFormat']) |
|
36 | - ->getMock(); |
|
37 | - |
|
38 | - $this->input = $this->createMock(InputInterface::class); |
|
39 | - $this->output = $this->createMock(OutputInterface::class); |
|
40 | - } |
|
41 | - |
|
42 | - public function testDoesNotExists(): void { |
|
43 | - $gid = 'myGroup'; |
|
44 | - $this->input->method('getArgument') |
|
45 | - ->willReturnCallback(function ($arg) use ($gid) { |
|
46 | - if ($arg === 'groupid') { |
|
47 | - return $gid; |
|
48 | - } |
|
49 | - throw new \Exception(); |
|
50 | - }); |
|
51 | - $this->groupManager->method('get') |
|
52 | - ->with($gid) |
|
53 | - ->willReturn(null); |
|
54 | - |
|
55 | - $this->output->expects($this->once()) |
|
56 | - ->method('writeln') |
|
57 | - ->with($this->equalTo('<error>Group "' . $gid . '" does not exist.</error>')); |
|
58 | - |
|
59 | - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); |
|
60 | - } |
|
61 | - |
|
62 | - public function testInfo(): void { |
|
63 | - $gid = 'myGroup'; |
|
64 | - $this->input->method('getArgument') |
|
65 | - ->willReturnCallback(function ($arg) use ($gid) { |
|
66 | - if ($arg === 'groupid') { |
|
67 | - return $gid; |
|
68 | - } |
|
69 | - throw new \Exception(); |
|
70 | - }); |
|
71 | - |
|
72 | - $group = $this->createMock(IGroup::class); |
|
73 | - $group->method('getGID')->willReturn($gid); |
|
74 | - $group->method('getDisplayName') |
|
75 | - ->willReturn('My Group'); |
|
76 | - $group->method('getBackendNames') |
|
77 | - ->willReturn(['Database']); |
|
78 | - |
|
79 | - $this->groupManager->method('get') |
|
80 | - ->with($gid) |
|
81 | - ->willReturn($group); |
|
82 | - |
|
83 | - $this->command->expects($this->once()) |
|
84 | - ->method('writeArrayInOutputFormat') |
|
85 | - ->with( |
|
86 | - $this->equalTo($this->input), |
|
87 | - $this->equalTo($this->output), |
|
88 | - [ |
|
89 | - 'groupID' => 'myGroup', |
|
90 | - 'displayName' => 'My Group', |
|
91 | - 'backends' => ['Database'], |
|
92 | - ] |
|
93 | - ); |
|
94 | - |
|
95 | - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); |
|
96 | - } |
|
17 | + /** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
18 | + private $groupManager; |
|
19 | + |
|
20 | + /** @var Info|\PHPUnit\Framework\MockObject\MockObject */ |
|
21 | + private $command; |
|
22 | + |
|
23 | + /** @var InputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
24 | + private $input; |
|
25 | + |
|
26 | + /** @var OutputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
27 | + private $output; |
|
28 | + |
|
29 | + protected function setUp(): void { |
|
30 | + parent::setUp(); |
|
31 | + |
|
32 | + $this->groupManager = $this->createMock(IGroupManager::class); |
|
33 | + $this->command = $this->getMockBuilder(Info::class) |
|
34 | + ->setConstructorArgs([$this->groupManager]) |
|
35 | + ->onlyMethods(['writeArrayInOutputFormat']) |
|
36 | + ->getMock(); |
|
37 | + |
|
38 | + $this->input = $this->createMock(InputInterface::class); |
|
39 | + $this->output = $this->createMock(OutputInterface::class); |
|
40 | + } |
|
41 | + |
|
42 | + public function testDoesNotExists(): void { |
|
43 | + $gid = 'myGroup'; |
|
44 | + $this->input->method('getArgument') |
|
45 | + ->willReturnCallback(function ($arg) use ($gid) { |
|
46 | + if ($arg === 'groupid') { |
|
47 | + return $gid; |
|
48 | + } |
|
49 | + throw new \Exception(); |
|
50 | + }); |
|
51 | + $this->groupManager->method('get') |
|
52 | + ->with($gid) |
|
53 | + ->willReturn(null); |
|
54 | + |
|
55 | + $this->output->expects($this->once()) |
|
56 | + ->method('writeln') |
|
57 | + ->with($this->equalTo('<error>Group "' . $gid . '" does not exist.</error>')); |
|
58 | + |
|
59 | + $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); |
|
60 | + } |
|
61 | + |
|
62 | + public function testInfo(): void { |
|
63 | + $gid = 'myGroup'; |
|
64 | + $this->input->method('getArgument') |
|
65 | + ->willReturnCallback(function ($arg) use ($gid) { |
|
66 | + if ($arg === 'groupid') { |
|
67 | + return $gid; |
|
68 | + } |
|
69 | + throw new \Exception(); |
|
70 | + }); |
|
71 | + |
|
72 | + $group = $this->createMock(IGroup::class); |
|
73 | + $group->method('getGID')->willReturn($gid); |
|
74 | + $group->method('getDisplayName') |
|
75 | + ->willReturn('My Group'); |
|
76 | + $group->method('getBackendNames') |
|
77 | + ->willReturn(['Database']); |
|
78 | + |
|
79 | + $this->groupManager->method('get') |
|
80 | + ->with($gid) |
|
81 | + ->willReturn($group); |
|
82 | + |
|
83 | + $this->command->expects($this->once()) |
|
84 | + ->method('writeArrayInOutputFormat') |
|
85 | + ->with( |
|
86 | + $this->equalTo($this->input), |
|
87 | + $this->equalTo($this->output), |
|
88 | + [ |
|
89 | + 'groupID' => 'myGroup', |
|
90 | + 'displayName' => 'My Group', |
|
91 | + 'backends' => ['Database'], |
|
92 | + ] |
|
93 | + ); |
|
94 | + |
|
95 | + $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); |
|
96 | + } |
|
97 | 97 | } |
@@ -15,189 +15,189 @@ |
||
15 | 15 | use Test\TestCase; |
16 | 16 | |
17 | 17 | class ListCommandTest extends TestCase { |
18 | - /** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
19 | - private $groupManager; |
|
20 | - |
|
21 | - /** @var ListCommand|\PHPUnit\Framework\MockObject\MockObject */ |
|
22 | - private $command; |
|
23 | - |
|
24 | - /** @var InputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
25 | - private $input; |
|
26 | - |
|
27 | - /** @var OutputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
28 | - private $output; |
|
29 | - |
|
30 | - protected function setUp(): void { |
|
31 | - parent::setUp(); |
|
32 | - |
|
33 | - $this->groupManager = $this->createMock(IGroupManager::class); |
|
34 | - $this->command = $this->getMockBuilder(ListCommand::class) |
|
35 | - ->setConstructorArgs([$this->groupManager]) |
|
36 | - ->onlyMethods(['writeArrayInOutputFormat']) |
|
37 | - ->getMock(); |
|
38 | - |
|
39 | - $this->input = $this->createMock(InputInterface::class); |
|
40 | - $this->output = $this->createMock(OutputInterface::class); |
|
41 | - } |
|
42 | - |
|
43 | - public function testExecute(): void { |
|
44 | - $group1 = $this->createMock(IGroup::class); |
|
45 | - $group1->method('getGID')->willReturn('group1'); |
|
46 | - $group2 = $this->createMock(IGroup::class); |
|
47 | - $group2->method('getGID')->willReturn('group2'); |
|
48 | - $group3 = $this->createMock(IGroup::class); |
|
49 | - $group3->method('getGID')->willReturn('group3'); |
|
50 | - |
|
51 | - $user = $this->createMock(IUser::class); |
|
52 | - |
|
53 | - $this->groupManager->method('search') |
|
54 | - ->with( |
|
55 | - '', |
|
56 | - 100, |
|
57 | - 42, |
|
58 | - )->willReturn([$group1, $group2, $group3]); |
|
59 | - |
|
60 | - $group1->method('getUsers') |
|
61 | - ->willReturn([ |
|
62 | - 'user1' => $user, |
|
63 | - 'user2' => $user, |
|
64 | - ]); |
|
65 | - |
|
66 | - $group2->method('getUsers') |
|
67 | - ->willReturn([ |
|
68 | - ]); |
|
69 | - |
|
70 | - $group3->method('getUsers') |
|
71 | - ->willReturn([ |
|
72 | - 'user1' => $user, |
|
73 | - 'user3' => $user, |
|
74 | - ]); |
|
75 | - |
|
76 | - $this->input->method('getOption') |
|
77 | - ->willReturnCallback(function ($arg) { |
|
78 | - if ($arg === 'limit') { |
|
79 | - return '100'; |
|
80 | - } elseif ($arg === 'offset') { |
|
81 | - return '42'; |
|
82 | - } elseif ($arg === 'info') { |
|
83 | - return null; |
|
84 | - } |
|
85 | - throw new \Exception(); |
|
86 | - }); |
|
87 | - |
|
88 | - $this->command->expects($this->once()) |
|
89 | - ->method('writeArrayInOutputFormat') |
|
90 | - ->with( |
|
91 | - $this->equalTo($this->input), |
|
92 | - $this->equalTo($this->output), |
|
93 | - $this->callback( |
|
94 | - fn ($iterator) => iterator_to_array($iterator) === [ |
|
95 | - 'group1' => [ |
|
96 | - 'user1', |
|
97 | - 'user2', |
|
98 | - ], |
|
99 | - 'group2' => [ |
|
100 | - ], |
|
101 | - 'group3' => [ |
|
102 | - 'user1', |
|
103 | - 'user3', |
|
104 | - ] |
|
105 | - ] |
|
106 | - ) |
|
107 | - ); |
|
108 | - |
|
109 | - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); |
|
110 | - } |
|
111 | - |
|
112 | - public function testInfo(): void { |
|
113 | - $group1 = $this->createMock(IGroup::class); |
|
114 | - $group1->method('getGID')->willReturn('group1'); |
|
115 | - $group1->method('getDisplayName')->willReturn('Group 1'); |
|
116 | - $group2 = $this->createMock(IGroup::class); |
|
117 | - $group2->method('getGID')->willReturn('group2'); |
|
118 | - $group2->method('getDisplayName')->willReturn('Group 2'); |
|
119 | - $group3 = $this->createMock(IGroup::class); |
|
120 | - $group3->method('getGID')->willReturn('group3'); |
|
121 | - $group3->method('getDisplayName')->willReturn('Group 3'); |
|
122 | - |
|
123 | - $user = $this->createMock(IUser::class); |
|
124 | - |
|
125 | - $this->groupManager->method('search') |
|
126 | - ->with( |
|
127 | - '', |
|
128 | - 100, |
|
129 | - 42, |
|
130 | - )->willReturn([$group1, $group2, $group3]); |
|
131 | - |
|
132 | - $group1->method('getUsers') |
|
133 | - ->willReturn([ |
|
134 | - 'user1' => $user, |
|
135 | - 'user2' => $user, |
|
136 | - ]); |
|
137 | - |
|
138 | - $group1->method('getBackendNames') |
|
139 | - ->willReturn(['Database']); |
|
140 | - |
|
141 | - $group2->method('getUsers') |
|
142 | - ->willReturn([ |
|
143 | - ]); |
|
144 | - |
|
145 | - $group2->method('getBackendNames') |
|
146 | - ->willReturn(['Database']); |
|
147 | - |
|
148 | - $group3->method('getUsers') |
|
149 | - ->willReturn([ |
|
150 | - 'user1' => $user, |
|
151 | - 'user3' => $user, |
|
152 | - ]); |
|
153 | - |
|
154 | - $group3->method('getBackendNames') |
|
155 | - ->willReturn(['LDAP']); |
|
156 | - |
|
157 | - $this->input->method('getOption') |
|
158 | - ->willReturnCallback(function ($arg) { |
|
159 | - if ($arg === 'limit') { |
|
160 | - return '100'; |
|
161 | - } elseif ($arg === 'offset') { |
|
162 | - return '42'; |
|
163 | - } elseif ($arg === 'info') { |
|
164 | - return true; |
|
165 | - } |
|
166 | - throw new \Exception(); |
|
167 | - }); |
|
168 | - |
|
169 | - $this->command->expects($this->once()) |
|
170 | - ->method('writeArrayInOutputFormat') |
|
171 | - ->with( |
|
172 | - $this->equalTo($this->input), |
|
173 | - $this->equalTo($this->output), |
|
174 | - $this->callback( |
|
175 | - fn ($iterator) => iterator_to_array($iterator) === [ |
|
176 | - 'group1' => [ |
|
177 | - 'displayName' => 'Group 1', |
|
178 | - 'backends' => ['Database'], |
|
179 | - 'users' => [ |
|
180 | - 'user1', |
|
181 | - 'user2', |
|
182 | - ], |
|
183 | - ], |
|
184 | - 'group2' => [ |
|
185 | - 'displayName' => 'Group 2', |
|
186 | - 'backends' => ['Database'], |
|
187 | - 'users' => [], |
|
188 | - ], |
|
189 | - 'group3' => [ |
|
190 | - 'displayName' => 'Group 3', |
|
191 | - 'backends' => ['LDAP'], |
|
192 | - 'users' => [ |
|
193 | - 'user1', |
|
194 | - 'user3', |
|
195 | - ], |
|
196 | - ] |
|
197 | - ] |
|
198 | - ) |
|
199 | - ); |
|
200 | - |
|
201 | - $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); |
|
202 | - } |
|
18 | + /** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
19 | + private $groupManager; |
|
20 | + |
|
21 | + /** @var ListCommand|\PHPUnit\Framework\MockObject\MockObject */ |
|
22 | + private $command; |
|
23 | + |
|
24 | + /** @var InputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
25 | + private $input; |
|
26 | + |
|
27 | + /** @var OutputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
28 | + private $output; |
|
29 | + |
|
30 | + protected function setUp(): void { |
|
31 | + parent::setUp(); |
|
32 | + |
|
33 | + $this->groupManager = $this->createMock(IGroupManager::class); |
|
34 | + $this->command = $this->getMockBuilder(ListCommand::class) |
|
35 | + ->setConstructorArgs([$this->groupManager]) |
|
36 | + ->onlyMethods(['writeArrayInOutputFormat']) |
|
37 | + ->getMock(); |
|
38 | + |
|
39 | + $this->input = $this->createMock(InputInterface::class); |
|
40 | + $this->output = $this->createMock(OutputInterface::class); |
|
41 | + } |
|
42 | + |
|
43 | + public function testExecute(): void { |
|
44 | + $group1 = $this->createMock(IGroup::class); |
|
45 | + $group1->method('getGID')->willReturn('group1'); |
|
46 | + $group2 = $this->createMock(IGroup::class); |
|
47 | + $group2->method('getGID')->willReturn('group2'); |
|
48 | + $group3 = $this->createMock(IGroup::class); |
|
49 | + $group3->method('getGID')->willReturn('group3'); |
|
50 | + |
|
51 | + $user = $this->createMock(IUser::class); |
|
52 | + |
|
53 | + $this->groupManager->method('search') |
|
54 | + ->with( |
|
55 | + '', |
|
56 | + 100, |
|
57 | + 42, |
|
58 | + )->willReturn([$group1, $group2, $group3]); |
|
59 | + |
|
60 | + $group1->method('getUsers') |
|
61 | + ->willReturn([ |
|
62 | + 'user1' => $user, |
|
63 | + 'user2' => $user, |
|
64 | + ]); |
|
65 | + |
|
66 | + $group2->method('getUsers') |
|
67 | + ->willReturn([ |
|
68 | + ]); |
|
69 | + |
|
70 | + $group3->method('getUsers') |
|
71 | + ->willReturn([ |
|
72 | + 'user1' => $user, |
|
73 | + 'user3' => $user, |
|
74 | + ]); |
|
75 | + |
|
76 | + $this->input->method('getOption') |
|
77 | + ->willReturnCallback(function ($arg) { |
|
78 | + if ($arg === 'limit') { |
|
79 | + return '100'; |
|
80 | + } elseif ($arg === 'offset') { |
|
81 | + return '42'; |
|
82 | + } elseif ($arg === 'info') { |
|
83 | + return null; |
|
84 | + } |
|
85 | + throw new \Exception(); |
|
86 | + }); |
|
87 | + |
|
88 | + $this->command->expects($this->once()) |
|
89 | + ->method('writeArrayInOutputFormat') |
|
90 | + ->with( |
|
91 | + $this->equalTo($this->input), |
|
92 | + $this->equalTo($this->output), |
|
93 | + $this->callback( |
|
94 | + fn ($iterator) => iterator_to_array($iterator) === [ |
|
95 | + 'group1' => [ |
|
96 | + 'user1', |
|
97 | + 'user2', |
|
98 | + ], |
|
99 | + 'group2' => [ |
|
100 | + ], |
|
101 | + 'group3' => [ |
|
102 | + 'user1', |
|
103 | + 'user3', |
|
104 | + ] |
|
105 | + ] |
|
106 | + ) |
|
107 | + ); |
|
108 | + |
|
109 | + $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); |
|
110 | + } |
|
111 | + |
|
112 | + public function testInfo(): void { |
|
113 | + $group1 = $this->createMock(IGroup::class); |
|
114 | + $group1->method('getGID')->willReturn('group1'); |
|
115 | + $group1->method('getDisplayName')->willReturn('Group 1'); |
|
116 | + $group2 = $this->createMock(IGroup::class); |
|
117 | + $group2->method('getGID')->willReturn('group2'); |
|
118 | + $group2->method('getDisplayName')->willReturn('Group 2'); |
|
119 | + $group3 = $this->createMock(IGroup::class); |
|
120 | + $group3->method('getGID')->willReturn('group3'); |
|
121 | + $group3->method('getDisplayName')->willReturn('Group 3'); |
|
122 | + |
|
123 | + $user = $this->createMock(IUser::class); |
|
124 | + |
|
125 | + $this->groupManager->method('search') |
|
126 | + ->with( |
|
127 | + '', |
|
128 | + 100, |
|
129 | + 42, |
|
130 | + )->willReturn([$group1, $group2, $group3]); |
|
131 | + |
|
132 | + $group1->method('getUsers') |
|
133 | + ->willReturn([ |
|
134 | + 'user1' => $user, |
|
135 | + 'user2' => $user, |
|
136 | + ]); |
|
137 | + |
|
138 | + $group1->method('getBackendNames') |
|
139 | + ->willReturn(['Database']); |
|
140 | + |
|
141 | + $group2->method('getUsers') |
|
142 | + ->willReturn([ |
|
143 | + ]); |
|
144 | + |
|
145 | + $group2->method('getBackendNames') |
|
146 | + ->willReturn(['Database']); |
|
147 | + |
|
148 | + $group3->method('getUsers') |
|
149 | + ->willReturn([ |
|
150 | + 'user1' => $user, |
|
151 | + 'user3' => $user, |
|
152 | + ]); |
|
153 | + |
|
154 | + $group3->method('getBackendNames') |
|
155 | + ->willReturn(['LDAP']); |
|
156 | + |
|
157 | + $this->input->method('getOption') |
|
158 | + ->willReturnCallback(function ($arg) { |
|
159 | + if ($arg === 'limit') { |
|
160 | + return '100'; |
|
161 | + } elseif ($arg === 'offset') { |
|
162 | + return '42'; |
|
163 | + } elseif ($arg === 'info') { |
|
164 | + return true; |
|
165 | + } |
|
166 | + throw new \Exception(); |
|
167 | + }); |
|
168 | + |
|
169 | + $this->command->expects($this->once()) |
|
170 | + ->method('writeArrayInOutputFormat') |
|
171 | + ->with( |
|
172 | + $this->equalTo($this->input), |
|
173 | + $this->equalTo($this->output), |
|
174 | + $this->callback( |
|
175 | + fn ($iterator) => iterator_to_array($iterator) === [ |
|
176 | + 'group1' => [ |
|
177 | + 'displayName' => 'Group 1', |
|
178 | + 'backends' => ['Database'], |
|
179 | + 'users' => [ |
|
180 | + 'user1', |
|
181 | + 'user2', |
|
182 | + ], |
|
183 | + ], |
|
184 | + 'group2' => [ |
|
185 | + 'displayName' => 'Group 2', |
|
186 | + 'backends' => ['Database'], |
|
187 | + 'users' => [], |
|
188 | + ], |
|
189 | + 'group3' => [ |
|
190 | + 'displayName' => 'Group 3', |
|
191 | + 'backends' => ['LDAP'], |
|
192 | + 'users' => [ |
|
193 | + 'user1', |
|
194 | + 'user3', |
|
195 | + ], |
|
196 | + ] |
|
197 | + ] |
|
198 | + ) |
|
199 | + ); |
|
200 | + |
|
201 | + $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); |
|
202 | + } |
|
203 | 203 | } |
@@ -16,449 +16,449 @@ |
||
16 | 16 | use Test\TestCase; |
17 | 17 | |
18 | 18 | class SettingTest extends TestCase { |
19 | - /** @var \OCP\IUserManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
20 | - protected $userManager; |
|
21 | - /** @var \OCP\IConfig|\PHPUnit\Framework\MockObject\MockObject */ |
|
22 | - protected $config; |
|
23 | - /** @var \OCP\IDBConnection|\PHPUnit\Framework\MockObject\MockObject */ |
|
24 | - protected $connection; |
|
25 | - /** @var \Symfony\Component\Console\Input\InputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
26 | - protected $consoleInput; |
|
27 | - /** @var \Symfony\Component\Console\Output\OutputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
28 | - protected $consoleOutput; |
|
29 | - |
|
30 | - protected function setUp(): void { |
|
31 | - parent::setUp(); |
|
32 | - |
|
33 | - $this->userManager = $this->getMockBuilder(IUserManager::class) |
|
34 | - ->disableOriginalConstructor() |
|
35 | - ->getMock(); |
|
36 | - $this->config = $this->getMockBuilder(IConfig::class) |
|
37 | - ->disableOriginalConstructor() |
|
38 | - ->getMock(); |
|
39 | - $this->connection = $this->getMockBuilder(IDBConnection::class) |
|
40 | - ->disableOriginalConstructor() |
|
41 | - ->getMock(); |
|
42 | - $this->consoleInput = $this->getMockBuilder(InputInterface::class) |
|
43 | - ->disableOriginalConstructor() |
|
44 | - ->getMock(); |
|
45 | - $this->consoleOutput = $this->getMockBuilder(OutputInterface::class) |
|
46 | - ->disableOriginalConstructor() |
|
47 | - ->getMock(); |
|
48 | - } |
|
49 | - |
|
50 | - public function getCommand(array $methods = []) { |
|
51 | - if (empty($methods)) { |
|
52 | - return new Setting($this->userManager, $this->config); |
|
53 | - } else { |
|
54 | - $mock = $this->getMockBuilder(Setting::class) |
|
55 | - ->setConstructorArgs([ |
|
56 | - $this->userManager, |
|
57 | - $this->config, |
|
58 | - ]) |
|
59 | - ->onlyMethods($methods) |
|
60 | - ->getMock(); |
|
61 | - return $mock; |
|
62 | - } |
|
63 | - } |
|
64 | - |
|
65 | - public static function dataCheckInput(): array { |
|
66 | - return [ |
|
67 | - [ |
|
68 | - [['uid', 'username']], |
|
69 | - [['ignore-missing-user', true]], |
|
70 | - [], |
|
71 | - false, |
|
72 | - false, |
|
73 | - ], |
|
74 | - [ |
|
75 | - [['uid', 'username']], |
|
76 | - [['ignore-missing-user', false]], |
|
77 | - [], |
|
78 | - null, |
|
79 | - 'The user "username" does not exist.', |
|
80 | - ], |
|
81 | - |
|
82 | - [ |
|
83 | - [['uid', 'username'], ['key', 'configkey']], |
|
84 | - [['ignore-missing-user', true]], |
|
85 | - [['--default-value', false, true]], |
|
86 | - false, |
|
87 | - false, |
|
88 | - ], |
|
89 | - [ |
|
90 | - [['uid', 'username'], ['key', '']], |
|
91 | - [['ignore-missing-user', true]], |
|
92 | - [['--default-value', false, true]], |
|
93 | - false, |
|
94 | - 'The "default-value" option can only be used when specifying a key.', |
|
95 | - ], |
|
96 | - |
|
97 | - [ |
|
98 | - [['uid', 'username'], ['key', 'configkey'], ['value', '']], |
|
99 | - [['ignore-missing-user', true]], |
|
100 | - [], |
|
101 | - false, |
|
102 | - false, |
|
103 | - ], |
|
104 | - [ |
|
105 | - [['uid', 'username'], ['key', ''], ['value', '']], |
|
106 | - [['ignore-missing-user', true]], |
|
107 | - [], |
|
108 | - false, |
|
109 | - 'The value argument can only be used when specifying a key.', |
|
110 | - ], |
|
111 | - [ |
|
112 | - [['uid', 'username'], ['key', 'configkey'], ['value', '']], |
|
113 | - [['ignore-missing-user', true]], |
|
114 | - [['--default-value', false, true]], |
|
115 | - false, |
|
116 | - 'The value argument can not be used together with "default-value".', |
|
117 | - ], |
|
118 | - [ |
|
119 | - [['uid', 'username'], ['key', 'configkey'], ['value', '']], |
|
120 | - [['ignore-missing-user', true], ['update-only', true]], |
|
121 | - [], |
|
122 | - false, |
|
123 | - false, |
|
124 | - ], |
|
125 | - [ |
|
126 | - [['uid', 'username'], ['key', 'configkey'], ['value', null]], |
|
127 | - [['ignore-missing-user', true], ['update-only', true]], |
|
128 | - [], |
|
129 | - false, |
|
130 | - 'The "update-only" option can only be used together with "value".', |
|
131 | - ], |
|
132 | - |
|
133 | - [ |
|
134 | - [['uid', 'username'], ['key', 'configkey']], |
|
135 | - [['ignore-missing-user', true], ['delete', true]], |
|
136 | - [], |
|
137 | - false, |
|
138 | - false, |
|
139 | - ], |
|
140 | - [ |
|
141 | - [['uid', 'username'], ['key', '']], |
|
142 | - [['ignore-missing-user', true], ['delete', true]], |
|
143 | - [], |
|
144 | - false, |
|
145 | - 'The "delete" option can only be used when specifying a key.', |
|
146 | - ], |
|
147 | - [ |
|
148 | - [['uid', 'username'], ['key', 'configkey']], |
|
149 | - [['ignore-missing-user', true], ['delete', true]], |
|
150 | - [['--default-value', false, true]], |
|
151 | - false, |
|
152 | - 'The "delete" option can not be used together with "default-value".', |
|
153 | - ], |
|
154 | - [ |
|
155 | - [['uid', 'username'], ['key', 'configkey'], ['value', '']], |
|
156 | - [['ignore-missing-user', true], ['delete', true]], |
|
157 | - [], |
|
158 | - false, |
|
159 | - 'The "delete" option can not be used together with "value".', |
|
160 | - ], |
|
161 | - [ |
|
162 | - [['uid', 'username'], ['key', 'configkey']], |
|
163 | - [['ignore-missing-user', true], ['delete', true], ['error-if-not-exists', true]], |
|
164 | - [], |
|
165 | - false, |
|
166 | - false, |
|
167 | - ], |
|
168 | - [ |
|
169 | - [['uid', 'username'], ['key', 'configkey']], |
|
170 | - [['ignore-missing-user', true], ['delete', false], ['error-if-not-exists', true]], |
|
171 | - [], |
|
172 | - false, |
|
173 | - 'The "error-if-not-exists" option can only be used together with "delete".', |
|
174 | - ], |
|
175 | - ]; |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * @dataProvider dataCheckInput |
|
180 | - * |
|
181 | - * @param array $arguments |
|
182 | - * @param array $options |
|
183 | - * @param array $parameterOptions |
|
184 | - * @param mixed $user |
|
185 | - * @param string $expectedException |
|
186 | - */ |
|
187 | - public function testCheckInput($arguments, $options, $parameterOptions, $user, $expectedException): void { |
|
188 | - $this->consoleInput->expects($this->any()) |
|
189 | - ->method('getArgument') |
|
190 | - ->willReturnMap($arguments); |
|
191 | - $this->consoleInput->expects($this->any()) |
|
192 | - ->method('getOption') |
|
193 | - ->willReturnMap($options); |
|
194 | - $this->consoleInput->expects($this->any()) |
|
195 | - ->method('hasParameterOption') |
|
196 | - ->willReturnCallback(function (string|array $config, bool $default = false) use ($parameterOptions): bool { |
|
197 | - foreach ($parameterOptions as $parameterOption) { |
|
198 | - if ($config === $parameterOption[0] |
|
199 | - // Check the default value if the maps has 3 entries |
|
200 | - && (!isset($parameterOption[2]) || $default === $parameterOption[1])) { |
|
201 | - return end($parameterOption); |
|
202 | - } |
|
203 | - } |
|
204 | - return false; |
|
205 | - }); |
|
206 | - |
|
207 | - if ($user !== false) { |
|
208 | - $this->userManager->expects($this->once()) |
|
209 | - ->method('get') |
|
210 | - ->willReturn($user); |
|
211 | - } else { |
|
212 | - $this->userManager->expects($this->never()) |
|
213 | - ->method('get'); |
|
214 | - } |
|
215 | - |
|
216 | - $command = $this->getCommand(); |
|
217 | - try { |
|
218 | - $this->invokePrivate($command, 'checkInput', [$this->consoleInput]); |
|
219 | - $this->assertFalse($expectedException); |
|
220 | - } catch (\InvalidArgumentException $e) { |
|
221 | - $this->assertEquals($expectedException, $e->getMessage()); |
|
222 | - } |
|
223 | - } |
|
224 | - |
|
225 | - public function testCheckInputExceptionCatch(): void { |
|
226 | - $command = $this->getCommand(['checkInput']); |
|
227 | - $command->expects($this->once()) |
|
228 | - ->method('checkInput') |
|
229 | - ->willThrowException(new \InvalidArgumentException('test')); |
|
230 | - |
|
231 | - $this->consoleOutput->expects($this->once()) |
|
232 | - ->method('writeln') |
|
233 | - ->with('<error>test</error>'); |
|
234 | - |
|
235 | - $this->assertEquals(1, $this->invokePrivate($command, 'execute', [$this->consoleInput, $this->consoleOutput])); |
|
236 | - } |
|
237 | - |
|
238 | - public static function dataExecuteDelete(): array { |
|
239 | - return [ |
|
240 | - ['config', false, null, 0], |
|
241 | - ['config', true, null, 0], |
|
242 | - [null, false, null, 0], |
|
243 | - [null, true, '<error>The setting does not exist for user "username".</error>', 1], |
|
244 | - ]; |
|
245 | - } |
|
246 | - |
|
247 | - /** |
|
248 | - * @dataProvider dataExecuteDelete |
|
249 | - * |
|
250 | - * @param string|null $value |
|
251 | - * @param bool $errorIfNotExists |
|
252 | - * @param string $expectedLine |
|
253 | - * @param int $expectedReturn |
|
254 | - */ |
|
255 | - public function testExecuteDelete($value, $errorIfNotExists, $expectedLine, $expectedReturn): void { |
|
256 | - $command = $this->getCommand([ |
|
257 | - 'writeArrayInOutputFormat', |
|
258 | - 'checkInput', |
|
259 | - 'getUserSettings', |
|
260 | - ]); |
|
261 | - |
|
262 | - $this->consoleInput->expects($this->any()) |
|
263 | - ->method('getArgument') |
|
264 | - ->willReturnMap([ |
|
265 | - ['uid', 'username'], |
|
266 | - ['app', 'appname'], |
|
267 | - ['key', 'configkey'], |
|
268 | - ]); |
|
269 | - |
|
270 | - $command->expects($this->once()) |
|
271 | - ->method('checkInput'); |
|
272 | - |
|
273 | - $this->config->expects($this->once()) |
|
274 | - ->method('getUserValue') |
|
275 | - ->with('username', 'appname', 'configkey', null) |
|
276 | - ->willReturn($value); |
|
277 | - |
|
278 | - $this->consoleInput->expects($this->atLeastOnce()) |
|
279 | - ->method('hasParameterOption') |
|
280 | - ->willReturnMap([ |
|
281 | - ['--delete', false, true], |
|
282 | - ['--error-if-not-exists', false, $errorIfNotExists], |
|
283 | - ]); |
|
284 | - |
|
285 | - if ($expectedLine === null) { |
|
286 | - $this->consoleOutput->expects($this->never()) |
|
287 | - ->method('writeln'); |
|
288 | - $this->config->expects($this->once()) |
|
289 | - ->method('deleteUserValue') |
|
290 | - ->with('username', 'appname', 'configkey'); |
|
291 | - } else { |
|
292 | - $this->consoleOutput->expects($this->once()) |
|
293 | - ->method('writeln') |
|
294 | - ->with($expectedLine); |
|
295 | - $this->config->expects($this->never()) |
|
296 | - ->method('deleteUserValue'); |
|
297 | - } |
|
298 | - |
|
299 | - $this->assertEquals($expectedReturn, $this->invokePrivate($command, 'execute', [$this->consoleInput, $this->consoleOutput])); |
|
300 | - } |
|
301 | - |
|
302 | - public static function dataExecuteSet(): array { |
|
303 | - return [ |
|
304 | - ['config', false, null, 0], |
|
305 | - ['config', true, null, 0], |
|
306 | - [null, false, null, 0], |
|
307 | - [null, true, '<error>The setting does not exist for user "username".</error>', 1], |
|
308 | - ]; |
|
309 | - } |
|
310 | - |
|
311 | - /** |
|
312 | - * @dataProvider dataExecuteSet |
|
313 | - * |
|
314 | - * @param string|null $value |
|
315 | - * @param bool $updateOnly |
|
316 | - * @param string $expectedLine |
|
317 | - * @param int $expectedReturn |
|
318 | - */ |
|
319 | - public function testExecuteSet($value, $updateOnly, $expectedLine, $expectedReturn): void { |
|
320 | - $command = $this->getCommand([ |
|
321 | - 'writeArrayInOutputFormat', |
|
322 | - 'checkInput', |
|
323 | - 'getUserSettings', |
|
324 | - ]); |
|
325 | - |
|
326 | - $this->consoleInput->expects($this->atLeast(4)) |
|
327 | - ->method('getArgument') |
|
328 | - ->willReturnMap([ |
|
329 | - ['uid', 'username'], |
|
330 | - ['app', 'appname'], |
|
331 | - ['key', 'configkey'], |
|
332 | - ['value', 'setValue'], |
|
333 | - ]); |
|
334 | - |
|
335 | - $command->expects($this->once()) |
|
336 | - ->method('checkInput'); |
|
337 | - |
|
338 | - $this->config->expects($this->once()) |
|
339 | - ->method('getUserValue') |
|
340 | - ->with('username', 'appname', 'configkey', null) |
|
341 | - ->willReturn($value); |
|
342 | - |
|
343 | - $this->consoleInput->expects($this->atLeastOnce()) |
|
344 | - ->method('hasParameterOption') |
|
345 | - ->willReturnMap([ |
|
346 | - ['--update-only', false, $updateOnly], |
|
347 | - ]); |
|
348 | - |
|
349 | - if ($expectedLine === null) { |
|
350 | - $this->consoleOutput->expects($this->never()) |
|
351 | - ->method('writeln'); |
|
352 | - |
|
353 | - $this->consoleInput->expects($this->never()) |
|
354 | - ->method('getOption'); |
|
355 | - |
|
356 | - $this->config->expects($this->once()) |
|
357 | - ->method('setUserValue') |
|
358 | - ->with('username', 'appname', 'configkey', 'setValue'); |
|
359 | - } else { |
|
360 | - $this->consoleOutput->expects($this->once()) |
|
361 | - ->method('writeln') |
|
362 | - ->with($expectedLine); |
|
363 | - $this->config->expects($this->never()) |
|
364 | - ->method('setUserValue'); |
|
365 | - } |
|
366 | - |
|
367 | - $this->assertEquals($expectedReturn, $this->invokePrivate($command, 'execute', [$this->consoleInput, $this->consoleOutput])); |
|
368 | - } |
|
369 | - |
|
370 | - public static function dataExecuteGet(): array { |
|
371 | - return [ |
|
372 | - ['config', null, 'config', 0], |
|
373 | - [null, 'config', 'config', 0], |
|
374 | - [null, null, '<error>The setting does not exist for user "username".</error>', 1], |
|
375 | - ]; |
|
376 | - } |
|
377 | - |
|
378 | - /** |
|
379 | - * @dataProvider dataExecuteGet |
|
380 | - * |
|
381 | - * @param string|null $value |
|
382 | - * @param string|null $defaultValue |
|
383 | - * @param string $expectedLine |
|
384 | - * @param int $expectedReturn |
|
385 | - */ |
|
386 | - public function testExecuteGet($value, $defaultValue, $expectedLine, $expectedReturn): void { |
|
387 | - $command = $this->getCommand([ |
|
388 | - 'writeArrayInOutputFormat', |
|
389 | - 'checkInput', |
|
390 | - 'getUserSettings', |
|
391 | - ]); |
|
392 | - |
|
393 | - $this->consoleInput->expects($this->any()) |
|
394 | - ->method('getArgument') |
|
395 | - ->willReturnMap([ |
|
396 | - ['uid', 'username'], |
|
397 | - ['app', 'appname'], |
|
398 | - ['key', 'configkey'], |
|
399 | - ]); |
|
400 | - |
|
401 | - $command->expects($this->once()) |
|
402 | - ->method('checkInput'); |
|
403 | - |
|
404 | - $this->config->expects($this->once()) |
|
405 | - ->method('getUserValue') |
|
406 | - ->with('username', 'appname', 'configkey', null) |
|
407 | - ->willReturn($value); |
|
408 | - |
|
409 | - if ($value === null) { |
|
410 | - if ($defaultValue === null) { |
|
411 | - $this->consoleInput->expects($this->atLeastOnce()) |
|
412 | - ->method('hasParameterOption') |
|
413 | - ->willReturn(false); |
|
414 | - } else { |
|
415 | - $this->consoleInput->expects($this->atLeastOnce()) |
|
416 | - ->method('hasParameterOption') |
|
417 | - ->willReturnCallback(function (string|array $config, bool $default = false): bool { |
|
418 | - if ($config === '--default-value' && $default === false) { |
|
419 | - return true; |
|
420 | - } |
|
421 | - return false; |
|
422 | - }); |
|
423 | - $this->consoleInput->expects($this->once()) |
|
424 | - ->method('getOption') |
|
425 | - ->with('default-value') |
|
426 | - ->willReturn($defaultValue); |
|
427 | - } |
|
428 | - } |
|
429 | - |
|
430 | - $this->consoleOutput->expects($this->once()) |
|
431 | - ->method('writeln') |
|
432 | - ->with($expectedLine); |
|
433 | - |
|
434 | - $this->assertEquals($expectedReturn, $this->invokePrivate($command, 'execute', [$this->consoleInput, $this->consoleOutput])); |
|
435 | - } |
|
436 | - |
|
437 | - public function testExecuteList(): void { |
|
438 | - $command = $this->getCommand([ |
|
439 | - 'writeArrayInOutputFormat', |
|
440 | - 'checkInput', |
|
441 | - 'getUserSettings', |
|
442 | - ]); |
|
443 | - |
|
444 | - $this->consoleInput->expects($this->any()) |
|
445 | - ->method('getArgument') |
|
446 | - ->willReturnMap([ |
|
447 | - ['uid', 'username'], |
|
448 | - ['app', 'appname'], |
|
449 | - ['key', ''], |
|
450 | - ]); |
|
451 | - |
|
452 | - $command->expects($this->once()) |
|
453 | - ->method('checkInput'); |
|
454 | - $command->expects($this->once()) |
|
455 | - ->method('getUserSettings') |
|
456 | - ->willReturn(['settings']); |
|
457 | - $command->expects($this->once()) |
|
458 | - ->method('writeArrayInOutputFormat') |
|
459 | - ->with($this->consoleInput, $this->consoleOutput, ['settings']); |
|
460 | - |
|
461 | - |
|
462 | - $this->assertEquals(0, $this->invokePrivate($command, 'execute', [$this->consoleInput, $this->consoleOutput])); |
|
463 | - } |
|
19 | + /** @var \OCP\IUserManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
20 | + protected $userManager; |
|
21 | + /** @var \OCP\IConfig|\PHPUnit\Framework\MockObject\MockObject */ |
|
22 | + protected $config; |
|
23 | + /** @var \OCP\IDBConnection|\PHPUnit\Framework\MockObject\MockObject */ |
|
24 | + protected $connection; |
|
25 | + /** @var \Symfony\Component\Console\Input\InputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
26 | + protected $consoleInput; |
|
27 | + /** @var \Symfony\Component\Console\Output\OutputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
28 | + protected $consoleOutput; |
|
29 | + |
|
30 | + protected function setUp(): void { |
|
31 | + parent::setUp(); |
|
32 | + |
|
33 | + $this->userManager = $this->getMockBuilder(IUserManager::class) |
|
34 | + ->disableOriginalConstructor() |
|
35 | + ->getMock(); |
|
36 | + $this->config = $this->getMockBuilder(IConfig::class) |
|
37 | + ->disableOriginalConstructor() |
|
38 | + ->getMock(); |
|
39 | + $this->connection = $this->getMockBuilder(IDBConnection::class) |
|
40 | + ->disableOriginalConstructor() |
|
41 | + ->getMock(); |
|
42 | + $this->consoleInput = $this->getMockBuilder(InputInterface::class) |
|
43 | + ->disableOriginalConstructor() |
|
44 | + ->getMock(); |
|
45 | + $this->consoleOutput = $this->getMockBuilder(OutputInterface::class) |
|
46 | + ->disableOriginalConstructor() |
|
47 | + ->getMock(); |
|
48 | + } |
|
49 | + |
|
50 | + public function getCommand(array $methods = []) { |
|
51 | + if (empty($methods)) { |
|
52 | + return new Setting($this->userManager, $this->config); |
|
53 | + } else { |
|
54 | + $mock = $this->getMockBuilder(Setting::class) |
|
55 | + ->setConstructorArgs([ |
|
56 | + $this->userManager, |
|
57 | + $this->config, |
|
58 | + ]) |
|
59 | + ->onlyMethods($methods) |
|
60 | + ->getMock(); |
|
61 | + return $mock; |
|
62 | + } |
|
63 | + } |
|
64 | + |
|
65 | + public static function dataCheckInput(): array { |
|
66 | + return [ |
|
67 | + [ |
|
68 | + [['uid', 'username']], |
|
69 | + [['ignore-missing-user', true]], |
|
70 | + [], |
|
71 | + false, |
|
72 | + false, |
|
73 | + ], |
|
74 | + [ |
|
75 | + [['uid', 'username']], |
|
76 | + [['ignore-missing-user', false]], |
|
77 | + [], |
|
78 | + null, |
|
79 | + 'The user "username" does not exist.', |
|
80 | + ], |
|
81 | + |
|
82 | + [ |
|
83 | + [['uid', 'username'], ['key', 'configkey']], |
|
84 | + [['ignore-missing-user', true]], |
|
85 | + [['--default-value', false, true]], |
|
86 | + false, |
|
87 | + false, |
|
88 | + ], |
|
89 | + [ |
|
90 | + [['uid', 'username'], ['key', '']], |
|
91 | + [['ignore-missing-user', true]], |
|
92 | + [['--default-value', false, true]], |
|
93 | + false, |
|
94 | + 'The "default-value" option can only be used when specifying a key.', |
|
95 | + ], |
|
96 | + |
|
97 | + [ |
|
98 | + [['uid', 'username'], ['key', 'configkey'], ['value', '']], |
|
99 | + [['ignore-missing-user', true]], |
|
100 | + [], |
|
101 | + false, |
|
102 | + false, |
|
103 | + ], |
|
104 | + [ |
|
105 | + [['uid', 'username'], ['key', ''], ['value', '']], |
|
106 | + [['ignore-missing-user', true]], |
|
107 | + [], |
|
108 | + false, |
|
109 | + 'The value argument can only be used when specifying a key.', |
|
110 | + ], |
|
111 | + [ |
|
112 | + [['uid', 'username'], ['key', 'configkey'], ['value', '']], |
|
113 | + [['ignore-missing-user', true]], |
|
114 | + [['--default-value', false, true]], |
|
115 | + false, |
|
116 | + 'The value argument can not be used together with "default-value".', |
|
117 | + ], |
|
118 | + [ |
|
119 | + [['uid', 'username'], ['key', 'configkey'], ['value', '']], |
|
120 | + [['ignore-missing-user', true], ['update-only', true]], |
|
121 | + [], |
|
122 | + false, |
|
123 | + false, |
|
124 | + ], |
|
125 | + [ |
|
126 | + [['uid', 'username'], ['key', 'configkey'], ['value', null]], |
|
127 | + [['ignore-missing-user', true], ['update-only', true]], |
|
128 | + [], |
|
129 | + false, |
|
130 | + 'The "update-only" option can only be used together with "value".', |
|
131 | + ], |
|
132 | + |
|
133 | + [ |
|
134 | + [['uid', 'username'], ['key', 'configkey']], |
|
135 | + [['ignore-missing-user', true], ['delete', true]], |
|
136 | + [], |
|
137 | + false, |
|
138 | + false, |
|
139 | + ], |
|
140 | + [ |
|
141 | + [['uid', 'username'], ['key', '']], |
|
142 | + [['ignore-missing-user', true], ['delete', true]], |
|
143 | + [], |
|
144 | + false, |
|
145 | + 'The "delete" option can only be used when specifying a key.', |
|
146 | + ], |
|
147 | + [ |
|
148 | + [['uid', 'username'], ['key', 'configkey']], |
|
149 | + [['ignore-missing-user', true], ['delete', true]], |
|
150 | + [['--default-value', false, true]], |
|
151 | + false, |
|
152 | + 'The "delete" option can not be used together with "default-value".', |
|
153 | + ], |
|
154 | + [ |
|
155 | + [['uid', 'username'], ['key', 'configkey'], ['value', '']], |
|
156 | + [['ignore-missing-user', true], ['delete', true]], |
|
157 | + [], |
|
158 | + false, |
|
159 | + 'The "delete" option can not be used together with "value".', |
|
160 | + ], |
|
161 | + [ |
|
162 | + [['uid', 'username'], ['key', 'configkey']], |
|
163 | + [['ignore-missing-user', true], ['delete', true], ['error-if-not-exists', true]], |
|
164 | + [], |
|
165 | + false, |
|
166 | + false, |
|
167 | + ], |
|
168 | + [ |
|
169 | + [['uid', 'username'], ['key', 'configkey']], |
|
170 | + [['ignore-missing-user', true], ['delete', false], ['error-if-not-exists', true]], |
|
171 | + [], |
|
172 | + false, |
|
173 | + 'The "error-if-not-exists" option can only be used together with "delete".', |
|
174 | + ], |
|
175 | + ]; |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * @dataProvider dataCheckInput |
|
180 | + * |
|
181 | + * @param array $arguments |
|
182 | + * @param array $options |
|
183 | + * @param array $parameterOptions |
|
184 | + * @param mixed $user |
|
185 | + * @param string $expectedException |
|
186 | + */ |
|
187 | + public function testCheckInput($arguments, $options, $parameterOptions, $user, $expectedException): void { |
|
188 | + $this->consoleInput->expects($this->any()) |
|
189 | + ->method('getArgument') |
|
190 | + ->willReturnMap($arguments); |
|
191 | + $this->consoleInput->expects($this->any()) |
|
192 | + ->method('getOption') |
|
193 | + ->willReturnMap($options); |
|
194 | + $this->consoleInput->expects($this->any()) |
|
195 | + ->method('hasParameterOption') |
|
196 | + ->willReturnCallback(function (string|array $config, bool $default = false) use ($parameterOptions): bool { |
|
197 | + foreach ($parameterOptions as $parameterOption) { |
|
198 | + if ($config === $parameterOption[0] |
|
199 | + // Check the default value if the maps has 3 entries |
|
200 | + && (!isset($parameterOption[2]) || $default === $parameterOption[1])) { |
|
201 | + return end($parameterOption); |
|
202 | + } |
|
203 | + } |
|
204 | + return false; |
|
205 | + }); |
|
206 | + |
|
207 | + if ($user !== false) { |
|
208 | + $this->userManager->expects($this->once()) |
|
209 | + ->method('get') |
|
210 | + ->willReturn($user); |
|
211 | + } else { |
|
212 | + $this->userManager->expects($this->never()) |
|
213 | + ->method('get'); |
|
214 | + } |
|
215 | + |
|
216 | + $command = $this->getCommand(); |
|
217 | + try { |
|
218 | + $this->invokePrivate($command, 'checkInput', [$this->consoleInput]); |
|
219 | + $this->assertFalse($expectedException); |
|
220 | + } catch (\InvalidArgumentException $e) { |
|
221 | + $this->assertEquals($expectedException, $e->getMessage()); |
|
222 | + } |
|
223 | + } |
|
224 | + |
|
225 | + public function testCheckInputExceptionCatch(): void { |
|
226 | + $command = $this->getCommand(['checkInput']); |
|
227 | + $command->expects($this->once()) |
|
228 | + ->method('checkInput') |
|
229 | + ->willThrowException(new \InvalidArgumentException('test')); |
|
230 | + |
|
231 | + $this->consoleOutput->expects($this->once()) |
|
232 | + ->method('writeln') |
|
233 | + ->with('<error>test</error>'); |
|
234 | + |
|
235 | + $this->assertEquals(1, $this->invokePrivate($command, 'execute', [$this->consoleInput, $this->consoleOutput])); |
|
236 | + } |
|
237 | + |
|
238 | + public static function dataExecuteDelete(): array { |
|
239 | + return [ |
|
240 | + ['config', false, null, 0], |
|
241 | + ['config', true, null, 0], |
|
242 | + [null, false, null, 0], |
|
243 | + [null, true, '<error>The setting does not exist for user "username".</error>', 1], |
|
244 | + ]; |
|
245 | + } |
|
246 | + |
|
247 | + /** |
|
248 | + * @dataProvider dataExecuteDelete |
|
249 | + * |
|
250 | + * @param string|null $value |
|
251 | + * @param bool $errorIfNotExists |
|
252 | + * @param string $expectedLine |
|
253 | + * @param int $expectedReturn |
|
254 | + */ |
|
255 | + public function testExecuteDelete($value, $errorIfNotExists, $expectedLine, $expectedReturn): void { |
|
256 | + $command = $this->getCommand([ |
|
257 | + 'writeArrayInOutputFormat', |
|
258 | + 'checkInput', |
|
259 | + 'getUserSettings', |
|
260 | + ]); |
|
261 | + |
|
262 | + $this->consoleInput->expects($this->any()) |
|
263 | + ->method('getArgument') |
|
264 | + ->willReturnMap([ |
|
265 | + ['uid', 'username'], |
|
266 | + ['app', 'appname'], |
|
267 | + ['key', 'configkey'], |
|
268 | + ]); |
|
269 | + |
|
270 | + $command->expects($this->once()) |
|
271 | + ->method('checkInput'); |
|
272 | + |
|
273 | + $this->config->expects($this->once()) |
|
274 | + ->method('getUserValue') |
|
275 | + ->with('username', 'appname', 'configkey', null) |
|
276 | + ->willReturn($value); |
|
277 | + |
|
278 | + $this->consoleInput->expects($this->atLeastOnce()) |
|
279 | + ->method('hasParameterOption') |
|
280 | + ->willReturnMap([ |
|
281 | + ['--delete', false, true], |
|
282 | + ['--error-if-not-exists', false, $errorIfNotExists], |
|
283 | + ]); |
|
284 | + |
|
285 | + if ($expectedLine === null) { |
|
286 | + $this->consoleOutput->expects($this->never()) |
|
287 | + ->method('writeln'); |
|
288 | + $this->config->expects($this->once()) |
|
289 | + ->method('deleteUserValue') |
|
290 | + ->with('username', 'appname', 'configkey'); |
|
291 | + } else { |
|
292 | + $this->consoleOutput->expects($this->once()) |
|
293 | + ->method('writeln') |
|
294 | + ->with($expectedLine); |
|
295 | + $this->config->expects($this->never()) |
|
296 | + ->method('deleteUserValue'); |
|
297 | + } |
|
298 | + |
|
299 | + $this->assertEquals($expectedReturn, $this->invokePrivate($command, 'execute', [$this->consoleInput, $this->consoleOutput])); |
|
300 | + } |
|
301 | + |
|
302 | + public static function dataExecuteSet(): array { |
|
303 | + return [ |
|
304 | + ['config', false, null, 0], |
|
305 | + ['config', true, null, 0], |
|
306 | + [null, false, null, 0], |
|
307 | + [null, true, '<error>The setting does not exist for user "username".</error>', 1], |
|
308 | + ]; |
|
309 | + } |
|
310 | + |
|
311 | + /** |
|
312 | + * @dataProvider dataExecuteSet |
|
313 | + * |
|
314 | + * @param string|null $value |
|
315 | + * @param bool $updateOnly |
|
316 | + * @param string $expectedLine |
|
317 | + * @param int $expectedReturn |
|
318 | + */ |
|
319 | + public function testExecuteSet($value, $updateOnly, $expectedLine, $expectedReturn): void { |
|
320 | + $command = $this->getCommand([ |
|
321 | + 'writeArrayInOutputFormat', |
|
322 | + 'checkInput', |
|
323 | + 'getUserSettings', |
|
324 | + ]); |
|
325 | + |
|
326 | + $this->consoleInput->expects($this->atLeast(4)) |
|
327 | + ->method('getArgument') |
|
328 | + ->willReturnMap([ |
|
329 | + ['uid', 'username'], |
|
330 | + ['app', 'appname'], |
|
331 | + ['key', 'configkey'], |
|
332 | + ['value', 'setValue'], |
|
333 | + ]); |
|
334 | + |
|
335 | + $command->expects($this->once()) |
|
336 | + ->method('checkInput'); |
|
337 | + |
|
338 | + $this->config->expects($this->once()) |
|
339 | + ->method('getUserValue') |
|
340 | + ->with('username', 'appname', 'configkey', null) |
|
341 | + ->willReturn($value); |
|
342 | + |
|
343 | + $this->consoleInput->expects($this->atLeastOnce()) |
|
344 | + ->method('hasParameterOption') |
|
345 | + ->willReturnMap([ |
|
346 | + ['--update-only', false, $updateOnly], |
|
347 | + ]); |
|
348 | + |
|
349 | + if ($expectedLine === null) { |
|
350 | + $this->consoleOutput->expects($this->never()) |
|
351 | + ->method('writeln'); |
|
352 | + |
|
353 | + $this->consoleInput->expects($this->never()) |
|
354 | + ->method('getOption'); |
|
355 | + |
|
356 | + $this->config->expects($this->once()) |
|
357 | + ->method('setUserValue') |
|
358 | + ->with('username', 'appname', 'configkey', 'setValue'); |
|
359 | + } else { |
|
360 | + $this->consoleOutput->expects($this->once()) |
|
361 | + ->method('writeln') |
|
362 | + ->with($expectedLine); |
|
363 | + $this->config->expects($this->never()) |
|
364 | + ->method('setUserValue'); |
|
365 | + } |
|
366 | + |
|
367 | + $this->assertEquals($expectedReturn, $this->invokePrivate($command, 'execute', [$this->consoleInput, $this->consoleOutput])); |
|
368 | + } |
|
369 | + |
|
370 | + public static function dataExecuteGet(): array { |
|
371 | + return [ |
|
372 | + ['config', null, 'config', 0], |
|
373 | + [null, 'config', 'config', 0], |
|
374 | + [null, null, '<error>The setting does not exist for user "username".</error>', 1], |
|
375 | + ]; |
|
376 | + } |
|
377 | + |
|
378 | + /** |
|
379 | + * @dataProvider dataExecuteGet |
|
380 | + * |
|
381 | + * @param string|null $value |
|
382 | + * @param string|null $defaultValue |
|
383 | + * @param string $expectedLine |
|
384 | + * @param int $expectedReturn |
|
385 | + */ |
|
386 | + public function testExecuteGet($value, $defaultValue, $expectedLine, $expectedReturn): void { |
|
387 | + $command = $this->getCommand([ |
|
388 | + 'writeArrayInOutputFormat', |
|
389 | + 'checkInput', |
|
390 | + 'getUserSettings', |
|
391 | + ]); |
|
392 | + |
|
393 | + $this->consoleInput->expects($this->any()) |
|
394 | + ->method('getArgument') |
|
395 | + ->willReturnMap([ |
|
396 | + ['uid', 'username'], |
|
397 | + ['app', 'appname'], |
|
398 | + ['key', 'configkey'], |
|
399 | + ]); |
|
400 | + |
|
401 | + $command->expects($this->once()) |
|
402 | + ->method('checkInput'); |
|
403 | + |
|
404 | + $this->config->expects($this->once()) |
|
405 | + ->method('getUserValue') |
|
406 | + ->with('username', 'appname', 'configkey', null) |
|
407 | + ->willReturn($value); |
|
408 | + |
|
409 | + if ($value === null) { |
|
410 | + if ($defaultValue === null) { |
|
411 | + $this->consoleInput->expects($this->atLeastOnce()) |
|
412 | + ->method('hasParameterOption') |
|
413 | + ->willReturn(false); |
|
414 | + } else { |
|
415 | + $this->consoleInput->expects($this->atLeastOnce()) |
|
416 | + ->method('hasParameterOption') |
|
417 | + ->willReturnCallback(function (string|array $config, bool $default = false): bool { |
|
418 | + if ($config === '--default-value' && $default === false) { |
|
419 | + return true; |
|
420 | + } |
|
421 | + return false; |
|
422 | + }); |
|
423 | + $this->consoleInput->expects($this->once()) |
|
424 | + ->method('getOption') |
|
425 | + ->with('default-value') |
|
426 | + ->willReturn($defaultValue); |
|
427 | + } |
|
428 | + } |
|
429 | + |
|
430 | + $this->consoleOutput->expects($this->once()) |
|
431 | + ->method('writeln') |
|
432 | + ->with($expectedLine); |
|
433 | + |
|
434 | + $this->assertEquals($expectedReturn, $this->invokePrivate($command, 'execute', [$this->consoleInput, $this->consoleOutput])); |
|
435 | + } |
|
436 | + |
|
437 | + public function testExecuteList(): void { |
|
438 | + $command = $this->getCommand([ |
|
439 | + 'writeArrayInOutputFormat', |
|
440 | + 'checkInput', |
|
441 | + 'getUserSettings', |
|
442 | + ]); |
|
443 | + |
|
444 | + $this->consoleInput->expects($this->any()) |
|
445 | + ->method('getArgument') |
|
446 | + ->willReturnMap([ |
|
447 | + ['uid', 'username'], |
|
448 | + ['app', 'appname'], |
|
449 | + ['key', ''], |
|
450 | + ]); |
|
451 | + |
|
452 | + $command->expects($this->once()) |
|
453 | + ->method('checkInput'); |
|
454 | + $command->expects($this->once()) |
|
455 | + ->method('getUserSettings') |
|
456 | + ->willReturn(['settings']); |
|
457 | + $command->expects($this->once()) |
|
458 | + ->method('writeArrayInOutputFormat') |
|
459 | + ->with($this->consoleInput, $this->consoleOutput, ['settings']); |
|
460 | + |
|
461 | + |
|
462 | + $this->assertEquals(0, $this->invokePrivate($command, 'execute', [$this->consoleInput, $this->consoleOutput])); |
|
463 | + } |
|
464 | 464 | } |
@@ -23,131 +23,131 @@ |
||
23 | 23 | use Test\TestCase; |
24 | 24 | |
25 | 25 | class AddTest extends TestCase { |
26 | - /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
27 | - private $userManager; |
|
28 | - |
|
29 | - /** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
30 | - private $groupManager; |
|
31 | - |
|
32 | - /** @var IMailer|\PHPUnit\Framework\MockObject\MockObject */ |
|
33 | - private $mailer; |
|
34 | - |
|
35 | - /** @var IAppConfig|\PHPUnit\Framework\MockObject\MockObject */ |
|
36 | - private $appConfig; |
|
37 | - |
|
38 | - /** @var NewUserMailHelper|\PHPUnit\Framework\MockObject\MockObject */ |
|
39 | - private $mailHelper; |
|
40 | - |
|
41 | - /** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */ |
|
42 | - private $eventDispatcher; |
|
43 | - |
|
44 | - /** @var ISecureRandom|\PHPUnit\Framework\MockObject\MockObject */ |
|
45 | - private $secureRandom; |
|
46 | - |
|
47 | - /** @var IUser|\PHPUnit\Framework\MockObject\MockObject */ |
|
48 | - private $user; |
|
49 | - |
|
50 | - /** @var InputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
51 | - private $consoleInput; |
|
52 | - |
|
53 | - /** @var OutputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
54 | - private $consoleOutput; |
|
55 | - |
|
56 | - /** @var Add */ |
|
57 | - private $addCommand; |
|
58 | - |
|
59 | - public function setUp(): void { |
|
60 | - parent::setUp(); |
|
61 | - |
|
62 | - $this->userManager = static::createMock(IUserManager::class); |
|
63 | - $this->groupManager = static::createStub(IGroupManager::class); |
|
64 | - $this->mailer = static::createMock(IMailer::class); |
|
65 | - $this->appConfig = static::createMock(IAppConfig::class); |
|
66 | - $this->mailHelper = static::createMock(NewUserMailHelper::class); |
|
67 | - $this->eventDispatcher = static::createStub(IEventDispatcher::class); |
|
68 | - $this->secureRandom = static::createStub(ISecureRandom::class); |
|
69 | - |
|
70 | - $this->user = static::createMock(IUser::class); |
|
71 | - |
|
72 | - $this->consoleInput = static::createMock(InputInterface::class); |
|
73 | - $this->consoleOutput = static::createMock(OutputInterface::class); |
|
74 | - |
|
75 | - $this->addCommand = new Add( |
|
76 | - $this->userManager, |
|
77 | - $this->groupManager, |
|
78 | - $this->mailer, |
|
79 | - $this->appConfig, |
|
80 | - $this->mailHelper, |
|
81 | - $this->eventDispatcher, |
|
82 | - $this->secureRandom |
|
83 | - ); |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * @dataProvider addEmailDataProvider |
|
88 | - */ |
|
89 | - public function testAddEmail( |
|
90 | - ?string $email, |
|
91 | - bool $isEmailValid, |
|
92 | - bool $shouldSendEmail, |
|
93 | - ): void { |
|
94 | - $this->user->expects($isEmailValid ? static::once() : static::never()) |
|
95 | - ->method('setSystemEMailAddress') |
|
96 | - ->with(static::equalTo($email)); |
|
97 | - |
|
98 | - $this->userManager->method('createUser') |
|
99 | - ->willReturn($this->user); |
|
100 | - |
|
101 | - $this->appConfig->method('getValueString') |
|
102 | - ->willReturn($shouldSendEmail ? 'yes' : 'no'); |
|
103 | - |
|
104 | - $this->mailer->method('validateMailAddress') |
|
105 | - ->willReturn($isEmailValid); |
|
106 | - |
|
107 | - $this->mailHelper->method('generateTemplate') |
|
108 | - ->willReturn(static::createMock(IEMailTemplate::class)); |
|
109 | - |
|
110 | - $this->mailHelper->expects($isEmailValid && $shouldSendEmail ? static::once() : static::never()) |
|
111 | - ->method('sendMail'); |
|
112 | - |
|
113 | - $this->consoleInput->method('getOption') |
|
114 | - ->will(static::returnValueMap([ |
|
115 | - ['generate-password', 'true'], |
|
116 | - ['email', $email], |
|
117 | - ['group', []], |
|
118 | - ])); |
|
119 | - |
|
120 | - $this->invokePrivate($this->addCommand, 'execute', [ |
|
121 | - $this->consoleInput, |
|
122 | - $this->consoleOutput |
|
123 | - ]); |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * @return array |
|
128 | - */ |
|
129 | - public static function addEmailDataProvider(): array { |
|
130 | - return [ |
|
131 | - 'Valid E-Mail' => [ |
|
132 | - '[email protected]', |
|
133 | - true, |
|
134 | - true, |
|
135 | - ], |
|
136 | - 'Invalid E-Mail' => [ |
|
137 | - 'info@@example.com', |
|
138 | - false, |
|
139 | - false, |
|
140 | - ], |
|
141 | - 'No E-Mail' => [ |
|
142 | - '', |
|
143 | - false, |
|
144 | - false, |
|
145 | - ], |
|
146 | - 'Valid E-Mail, but no mail should be sent' => [ |
|
147 | - '[email protected]', |
|
148 | - true, |
|
149 | - false, |
|
150 | - ], |
|
151 | - ]; |
|
152 | - } |
|
26 | + /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
27 | + private $userManager; |
|
28 | + |
|
29 | + /** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
30 | + private $groupManager; |
|
31 | + |
|
32 | + /** @var IMailer|\PHPUnit\Framework\MockObject\MockObject */ |
|
33 | + private $mailer; |
|
34 | + |
|
35 | + /** @var IAppConfig|\PHPUnit\Framework\MockObject\MockObject */ |
|
36 | + private $appConfig; |
|
37 | + |
|
38 | + /** @var NewUserMailHelper|\PHPUnit\Framework\MockObject\MockObject */ |
|
39 | + private $mailHelper; |
|
40 | + |
|
41 | + /** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */ |
|
42 | + private $eventDispatcher; |
|
43 | + |
|
44 | + /** @var ISecureRandom|\PHPUnit\Framework\MockObject\MockObject */ |
|
45 | + private $secureRandom; |
|
46 | + |
|
47 | + /** @var IUser|\PHPUnit\Framework\MockObject\MockObject */ |
|
48 | + private $user; |
|
49 | + |
|
50 | + /** @var InputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
51 | + private $consoleInput; |
|
52 | + |
|
53 | + /** @var OutputInterface|\PHPUnit\Framework\MockObject\MockObject */ |
|
54 | + private $consoleOutput; |
|
55 | + |
|
56 | + /** @var Add */ |
|
57 | + private $addCommand; |
|
58 | + |
|
59 | + public function setUp(): void { |
|
60 | + parent::setUp(); |
|
61 | + |
|
62 | + $this->userManager = static::createMock(IUserManager::class); |
|
63 | + $this->groupManager = static::createStub(IGroupManager::class); |
|
64 | + $this->mailer = static::createMock(IMailer::class); |
|
65 | + $this->appConfig = static::createMock(IAppConfig::class); |
|
66 | + $this->mailHelper = static::createMock(NewUserMailHelper::class); |
|
67 | + $this->eventDispatcher = static::createStub(IEventDispatcher::class); |
|
68 | + $this->secureRandom = static::createStub(ISecureRandom::class); |
|
69 | + |
|
70 | + $this->user = static::createMock(IUser::class); |
|
71 | + |
|
72 | + $this->consoleInput = static::createMock(InputInterface::class); |
|
73 | + $this->consoleOutput = static::createMock(OutputInterface::class); |
|
74 | + |
|
75 | + $this->addCommand = new Add( |
|
76 | + $this->userManager, |
|
77 | + $this->groupManager, |
|
78 | + $this->mailer, |
|
79 | + $this->appConfig, |
|
80 | + $this->mailHelper, |
|
81 | + $this->eventDispatcher, |
|
82 | + $this->secureRandom |
|
83 | + ); |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * @dataProvider addEmailDataProvider |
|
88 | + */ |
|
89 | + public function testAddEmail( |
|
90 | + ?string $email, |
|
91 | + bool $isEmailValid, |
|
92 | + bool $shouldSendEmail, |
|
93 | + ): void { |
|
94 | + $this->user->expects($isEmailValid ? static::once() : static::never()) |
|
95 | + ->method('setSystemEMailAddress') |
|
96 | + ->with(static::equalTo($email)); |
|
97 | + |
|
98 | + $this->userManager->method('createUser') |
|
99 | + ->willReturn($this->user); |
|
100 | + |
|
101 | + $this->appConfig->method('getValueString') |
|
102 | + ->willReturn($shouldSendEmail ? 'yes' : 'no'); |
|
103 | + |
|
104 | + $this->mailer->method('validateMailAddress') |
|
105 | + ->willReturn($isEmailValid); |
|
106 | + |
|
107 | + $this->mailHelper->method('generateTemplate') |
|
108 | + ->willReturn(static::createMock(IEMailTemplate::class)); |
|
109 | + |
|
110 | + $this->mailHelper->expects($isEmailValid && $shouldSendEmail ? static::once() : static::never()) |
|
111 | + ->method('sendMail'); |
|
112 | + |
|
113 | + $this->consoleInput->method('getOption') |
|
114 | + ->will(static::returnValueMap([ |
|
115 | + ['generate-password', 'true'], |
|
116 | + ['email', $email], |
|
117 | + ['group', []], |
|
118 | + ])); |
|
119 | + |
|
120 | + $this->invokePrivate($this->addCommand, 'execute', [ |
|
121 | + $this->consoleInput, |
|
122 | + $this->consoleOutput |
|
123 | + ]); |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * @return array |
|
128 | + */ |
|
129 | + public static function addEmailDataProvider(): array { |
|
130 | + return [ |
|
131 | + 'Valid E-Mail' => [ |
|
132 | + '[email protected]', |
|
133 | + true, |
|
134 | + true, |
|
135 | + ], |
|
136 | + 'Invalid E-Mail' => [ |
|
137 | + 'info@@example.com', |
|
138 | + false, |
|
139 | + false, |
|
140 | + ], |
|
141 | + 'No E-Mail' => [ |
|
142 | + '', |
|
143 | + false, |
|
144 | + false, |
|
145 | + ], |
|
146 | + 'Valid E-Mail, but no mail should be sent' => [ |
|
147 | + '[email protected]', |
|
148 | + true, |
|
149 | + false, |
|
150 | + ], |
|
151 | + ]; |
|
152 | + } |
|
153 | 153 | } |
@@ -15,81 +15,81 @@ |
||
15 | 15 | use Test\TestCase; |
16 | 16 | |
17 | 17 | class DeleteTest extends TestCase { |
18 | - /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
19 | - protected $userManager; |
|
20 | - /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
21 | - protected $consoleInput; |
|
22 | - /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
23 | - protected $consoleOutput; |
|
24 | - |
|
25 | - /** @var \Symfony\Component\Console\Command\Command */ |
|
26 | - protected $command; |
|
27 | - |
|
28 | - protected function setUp(): void { |
|
29 | - parent::setUp(); |
|
30 | - |
|
31 | - $userManager = $this->userManager = $this->getMockBuilder(IUserManager::class) |
|
32 | - ->disableOriginalConstructor() |
|
33 | - ->getMock(); |
|
34 | - $this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock(); |
|
35 | - $this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock(); |
|
36 | - |
|
37 | - /** @var \OCP\IUserManager $userManager */ |
|
38 | - $this->command = new Delete($userManager); |
|
39 | - } |
|
40 | - |
|
41 | - |
|
42 | - public static function validUserLastSeen(): array { |
|
43 | - return [ |
|
44 | - [true, 'The specified user was deleted'], |
|
45 | - [false, 'The specified user could not be deleted'], |
|
46 | - ]; |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * @dataProvider validUserLastSeen |
|
51 | - * |
|
52 | - * @param bool $deleteSuccess |
|
53 | - * @param string $expectedString |
|
54 | - */ |
|
55 | - public function testValidUser($deleteSuccess, $expectedString): void { |
|
56 | - $user = $this->getMockBuilder(IUser::class)->getMock(); |
|
57 | - $user->expects($this->once()) |
|
58 | - ->method('delete') |
|
59 | - ->willReturn($deleteSuccess); |
|
60 | - |
|
61 | - $this->userManager->expects($this->once()) |
|
62 | - ->method('get') |
|
63 | - ->with('user') |
|
64 | - ->willReturn($user); |
|
65 | - |
|
66 | - $this->consoleInput->expects($this->once()) |
|
67 | - ->method('getArgument') |
|
68 | - ->with('uid') |
|
69 | - ->willReturn('user'); |
|
70 | - |
|
71 | - $this->consoleOutput->expects($this->once()) |
|
72 | - ->method('writeln') |
|
73 | - ->with($this->stringContains($expectedString)); |
|
74 | - |
|
75 | - self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
76 | - } |
|
77 | - |
|
78 | - public function testInvalidUser(): void { |
|
79 | - $this->userManager->expects($this->once()) |
|
80 | - ->method('get') |
|
81 | - ->with('user') |
|
82 | - ->willReturn(null); |
|
83 | - |
|
84 | - $this->consoleInput->expects($this->once()) |
|
85 | - ->method('getArgument') |
|
86 | - ->with('uid') |
|
87 | - ->willReturn('user'); |
|
88 | - |
|
89 | - $this->consoleOutput->expects($this->once()) |
|
90 | - ->method('writeln') |
|
91 | - ->with($this->stringContains('User does not exist')); |
|
92 | - |
|
93 | - self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
94 | - } |
|
18 | + /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
19 | + protected $userManager; |
|
20 | + /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
21 | + protected $consoleInput; |
|
22 | + /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
23 | + protected $consoleOutput; |
|
24 | + |
|
25 | + /** @var \Symfony\Component\Console\Command\Command */ |
|
26 | + protected $command; |
|
27 | + |
|
28 | + protected function setUp(): void { |
|
29 | + parent::setUp(); |
|
30 | + |
|
31 | + $userManager = $this->userManager = $this->getMockBuilder(IUserManager::class) |
|
32 | + ->disableOriginalConstructor() |
|
33 | + ->getMock(); |
|
34 | + $this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock(); |
|
35 | + $this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock(); |
|
36 | + |
|
37 | + /** @var \OCP\IUserManager $userManager */ |
|
38 | + $this->command = new Delete($userManager); |
|
39 | + } |
|
40 | + |
|
41 | + |
|
42 | + public static function validUserLastSeen(): array { |
|
43 | + return [ |
|
44 | + [true, 'The specified user was deleted'], |
|
45 | + [false, 'The specified user could not be deleted'], |
|
46 | + ]; |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * @dataProvider validUserLastSeen |
|
51 | + * |
|
52 | + * @param bool $deleteSuccess |
|
53 | + * @param string $expectedString |
|
54 | + */ |
|
55 | + public function testValidUser($deleteSuccess, $expectedString): void { |
|
56 | + $user = $this->getMockBuilder(IUser::class)->getMock(); |
|
57 | + $user->expects($this->once()) |
|
58 | + ->method('delete') |
|
59 | + ->willReturn($deleteSuccess); |
|
60 | + |
|
61 | + $this->userManager->expects($this->once()) |
|
62 | + ->method('get') |
|
63 | + ->with('user') |
|
64 | + ->willReturn($user); |
|
65 | + |
|
66 | + $this->consoleInput->expects($this->once()) |
|
67 | + ->method('getArgument') |
|
68 | + ->with('uid') |
|
69 | + ->willReturn('user'); |
|
70 | + |
|
71 | + $this->consoleOutput->expects($this->once()) |
|
72 | + ->method('writeln') |
|
73 | + ->with($this->stringContains($expectedString)); |
|
74 | + |
|
75 | + self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
76 | + } |
|
77 | + |
|
78 | + public function testInvalidUser(): void { |
|
79 | + $this->userManager->expects($this->once()) |
|
80 | + ->method('get') |
|
81 | + ->with('user') |
|
82 | + ->willReturn(null); |
|
83 | + |
|
84 | + $this->consoleInput->expects($this->once()) |
|
85 | + ->method('getArgument') |
|
86 | + ->with('uid') |
|
87 | + ->willReturn('user'); |
|
88 | + |
|
89 | + $this->consoleOutput->expects($this->once()) |
|
90 | + ->method('writeln') |
|
91 | + ->with($this->stringContains('User does not exist')); |
|
92 | + |
|
93 | + self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
94 | + } |
|
95 | 95 | } |
@@ -15,80 +15,80 @@ |
||
15 | 15 | use Test\TestCase; |
16 | 16 | |
17 | 17 | class LastSeenTest extends TestCase { |
18 | - /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
19 | - protected $userManager; |
|
20 | - /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
21 | - protected $consoleInput; |
|
22 | - /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
23 | - protected $consoleOutput; |
|
24 | - |
|
25 | - /** @var \Symfony\Component\Console\Command\Command */ |
|
26 | - protected $command; |
|
27 | - |
|
28 | - protected function setUp(): void { |
|
29 | - parent::setUp(); |
|
30 | - |
|
31 | - $userManager = $this->userManager = $this->getMockBuilder(IUserManager::class) |
|
32 | - ->disableOriginalConstructor() |
|
33 | - ->getMock(); |
|
34 | - $this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock(); |
|
35 | - $this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock(); |
|
36 | - |
|
37 | - /** @var \OCP\IUserManager $userManager */ |
|
38 | - $this->command = new LastSeen($userManager); |
|
39 | - } |
|
40 | - |
|
41 | - public static function validUserLastSeen(): array { |
|
42 | - return [ |
|
43 | - [0, 'never logged in'], |
|
44 | - [time(), 'last login'], |
|
45 | - ]; |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * @dataProvider validUserLastSeen |
|
50 | - * |
|
51 | - * @param int $lastSeen |
|
52 | - * @param string $expectedString |
|
53 | - */ |
|
54 | - public function testValidUser($lastSeen, $expectedString): void { |
|
55 | - $user = $this->getMockBuilder(IUser::class)->getMock(); |
|
56 | - $user->expects($this->once()) |
|
57 | - ->method('getLastLogin') |
|
58 | - ->willReturn($lastSeen); |
|
59 | - |
|
60 | - $this->userManager->expects($this->once()) |
|
61 | - ->method('get') |
|
62 | - ->with('user') |
|
63 | - ->willReturn($user); |
|
64 | - |
|
65 | - $this->consoleInput->expects($this->once()) |
|
66 | - ->method('getArgument') |
|
67 | - ->with('uid') |
|
68 | - ->willReturn('user'); |
|
69 | - |
|
70 | - $this->consoleOutput->expects($this->once()) |
|
71 | - ->method('writeln') |
|
72 | - ->with($this->stringContains($expectedString)); |
|
73 | - |
|
74 | - self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
75 | - } |
|
76 | - |
|
77 | - public function testInvalidUser(): void { |
|
78 | - $this->userManager->expects($this->once()) |
|
79 | - ->method('get') |
|
80 | - ->with('user') |
|
81 | - ->willReturn(null); |
|
82 | - |
|
83 | - $this->consoleInput->expects($this->once()) |
|
84 | - ->method('getArgument') |
|
85 | - ->with('uid') |
|
86 | - ->willReturn('user'); |
|
87 | - |
|
88 | - $this->consoleOutput->expects($this->once()) |
|
89 | - ->method('writeln') |
|
90 | - ->with($this->stringContains('User does not exist')); |
|
91 | - |
|
92 | - self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
93 | - } |
|
18 | + /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
19 | + protected $userManager; |
|
20 | + /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
21 | + protected $consoleInput; |
|
22 | + /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
23 | + protected $consoleOutput; |
|
24 | + |
|
25 | + /** @var \Symfony\Component\Console\Command\Command */ |
|
26 | + protected $command; |
|
27 | + |
|
28 | + protected function setUp(): void { |
|
29 | + parent::setUp(); |
|
30 | + |
|
31 | + $userManager = $this->userManager = $this->getMockBuilder(IUserManager::class) |
|
32 | + ->disableOriginalConstructor() |
|
33 | + ->getMock(); |
|
34 | + $this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock(); |
|
35 | + $this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock(); |
|
36 | + |
|
37 | + /** @var \OCP\IUserManager $userManager */ |
|
38 | + $this->command = new LastSeen($userManager); |
|
39 | + } |
|
40 | + |
|
41 | + public static function validUserLastSeen(): array { |
|
42 | + return [ |
|
43 | + [0, 'never logged in'], |
|
44 | + [time(), 'last login'], |
|
45 | + ]; |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * @dataProvider validUserLastSeen |
|
50 | + * |
|
51 | + * @param int $lastSeen |
|
52 | + * @param string $expectedString |
|
53 | + */ |
|
54 | + public function testValidUser($lastSeen, $expectedString): void { |
|
55 | + $user = $this->getMockBuilder(IUser::class)->getMock(); |
|
56 | + $user->expects($this->once()) |
|
57 | + ->method('getLastLogin') |
|
58 | + ->willReturn($lastSeen); |
|
59 | + |
|
60 | + $this->userManager->expects($this->once()) |
|
61 | + ->method('get') |
|
62 | + ->with('user') |
|
63 | + ->willReturn($user); |
|
64 | + |
|
65 | + $this->consoleInput->expects($this->once()) |
|
66 | + ->method('getArgument') |
|
67 | + ->with('uid') |
|
68 | + ->willReturn('user'); |
|
69 | + |
|
70 | + $this->consoleOutput->expects($this->once()) |
|
71 | + ->method('writeln') |
|
72 | + ->with($this->stringContains($expectedString)); |
|
73 | + |
|
74 | + self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
75 | + } |
|
76 | + |
|
77 | + public function testInvalidUser(): void { |
|
78 | + $this->userManager->expects($this->once()) |
|
79 | + ->method('get') |
|
80 | + ->with('user') |
|
81 | + ->willReturn(null); |
|
82 | + |
|
83 | + $this->consoleInput->expects($this->once()) |
|
84 | + ->method('getArgument') |
|
85 | + ->with('uid') |
|
86 | + ->willReturn('user'); |
|
87 | + |
|
88 | + $this->consoleOutput->expects($this->once()) |
|
89 | + ->method('writeln') |
|
90 | + ->with($this->stringContains('User does not exist')); |
|
91 | + |
|
92 | + self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
93 | + } |
|
94 | 94 | } |
@@ -14,151 +14,151 @@ |
||
14 | 14 | use Test\TestCase; |
15 | 15 | |
16 | 16 | class SetConfigTest extends TestCase { |
17 | - /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
18 | - protected $systemConfig; |
|
19 | - |
|
20 | - /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
21 | - protected $consoleInput; |
|
22 | - /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
23 | - protected $consoleOutput; |
|
24 | - |
|
25 | - /** @var \Symfony\Component\Console\Command\Command */ |
|
26 | - protected $command; |
|
27 | - |
|
28 | - protected function setUp(): void { |
|
29 | - parent::setUp(); |
|
30 | - |
|
31 | - $systemConfig = $this->systemConfig = $this->getMockBuilder(SystemConfig::class) |
|
32 | - ->disableOriginalConstructor() |
|
33 | - ->getMock(); |
|
34 | - $this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock(); |
|
35 | - $this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock(); |
|
36 | - |
|
37 | - /** @var \OC\SystemConfig $systemConfig */ |
|
38 | - $this->command = new SetConfig($systemConfig); |
|
39 | - } |
|
40 | - |
|
41 | - |
|
42 | - public static function dataTest() { |
|
43 | - return [ |
|
44 | - [['name'], 'newvalue', null, 'newvalue'], |
|
45 | - [['a', 'b', 'c'], 'foobar', null, ['b' => ['c' => 'foobar']]], |
|
46 | - [['a', 'b', 'c'], 'foobar', ['b' => ['d' => 'barfoo']], ['b' => ['d' => 'barfoo', 'c' => 'foobar']]], |
|
47 | - ]; |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * @dataProvider dataTest |
|
52 | - * |
|
53 | - * @param array $configNames |
|
54 | - * @param string $newValue |
|
55 | - * @param mixed $existingData |
|
56 | - * @param mixed $expectedValue |
|
57 | - */ |
|
58 | - public function testSet($configNames, $newValue, $existingData, $expectedValue): void { |
|
59 | - $this->systemConfig->expects($this->once()) |
|
60 | - ->method('setValue') |
|
61 | - ->with($configNames[0], $expectedValue); |
|
62 | - $this->systemConfig->method('getValue') |
|
63 | - ->with($configNames[0]) |
|
64 | - ->willReturn($existingData); |
|
65 | - |
|
66 | - $this->consoleInput->expects($this->once()) |
|
67 | - ->method('getArgument') |
|
68 | - ->with('name') |
|
69 | - ->willReturn($configNames); |
|
70 | - $this->consoleInput->method('getOption') |
|
71 | - ->willReturnMap([ |
|
72 | - ['value', $newValue], |
|
73 | - ['type', 'string'], |
|
74 | - ]); |
|
75 | - |
|
76 | - $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
77 | - } |
|
78 | - |
|
79 | - public static function setUpdateOnlyProvider(): array { |
|
80 | - return [ |
|
81 | - [['name'], null], |
|
82 | - [['a', 'b', 'c'], null], |
|
83 | - [['a', 'b', 'c'], ['b' => 'foobar']], |
|
84 | - [['a', 'b', 'c'], ['b' => ['d' => 'foobar']]], |
|
85 | - ]; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * @dataProvider setUpdateOnlyProvider |
|
90 | - */ |
|
91 | - public function testSetUpdateOnly($configNames, $existingData): void { |
|
92 | - $this->expectException(\UnexpectedValueException::class); |
|
93 | - |
|
94 | - $this->systemConfig->expects($this->never()) |
|
95 | - ->method('setValue'); |
|
96 | - $this->systemConfig->method('getValue') |
|
97 | - ->with($configNames[0]) |
|
98 | - ->willReturn($existingData); |
|
99 | - $this->systemConfig->method('getKeys') |
|
100 | - ->willReturn($existingData ? $configNames[0] : []); |
|
101 | - |
|
102 | - $this->consoleInput->expects($this->once()) |
|
103 | - ->method('getArgument') |
|
104 | - ->with('name') |
|
105 | - ->willReturn($configNames); |
|
106 | - $this->consoleInput->method('getOption') |
|
107 | - ->willReturnMap([ |
|
108 | - ['value', 'foobar'], |
|
109 | - ['type', 'string'], |
|
110 | - ['update-only', true], |
|
111 | - ]); |
|
112 | - |
|
113 | - $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
114 | - } |
|
115 | - |
|
116 | - public static function castValueProvider(): array { |
|
117 | - return [ |
|
118 | - [null, 'string', ['value' => '', 'readable-value' => 'empty string']], |
|
119 | - |
|
120 | - ['abc', 'string', ['value' => 'abc', 'readable-value' => 'string abc']], |
|
121 | - |
|
122 | - ['123', 'integer', ['value' => 123, 'readable-value' => 'integer 123']], |
|
123 | - ['456', 'int', ['value' => 456, 'readable-value' => 'integer 456']], |
|
124 | - |
|
125 | - ['2.25', 'double', ['value' => 2.25, 'readable-value' => 'double 2.25']], |
|
126 | - ['0.5', 'float', ['value' => 0.5, 'readable-value' => 'double 0.5']], |
|
127 | - |
|
128 | - ['', 'null', ['value' => null, 'readable-value' => 'null']], |
|
129 | - |
|
130 | - ['true', 'boolean', ['value' => true, 'readable-value' => 'boolean true']], |
|
131 | - ['false', 'bool', ['value' => false, 'readable-value' => 'boolean false']], |
|
132 | - ]; |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * @dataProvider castValueProvider |
|
137 | - */ |
|
138 | - public function testCastValue($value, $type, $expectedValue): void { |
|
139 | - $this->assertSame($expectedValue, |
|
140 | - $this->invokePrivate($this->command, 'castValue', [$value, $type]) |
|
141 | - ); |
|
142 | - } |
|
143 | - |
|
144 | - public static function castValueInvalidProvider(): array { |
|
145 | - return [ |
|
146 | - ['123', 'foobar'], |
|
147 | - |
|
148 | - [null, 'integer'], |
|
149 | - ['abc', 'integer'], |
|
150 | - ['76ggg', 'double'], |
|
151 | - ['true', 'float'], |
|
152 | - ['foobar', 'boolean'], |
|
153 | - ]; |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * @dataProvider castValueInvalidProvider |
|
158 | - */ |
|
159 | - public function testCastValueInvalid($value, $type): void { |
|
160 | - $this->expectException(\InvalidArgumentException::class); |
|
161 | - |
|
162 | - $this->invokePrivate($this->command, 'castValue', [$value, $type]); |
|
163 | - } |
|
17 | + /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
18 | + protected $systemConfig; |
|
19 | + |
|
20 | + /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
21 | + protected $consoleInput; |
|
22 | + /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
23 | + protected $consoleOutput; |
|
24 | + |
|
25 | + /** @var \Symfony\Component\Console\Command\Command */ |
|
26 | + protected $command; |
|
27 | + |
|
28 | + protected function setUp(): void { |
|
29 | + parent::setUp(); |
|
30 | + |
|
31 | + $systemConfig = $this->systemConfig = $this->getMockBuilder(SystemConfig::class) |
|
32 | + ->disableOriginalConstructor() |
|
33 | + ->getMock(); |
|
34 | + $this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock(); |
|
35 | + $this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock(); |
|
36 | + |
|
37 | + /** @var \OC\SystemConfig $systemConfig */ |
|
38 | + $this->command = new SetConfig($systemConfig); |
|
39 | + } |
|
40 | + |
|
41 | + |
|
42 | + public static function dataTest() { |
|
43 | + return [ |
|
44 | + [['name'], 'newvalue', null, 'newvalue'], |
|
45 | + [['a', 'b', 'c'], 'foobar', null, ['b' => ['c' => 'foobar']]], |
|
46 | + [['a', 'b', 'c'], 'foobar', ['b' => ['d' => 'barfoo']], ['b' => ['d' => 'barfoo', 'c' => 'foobar']]], |
|
47 | + ]; |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * @dataProvider dataTest |
|
52 | + * |
|
53 | + * @param array $configNames |
|
54 | + * @param string $newValue |
|
55 | + * @param mixed $existingData |
|
56 | + * @param mixed $expectedValue |
|
57 | + */ |
|
58 | + public function testSet($configNames, $newValue, $existingData, $expectedValue): void { |
|
59 | + $this->systemConfig->expects($this->once()) |
|
60 | + ->method('setValue') |
|
61 | + ->with($configNames[0], $expectedValue); |
|
62 | + $this->systemConfig->method('getValue') |
|
63 | + ->with($configNames[0]) |
|
64 | + ->willReturn($existingData); |
|
65 | + |
|
66 | + $this->consoleInput->expects($this->once()) |
|
67 | + ->method('getArgument') |
|
68 | + ->with('name') |
|
69 | + ->willReturn($configNames); |
|
70 | + $this->consoleInput->method('getOption') |
|
71 | + ->willReturnMap([ |
|
72 | + ['value', $newValue], |
|
73 | + ['type', 'string'], |
|
74 | + ]); |
|
75 | + |
|
76 | + $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
77 | + } |
|
78 | + |
|
79 | + public static function setUpdateOnlyProvider(): array { |
|
80 | + return [ |
|
81 | + [['name'], null], |
|
82 | + [['a', 'b', 'c'], null], |
|
83 | + [['a', 'b', 'c'], ['b' => 'foobar']], |
|
84 | + [['a', 'b', 'c'], ['b' => ['d' => 'foobar']]], |
|
85 | + ]; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * @dataProvider setUpdateOnlyProvider |
|
90 | + */ |
|
91 | + public function testSetUpdateOnly($configNames, $existingData): void { |
|
92 | + $this->expectException(\UnexpectedValueException::class); |
|
93 | + |
|
94 | + $this->systemConfig->expects($this->never()) |
|
95 | + ->method('setValue'); |
|
96 | + $this->systemConfig->method('getValue') |
|
97 | + ->with($configNames[0]) |
|
98 | + ->willReturn($existingData); |
|
99 | + $this->systemConfig->method('getKeys') |
|
100 | + ->willReturn($existingData ? $configNames[0] : []); |
|
101 | + |
|
102 | + $this->consoleInput->expects($this->once()) |
|
103 | + ->method('getArgument') |
|
104 | + ->with('name') |
|
105 | + ->willReturn($configNames); |
|
106 | + $this->consoleInput->method('getOption') |
|
107 | + ->willReturnMap([ |
|
108 | + ['value', 'foobar'], |
|
109 | + ['type', 'string'], |
|
110 | + ['update-only', true], |
|
111 | + ]); |
|
112 | + |
|
113 | + $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); |
|
114 | + } |
|
115 | + |
|
116 | + public static function castValueProvider(): array { |
|
117 | + return [ |
|
118 | + [null, 'string', ['value' => '', 'readable-value' => 'empty string']], |
|
119 | + |
|
120 | + ['abc', 'string', ['value' => 'abc', 'readable-value' => 'string abc']], |
|
121 | + |
|
122 | + ['123', 'integer', ['value' => 123, 'readable-value' => 'integer 123']], |
|
123 | + ['456', 'int', ['value' => 456, 'readable-value' => 'integer 456']], |
|
124 | + |
|
125 | + ['2.25', 'double', ['value' => 2.25, 'readable-value' => 'double 2.25']], |
|
126 | + ['0.5', 'float', ['value' => 0.5, 'readable-value' => 'double 0.5']], |
|
127 | + |
|
128 | + ['', 'null', ['value' => null, 'readable-value' => 'null']], |
|
129 | + |
|
130 | + ['true', 'boolean', ['value' => true, 'readable-value' => 'boolean true']], |
|
131 | + ['false', 'bool', ['value' => false, 'readable-value' => 'boolean false']], |
|
132 | + ]; |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * @dataProvider castValueProvider |
|
137 | + */ |
|
138 | + public function testCastValue($value, $type, $expectedValue): void { |
|
139 | + $this->assertSame($expectedValue, |
|
140 | + $this->invokePrivate($this->command, 'castValue', [$value, $type]) |
|
141 | + ); |
|
142 | + } |
|
143 | + |
|
144 | + public static function castValueInvalidProvider(): array { |
|
145 | + return [ |
|
146 | + ['123', 'foobar'], |
|
147 | + |
|
148 | + [null, 'integer'], |
|
149 | + ['abc', 'integer'], |
|
150 | + ['76ggg', 'double'], |
|
151 | + ['true', 'float'], |
|
152 | + ['foobar', 'boolean'], |
|
153 | + ]; |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * @dataProvider castValueInvalidProvider |
|
158 | + */ |
|
159 | + public function testCastValueInvalid($value, $type): void { |
|
160 | + $this->expectException(\InvalidArgumentException::class); |
|
161 | + |
|
162 | + $this->invokePrivate($this->command, 'castValue', [$value, $type]); |
|
163 | + } |
|
164 | 164 | } |
@@ -14,147 +14,147 @@ |
||
14 | 14 | use Test\TestCase; |
15 | 15 | |
16 | 16 | class GetConfigTest extends TestCase { |
17 | - /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
18 | - protected $systemConfig; |
|
19 | - |
|
20 | - /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
21 | - protected $consoleInput; |
|
22 | - /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
23 | - protected $consoleOutput; |
|
24 | - |
|
25 | - /** @var \Symfony\Component\Console\Command\Command */ |
|
26 | - protected $command; |
|
27 | - |
|
28 | - protected function setUp(): void { |
|
29 | - parent::setUp(); |
|
30 | - |
|
31 | - $systemConfig = $this->systemConfig = $this->getMockBuilder(SystemConfig::class) |
|
32 | - ->disableOriginalConstructor() |
|
33 | - ->getMock(); |
|
34 | - $this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock(); |
|
35 | - $this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock(); |
|
36 | - |
|
37 | - /** @var \OC\SystemConfig $systemConfig */ |
|
38 | - $this->command = new GetConfig($systemConfig); |
|
39 | - } |
|
40 | - |
|
41 | - |
|
42 | - public static function getData(): array { |
|
43 | - return [ |
|
44 | - // String output as json |
|
45 | - ['name', 'newvalue', true, null, false, 'json', 0, json_encode('newvalue')], |
|
46 | - // String output as plain text |
|
47 | - ['name', 'newvalue', true, null, false, 'plain', 0, 'newvalue'], |
|
48 | - // String falling back to default output as json |
|
49 | - ['name', null, false, 'newvalue', true, 'json', 0, json_encode('newvalue')], |
|
50 | - // String falling back without default: error |
|
51 | - ['name', null, false, null, false, 'json', 1, null], |
|
52 | - |
|
53 | - // Int "0" output as json/plain |
|
54 | - ['name', 0, true, null, false, 'json', 0, json_encode(0)], |
|
55 | - ['name', 0, true, null, false, 'plain', 0, '0'], |
|
56 | - // Int "1" output as json/plain |
|
57 | - ['name', 1, true, null, false, 'json', 0, json_encode(1)], |
|
58 | - ['name', 1, true, null, false, 'plain', 0, '1'], |
|
59 | - |
|
60 | - // Bool "true" output as json/plain |
|
61 | - ['name', true, true, null, false, 'json', 0, json_encode(true)], |
|
62 | - ['name', true, true, null, false, 'plain', 0, 'true'], |
|
63 | - // Bool "false" output as json/plain |
|
64 | - ['name', false, true, null, false, 'json', 0, json_encode(false)], |
|
65 | - ['name', false, true, null, false, 'plain', 0, 'false'], |
|
66 | - |
|
67 | - // Null output as json/plain |
|
68 | - ['name', null, true, null, false, 'json', 0, json_encode(null)], |
|
69 | - ['name', null, true, null, false, 'plain', 0, 'null'], |
|
70 | - |
|
71 | - // Array output as json/plain |
|
72 | - ['name', ['a', 'b'], true, null, false, 'json', 0, json_encode(['a', 'b'])], |
|
73 | - ['name', ['a', 'b'], true, null, false, 'plain', 0, "a\nb"], |
|
74 | - // Key array output as json/plain |
|
75 | - ['name', [0 => 'a', 1 => 'b'], true, null, false, 'json', 0, json_encode(['a', 'b'])], |
|
76 | - ['name', [0 => 'a', 1 => 'b'], true, null, false, 'plain', 0, "a\nb"], |
|
77 | - // Associative array output as json/plain |
|
78 | - ['name', ['a' => 1, 'b' => 2], true, null, false, 'json', 0, json_encode(['a' => 1, 'b' => 2])], |
|
79 | - ['name', ['a' => 1, 'b' => 2], true, null, false, 'plain', 0, "a: 1\nb: 2"], |
|
80 | - |
|
81 | - // Nested depth |
|
82 | - [['name', 'a'], ['a' => 1, 'b' => 2], true, null, false, 'json', 0, json_encode(1)], |
|
83 | - [['name', 'a'], ['a' => 1, 'b' => 2], true, null, false, 'plain', 0, '1'], |
|
84 | - [['name', 'c'], ['a' => 1, 'b' => 2], true, true, true, 'json', 0, json_encode(true)], |
|
85 | - [['name', 'c'], ['a' => 1, 'b' => 2], true, true, false, 'json', 1, null], |
|
86 | - |
|
87 | - ]; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * @dataProvider getData |
|
92 | - * |
|
93 | - * @param string[] $configNames |
|
94 | - * @param mixed $value |
|
95 | - * @param bool $configExists |
|
96 | - * @param mixed $defaultValue |
|
97 | - * @param bool $hasDefault |
|
98 | - * @param string $outputFormat |
|
99 | - * @param int $expectedReturn |
|
100 | - * @param string $expectedMessage |
|
101 | - */ |
|
102 | - public function testGet($configNames, $value, $configExists, $defaultValue, $hasDefault, $outputFormat, $expectedReturn, $expectedMessage): void { |
|
103 | - if (is_array($configNames)) { |
|
104 | - $configName = $configNames[0]; |
|
105 | - } else { |
|
106 | - $configName = $configNames; |
|
107 | - $configNames = [$configName]; |
|
108 | - } |
|
109 | - $this->systemConfig->expects($this->atLeastOnce()) |
|
110 | - ->method('getKeys') |
|
111 | - ->willReturn($configExists ? [$configName] : []); |
|
112 | - |
|
113 | - if (!$expectedReturn) { |
|
114 | - if ($configExists) { |
|
115 | - $this->systemConfig->expects($this->once()) |
|
116 | - ->method('getValue') |
|
117 | - ->with($configName) |
|
118 | - ->willReturn($value); |
|
119 | - } |
|
120 | - } |
|
121 | - |
|
122 | - $this->consoleInput->expects($this->once()) |
|
123 | - ->method('getArgument') |
|
124 | - ->with('name') |
|
125 | - ->willReturn($configNames); |
|
126 | - $this->consoleInput->expects($this->any()) |
|
127 | - ->method('getOption') |
|
128 | - ->willReturnMap([ |
|
129 | - ['default-value', $defaultValue], |
|
130 | - ['output', $outputFormat], |
|
131 | - ]); |
|
132 | - $this->consoleInput->expects($this->any()) |
|
133 | - ->method('hasParameterOption') |
|
134 | - ->willReturnMap([ |
|
135 | - ['--output', false, true], |
|
136 | - ['--default-value', false,$hasDefault], |
|
137 | - ]); |
|
138 | - |
|
139 | - if ($expectedMessage !== null) { |
|
140 | - global $output; |
|
141 | - |
|
142 | - $output = ''; |
|
143 | - $this->consoleOutput->expects($this->any()) |
|
144 | - ->method('writeln') |
|
145 | - ->willReturnCallback(function ($value) { |
|
146 | - global $output; |
|
147 | - $output .= $value . "\n"; |
|
148 | - return $output; |
|
149 | - }); |
|
150 | - } |
|
151 | - |
|
152 | - $this->assertSame($expectedReturn, $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput])); |
|
153 | - |
|
154 | - if ($expectedMessage !== null) { |
|
155 | - global $output; |
|
156 | - // Remove the trailing newline |
|
157 | - $this->assertSame($expectedMessage, substr($output, 0, -1)); |
|
158 | - } |
|
159 | - } |
|
17 | + /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
18 | + protected $systemConfig; |
|
19 | + |
|
20 | + /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
21 | + protected $consoleInput; |
|
22 | + /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
23 | + protected $consoleOutput; |
|
24 | + |
|
25 | + /** @var \Symfony\Component\Console\Command\Command */ |
|
26 | + protected $command; |
|
27 | + |
|
28 | + protected function setUp(): void { |
|
29 | + parent::setUp(); |
|
30 | + |
|
31 | + $systemConfig = $this->systemConfig = $this->getMockBuilder(SystemConfig::class) |
|
32 | + ->disableOriginalConstructor() |
|
33 | + ->getMock(); |
|
34 | + $this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock(); |
|
35 | + $this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock(); |
|
36 | + |
|
37 | + /** @var \OC\SystemConfig $systemConfig */ |
|
38 | + $this->command = new GetConfig($systemConfig); |
|
39 | + } |
|
40 | + |
|
41 | + |
|
42 | + public static function getData(): array { |
|
43 | + return [ |
|
44 | + // String output as json |
|
45 | + ['name', 'newvalue', true, null, false, 'json', 0, json_encode('newvalue')], |
|
46 | + // String output as plain text |
|
47 | + ['name', 'newvalue', true, null, false, 'plain', 0, 'newvalue'], |
|
48 | + // String falling back to default output as json |
|
49 | + ['name', null, false, 'newvalue', true, 'json', 0, json_encode('newvalue')], |
|
50 | + // String falling back without default: error |
|
51 | + ['name', null, false, null, false, 'json', 1, null], |
|
52 | + |
|
53 | + // Int "0" output as json/plain |
|
54 | + ['name', 0, true, null, false, 'json', 0, json_encode(0)], |
|
55 | + ['name', 0, true, null, false, 'plain', 0, '0'], |
|
56 | + // Int "1" output as json/plain |
|
57 | + ['name', 1, true, null, false, 'json', 0, json_encode(1)], |
|
58 | + ['name', 1, true, null, false, 'plain', 0, '1'], |
|
59 | + |
|
60 | + // Bool "true" output as json/plain |
|
61 | + ['name', true, true, null, false, 'json', 0, json_encode(true)], |
|
62 | + ['name', true, true, null, false, 'plain', 0, 'true'], |
|
63 | + // Bool "false" output as json/plain |
|
64 | + ['name', false, true, null, false, 'json', 0, json_encode(false)], |
|
65 | + ['name', false, true, null, false, 'plain', 0, 'false'], |
|
66 | + |
|
67 | + // Null output as json/plain |
|
68 | + ['name', null, true, null, false, 'json', 0, json_encode(null)], |
|
69 | + ['name', null, true, null, false, 'plain', 0, 'null'], |
|
70 | + |
|
71 | + // Array output as json/plain |
|
72 | + ['name', ['a', 'b'], true, null, false, 'json', 0, json_encode(['a', 'b'])], |
|
73 | + ['name', ['a', 'b'], true, null, false, 'plain', 0, "a\nb"], |
|
74 | + // Key array output as json/plain |
|
75 | + ['name', [0 => 'a', 1 => 'b'], true, null, false, 'json', 0, json_encode(['a', 'b'])], |
|
76 | + ['name', [0 => 'a', 1 => 'b'], true, null, false, 'plain', 0, "a\nb"], |
|
77 | + // Associative array output as json/plain |
|
78 | + ['name', ['a' => 1, 'b' => 2], true, null, false, 'json', 0, json_encode(['a' => 1, 'b' => 2])], |
|
79 | + ['name', ['a' => 1, 'b' => 2], true, null, false, 'plain', 0, "a: 1\nb: 2"], |
|
80 | + |
|
81 | + // Nested depth |
|
82 | + [['name', 'a'], ['a' => 1, 'b' => 2], true, null, false, 'json', 0, json_encode(1)], |
|
83 | + [['name', 'a'], ['a' => 1, 'b' => 2], true, null, false, 'plain', 0, '1'], |
|
84 | + [['name', 'c'], ['a' => 1, 'b' => 2], true, true, true, 'json', 0, json_encode(true)], |
|
85 | + [['name', 'c'], ['a' => 1, 'b' => 2], true, true, false, 'json', 1, null], |
|
86 | + |
|
87 | + ]; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * @dataProvider getData |
|
92 | + * |
|
93 | + * @param string[] $configNames |
|
94 | + * @param mixed $value |
|
95 | + * @param bool $configExists |
|
96 | + * @param mixed $defaultValue |
|
97 | + * @param bool $hasDefault |
|
98 | + * @param string $outputFormat |
|
99 | + * @param int $expectedReturn |
|
100 | + * @param string $expectedMessage |
|
101 | + */ |
|
102 | + public function testGet($configNames, $value, $configExists, $defaultValue, $hasDefault, $outputFormat, $expectedReturn, $expectedMessage): void { |
|
103 | + if (is_array($configNames)) { |
|
104 | + $configName = $configNames[0]; |
|
105 | + } else { |
|
106 | + $configName = $configNames; |
|
107 | + $configNames = [$configName]; |
|
108 | + } |
|
109 | + $this->systemConfig->expects($this->atLeastOnce()) |
|
110 | + ->method('getKeys') |
|
111 | + ->willReturn($configExists ? [$configName] : []); |
|
112 | + |
|
113 | + if (!$expectedReturn) { |
|
114 | + if ($configExists) { |
|
115 | + $this->systemConfig->expects($this->once()) |
|
116 | + ->method('getValue') |
|
117 | + ->with($configName) |
|
118 | + ->willReturn($value); |
|
119 | + } |
|
120 | + } |
|
121 | + |
|
122 | + $this->consoleInput->expects($this->once()) |
|
123 | + ->method('getArgument') |
|
124 | + ->with('name') |
|
125 | + ->willReturn($configNames); |
|
126 | + $this->consoleInput->expects($this->any()) |
|
127 | + ->method('getOption') |
|
128 | + ->willReturnMap([ |
|
129 | + ['default-value', $defaultValue], |
|
130 | + ['output', $outputFormat], |
|
131 | + ]); |
|
132 | + $this->consoleInput->expects($this->any()) |
|
133 | + ->method('hasParameterOption') |
|
134 | + ->willReturnMap([ |
|
135 | + ['--output', false, true], |
|
136 | + ['--default-value', false,$hasDefault], |
|
137 | + ]); |
|
138 | + |
|
139 | + if ($expectedMessage !== null) { |
|
140 | + global $output; |
|
141 | + |
|
142 | + $output = ''; |
|
143 | + $this->consoleOutput->expects($this->any()) |
|
144 | + ->method('writeln') |
|
145 | + ->willReturnCallback(function ($value) { |
|
146 | + global $output; |
|
147 | + $output .= $value . "\n"; |
|
148 | + return $output; |
|
149 | + }); |
|
150 | + } |
|
151 | + |
|
152 | + $this->assertSame($expectedReturn, $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput])); |
|
153 | + |
|
154 | + if ($expectedMessage !== null) { |
|
155 | + global $output; |
|
156 | + // Remove the trailing newline |
|
157 | + $this->assertSame($expectedMessage, substr($output, 0, -1)); |
|
158 | + } |
|
159 | + } |
|
160 | 160 | } |
@@ -14,193 +14,193 @@ |
||
14 | 14 | use Test\TestCase; |
15 | 15 | |
16 | 16 | class DeleteConfigTest extends TestCase { |
17 | - /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
18 | - protected $systemConfig; |
|
19 | - |
|
20 | - /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
21 | - protected $consoleInput; |
|
22 | - /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
23 | - protected $consoleOutput; |
|
24 | - |
|
25 | - /** @var \Symfony\Component\Console\Command\Command */ |
|
26 | - protected $command; |
|
27 | - |
|
28 | - protected function setUp(): void { |
|
29 | - parent::setUp(); |
|
30 | - |
|
31 | - $systemConfig = $this->systemConfig = $this->getMockBuilder(SystemConfig::class) |
|
32 | - ->disableOriginalConstructor() |
|
33 | - ->getMock(); |
|
34 | - $this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock(); |
|
35 | - $this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock(); |
|
36 | - |
|
37 | - /** @var \OC\SystemConfig $systemConfig */ |
|
38 | - $this->command = new DeleteConfig($systemConfig); |
|
39 | - } |
|
40 | - |
|
41 | - public static function deleteData(): array { |
|
42 | - return [ |
|
43 | - [ |
|
44 | - 'name1', |
|
45 | - true, |
|
46 | - true, |
|
47 | - 0, |
|
48 | - 'info', |
|
49 | - ], |
|
50 | - [ |
|
51 | - 'name2', |
|
52 | - true, |
|
53 | - false, |
|
54 | - 0, |
|
55 | - 'info', |
|
56 | - ], |
|
57 | - [ |
|
58 | - 'name3', |
|
59 | - false, |
|
60 | - false, |
|
61 | - 0, |
|
62 | - 'info', |
|
63 | - ], |
|
64 | - [ |
|
65 | - 'name4', |
|
66 | - false, |
|
67 | - true, |
|
68 | - 1, |
|
69 | - 'error', |
|
70 | - ], |
|
71 | - ]; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * @dataProvider deleteData |
|
76 | - * |
|
77 | - * @param string $configName |
|
78 | - * @param bool $configExists |
|
79 | - * @param bool $checkIfExists |
|
80 | - * @param int $expectedReturn |
|
81 | - * @param string $expectedMessage |
|
82 | - */ |
|
83 | - public function testDelete($configName, $configExists, $checkIfExists, $expectedReturn, $expectedMessage): void { |
|
84 | - $this->systemConfig->expects(($checkIfExists) ? $this->once() : $this->never()) |
|
85 | - ->method('getKeys') |
|
86 | - ->willReturn($configExists ? [$configName] : []); |
|
87 | - |
|
88 | - $this->systemConfig->expects(($expectedReturn === 0) ? $this->once() : $this->never()) |
|
89 | - ->method('deleteValue') |
|
90 | - ->with($configName); |
|
91 | - |
|
92 | - $this->consoleInput->expects($this->once()) |
|
93 | - ->method('getArgument') |
|
94 | - ->with('name') |
|
95 | - ->willReturn([$configName]); |
|
96 | - $this->consoleInput->expects($this->any()) |
|
97 | - ->method('hasParameterOption') |
|
98 | - ->with('--error-if-not-exists') |
|
99 | - ->willReturn($checkIfExists); |
|
100 | - |
|
101 | - $this->consoleOutput->expects($this->any()) |
|
102 | - ->method('writeln') |
|
103 | - ->with($this->stringContains($expectedMessage)); |
|
104 | - |
|
105 | - $this->assertSame($expectedReturn, $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput])); |
|
106 | - } |
|
107 | - |
|
108 | - public static function deleteArrayData(): array { |
|
109 | - return [ |
|
110 | - [ |
|
111 | - ['name', 'sub'], |
|
112 | - true, |
|
113 | - false, |
|
114 | - true, |
|
115 | - true, |
|
116 | - 0, |
|
117 | - 'info', |
|
118 | - ], |
|
119 | - [ |
|
120 | - ['name', 'sub', '2sub'], |
|
121 | - true, |
|
122 | - false, |
|
123 | - ['sub' => ['2sub' => 1], 'sub2' => false], |
|
124 | - ['sub' => [], 'sub2' => false], |
|
125 | - 0, |
|
126 | - 'info', |
|
127 | - ], |
|
128 | - [ |
|
129 | - ['name', 'sub3'], |
|
130 | - true, |
|
131 | - false, |
|
132 | - ['sub' => ['2sub' => 1], 'sub2' => false], |
|
133 | - ['sub' => ['2sub' => 1], 'sub2' => false], |
|
134 | - 0, |
|
135 | - 'info', |
|
136 | - ], |
|
137 | - [ |
|
138 | - ['name', 'sub'], |
|
139 | - false, |
|
140 | - true, |
|
141 | - true, |
|
142 | - true, |
|
143 | - 1, |
|
144 | - 'error', |
|
145 | - ], |
|
146 | - [ |
|
147 | - ['name', 'sub'], |
|
148 | - true, |
|
149 | - true, |
|
150 | - true, |
|
151 | - true, |
|
152 | - 1, |
|
153 | - 'error', |
|
154 | - ], |
|
155 | - [ |
|
156 | - ['name', 'sub3'], |
|
157 | - true, |
|
158 | - true, |
|
159 | - ['sub' => ['2sub' => 1], 'sub2' => false], |
|
160 | - ['sub' => ['2sub' => 1], 'sub2' => false], |
|
161 | - 1, |
|
162 | - 'error', |
|
163 | - ], |
|
164 | - ]; |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * @dataProvider deleteArrayData |
|
169 | - * |
|
170 | - * @param string[] $configNames |
|
171 | - * @param bool $configKeyExists |
|
172 | - * @param bool $checkIfKeyExists |
|
173 | - * @param mixed $configValue |
|
174 | - * @param mixed $updateValue |
|
175 | - * @param int $expectedReturn |
|
176 | - * @param string $expectedMessage |
|
177 | - */ |
|
178 | - public function testArrayDelete(array $configNames, $configKeyExists, $checkIfKeyExists, $configValue, $updateValue, $expectedReturn, $expectedMessage): void { |
|
179 | - $this->systemConfig->expects(($checkIfKeyExists) ? $this->once() : $this->never()) |
|
180 | - ->method('getKeys') |
|
181 | - ->willReturn($configKeyExists ? [$configNames[0]] : []); |
|
182 | - |
|
183 | - $this->systemConfig->expects(($configKeyExists) ? $this->once() : $this->never()) |
|
184 | - ->method('getValue') |
|
185 | - ->willReturn($configValue); |
|
186 | - |
|
187 | - $this->systemConfig->expects(($expectedReturn === 0) ? $this->once() : $this->never()) |
|
188 | - ->method('setValue') |
|
189 | - ->with($configNames[0], $updateValue); |
|
190 | - |
|
191 | - $this->consoleInput->expects($this->once()) |
|
192 | - ->method('getArgument') |
|
193 | - ->with('name') |
|
194 | - ->willReturn($configNames); |
|
195 | - $this->consoleInput->expects($this->any()) |
|
196 | - ->method('hasParameterOption') |
|
197 | - ->with('--error-if-not-exists') |
|
198 | - ->willReturn($checkIfKeyExists); |
|
199 | - |
|
200 | - $this->consoleOutput->expects($this->any()) |
|
201 | - ->method('writeln') |
|
202 | - ->with($this->stringContains($expectedMessage)); |
|
203 | - |
|
204 | - $this->assertSame($expectedReturn, $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput])); |
|
205 | - } |
|
17 | + /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
18 | + protected $systemConfig; |
|
19 | + |
|
20 | + /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
21 | + protected $consoleInput; |
|
22 | + /** @var \PHPUnit\Framework\MockObject\MockObject */ |
|
23 | + protected $consoleOutput; |
|
24 | + |
|
25 | + /** @var \Symfony\Component\Console\Command\Command */ |
|
26 | + protected $command; |
|
27 | + |
|
28 | + protected function setUp(): void { |
|
29 | + parent::setUp(); |
|
30 | + |
|
31 | + $systemConfig = $this->systemConfig = $this->getMockBuilder(SystemConfig::class) |
|
32 | + ->disableOriginalConstructor() |
|
33 | + ->getMock(); |
|
34 | + $this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock(); |
|
35 | + $this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock(); |
|
36 | + |
|
37 | + /** @var \OC\SystemConfig $systemConfig */ |
|
38 | + $this->command = new DeleteConfig($systemConfig); |
|
39 | + } |
|
40 | + |
|
41 | + public static function deleteData(): array { |
|
42 | + return [ |
|
43 | + [ |
|
44 | + 'name1', |
|
45 | + true, |
|
46 | + true, |
|
47 | + 0, |
|
48 | + 'info', |
|
49 | + ], |
|
50 | + [ |
|
51 | + 'name2', |
|
52 | + true, |
|
53 | + false, |
|
54 | + 0, |
|
55 | + 'info', |
|
56 | + ], |
|
57 | + [ |
|
58 | + 'name3', |
|
59 | + false, |
|
60 | + false, |
|
61 | + 0, |
|
62 | + 'info', |
|
63 | + ], |
|
64 | + [ |
|
65 | + 'name4', |
|
66 | + false, |
|
67 | + true, |
|
68 | + 1, |
|
69 | + 'error', |
|
70 | + ], |
|
71 | + ]; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * @dataProvider deleteData |
|
76 | + * |
|
77 | + * @param string $configName |
|
78 | + * @param bool $configExists |
|
79 | + * @param bool $checkIfExists |
|
80 | + * @param int $expectedReturn |
|
81 | + * @param string $expectedMessage |
|
82 | + */ |
|
83 | + public function testDelete($configName, $configExists, $checkIfExists, $expectedReturn, $expectedMessage): void { |
|
84 | + $this->systemConfig->expects(($checkIfExists) ? $this->once() : $this->never()) |
|
85 | + ->method('getKeys') |
|
86 | + ->willReturn($configExists ? [$configName] : []); |
|
87 | + |
|
88 | + $this->systemConfig->expects(($expectedReturn === 0) ? $this->once() : $this->never()) |
|
89 | + ->method('deleteValue') |
|
90 | + ->with($configName); |
|
91 | + |
|
92 | + $this->consoleInput->expects($this->once()) |
|
93 | + ->method('getArgument') |
|
94 | + ->with('name') |
|
95 | + ->willReturn([$configName]); |
|
96 | + $this->consoleInput->expects($this->any()) |
|
97 | + ->method('hasParameterOption') |
|
98 | + ->with('--error-if-not-exists') |
|
99 | + ->willReturn($checkIfExists); |
|
100 | + |
|
101 | + $this->consoleOutput->expects($this->any()) |
|
102 | + ->method('writeln') |
|
103 | + ->with($this->stringContains($expectedMessage)); |
|
104 | + |
|
105 | + $this->assertSame($expectedReturn, $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput])); |
|
106 | + } |
|
107 | + |
|
108 | + public static function deleteArrayData(): array { |
|
109 | + return [ |
|
110 | + [ |
|
111 | + ['name', 'sub'], |
|
112 | + true, |
|
113 | + false, |
|
114 | + true, |
|
115 | + true, |
|
116 | + 0, |
|
117 | + 'info', |
|
118 | + ], |
|
119 | + [ |
|
120 | + ['name', 'sub', '2sub'], |
|
121 | + true, |
|
122 | + false, |
|
123 | + ['sub' => ['2sub' => 1], 'sub2' => false], |
|
124 | + ['sub' => [], 'sub2' => false], |
|
125 | + 0, |
|
126 | + 'info', |
|
127 | + ], |
|
128 | + [ |
|
129 | + ['name', 'sub3'], |
|
130 | + true, |
|
131 | + false, |
|
132 | + ['sub' => ['2sub' => 1], 'sub2' => false], |
|
133 | + ['sub' => ['2sub' => 1], 'sub2' => false], |
|
134 | + 0, |
|
135 | + 'info', |
|
136 | + ], |
|
137 | + [ |
|
138 | + ['name', 'sub'], |
|
139 | + false, |
|
140 | + true, |
|
141 | + true, |
|
142 | + true, |
|
143 | + 1, |
|
144 | + 'error', |
|
145 | + ], |
|
146 | + [ |
|
147 | + ['name', 'sub'], |
|
148 | + true, |
|
149 | + true, |
|
150 | + true, |
|
151 | + true, |
|
152 | + 1, |
|
153 | + 'error', |
|
154 | + ], |
|
155 | + [ |
|
156 | + ['name', 'sub3'], |
|
157 | + true, |
|
158 | + true, |
|
159 | + ['sub' => ['2sub' => 1], 'sub2' => false], |
|
160 | + ['sub' => ['2sub' => 1], 'sub2' => false], |
|
161 | + 1, |
|
162 | + 'error', |
|
163 | + ], |
|
164 | + ]; |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * @dataProvider deleteArrayData |
|
169 | + * |
|
170 | + * @param string[] $configNames |
|
171 | + * @param bool $configKeyExists |
|
172 | + * @param bool $checkIfKeyExists |
|
173 | + * @param mixed $configValue |
|
174 | + * @param mixed $updateValue |
|
175 | + * @param int $expectedReturn |
|
176 | + * @param string $expectedMessage |
|
177 | + */ |
|
178 | + public function testArrayDelete(array $configNames, $configKeyExists, $checkIfKeyExists, $configValue, $updateValue, $expectedReturn, $expectedMessage): void { |
|
179 | + $this->systemConfig->expects(($checkIfKeyExists) ? $this->once() : $this->never()) |
|
180 | + ->method('getKeys') |
|
181 | + ->willReturn($configKeyExists ? [$configNames[0]] : []); |
|
182 | + |
|
183 | + $this->systemConfig->expects(($configKeyExists) ? $this->once() : $this->never()) |
|
184 | + ->method('getValue') |
|
185 | + ->willReturn($configValue); |
|
186 | + |
|
187 | + $this->systemConfig->expects(($expectedReturn === 0) ? $this->once() : $this->never()) |
|
188 | + ->method('setValue') |
|
189 | + ->with($configNames[0], $updateValue); |
|
190 | + |
|
191 | + $this->consoleInput->expects($this->once()) |
|
192 | + ->method('getArgument') |
|
193 | + ->with('name') |
|
194 | + ->willReturn($configNames); |
|
195 | + $this->consoleInput->expects($this->any()) |
|
196 | + ->method('hasParameterOption') |
|
197 | + ->with('--error-if-not-exists') |
|
198 | + ->willReturn($checkIfKeyExists); |
|
199 | + |
|
200 | + $this->consoleOutput->expects($this->any()) |
|
201 | + ->method('writeln') |
|
202 | + ->with($this->stringContains($expectedMessage)); |
|
203 | + |
|
204 | + $this->assertSame($expectedReturn, $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput])); |
|
205 | + } |
|
206 | 206 | } |