Permalink
Browse files

add two new tests for deleting attribute values (needed for testing o…

…f bug#4589)

git-svn-id: http://svn.php.net/repository/pear/packages/Net_LDAP/branches/NET_LDAP_0_6@188446 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
1 parent da3c857 commit 988f20d9b0821c4d335c3d9b2a04f44fc3853924 Jan Wagner committed Jun 15, 2005
Showing with 106 additions and 7 deletions.
  1. +97 −0 tests/PHPUnit/Net_LDAP.php
  2. +9 −7 tests/PHPUnit/config.php
View
@@ -127,6 +127,103 @@ function testRename()
$this->assertFalse(Net_LDAP::isError($msg), 'Could not rename entry');
}
}
+
+ function testDeleteWholeAttribute()
+ {
+ if (empty($GLOBALS['delete_attr'])) {
+ $this->fail('You need to supply delete_attr for this test');
+ return false;
+ }
+
+ $entry = $this->ldap->getEntry($GLOBALS['existing_dn']);
+ if (Net_LDAP::isError($entry) || $entry === false) {
+ $this->fail("Could not fetch entry {$GLOBALS['existing_dn']}");
+ return false;
+ }
+
+ $attrs = $GLOBALS['delete_attr'];
+
+ // first delete the whole attribute
+ $attr = array_shift(array_keys($attrs));
+ $oldAttrs = $entry->get_value($attr); // save
+
+ $entry->delete(array($attr => array()));
+ $err = $entry->update();
+ if (Net_LDAP::isError($err)) {
+ $this->fail($err->getMessage());
+ return;
+ }
+ unset($entry);
+
+ // refetch the entry
+ $entry = $this->ldap->getEntry($GLOBALS['existing_dn']);
+ if (Net_LDAP::isError($entry) || $entry === false) {
+ $this->fail("Could not fetch entry {$GLOBALS['existing_dn']}");
+ return false;
+ }
+ $this->assertEquals('', $entry->get_value($attr));
+ // undo delete
+
+ $err = $entry->add(array($attr => $oldAttrs));
+ if (Net_LDAP::isError($err)) {
+ $this->fail($err->getMessage());
+ return;
+ }
+ $err = $entry->update();
+ if (Net_LDAP::isError($err)) {
+ $this->fail($err->getMessage());
+ return;
+ }
+ }
+
+ function testModDelete()
+ {
+ if (empty($GLOBALS['delete_attr'])) {
+ $this->fail('You need to supply delete_attr for this test');
+ return false;
+ }
+
+ $entry = $this->ldap->getEntry($GLOBALS['existing_dn']);
+ if (Net_LDAP::isError($entry) || $entry === false) {
+ $this->fail("Could not fetch entry {$GLOBALS['existing_dn']}");
+ return false;
+ }
+ $attrs = $GLOBALS['delete_attr'];
+
+ $attr = array_shift(array_keys($attrs));
+ $value = array_shift($attrs[$attr]);
+
+ $this->assertTrue(in_array($value, $entry->get_value($attr)), 'value to delete not in attribute');
+
+ $entry->delete(array($attr => $value));
+ $err = $entry->update();
+ if (Net_LDAP::isError($err)) {
+ $this->fail($err->getMessage());
+ return;
+ }
+ unset($entry);
+
+ // refetch the entry
+ $entry = $this->ldap->getEntry($GLOBALS['existing_dn']);
+ if (Net_LDAP::isError($entry) || $entry === false) {
+ $this->fail("Could not fetch entry {$GLOBALS['existing_dn']}");
+ return false;
+ }
+ $newAttrs = $entry->get_value($attr);
+ $this->assertFalse(in_array($value, $newAttrs), 'deleted value still in attribute');
+
+ // undo delete
+ $err = $entry->add(array($attr => array($value)));
+ if (Net_LDAP::isError($err)) {
+ $this->fail($err->getMessage());
+ return;
+ }
+ $err = $entry->update();
+ if (Net_LDAP::isError($err)) {
+ $this->fail($err->getMessage());
+ return;
+ }
+ }
}
?>
View
@@ -1,20 +1,22 @@
<?php
// these should be valid connection parameters for your ldap server
-$ldap_config= array('host' => '192.168.123.253',
- 'version' => 3,
+$ldap_config= array('host' => 'localhost',
+ 'version' => 3,
+ 'options' => array('LDAP_OPT_REFERRALS' => 0),
'base' => 'o=netsols,c=de',
'dn' => 'cn=admin,o=netsols,c=de',
- 'password' => '******',
+ 'password' => '********',
'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';
-$rename_dn = 'uid=wagner2,ou=mailAccounts,cn=netsols.de,ou=Domains,o=netsols,c=de';
+$existing_dn = 'cn=Jan Wagner,ou=testing,o=netsols,c=de';
+$rename_dn = 'cn=Jan Wagner2,ou=testing,o=netsols,c=de';
+$delete_attr = array('mail' => array('wagner@netsols.de', 'skywalker@wh2.tu-dresden.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',
+$search2 = array('filter' => '(objectClass=*)',
+ 'base' => 'ou=testing,o=netsols,c=de',
'parms' => array('scope' => 'one', 'attributes' => array('cn')));
?>

0 comments on commit 988f20d

Please sign in to comment.