cvs: pear /Net_LDAP/tests/PHPUnit Net_LDAP.php config.php
| From: | Del Elson | Date: | Fri, 24 Feb 2006 03:40:11 +0000 |
| Subject: | cvs: pear /Net_LDAP/tests/PHPUnit Net_LDAP.php config.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-38544@lists.php.net to get a copy of this message | ||
delatbabel Fri Feb 24 03:40:11 2006 UTC
Modified files:
/pear/Net_LDAP/tests/PHPUnit Net_LDAP.php config.php
Log:
Added additional test cases.
http://cvs.php.net/viewcvs.cgi/pear/Net_LDAP/tests/PHPUnit/Net_LDAP.php?r1=1.6&r2=1.7&diff_format=u Index: pear/Net_LDAP/tests/PHPUnit/Net_LDAP.php diff -u pear/Net_LDAP/tests/PHPUnit/Net_LDAP.php:1.6 pear/Net_LDAP/tests/PHPUnit/Net_LDAP.php:1.7 --- pear/Net_LDAP/tests/PHPUnit/Net_LDAP.php:1.6 Mon Apr 12 10:53:44 2004 +++ pear/Net_LDAP/tests/PHPUnit/Net_LDAP.php Fri Feb 24 03:40:11 2006 @@ -4,41 +4,55 @@ { 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); + $this->ldap = Net_LDAP::connect($this->config); if (Net_LDAP::isError($this->ldap)) { die($this->ldap->getMessage()); } } - + function tearDown() { $this->ldap->done(); } - + function testConnection() { return $this->assertEquals('net_ldap', strtolower(get_class($this->ldap))); } - + + function testInvalidConnection() + { + $invalid_config = $GLOBALS['ldap_invalid_config']; + $invalid_ldap = Net_LDAP::connect($invalid_config); + if (Net_LDAP::isError($invalid_ldap)) { + // + // Yes, this is supposed to fail. + // + return true; + } + $this->fail(print_r($invalid_ldap, true)); + return false; + } + function testgetLDAPVersion() { return $this->assertEquals($this->config['version'], $this->ldap->getLDAPVersion()); } - + function testdnExists() { $this->assertTrue($this->ldap->dnExists($GLOBALS['existing_dn'])); } - + function testgetEntry() { $entry = $this->ldap->getEntry($GLOBALS['existing_dn']); @@ -48,30 +62,38 @@ } return true; } - + function testRootDSE() { $root_dse = $this->ldap->rootDSE(); $this->assertTrue(is_a($root_dse, 'net_ldap_rootdse')); } - - function testSchema() + + function testSchema() { $schema = $this->ldap->schema(); $this->assertTrue(is_a($schema, 'net_ldap_schema')); } - + + function testSchemaInternals() + { + $schema = $this->ldap->schema(); + $this->assertTrue(is_array($schema->types)); + $this->assertTrue(is_array($schema->_attributeTypes)); + $this->assertTrue(is_array($schema->_objectClasses)); + } + 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.'); - + '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'], @@ -80,17 +102,17 @@ $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 testSearch() - { + { $test = $GLOBALS['search']; - $result = $this->ldap->search($test['base'], $test['filter'], $test['parms']); + $result = $this->ldap->search($test['base'], $test['filter'], $test['parms']); if (Net_LDAP::isError($result)) { $this->fail($result->getMessage()); return false; - } + } $entry = $result->shiftEntry(); if (false === $entry) { $this->fail('No entry could be fetched'); @@ -99,7 +121,58 @@ $value = $entry->getValue($test['parms']['attributes'][0], 'single'); $this->assertTrue(is_string($value) && $value != '', 'Attribute value was not a string or empty'); } - + + function testShiftEntry() + { + $test = $GLOBALS['multi_search']; + $result = $this->ldap->search($test['base'], $test['filter'], $test['parms']); + if (Net_LDAP::isError($result)) { + $this->fail($result->getMessage()); + return false; + } + + // + // Extract 3 entries from the search result, check that they are not all + // the same, and check that the two shiftentry functions return the same + // result (bug 5191). + // + $values = array(); + for ($i=1; $i<4; $i++) { + $entry = $result->shiftEntry(); + if (false === $entry) { + $this->fail('No entry could be fetched'); + return false; + } + $value = $entry->getValue($test['parms']['attributes'][0], 'single'); + $this->assertTrue(is_string($value) && $value != '', 'Attribute value was not a string or empty'); + if (in_array($value, $values)) { + $this->fail('The same value was returned more than once.'); + return false; + } + $values[] = $value; + } + + $result = $this->ldap->search($test['base'], $test['filter'], $test['parms']); + if (Net_LDAP::isError($result)) { + $this->fail($result->getMessage()); + return false; + } + for ($i=1; $i<4; $i++) { + $entry = $result->shift_entry(); + if (false === $entry) { + $this->fail('No entry could be fetched'); + return false; + } + $value = $entry->getValue($test['parms']['attributes'][0], 'single'); + $this->assertTrue(is_string($value) && $value != '', 'Attribute value was not a string or empty'); + if (! in_array($value, $values)) { + $this->fail('The value fetched by shiftEntry was not fetched by shift_entry.'); + return false; + } + } + + } + function testAdd() { $entry = $this->ldap->getEntry($GLOBALS['existing_dn']); @@ -112,26 +185,26 @@ $this->fail($msg->getMessage()); return false; } - + $parts = ldap_explode_dn($entry->dn(), 0); list($attr,$value) = explode('=', $parts[0]); $newdn->delete(array($attr => $value)); - + $parts = ldap_explode_dn($newdn->dn(), 0); list($attr,$value) = explode('=', $parts[0]); $newdn->add(array($attr => $value)); - + if (Net_LDAP::isError($msg = $this->ldap->add($newdn))) { $this->fail($msg->getMessage()); return false; - } + } if (Net_LDAP::isError($msg = $this->ldap->delete($newdn))) { $this->fail($msg->getMessage()); return false; } return true; } - + function testReBind() { $this->ldap->done(); @@ -153,9 +226,9 @@ $this->fail($msg->getMessage()); return false; } - return true; + return true; } - + function testRecursiveDelete() { // get existing entry for copy @@ -176,7 +249,7 @@ unset($rdn['count']); } $rdn = array_shift($rdn); - + // add a copy of new entry as subentry to itself $msg = $newentry->copy($this->ldap, $rdn, true); if (Net_LDAP::isError($msg)) { @@ -191,18 +264,18 @@ } return true; } - + function testModifyAdd() { global $existing_dn, $existing_dn_changes; - + $msg = $this->ldap->modify($existing_dn, array('add' => $existing_dn_changes['add'])); if (Net_LDAP::isError($msg)) { $this->fail($msg->getMessage()); return false; } - + $entry = &$this->ldap->getEntry($existing_dn); foreach($existing_dn_changes['add'] as $attr => $vals) { $values = $entry->getValue($attr, 'all'); @@ -213,18 +286,18 @@ } return true; } - + function testModifyDelete() { global $existing_dn, $existing_dn_changes; - + $msg = $this->ldap->modify($existing_dn, array('delete' => $existing_dn_changes['add'])); if (Net_LDAP::isError($msg)) { $this->fail($msg->getMessage()); return false; } - + $entry = &$this->ldap->getEntry($existing_dn); foreach($existing_dn_changes['add'] as $attr => $vals) { $values = $entry->getValue($attr, 'all'); @@ -235,22 +308,22 @@ } return true; } - + function testModifyReplace() { global $existing_dn, $existing_dn_changes; - + $original = &$this->ldap->getEntry($existing_dn); - + $msg = $this->ldap->modify($existing_dn, array('replace' => $existing_dn_changes['replace'])); if (Net_LDAP::isError($msg)) { $this->fail($msg->getMessage()); return false; } - + $entry = &$this->ldap->getEntry($existing_dn); - + foreach ($existing_dn_changes['replace'] as $attr => $vals) { $values = $entry->getValue($attr, 'all'); $this->assertTrue(count($vals) == count($values)); @@ -259,7 +332,7 @@ } $entry->replace(array($attr => $original->getValue($attr, 'all'))); } - + $msg = $entry->update($this->ldap); if (Net_LDAP::isError($msg)) { $this->fail($msg->getMessage()); @@ -267,13 +340,13 @@ } return true; } - + function testModifyChanges() { global $existing_dn, $existing_dn_changes; - + $original = &$this->ldap->getEntry($existing_dn); - + $msg = $this->ldap->modify($existing_dn, array('changes' => array('add' => $existing_dn_changes['add'], 'replace' => $existing_dn_changes['replace']))); @@ -291,7 +364,7 @@ } $entry->replace(array($attr => $original->getValue($attr, 'all'))); } - + foreach ($existing_dn_changes['replace'] as $attr => $vals) { $values = $entry->getValue($attr, 'all'); $this->assertTrue(count($vals) == count($values)); @@ -300,7 +373,7 @@ } $entry->replace(array($attr => $original->getValue($attr, 'all'))); } - + $msg = $entry->update($this->ldap); if (Net_LDAP::isError($msg)) { $this->fail($msg->getMessage()); http://cvs.php.net/viewcvs.cgi/pear/Net_LDAP/tests/PHPUnit/config.php?r1=1.4&r2=1.5&diff_format=u Index: pear/Net_LDAP/tests/PHPUnit/config.php diff -u pear/Net_LDAP/tests/PHPUnit/config.php:1.4 pear/Net_LDAP/tests/PHPUnit/config.php:1.5 --- pear/Net_LDAP/tests/PHPUnit/config.php:1.4 Mon Apr 12 10:54:06 2004 +++ pear/Net_LDAP/tests/PHPUnit/config.php Fri Feb 24 03:40:11 2006 @@ -9,6 +9,14 @@ 'bindpw' => '', 'filter' => '(objectClass=*)'); +$ldap_invalid_config= array('host' => 'localhost', + 'version' => 3, + 'starttls' => false, + 'basedn' => 'dc=babel,dc=home', + 'binddn' => 'cn=Directory Manager', + 'bindpw' => 'theWRONGpassWORD', + 'filter' => '(objectClass=*)'); + // this should be an existing dn which can be fetched with the above connection parameters $existing_dn = 'cn=Jan Wagner,ou=testing,o=netsols,c=de'; $existing_dn_changes = array('add' => array('cn' => array('Testing')), @@ -22,4 +30,9 @@ 'base' => 'ou=ispman,o=netsols,c=de', 'parms' => array('scope' => 'one', 'attributes' => array('cn'))); +// these should be parameters for an ldap query that returns at least 3 entries with one attribute +$multi_search = array('filter' => '(objectClass=posixAccount)', + 'base' => 'ou=ispman,o=netsols,c=de', + 'parms' => array('scope' => 'one', 'attributes' => array('cn'))); + ?> \ No newline at end of file
http://cvs.php.net/viewcvs.cgi/pear/Net_LDAP/tests/PHPUnit/Net_LDAP.php?r1=1.6&r2=1.7&diff_format=u Index: pear/Net_LDAP/tests/PHPUnit/Net_LDAP.php diff -u pear/Net_LDAP/tests/PHPUnit/Net_LDAP.php:1.6 pear/Net_LDAP/tests/PHPUnit/Net_LDAP.php:1.7 --- pear/Net_LDAP/tests/PHPUnit/Net_LDAP.php:1.6 Mon Apr 12 10:53:44 2004 +++ pear/Net_LDAP/tests/PHPUnit/Net_LDAP.php Fri Feb 24 03:40:11 2006 @@ -4,41 +4,55 @@ { 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); + $this->ldap = Net_LDAP::connect($this->config); if (Net_LDAP::isError($this->ldap)) { die($this->ldap->getMessage()); } } - + function tearDown() { $this->ldap->done(); } - + function testConnection() { return $this->assertEquals('net_ldap', strtolower(get_class($this->ldap))); } - + + function testInvalidConnection() + { + $invalid_config = $GLOBALS['ldap_invalid_config']; + $invalid_ldap = Net_LDAP::connect($invalid_config); + if (Net_LDAP::isError($invalid_ldap)) { + // + // Yes, this is supposed to fail. + // + return true; + } + $this->fail(print_r($invalid_ldap, true)); + return false; + } + function testgetLDAPVersion() { return $this->assertEquals($this->config['version'], $this->ldap->getLDAPVersion()); } - + function testdnExists() { $this->assertTrue($this->ldap->dnExists($GLOBALS['existing_dn'])); } - + function testgetEntry() { $entry = $this->ldap->getEntry($GLOBALS['existing_dn']); @@ -48,30 +62,38 @@ } return true; } - + function testRootDSE() { $root_dse = $this->ldap->rootDSE(); $this->assertTrue(is_a($root_dse, 'net_ldap_rootdse')); } - - function testSchema() + + function testSchema() { $schema = $this->ldap->schema(); $this->assertTrue(is_a($schema, 'net_ldap_schema')); } - + + function testSchemaInternals() + { + $schema = $this->ldap->schema(); + $this->assertTrue(is_array($schema->types)); + $this->assertTrue(is_array($schema->_attributeTypes)); + $this->assertTrue(is_array($schema->_objectClasses)); + } + 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.'); - + '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'], @@ -80,17 +102,17 @@ $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 testSearch() - { + { $test = $GLOBALS['search']; - $result = $this->ldap->search($test['base'], $test['filter'], $test['parms']); + $result = $this->ldap->search($test['base'], $test['filter'], $test['parms']); if (Net_LDAP::isError($result)) { $this->fail($result->getMessage()); return false; - } + } $entry = $result->shiftEntry(); if (false === $entry) { $this->fail('No entry could be fetched'); @@ -99,7 +121,58 @@ $value = $entry->getValue($test['parms']['attributes'][0], 'single'); $this->assertTrue(is_string($value) && $value != '', 'Attribute value was not a string or empty'); } - + + function testShiftEntry() + { + $test = $GLOBALS['multi_search']; + $result = $this->ldap->search($test['base'], $test['filter'], $test['parms']); + if (Net_LDAP::isError($result)) { + $this->fail($result->getMessage()); + return false; + } + + // + // Extract 3 entries from the search result, check that they are not all + // the same, and check that the two shiftentry functions return the same + // result (bug 5191). + // + $values = array(); + for ($i=1; $i<4; $i++) { + $entry = $result->shiftEntry(); + if (false === $entry) { + $this->fail('No entry could be fetched'); + return false; + } + $value = $entry->getValue($test['parms']['attributes'][0], 'single'); + $this->assertTrue(is_string($value) && $value != '', 'Attribute value was not a string or empty'); + if (in_array($value, $values)) { + $this->fail('The same value was returned more than once.'); + return false; + } + $values[] = $value; + } + + $result = $this->ldap->search($test['base'], $test['filter'], $test['parms']); + if (Net_LDAP::isError($result)) { + $this->fail($result->getMessage()); + return false; + } + for ($i=1; $i<4; $i++) { + $entry = $result->shift_entry(); + if (false === $entry) { + $this->fail('No entry could be fetched'); + return false; + } + $value = $entry->getValue($test['parms']['attributes'][0], 'single'); + $this->assertTrue(is_string($value) && $value != '', 'Attribute value was not a string or empty'); + if (! in_array($value, $values)) { + $this->fail('The value fetched by shiftEntry was not fetched by shift_entry.'); + return false; + } + } + + } + function testAdd() { $entry = $this->ldap->getEntry($GLOBALS['existing_dn']); @@ -112,26 +185,26 @@ $this->fail($msg->getMessage()); return false; } - + $parts = ldap_explode_dn($entry->dn(), 0); list($attr,$value) = explode('=', $parts[0]); $newdn->delete(array($attr => $value)); - + $parts = ldap_explode_dn($newdn->dn(), 0); list($attr,$value) = explode('=', $parts[0]); $newdn->add(array($attr => $value)); - + if (Net_LDAP::isError($msg = $this->ldap->add($newdn))) { $this->fail($msg->getMessage()); return false; - } + } if (Net_LDAP::isError($msg = $this->ldap->delete($newdn))) { $this->fail($msg->getMessage()); return false; } return true; } - + function testReBind() { $this->ldap->done(); @@ -153,9 +226,9 @@ $this->fail($msg->getMessage()); return false; } - return true; + return true; } - + function testRecursiveDelete() { // get existing entry for copy @@ -176,7 +249,7 @@ unset($rdn['count']); } $rdn = array_shift($rdn); - + // add a copy of new entry as subentry to itself $msg = $newentry->copy($this->ldap, $rdn, true); if (Net_LDAP::isError($msg)) { @@ -191,18 +264,18 @@ } return true; } - + function testModifyAdd() { global $existing_dn, $existing_dn_changes; - + $msg = $this->ldap->modify($existing_dn, array('add' => $existing_dn_changes['add'])); if (Net_LDAP::isError($msg)) { $this->fail($msg->getMessage()); return false; } - + $entry = &$this->ldap->getEntry($existing_dn); foreach($existing_dn_changes['add'] as $attr => $vals) { $values = $entry->getValue($attr, 'all'); @@ -213,18 +286,18 @@ } return true; } - + function testModifyDelete() { global $existing_dn, $existing_dn_changes; - + $msg = $this->ldap->modify($existing_dn, array('delete' => $existing_dn_changes['add'])); if (Net_LDAP::isError($msg)) { $this->fail($msg->getMessage()); return false; } - + $entry = &$this->ldap->getEntry($existing_dn); foreach($existing_dn_changes['add'] as $attr => $vals) { $values = $entry->getValue($attr, 'all'); @@ -235,22 +308,22 @@ } return true; } - + function testModifyReplace() { global $existing_dn, $existing_dn_changes; - + $original = &$this->ldap->getEntry($existing_dn); - + $msg = $this->ldap->modify($existing_dn, array('replace' => $existing_dn_changes['replace'])); if (Net_LDAP::isError($msg)) { $this->fail($msg->getMessage()); return false; } - + $entry = &$this->ldap->getEntry($existing_dn); - + foreach ($existing_dn_changes['replace'] as $attr => $vals) { $values = $entry->getValue($attr, 'all'); $this->assertTrue(count($vals) == count($values)); @@ -259,7 +332,7 @@ } $entry->replace(array($attr => $original->getValue($attr, 'all'))); } - + $msg = $entry->update($this->ldap); if (Net_LDAP::isError($msg)) { $this->fail($msg->getMessage()); @@ -267,13 +340,13 @@ } return true; } - + function testModifyChanges() { global $existing_dn, $existing_dn_changes; - + $original = &$this->ldap->getEntry($existing_dn); - + $msg = $this->ldap->modify($existing_dn, array('changes' => array('add' => $existing_dn_changes['add'], 'replace' => $existing_dn_changes['replace']))); @@ -291,7 +364,7 @@ } $entry->replace(array($attr => $original->getValue($attr, 'all'))); } - + foreach ($existing_dn_changes['replace'] as $attr => $vals) { $values = $entry->getValue($attr, 'all'); $this->assertTrue(count($vals) == count($values)); @@ -300,7 +373,7 @@ } $entry->replace(array($attr => $original->getValue($attr, 'all'))); } - + $msg = $entry->update($this->ldap); if (Net_LDAP::isError($msg)) { $this->fail($msg->getMessage()); http://cvs.php.net/viewcvs.cgi/pear/Net_LDAP/tests/PHPUnit/config.php?r1=1.4&r2=1.5&diff_format=u Index: pear/Net_LDAP/tests/PHPUnit/config.php diff -u pear/Net_LDAP/tests/PHPUnit/config.php:1.4 pear/Net_LDAP/tests/PHPUnit/config.php:1.5 --- pear/Net_LDAP/tests/PHPUnit/config.php:1.4 Mon Apr 12 10:54:06 2004 +++ pear/Net_LDAP/tests/PHPUnit/config.php Fri Feb 24 03:40:11 2006 @@ -9,6 +9,14 @@ 'bindpw' => '', 'filter' => '(objectClass=*)'); +$ldap_invalid_config= array('host' => 'localhost', + 'version' => 3, + 'starttls' => false, + 'basedn' => 'dc=babel,dc=home', + 'binddn' => 'cn=Directory Manager', + 'bindpw' => 'theWRONGpassWORD', + 'filter' => '(objectClass=*)'); + // this should be an existing dn which can be fetched with the above connection parameters $existing_dn = 'cn=Jan Wagner,ou=testing,o=netsols,c=de'; $existing_dn_changes = array('add' => array('cn' => array('Testing')), @@ -22,4 +30,9 @@ 'base' => 'ou=ispman,o=netsols,c=de', 'parms' => array('scope' => 'one', 'attributes' => array('cn'))); +// these should be parameters for an ldap query that returns at least 3 entries with one attribute +$multi_search = array('filter' => '(objectClass=posixAccount)', + 'base' => 'ou=ispman,o=netsols,c=de', + 'parms' => array('scope' => 'one', 'attributes' => array('cn'))); + ?> \ No newline at end of file