[prev in list] [next in list] [prev in thread] [next in thread]
List: pear-cvs
Subject: [PEAR-CVS] cvs: pear /Net_LDAP2 LDAP2.php package2.xml /Net_LDAP2/tests Net_LDAP2Test.php
From: "Benedikt Hallinger" <beni () php ! net>
Date: 2008-05-29 13:04:27
Message-ID: cvsbeni1212066267 () cvsserver
[Download RAW message or body]
beni Thu May 29 13:04:27 2008 UTC
Modified files:
/pear/Net_LDAP2 LDAP2.php package2.xml
/pear/Net_LDAP2/tests Net_LDAP2Test.php
Log:
* Net_LDAP2->search() can handle Net_LDAP2_Entry objects as parameter $base now.
* Implemented tests for that and improved search tests a bit
http://cvs.php.net/viewvc.cgi/pear/Net_LDAP2/LDAP2.php?r1=1.3&r2=1.4&diff_format=u
Index: pear/Net_LDAP2/LDAP2.php
diff -u pear/Net_LDAP2/LDAP2.php:1.3 pear/Net_LDAP2/LDAP2.php:1.4
--- pear/Net_LDAP2/LDAP2.php:1.3 Mon Apr 21 05:37:01 2008
+++ pear/Net_LDAP2/LDAP2.php Thu May 29 13:04:27 2008
@@ -13,7 +13,7 @@
* @author Benedikt Hallinger <beni@php.net>
* @copyright 2003-2007 Tarjej Huse, Jan Wagner, Del Elson, Benedikt Hallinger
* @license http://www.gnu.org/copyleft/lesser.html LGPL
-* @version CVS: $Id: LDAP2.php,v 1.3 2008/04/21 05:37:01 beni Exp $
+* @version CVS: $Id: LDAP2.php,v 1.4 2008/05/29 13:04:27 beni Exp $
* @link http://pear.php.net/package/Net_LDAP22/
*/
@@ -50,7 +50,7 @@
* @author Benedikt Hallinger <beni@php.net>
* @copyright 2003-2007 Tarjej Huse, Jan Wagner, Del Elson, Benedikt Hallinger
* @license http://www.gnu.org/copyleft/lesser.html LGPL
-* @version CVS: $Id: LDAP2.php,v 1.3 2008/04/21 05:37:01 beni Exp $
+* @version CVS: $Id: LDAP2.php,v 1.4 2008/05/29 13:04:27 beni Exp $
* @link http://pear.php.net/package/Net_LDAP22/
*/
class Net_LDAP2 extends PEAR
@@ -662,7 +662,10 @@
* Run a ldap query
*
* Search is used to query the ldap-database.
- * $base and $filter may be ommitted.The one from config will then be used.
+ * $base and $filter may be ommitted. The one from config will
+ * then be used. $base is either a DN-string or an Net_LDAP2_Entry
+ * object in which case its DN willb e used.
+ *
* Params may contain:
*
* scope: The scope which will be used for searching
@@ -688,7 +691,7 @@
* Please note, that you cannot override server side limitations to sizelimit
* and timelimit: You can always only lower a given limit.
*
- * @param string $base LDAP searchbase
+ * @param string|Net_LDAP2_Entry $base LDAP searchbase
* @param string|Net_LDAP2_Filter $filter LDAP search filter or a Net_LDAP2_Filter object
* @param array $params Array of options
*
@@ -700,6 +703,9 @@
if (is_null($base)) {
$base = $this->_config['basedn'];
}
+ if ($base instanceof Net_LDAP2_Entry) {
+ $base = $base->dn(); // fetch DN og entry, making searchbase relative to the entry
+ }
if (is_null($filter)) {
$filter = $this->_config['filter'];
}
@@ -709,6 +715,9 @@
if (PEAR::isError($filter)) {
return $filter;
}
+ if (PEAR::isError($base)) {
+ return $base;
+ }
/* setting searchparameters */
(isset($params['sizelimit'])) ? $sizelimit = $params['sizelimit'] : $sizelimit = 0;
http://cvs.php.net/viewvc.cgi/pear/Net_LDAP2/package2.xml?r1=1.11&r2=1.12&diff_format=u
Index: pear/Net_LDAP2/package2.xml
diff -u pear/Net_LDAP2/package2.xml:1.11 pear/Net_LDAP2/package2.xml:1.12
--- pear/Net_LDAP2/package2.xml:1.11 Thu May 29 12:23:37 2008
+++ pear/Net_LDAP2/package2.xml Thu May 29 13:04:27 2008
@@ -39,6 +39,7 @@
* New constructor factory for Entry objects: createExisting()
* Some small bugfixes
* New method Entry->isNew()
+ * Net_LDAP2->search() can handle entry objects as $base now
</notes>
<contents>
http://cvs.php.net/viewvc.cgi/pear/Net_LDAP2/tests/Net_LDAP2Test.php?r1=1.3&r2=1.4&diff_format=u
Index: pear/Net_LDAP2/tests/Net_LDAP2Test.php
diff -u pear/Net_LDAP2/tests/Net_LDAP2Test.php:1.3 pear/Net_LDAP2/tests/Net_LDAP2Test.php:1.4
--- pear/Net_LDAP2/tests/Net_LDAP2Test.php:1.3 Mon Apr 21 08:10:03 2008
+++ pear/Net_LDAP2/tests/Net_LDAP2Test.php Thu May 29 13:04:27 2008
@@ -410,6 +410,11 @@
'objectClass' => array('top','organizationalUnit'),
'ou' => 'Net_LDAP2_Test_search1'
));
+ $ou1_1 = Net_LDAP2_Entry::createFresh('ou=Net_LDAP2_Test_search1_1,'.$ou1->dn(),
+ array(
+ 'objectClass' => array('top','organizationalUnit'),
+ 'ou' => 'Net_LDAP2_Test_search2'
+ ));
$ou2 = Net_LDAP2_Entry::createFresh('ou=Net_LDAP2_Test_search2,'.$base,
array(
'objectClass' => array('top','organizationalUnit'),
@@ -417,6 +422,8 @@
));
$this->assertTrue($ldap->add($ou1));
$this->assertTrue($ldap->dnExists($ou1->dn()));
+ $this->assertTrue($ldap->add($ou1_1));
+ $this->assertTrue($ldap->dnExists($ou1_1->dn()));
$this->assertTrue($ldap->add($ou2));
$this->assertTrue($ldap->dnExists($ou2->dn()));
@@ -445,6 +452,23 @@
$this->assertType('Net_LDAP2_Search', $res);
$this->assertThat($res->count(), $this->greaterThanOrEqual(2));
+ // Base-search using custom base (string)
+ // should only return the test entry $ou1 and not the entry below it.
+ $res = $ldap->search($ou1->dn(), null,
+ array('scope' => 'base', 'attributes' => '1.1')
+ );
+ $this->assertType('Net_LDAP2_Search', $res);
+ $this->assertEquals(1, $res->count());
+
+ // Search using custom base, this time using an entry object
+ // This tests if passing an entry object as base works
+ // should only return the test entry $ou1
+ $res = $ldap->search($ou1, '(ou=*)',
+ array('scope' => 'base', 'attributes' => '1.1')
+ );
+ $this->assertType('Net_LDAP2_Search', $res);
+ $this->assertEquals(1, $res->count());
+
// Search using default filter for base-onelevel scope with sizelimit
// should of course return more than one entry,
// but not more than sizelimit
@@ -467,6 +491,17 @@
);
$this->assertType('Net_LDAP2_Error', $res);
+ // Passing Error object as base and as filter object
+ $error = new Net_LDAP2_Error('Testerror');
+ $res = $ldap->search($error, null, // error base
+ array('attributes' => '1.1')
+ );
+ $this->assertType('Net_LDAP2_Error', $res);
+ $res = $ldap->search(null, $error, // error filter
+ array('attributes' => '1.1')
+ );
+ $this->assertType('Net_LDAP2_Error', $res);
+
// Nullresult
$res = $ldap->search(null, '(cn=nevermatching_filter)',
array('scope' => 'base', 'attributes' => '1.1')
@@ -476,8 +511,9 @@
// cleanup
- $this->assertTrue($ldap->delete($ou1), 'Cleanup failed, please delete manually');
- $this->assertTrue($ldap->delete($ou2), 'Cleanup failed, please delete manually');
+ $this->assertTrue($ldap->delete($ou1_1), 'Cleanup failed, please delete manually');
+ $this->assertTrue($ldap->delete($ou1), 'Cleanup failed, please delete manually');
+ $this->assertTrue($ldap->delete($ou2), 'Cleanup failed, please delete manually');
}
}
--
PEAR CVS Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic