|
32 | 32 | use OCP\IL10N; |
33 | 33 | use OCP\ILogger; |
34 | 34 | use OCP\RichObjectStrings\IValidator; |
| 35 | +use PHPUnit\Framework\MockObject\MockObject; |
35 | 36 |
|
36 | 37 | class GroupHelperTest extends TestCase { |
37 | 38 | /** @var IManager|\PHPUnit_Framework_MockObject_MockObject */ |
@@ -202,7 +203,48 @@ public function testGetEventFromArray(array $activity) { |
202 | 203 | ->willReturn($event); |
203 | 204 |
|
204 | 205 | $helper = $this->getHelper(); |
205 | | - $instance = $this->invokePrivate($helper, 'arrayToEvent', [$activity]); |
| 206 | + $instance = self::invokePrivate($helper, 'arrayToEvent', [$activity]); |
206 | 207 | $this->assertSame($event, $instance); |
207 | 208 | } |
| 209 | + |
| 210 | + |
| 211 | + protected function createEvent(array $data): IEvent { |
| 212 | + /** @var IEvent|MockObject $event */ |
| 213 | + $event = $this->createMock(IEvent::class); |
| 214 | + $event->expects($this->atLeastOnce()) |
| 215 | + ->method('getObjectId') |
| 216 | + ->willReturn($data['id']); |
| 217 | + $event->expects($this->atLeastOnce()) |
| 218 | + ->method('getObjectName') |
| 219 | + ->willReturn($data['name']); |
| 220 | + |
| 221 | + if (isset($data['child'])) { |
| 222 | + $event->expects($this->once()) |
| 223 | + ->method('getChildEvent') |
| 224 | + ->willReturn($this->createEvent($data['child'])); |
| 225 | + } |
| 226 | + |
| 227 | + return $event; |
| 228 | + } |
| 229 | + |
| 230 | + public function dataGetObjectsFromChildren() { |
| 231 | + return [ |
| 232 | + [['id' => 0, 'name' => ''], []], |
| 233 | + [['id' => 12, 'name' => ''], [12 => '']], |
| 234 | + [['id' => 0, 'name' => 'zero'], [0 => 'zero']], |
| 235 | + [['id' => 12, 'name' => 'twelve'], [12 => 'twelve']], |
| 236 | + [['id' => 12, 'name' => 'twelve', 'child' => ['id' => 11, 'name' => 'eleven', 'child' => ['id' => 10, 'name' => 'ten']]], [10 => 'ten', 11 => 'eleven', 12 => 'twelve']], |
| 237 | + ]; |
| 238 | + } |
| 239 | + |
| 240 | + /** |
| 241 | + * @dataProvider dataGetObjectsFromChildren |
| 242 | + * @param array $data |
| 243 | + * @param array $expected |
| 244 | + */ |
| 245 | + public function testGetObjectsFromChildren(array $data, array $expected) { |
| 246 | + $event = $this->createEvent($data); |
| 247 | + $helper = $this->getHelper(); |
| 248 | + $this->assertSame($expected, self::invokePrivate($helper, 'getObjectsFromChildren', [$event])); |
| 249 | + } |
208 | 250 | } |
0 commit comments