|
| 1 | +<?php declare(strict_types=1); |
| 2 | + |
| 3 | +namespace LinkORB\OrgSync\Tests\Unit\Services\Ldap; |
| 4 | + |
| 5 | +use LinkORB\OrgSync\DTO\Group; |
| 6 | +use LinkORB\OrgSync\Services\Ldap\LdapParentHelper; |
| 7 | +use PHPUnit\Framework\TestCase; |
| 8 | + |
| 9 | +class LdapParentHelperTest extends TestCase |
| 10 | +{ |
| 11 | + /** @var LdapParentHelper */ |
| 12 | + private $parentHelper; |
| 13 | + |
| 14 | + protected function setUp(): void |
| 15 | + { |
| 16 | + $this->parentHelper = new LdapParentHelper(); |
| 17 | + } |
| 18 | + |
| 19 | + /** |
| 20 | + * @dataProvider getParentData |
| 21 | + */ |
| 22 | + public function testGetParentGroups(Group $group, array $expectedParents, array $initialParents = []) |
| 23 | + { |
| 24 | + $this->assertEquals($expectedParents, $this->parentHelper->getParentGroups($initialParents, $group)); |
| 25 | + } |
| 26 | + |
| 27 | + public function testGetParentsCircularReference() |
| 28 | + { |
| 29 | + $this->expectExceptionMessage('Circular reference detected'); |
| 30 | + $this->expectException(\UnexpectedValueException::class); |
| 31 | + |
| 32 | + $group1 = new Group('test1', ''); |
| 33 | + $group2 = new Group('test2', ''); |
| 34 | + $group1->setParent($group2); |
| 35 | + $group2->setParent($group1); |
| 36 | + |
| 37 | + $this->parentHelper->getParentGroups([], $group1); |
| 38 | + } |
| 39 | + |
| 40 | + public function getParentData(): array |
| 41 | + { |
| 42 | + return [ |
| 43 | + [ |
| 44 | + new Group('hello', '', '', new Group('to', '', '', new Group('all', '', '', new Group('world', '')))), |
| 45 | + ['to', 'all', 'world'], |
| 46 | + ], |
| 47 | + [ |
| 48 | + new Group('empty', ''), |
| 49 | + [], |
| 50 | + ], |
| 51 | + [ |
| 52 | + new Group('empty', ''), |
| 53 | + ['initial', 'set'], |
| 54 | + ['initial', 'set'] |
| 55 | + ], |
| 56 | + [ |
| 57 | + new Group('Earth', '', '', new Group('Eurasia', '', '', new Group('Europe', '',))), |
| 58 | + ['space', 'MilkyWay', 'Eurasia', 'Europe'], |
| 59 | + ['space', 'MilkyWay'] |
| 60 | + ], |
| 61 | + [ |
| 62 | + new Group('Earth', ''), |
| 63 | + [], |
| 64 | + [] |
| 65 | + ], |
| 66 | + ]; |
| 67 | + } |
| 68 | +} |
0 commit comments