Skip to content

Commit bcb987a

Browse files
committed
Added more tests
1 parent be3447b commit bcb987a

File tree

5 files changed

+102
-18
lines changed

5 files changed

+102
-18
lines changed

tests/DirectoryEmulatorTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace LdapRecord\Lumen\Tests;
4+
5+
use LdapRecord\Lumen\LdapServiceProvider;
6+
use LdapRecord\Models\ActiveDirectory\User;
7+
use LdapRecord\Laravel\Testing\DirectoryEmulator;
8+
use LdapRecord\Laravel\Testing\EmulatedConnectionFake;
9+
10+
class DirectoryEmulatorTest extends TestCase
11+
{
12+
protected function setUp(): void
13+
{
14+
parent::setUp();
15+
16+
config(['ldap.default' => 'default']);
17+
config(['ldap.connections.default' => [
18+
'hosts' => ['localhost'],
19+
'username' => 'user',
20+
'password' => 'secret',
21+
'base_dn' => 'dc=local,dc=com',
22+
]]);
23+
24+
app()->register(LdapServiceProvider::class);
25+
}
26+
27+
public function test_emulator_can_be_used()
28+
{
29+
$fake = DirectoryEmulator::setup();
30+
31+
$this->assertInstanceOf(EmulatedConnectionFake::class, $fake);
32+
33+
$user = User::create(['cn' => 'John Doe']);
34+
35+
$this->assertTrue($user->exists);
36+
$this->assertEquals('John Doe', $user->getName());
37+
$this->assertEquals('cn=John Doe,dc=local,dc=com', $user->getDn());
38+
}
39+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace LdapRecord\Lumen\Tests;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
use Illuminate\Support\Facades\Auth;
7+
use LdapRecord\Laravel\Auth\DatabaseUserProvider;
8+
use LdapRecord\Laravel\Auth\NoDatabaseUserProvider;
9+
use LdapRecord\Lumen\LdapAuthServiceProvider;
10+
use LdapRecord\Lumen\LdapServiceProvider;
11+
use LdapRecord\Models\ActiveDirectory\User;
12+
13+
class LdapAuthServiceProviderTest extends TestCase
14+
{
15+
protected function setUp(): void
16+
{
17+
parent::setUp();
18+
19+
app()->register(LdapServiceProvider::class);
20+
app()->register(LdapAuthServiceProvider::class);
21+
}
22+
23+
public function test_no_database_user_provider_is_loaded()
24+
{
25+
config(['auth.defaults.guard' => 'api']);
26+
config(['auth.guards.api' => [
27+
'driver' => 'api',
28+
'provider' => 'ldap',
29+
]]);
30+
config(['auth.providers.ldap' => [
31+
'driver' => 'ldap',
32+
'model' => User::class,
33+
]]);
34+
35+
$this->assertInstanceOf(NoDatabaseUserProvider::class, Auth::createUserProvider('ldap'));
36+
}
37+
38+
public function test_database_user_provider_is_loaded()
39+
{
40+
config(['auth.defaults.guard' => 'api']);
41+
config(['auth.guards.api' => [
42+
'driver' => 'api',
43+
'provider' => 'ldap',
44+
]]);
45+
config(['auth.providers.ldap' => [
46+
'driver' => 'ldap',
47+
'model' => User::class,
48+
'database' => [
49+
'model' => Model::class,
50+
]
51+
]]);
52+
53+
$this->assertInstanceOf(DatabaseUserProvider::class, Auth::createUserProvider('ldap'));
54+
}
55+
}

tests/LdapServiceProviderTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@ protected function setUp(): void
2222
app()->register(LdapServiceProvider::class);
2323
}
2424

25-
public function test_connections_are_registered()
25+
public function test_connections_are_auto_loaded()
2626
{
2727
$this->assertIsArray($connections = Container::getInstance()->all());
2828
$this->assertCount(1, $connections);
2929

3030
$this->assertInstanceOf(Connection::class, $default = $connections['default']);
31-
$this->assertEquals(['localhost'], $default->getConfiguration()->get('hosts'));
31+
32+
$config = $default->getConfiguration();
33+
$this->assertEquals(['localhost'], $config->get('hosts'));
34+
$this->assertEquals('user', $config->get('username'));
35+
$this->assertEquals('secret', $config->get('password'));
3236
}
3337
}

tests/MakeLdapConfigTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected function configFileFolder()
3939
return __DIR__.'/../config';
4040
}
4141

42-
public function test_configuration_can_be_published()
42+
public function test_configuration_file_can_be_published()
4343
{
4444
$this->artisan('make:ldap-config');
4545

tests/bootstrap.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
);
2525

2626
$app->withFacades();
27-
28-
// $app->withEloquent();
27+
$app->withEloquent();
2928

3029
/*
3130
|--------------------------------------------------------------------------
@@ -60,19 +59,6 @@
6059
*/
6160

6261
$app->configure('app');
63-
$app->configure('ldap');
64-
65-
/*
66-
|--------------------------------------------------------------------------
67-
| Register Service Providers
68-
|--------------------------------------------------------------------------
69-
|
70-
| Here we will register all of the application's service providers which
71-
| are used to bind services into the container. Service providers are
72-
| totally optional, so you are not required to uncomment this line.
73-
|
74-
*/
75-
7662

7763
/*
7864
|--------------------------------------------------------------------------

0 commit comments

Comments
 (0)