142 lines
3.2 KiB
PHP
142 lines
3.2 KiB
PHP
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
/**
|
|
* This will test our LDAPResult array is working as expected
|
|
*
|
|
* @package Kohana/LDAP
|
|
* @category Test
|
|
* @author Deon George
|
|
* @copyright (c) 2013 phpLDAPadmin Development Team
|
|
* @license http://dev.phpldapadmin.org/license.html
|
|
* @group ldap
|
|
* @group ldap.server
|
|
*/
|
|
Class LDAPResult extends Unittest_TestCase {
|
|
function testDatabase_LDAP_Result_One() {
|
|
$x = LDAP::factory('user');
|
|
$x->connect();
|
|
|
|
// We'll do a query first.
|
|
$u = $x->search(array(''))
|
|
->scope('base')
|
|
->execute();
|
|
|
|
$this->assertEquals(1,$u->count());
|
|
|
|
foreach ($u[''] as $k => $v) {
|
|
$this->assertEquals('',$k);
|
|
$this->assertTrue(is_array($v));
|
|
}
|
|
|
|
$x->disconnect();
|
|
}
|
|
|
|
function testDatabase_LDAP_Result_Many() {
|
|
$x = LDAP::factory('user');
|
|
$x->connect();
|
|
$y = LDAP::factory('auth');
|
|
$y->connect();
|
|
|
|
// We'll do a query first.
|
|
$u = $x->search(NULL)
|
|
->scope('sub')
|
|
->where('uid','=','bart*')
|
|
->execute();
|
|
|
|
foreach ($u['dc=example.com'] as $k => $v) {
|
|
$this->assertEquals('cn=Bart Simpson,dc=example.com',$k);
|
|
$this->assertTrue(is_array($v));
|
|
}
|
|
|
|
$this->assertEquals(2,count($u['o=Simpsons']));
|
|
$this->assertEquals(count($u['o=Simpsons']),$u['o=Simpsons']->count());
|
|
|
|
$c = 0;
|
|
foreach ($u['o=Simpsons'] as $k => $v) {
|
|
if (! $c++)
|
|
$this->assertEquals('cn=Bart Simpson,ou=People,o=Simpsons',$k);
|
|
else
|
|
$this->assertEquals('cn=Bart Simpson-ML,ou=People,o=Simpsons',$k);
|
|
|
|
$this->assertTrue(is_array($v));
|
|
}
|
|
|
|
$x->disconnect();
|
|
}
|
|
|
|
function testDatabase_LDAP_Search_Result_One() {
|
|
$x = LDAP::factory('user');
|
|
$x->connect();
|
|
|
|
// We'll do a query first.
|
|
$u = $x->search(array(''))
|
|
->scope('base')
|
|
->execute();
|
|
|
|
$this->assertEquals(1,$u->count());
|
|
|
|
foreach ($u as $k => $v) {
|
|
$this->assertEquals('',$k);
|
|
$this->assertTrue(is_array($v));
|
|
}
|
|
|
|
$x->disconnect();
|
|
}
|
|
|
|
function testDatabase_LDAP_Search_Result_Many() {
|
|
$x = LDAP::factory('user');
|
|
$x->connect();
|
|
$y = LDAP::factory('auth');
|
|
$y->connect();
|
|
|
|
// We'll do a query first.
|
|
$u = $x->search(NULL)
|
|
->scope('sub')
|
|
->where('uid','=','bart*')
|
|
->execute();
|
|
|
|
$this->assertEquals(3,count($u));
|
|
|
|
$c = 0;
|
|
foreach ($u as $k => $v) {
|
|
switch (++$c) {
|
|
case 1: $this->assertEquals('cn=Bart Simpson,dc=example.com',$k); break;
|
|
case 2: $this->assertEquals('cn=Bart Simpson,ou=People,o=Simpsons',$k); break;
|
|
case 3: $this->assertEquals('cn=Bart Simpson-ML,ou=People,o=Simpsons',$k); break;
|
|
default: throw new Kohana_Exception('Unknown value of c? (:c)',array(':c'=>serialize($c)));
|
|
}
|
|
|
|
$this->assertTrue(is_array($v));
|
|
}
|
|
|
|
$x->disconnect();
|
|
}
|
|
|
|
function testDatabase_LDAP_Search_Result_OneDeep() {
|
|
$x = LDAP::factory('user');
|
|
$x->connect();
|
|
$y = LDAP::factory('auth');
|
|
$y->connect();
|
|
|
|
// We'll do a query first.
|
|
$u = $x->search(NULL)
|
|
->scope('sub')
|
|
->where('uid','=','bart-ml')
|
|
->execute();
|
|
|
|
$this->assertEquals(1,count($u));
|
|
|
|
$c = 0;
|
|
foreach ($u as $k => $v) {
|
|
switch (++$c) {
|
|
case 1: $this->assertEquals('cn=Bart Simpson-ML,ou=People,o=Simpsons',$k); break;
|
|
default: throw new Kohana_Exception('Unknown value of c? (:c)',array(':c'=>serialize($c)));
|
|
}
|
|
|
|
$this->assertTrue(is_array($v));
|
|
}
|
|
|
|
$x->disconnect();
|
|
}
|
|
}
|