Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Console/Data/Import/LdifTest.php
- This file was added.
<?php | |||||
namespace Tests\Feature\Console\Data\Import; | |||||
use Tests\TestCase; | |||||
class LdifTest extends TestCase | |||||
{ | |||||
/** | |||||
* {@inheritDoc} | |||||
*/ | |||||
public function setUp(): void | |||||
{ | |||||
parent::setUp(); | |||||
$this->deleteTestUser('owner@kolab3.com'); | |||||
} | |||||
/** | |||||
* {@inheritDoc} | |||||
*/ | |||||
public function tearDown(): void | |||||
{ | |||||
$this->deleteTestUser('owner@kolab3.com'); | |||||
parent::tearDown(); | |||||
} | |||||
/** | |||||
* Test the command | |||||
*/ | |||||
public function testHandle(): void | |||||
{ | |||||
$code = \Artisan::call("data:import:ldif tests/data/kolab3.ldif owner@kolab3.com"); | |||||
$this->assertSame(0, $code); | |||||
$owner = \App\User::where('email', 'owner@kolab3.com')->first(); | |||||
$this->assertNull($owner->password); | |||||
$this->assertSame( | |||||
'{SSHA512}g74+SECTLsM1x0aYkSrTG9sOFzEp8wjCflhshr2DjE7mi1G3iNb4ClH3ljorPRlTgZ105PsQGEpNtNr+XRjigg==', | |||||
$owner->password_ldap | |||||
); | |||||
// User settings | |||||
$this->assertSame('Aleksander', $owner->getSetting('first_name')); | |||||
$this->assertSame('Machniak', $owner->getSetting('last_name')); | |||||
$this->assertSame('123456789', $owner->getSetting('phone')); | |||||
$this->assertSame('external@gmail.com', $owner->getSetting('external_email')); | |||||
$this->assertSame('Organization AG', $owner->getSetting('organization')); | |||||
// User aliases | |||||
$aliases = $owner->aliases()->orderBy('alias')->pluck('alias')->all(); | |||||
$this->assertSame(['alias@kolab3-alias.com', 'alias@kolab3.com'], $aliases); | |||||
// Wallet, entitlements | |||||
$wallet = $owner->wallets->first(); | |||||
$this->assertEntitlements($owner, [ | |||||
'groupware', | |||||
'mailbox', | |||||
'storage', 'storage', 'storage', 'storage', 'storage', 'storage', 'storage', 'storage', | |||||
]); | |||||
// Users | |||||
$this->assertSame(2, $owner->users(false)->count()); | |||||
$user = $owner->users(false)->where('email', 'user@kolab3.com')->first(); | |||||
// User settings | |||||
$this->assertSame('Jane', $user->getSetting('first_name')); | |||||
$this->assertSame('Doe', $user->getSetting('last_name')); | |||||
$this->assertSame('1234567890', $user->getSetting('phone')); | |||||
$this->assertSame('ext@gmail.com', $user->getSetting('external_email')); | |||||
$this->assertSame('Org AG', $user->getSetting('organization')); | |||||
// User aliases | |||||
$aliases = $user->aliases()->orderBy('alias')->pluck('alias')->all(); | |||||
$this->assertSame(['alias2@kolab3.com'], $aliases); | |||||
$this->assertEntitlements($user, [ | |||||
'groupware', | |||||
'mailbox', | |||||
'storage', 'storage', 'storage', 'storage', 'storage', | |||||
]); | |||||
// Domains | |||||
$domains = $owner->domains(false, false)->orderBy('namespace')->get(); | |||||
$this->assertCount(2, $domains); | |||||
$this->assertSame('kolab3-alias.com', $domains[0]->namespace); | |||||
$this->assertSame('kolab3.com', $domains[1]->namespace); | |||||
$this->assertSame(\App\Domain::TYPE_EXTERNAL, $domains[0]->type); | |||||
$this->assertSame(\App\Domain::TYPE_EXTERNAL, $domains[1]->type); | |||||
$this->assertEntitlements($domains[0], ['domain-hosting']); | |||||
$this->assertEntitlements($domains[1], ['domain-hosting']); | |||||
// Shared folders | |||||
$folders = $owner->sharedFolders(false)->orderBy('email')->get(); | |||||
$this->assertCount(2, $folders); | |||||
$this->assertSame('folder1@kolab3.com', $folders[0]->email); | |||||
$this->assertSame('folder2@kolab3.com', $folders[1]->email); | |||||
$this->assertSame('Folder1', $folders[0]->name); | |||||
$this->assertSame('Folder2', $folders[1]->name); | |||||
$this->assertSame('mail', $folders[0]->type); | |||||
$this->assertSame('event', $folders[1]->type); | |||||
$this->assertSame('["anyone, read-write","owner@kolab3.com, full"]', $folders[0]->getSetting('acl')); | |||||
$this->assertSame('shared/Folder1@kolab3.com', $folders[0]->getSetting('folder')); | |||||
$this->assertSame('["anyone, read-only"]', $folders[1]->getSetting('acl')); | |||||
$this->assertSame('shared/Folder2@kolab3.com', $folders[1]->getSetting('folder')); | |||||
// TODO: Groups, Resources | |||||
// TODO: Error handling | |||||
} | |||||
/** | |||||
* Test parseACL() method | |||||
*/ | |||||
public function testParseACL(): void | |||||
{ | |||||
$command = new \App\Console\Commands\Data\Import\LdifCommand(); | |||||
$result = $this->invokeMethod($command, 'parseACL', [[]]); | |||||
$this->assertSame([], $result); | |||||
$acl = [ | |||||
'anyone, read-write', | |||||
'read-only@kolab3.com, read-only', | |||||
'read-only@kolab3.com, read', | |||||
'full@kolab3.com,full', | |||||
'lrswipkxtecdn@kolab3.com, lrswipkxtecdn', // full | |||||
'lrs@kolab3.com, lrs', // read-only | |||||
'lrswitedn@kolab3.com, lrswitedn', // read-write | |||||
// unsupported: | |||||
'anonymous, read-only', | |||||
'group:test, lrs', | |||||
'test@kolab3.com, lrspkxtdn', | |||||
]; | |||||
$expected = [ | |||||
'anyone, read-write', | |||||
'read-only@kolab3.com, read-only', | |||||
'read-only@kolab3.com, read-only', | |||||
'full@kolab3.com, full', | |||||
'lrswipkxtecdn@kolab3.com, full', | |||||
'lrs@kolab3.com, read-only', | |||||
'lrswitedn@kolab3.com, read-write', | |||||
]; | |||||
$result = $this->invokeMethod($command, 'parseACL', [$acl]); | |||||
$this->assertSame($expected, $result); | |||||
} | |||||
/** | |||||
* Test parseInvitationPolicy() method | |||||
*/ | |||||
public function testParseInvitationPolicy(): void | |||||
{ | |||||
$command = new \App\Console\Commands\Data\Import\LdifCommand(); | |||||
$result = $this->invokeMethod($command, 'parseInvitationPolicy', [[]]); | |||||
$this->assertSame(null, $result); | |||||
$result = $this->invokeMethod($command, 'parseInvitationPolicy', [['UNKNOWN']]); | |||||
$this->assertSame(null, $result); | |||||
$result = $this->invokeMethod($command, 'parseInvitationPolicy', [['ACT_ACCEPT']]); | |||||
$this->assertSame(null, $result); | |||||
$result = $this->invokeMethod($command, 'parseInvitationPolicy', [['ACT_MANUAL']]); | |||||
$this->assertSame('manual', $result); | |||||
$result = $this->invokeMethod($command, 'parseInvitationPolicy', [['ACT_REJECT']]); | |||||
$this->assertSame('reject', $result); | |||||
$result = $this->invokeMethod($command, 'parseInvitationPolicy', [['ACT_ACCEPT_AND_NOTIFY', 'ACT_REJECT']]); | |||||
$this->assertSame(null, $result); | |||||
} | |||||
/** | |||||
* Test parseSenderPolicy() method | |||||
*/ | |||||
public function testParseSenderPolicy(): void | |||||
{ | |||||
$command = new \App\Console\Commands\Data\Import\LdifCommand(); | |||||
$result = $this->invokeMethod($command, 'parseSenderPolicy', [[]]); | |||||
$this->assertSame([], $result); | |||||
$result = $this->invokeMethod($command, 'parseSenderPolicy', [['test']]); | |||||
$this->assertSame(['test', '-'], $result); | |||||
$result = $this->invokeMethod($command, 'parseSenderPolicy', [['test', '-test2', 'test3', '']]); | |||||
$this->assertSame(['test', 'test3', '-'], $result); | |||||
} | |||||
} |