cvs: pear /Net_LDAP/tests/PHPUnit Net_LDAP.php config.php unittests.php
| From: | Jan Wagner | Date: | Fri, 14 Nov 2003 15:43:04 +0000 |
| Subject: | cvs: pear /Net_LDAP/tests/PHPUnit Net_LDAP.php config.php unittests.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-14273@lists.php.net to get a copy of this message | ||
jw Fri Nov 14 10:43:04 2003 EDT
Added files:
/pear/Net_LDAP/tests/PHPUnit Net_LDAP.php config.php unittests.php
Log:
added PHPUnit tests
Index: pear/Net_LDAP/tests/PHPUnit/Net_LDAP.php
+++ pear/Net_LDAP/tests/PHPUnit/Net_LDAP.php
<?php
class Net_LDAP_Test extends PHPUnit_TestCase
{
var $ldap;
var $config;
function Net_LDAP_Test($name)
{
$this->PHPUnit_TestCase($name);
}
function setUp()
{
$this->config = $GLOBALS['ldap_config'];
$this->ldap = Net_LDAP::connect($this->config);
}
function testConnection()
{
return $this->assertEquals('net_ldap', get_class($this->ldap));
}
function testgetLDAPVersion()
{
return $this->assertEquals($this->config['version'],
$this->ldap->getLDAPVersion());
}
function testRootDSE()
{
$root_dse = $this->ldap->rootDSE();
$this->assertEquals('net_ldap_rootdse', get_class($root_dse));
}
function testSchema()
{
$schema = $this->ldap->schema();
$this->assertEquals('net_ldap_schema', get_class($schema));
}
function testUTF8()
{
$array1 = array('street' => 'Bärensteiner Str. 30');
$test = $this->ldap->utf8Encode($array1);
$this->assertEquals(utf8_encode($array1['street']), $test['street'],
'Encoding an attribute that should be encoded, was not.');
$test = $this->ldap->utf8Decode($test);
$this->assertEquals($array1['street'], $test['street'],
'An attribute that should have been decoded, was not');
$array2 = array('rfc822Mailbox' => 'krämer');
$test = $this->ldap->utf8Encode($array2);
$this->assertEquals($array2['rfc822Mailbox'], $test['rfc822Mailbox'],
'An attribute that should not be encoded, was encoded');
$test = $this->ldap->utf8Decode(array('rfc822Mailbox' =>
utf8_encode('krämer')));
$this->assertFalse($array2['rfc822Mailbox'] ==
$test['rfc822Mailbox'],
'An attribute that should not be decoded, was decoded');
}
function testSearch1()
{
$base = $GLOBALS['existing_dn'];
$parms = array('scope' => 'base', 'attributes' =>
array('objectClass'));
$result = $this->ldap->search($base, null, $parms);
$this->assertFalse(Net_Ldap::isError($result), 'Error searching for a specific
entry');
$this->assertFalse( $result->count() == 0, 'Specified exisiting dn could not be
found');
$entry = $result->shiftEntry();
$this->assertEquals('net_ldap_entry', get_class($entry), 'Could not fetch
specified entry');
$oc = $entry->get_value('objectClass');
$this->assertTrue(is_array($oc), 'objectClass attribute value was no array');
}
function testSearch2()
{
$test = $GLOBALS['search2'];
$result = $this->ldap->search($test['base'], $test['filter'],
$test['parms']);
$this->assertFalse(Net_Ldap::isError($result), 'Search failed');
if(!Net_LDAP::isError($result)) {
$this->assertTrue($result->count() >= 1, 'Empty Result set');
$entry = $result->shiftEntry();
$this->assertTrue($entry, 'No entry could be fetched');
$attrs = array_keys($test['parms']['attributes']);
$value = $entry->get_value($attrs[0], 'single');
$this->assertTrue(is_string($value) && $value != '',
'Attribute value was not a string or empty');
}
}
}
?>
Index: pear/Net_LDAP/tests/PHPUnit/config.php
+++ pear/Net_LDAP/tests/PHPUnit/config.php
<?php
// these should be valid connection parameters for your ldap server
$ldap_config= array('host' => '192.168.123.253',
'version' => 3,
'base' => 'o=netsols,c=de',
'filter' => '(objectClass=*)');
// this should be an existing dn which can be fetched with the above connection parameters
$existing_dn = 'uid=wagner,ou=mailAccounts,cn=netsols.de,ou=Domains,o=netsols,c=de';
// these should be parameters for an ldap query that returns at least one entry with one attribute
$search2 = array('filter' =>
'(&(objectClass=domainRelatedObject)(domainStatus=active))',
'base' => 'ou=Domains,o=netsols,c=de',
'parms' => array('scope' => 'one',
'attributes' => array('cn')));
?>
Index: pear/Net_LDAP/tests/PHPUnit/unittests.php
+++ pear/Net_LDAP/tests/PHPUnit/unittests.php
<?php
require_once('Net/LDAP.php');
require_once('PHPUnit.php');
require_once('PHPUnit/GUI/HTML.php');
set_time_limit(0);
require_once('Net_LDAP.php');
require_once('config.php');
$suite = new PHPUnit_TestSuite('Net_LDAP_Test');
$gui = new PHPUnit_GUI_HTML($suite);
$gui->show();
?>