From 1396fff65fdbf27459095d96c8055a561201ae7a Mon Sep 17 00:00:00 2001 From: Jan Wagner Date: Fri, 14 Nov 2003 15:43:04 +0000 Subject: [PATCH] added PHPUnit tests git-svn-id: http://svn.php.net/repository/pear/packages/Net_LDAP/trunk@144353 c90b9560-bf6c-de11-be94-00142212c4b1 --- tests/PHPUnit/Net_LDAP.php | 100 ++++++++++++++++++++++++++++++++++++ tests/PHPUnit/config.php | 17 ++++++ tests/PHPUnit/unittests.php | 16 ++++++ 3 files changed, 133 insertions(+) create mode 100644 tests/PHPUnit/Net_LDAP.php create mode 100644 tests/PHPUnit/config.php create mode 100644 tests/PHPUnit/unittests.php diff --git a/tests/PHPUnit/Net_LDAP.php b/tests/PHPUnit/Net_LDAP.php new file mode 100644 index 0000000..c662a79 --- /dev/null +++ b/tests/PHPUnit/Net_LDAP.php @@ -0,0 +1,100 @@ +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'); + } + } +} + +?> \ No newline at end of file diff --git a/tests/PHPUnit/config.php b/tests/PHPUnit/config.php new file mode 100644 index 0000000..4836754 --- /dev/null +++ b/tests/PHPUnit/config.php @@ -0,0 +1,17 @@ + '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'))); + +?> \ No newline at end of file diff --git a/tests/PHPUnit/unittests.php b/tests/PHPUnit/unittests.php new file mode 100644 index 0000000..334db20 --- /dev/null +++ b/tests/PHPUnit/unittests.php @@ -0,0 +1,16 @@ +show(); + +?> \ No newline at end of file