-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix inconsistencies, increase test coverage, update README
- Loading branch information
Showing
11 changed files
with
536 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace LinkORB\OrgSync\Tests\Unit\Services\Ldap; | ||
|
||
use LinkORB\OrgSync\DTO\Target\Ldap; | ||
use LinkORB\OrgSync\Services\Ldap\Client; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class ClientTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider getGenerateDnData | ||
*/ | ||
public function testGenerateDn(array $domain, array $rdn, string $expectedDn) | ||
{ | ||
$ldap = new Ldap('', '', '', '', $domain); | ||
|
||
$client = $this->createPartialMock(Client::class, ['__destruct']); | ||
$client->__construct($ldap); | ||
|
||
$this->assertEquals($expectedDn, $client->generateDn($rdn)); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getGenerateDnData(): array | ||
{ | ||
return [ | ||
[ | ||
['internal', 'com'], | ||
['cn' => ['test', 'somewhere'], 'ou' => 'org'], | ||
'cn=test,cn=somewhere,ou=org,dc=internal,dc=com' | ||
], | ||
[ | ||
['com', 'internal'], | ||
['cn' => ['somewhere', 'test']], | ||
'cn=somewhere,cn=test,dc=com,dc=internal' | ||
], | ||
[ | ||
[], | ||
['uid' => 111222,'ou' => 'org'], | ||
'uid=111222,ou=org' | ||
], | ||
[ | ||
['abc', 'xyz'], | ||
[], | ||
'dc=abc,dc=xyz' | ||
], | ||
[ | ||
[], | ||
[], | ||
'' | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace LinkORB\OrgSync\Tests\Unit\Services\Ldap; | ||
|
||
use LinkORB\OrgSync\DTO\Group; | ||
use LinkORB\OrgSync\Services\Ldap\LdapParentHelper; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class LdapParentHelperTest extends TestCase | ||
{ | ||
/** @var LdapParentHelper */ | ||
private $parentHelper; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->parentHelper = new LdapParentHelper(); | ||
} | ||
|
||
/** | ||
* @dataProvider getParentData | ||
*/ | ||
public function testGetParentGroups(Group $group, array $expectedParents, array $initialParents = []) | ||
{ | ||
$this->assertEquals($expectedParents, $this->parentHelper->getParentGroups($initialParents, $group)); | ||
} | ||
|
||
public function testGetParentsCircularReference() | ||
{ | ||
$this->expectExceptionMessage('Circular reference detected'); | ||
$this->expectException(\UnexpectedValueException::class); | ||
|
||
$group1 = new Group('test1', ''); | ||
$group2 = new Group('test2', ''); | ||
$group1->setParent($group2); | ||
$group2->setParent($group1); | ||
|
||
$this->parentHelper->getParentGroups([], $group1); | ||
} | ||
|
||
public function getParentData(): array | ||
{ | ||
return [ | ||
[ | ||
new Group('hello', '', '', new Group('to', '', '', new Group('all', '', '', new Group('world', '')))), | ||
['to', 'all', 'world'], | ||
], | ||
[ | ||
new Group('empty', ''), | ||
[], | ||
], | ||
[ | ||
new Group('empty', ''), | ||
['initial', 'set'], | ||
['initial', 'set'] | ||
], | ||
[ | ||
new Group('Earth', '', '', new Group('Eurasia', '', '', new Group('Europe', '',))), | ||
['space', 'MilkyWay', 'Eurasia', 'Europe'], | ||
['space', 'MilkyWay'] | ||
], | ||
[ | ||
new Group('Earth', ''), | ||
[], | ||
[] | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace LinkORB\OrgSync\Tests\Unit\Services\Ldap; | ||
|
||
use LinkORB\OrgSync\DTO\User; | ||
use LinkORB\OrgSync\Services\Ldap\UserDataMapper; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class UserDataMapperTest extends TestCase | ||
{ | ||
/** @var UserDataMapper */ | ||
private $mapper; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->mapper = new UserDataMapper(); | ||
} | ||
|
||
/** | ||
* @dataProvider getMapData | ||
*/ | ||
public function testMap(User $user, array $expectedUserData) | ||
{ | ||
$this->assertEquals($expectedUserData, $this->mapper->map($user)); | ||
} | ||
|
||
public function getMapData(): array | ||
{ | ||
return [ | ||
[ | ||
new User(''), | ||
[ | ||
'cn' => '', | ||
'uid' => '', | ||
'sn' => '', | ||
'objectClass' => ['inetOrgPerson', 'organizationalPerson', 'person', 'top'] | ||
], | ||
], | ||
[ | ||
new User('uadmin', 'p@ss', '[email protected]', 'superadm', '1.jpg', ['lastName' => 'Jong']), | ||
[ | ||
'cn' => 'uadmin', | ||
'uid' => 'uadmin', | ||
'sn' => 'Jong', | ||
'objectClass' => ['inetOrgPerson', 'organizationalPerson', 'person', 'top'], | ||
'mail' => '[email protected]', | ||
'displayName' => 'superadm', | ||
'Photo' => '1.jpg', | ||
], | ||
], | ||
[ | ||
new User('uadmin', 'p@ss', '', 'superadm'), | ||
[ | ||
'cn' => 'uadmin', | ||
'uid' => 'uadmin', | ||
'sn' => 'superadm', | ||
'objectClass' => ['inetOrgPerson', 'organizationalPerson', 'person', 'top'], | ||
'displayName' => 'superadm', | ||
], | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.