Permalink
Browse files

added PHPUnit tests

git-svn-id: http://svn.php.net/repository/pear/packages/Net_LDAP/trunk@144353 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
Jan Wagner
Jan Wagner committed Nov 14, 2003
1 parent 4e21a12 commit 1396fff65fdbf27459095d96c8055a561201ae7a
Showing with 133 additions and 0 deletions.
  1. +100 −0 tests/PHPUnit/Net_LDAP.php
  2. +17 −0 tests/PHPUnit/config.php
  3. +16 −0 tests/PHPUnit/unittests.php
View
@@ -0,0 +1,100 @@
+<?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');
+ }
+ }
+}
+
+?>
View
@@ -0,0 +1,17 @@
+<?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')));
+
+?>
@@ -0,0 +1,16 @@
+<?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();
+
+?>

0 comments on commit 1396fff

Please sign in to comment.