]> granicus.if.org Git - php/commitdiff
MFH: Tests for ext/ldap from PHPBelgium TestFest
authorPatrick Allaert <patrickallaert@php.net>
Fri, 3 Jul 2009 10:57:04 +0000 (10:57 +0000)
committerPatrick Allaert <patrickallaert@php.net>
Fri, 3 Jul 2009 10:57:04 +0000 (10:57 +0000)
88 files changed:
ext/ldap/tests/README [new file with mode: 0644]
ext/ldap/tests/ldap_add_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_add_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_bind_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_bind_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_bind_variation.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_compare_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_compare_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_connect_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_connect_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_connect_variation.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_count_entries_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_count_entries_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_delete_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_delete_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_err2str_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_err2str_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_errno_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_errno_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_error_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_error_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_first_attribute_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_first_attribute_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_first_entry_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_first_entry_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_first_reference_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_first_reference_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_free_result_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_free_result_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_get_attributes_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_get_attributes_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_get_dn_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_get_dn_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_get_entries_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_get_entries_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_get_entries_variation.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_get_option_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_get_option_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_get_option_variation.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_get_values_len_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_get_values_len_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_list_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_list_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_mod_add_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_mod_add_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_mod_del_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_mod_del_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_mod_replace_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_mod_replace_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_modify_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_modify_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_next_attribute_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_next_attribute_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_next_entry_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_next_entry_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_next_reference_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_next_reference_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_parse_reference_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_parse_reference_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_parse_result_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_parse_result_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_read_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_read_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_rename_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_rename_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_sasl_bind_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_sasl_bind_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_search_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_search_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_search_variation1.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_search_variation2.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_search_variation3.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_search_variation4.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_search_variation5.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_search_variation6.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_set_option_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_set_option_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_set_option_variation.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_set_rebind_proc_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_set_rebind_proc_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_sort_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_sort_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_sort_variation.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_start_tls_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_start_tls_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_unbind_basic.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_unbind_error.phpt [new file with mode: 0644]
ext/ldap/tests/ldap_unbind_variation.phpt [new file with mode: 0644]

diff --git a/ext/ldap/tests/README b/ext/ldap/tests/README
new file mode 100644 (file)
index 0000000..7dccd27
--- /dev/null
@@ -0,0 +1,53 @@
+Most tests here relies on the availability of an LDAP server configured with TLS.
+
+Client/Server configuration:
+===========================================================
+OpenLDAP 2.3.43 has been used with the configuration below.
+
+Notes:
+1.  A self signed certificate can be generated using:
+    $ openssl req -newkey rsa:1024 -x509 -nodes -out server.pem -keyout server.pem -days 3650
+    It is used for testing ldap_start_tls(), which also requires "TLS_REQCERT never" in client configuration
+2.  An empty LDAP structure is required for the tests to be PASSed
+
+(/etc/openldap/)slapd.conf:
+-----------------------------------------------------------
+TLSCACertificateFile /etc/openldap/ssl/server.pem
+TLSCertificateFile /etc/openldap/ssl/server.pem
+TLSCertificateKeyFile /etc/openldap/ssl/server.pem
+TLSVerifyClient never
+
+# hdb is used instead of bdb as it enables the usage of referrals & aliases
+database        hdb
+suffix          "dc=my-domain,dc=com"
+checkpoint      32      30
+rootdn          "cn=Manager,dc=my-domain,dc=com"
+rootpw          secret
+directory       /var/lib/openldap-data
+index   objectClass     eq
+
+authz-regexp
+       uid=Manager,cn=digest-md5,cn=auth
+       cn=Manager,dc=my-domain,dc=com
+
+
+(/etc/openldap/)ldap.conf:
+-----------------------------------------------------------
+TLS_REQCERT never
+
+Tests configuration:
+===========================================================
+The following environment variables may be defined:
+LDAP_TEST_HOST (default: localhost)                        Host to connect to
+LDAP_TEST_PORT (default: 389)                              Port to connect to
+LDAP_TEST_USER (default: cn=Manager,dc=my-domain,dc=com)   DN used for binding
+LDAP_TEST_SASL_USER (default: Manager)                     SASL user used for SASL binding
+LDAP_TEST_PASSWD (default: secret)                         Password used for plain and SASL binding
+LDAP_TEST_OPT_PROTOCOL_VERSION (default: 3)                Version of LDAP protocol to use
+LDAP_TEST_SKIP_BIND_FAILURE (default: true)                Whether to fail the test or not in case binding fails
+
+Credits:
+===========================================================
+Davide Mendolia <idaf1er@gmail.com>
+Patrick Allaert <patrick.allaert@gmail.com>
+
diff --git a/ext/ldap/tests/ldap_add_basic.phpt b/ext/ldap/tests/ldap_add_basic.phpt
new file mode 100644 (file)
index 0000000..ca65e49
--- /dev/null
@@ -0,0 +1,83 @@
+--TEST--
+ldap_add() - Basic add operation
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+var_dump(
+       ldap_add($link, "dc=my-domain,dc=com", array(
+               "objectClass"   => array(
+                       "top",
+                       "dcObject",
+                       "organization"),
+               "dc"                    => "my-domain",
+               "o"                             => "my-domain",
+       )),
+       ldap_get_entries(
+               $link,
+               ldap_search($link, "dc=my-domain,dc=com", "(o=my-domain)")
+       )
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+ldap_delete($link, "dc=my-domain,dc=com");
+?>
+--EXPECT--
+bool(true)
+array(2) {
+  ["count"]=>
+  int(1)
+  [0]=>
+  array(8) {
+    ["objectclass"]=>
+    array(4) {
+      ["count"]=>
+      int(3)
+      [0]=>
+      string(3) "top"
+      [1]=>
+      string(8) "dcObject"
+      [2]=>
+      string(12) "organization"
+    }
+    [0]=>
+    string(11) "objectclass"
+    ["dc"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(9) "my-domain"
+    }
+    [1]=>
+    string(2) "dc"
+    ["o"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(9) "my-domain"
+    }
+    [2]=>
+    string(1) "o"
+    ["count"]=>
+    int(3)
+    ["dn"]=>
+    string(19) "dc=my-domain,dc=com"
+  }
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_add_error.phpt b/ext/ldap/tests/ldap_add_error.phpt
new file mode 100644 (file)
index 0000000..943c1a5
--- /dev/null
@@ -0,0 +1,136 @@
+--TEST--
+ldap_add() - Add operation that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+// Too few parameters
+var_dump(ldap_add());
+var_dump(ldap_add($link));
+var_dump(ldap_add($link, "dc=my-domain,dc=com"));
+
+// Too many parameters
+var_dump(ldap_add($link, "dc=my-domain,dc=com", array(), "Additional data"));
+
+var_dump(ldap_add($link, "dc=my-domain,dc=com", array()));
+
+// Invalid DN
+var_dump(
+       ldap_add($link, "weirdAttribute=val", array(
+               "weirdAttribute"                        => "val",
+       )),
+       ldap_error($link),
+       ldap_errno($link)
+);
+
+// Duplicate entry
+for ($i = 0; $i < 2; $i++)
+       var_dump(
+               ldap_add($link, "dc=my-domain,dc=com", array(
+                       "objectClass"   => array(
+                               "top",
+                               "dcObject",
+                               "organization"),
+                       "dc"                    => "my-domain",
+                       "o"                             => "my-domain",
+               ))
+       );
+var_dump(ldap_error($link), ldap_errno($link));
+
+// Wrong array indexes
+var_dump(
+       ldap_add($link, "dc=my-domain2,dc=com", array(
+               "objectClass"   => array(
+                       0       => "top",
+                       2       => "dcObject",
+                       5       => "organization"),
+               "dc"                    => "my-domain",
+               "o"                             => "my-domain",
+       ))
+       /* Is this correct behaviour to still have "Already exists" as error/errno?
+       ,
+       ldap_error($link),
+       ldap_errno($link)
+       */
+);
+
+// Invalid attribute
+var_dump(
+       ldap_add($link, "dc=my-domain,dc=com", array(
+               "objectClass"   => array(
+                       "top",
+                       "dcObject",
+                       "organization"),
+               "dc"                    => "my-domain",
+               "o"                             => "my-domain",
+               "weirdAttr"             => "weirdVal",
+       )),
+       ldap_error($link),
+       ldap_errno($link)
+);
+
+var_dump(
+       ldap_add($link, "dc=my-domain,dc=com", array(array( "Oops"
+       )))
+       /* Is this correct behaviour to still have "Undefined attribute type" as error/errno?
+       ,
+       ldap_error($link),
+       ldap_errno($link)
+       */
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+ldap_delete($link, "dc=my-domain,dc=com");
+?>
+--EXPECTF--
+Warning: Wrong parameter count for ldap_add() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_add() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_add() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_add() in %s on line %d
+NULL
+
+Warning: ldap_add(): Add: Protocol error in %s on line %d
+bool(false)
+
+Warning: ldap_add(): Add: Invalid DN syntax in %s on line %d
+bool(false)
+string(17) "Invalid DN syntax"
+int(34)
+bool(true)
+
+Warning: ldap_add(): Add: Already exists in %s on line %d
+bool(false)
+string(14) "Already exists"
+int(68)
+
+Warning: ldap_add(): Value array must have consecutive indices 0, 1, ... in %s on line %d
+bool(false)
+
+Warning: ldap_add(): Add: Undefined attribute type in %s on line %d
+bool(false)
+string(24) "Undefined attribute type"
+int(17)
+
+Warning: ldap_add(): Unknown attribute in the data in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_bind_basic.phpt b/ext/ldap/tests/ldap_bind_basic.phpt
new file mode 100644 (file)
index 0000000..bac8d0d
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--
+ldap_bind() - Basic anonymous binding
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
+var_dump(ldap_bind($link));
+?>
+===DONE===
+--EXPECT--
+bool(true)
+===DONE===
diff --git a/ext/ldap/tests/ldap_bind_error.phpt b/ext/ldap/tests/ldap_bind_error.phpt
new file mode 100644 (file)
index 0000000..a569ce6
--- /dev/null
@@ -0,0 +1,35 @@
+--TEST--
+ldap_bind() - Binding that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
+
+// Invalid parameter count
+var_dump(ldap_bind($link, $user, $passwd, null));
+
+// Invalid password
+var_dump(ldap_bind($link, $user, "ThisIsNotCorrect$passwd"));
+
+// Invalid DN syntax
+var_dump(ldap_bind($link, "unexistingProperty=weirdValue,$user", $passwd));
+?>
+===DONE===
+--EXPECTF--
+Warning: ldap_bind() expects at most 3 parameters, 4 given in %s on line %d
+bool(false)
+
+Warning: ldap_bind(): Unable to bind to server: Invalid credentials in %s on line %d
+bool(false)
+
+Warning: ldap_bind(): Unable to bind to server: Invalid DN syntax in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_bind_variation.phpt b/ext/ldap/tests/ldap_bind_variation.phpt
new file mode 100644 (file)
index 0000000..64abf6c
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--
+ldap_bind() - Advanced binding
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
+var_dump(ldap_bind($link, $user, $passwd));
+?>
+===DONE===
+--EXPECT--
+bool(true)
+===DONE===
diff --git a/ext/ldap/tests/ldap_compare_basic.phpt b/ext/ldap/tests/ldap_compare_basic.phpt
new file mode 100644 (file)
index 0000000..b0c5e97
--- /dev/null
@@ -0,0 +1,31 @@
+--TEST--
+ldap_compare() - Basic ldap_compare test
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+var_dump(
+       ldap_compare($link, "cn=userA,dc=my-domain,dc=com", "sn", "testSN1"),
+       ldap_compare($link, "cn=userA,dc=my-domain,dc=com", "telephoneNumber", "yy-yy-yy-yy-yy")
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECT--
+bool(true)
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_compare_error.phpt b/ext/ldap/tests/ldap_compare_error.phpt
new file mode 100644 (file)
index 0000000..15505ed
--- /dev/null
@@ -0,0 +1,55 @@
+--TEST--
+ldap_compare() - Testing ldap_compare() that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+
+// Too few parameters
+var_dump(ldap_compare($link));
+var_dump(ldap_compare($link, $link));
+var_dump(ldap_compare($link, $link, $link));
+
+// Too many parameters
+var_dump(ldap_compare($link, $link, $link, $link, "Additional data"));
+
+var_dump(
+       ldap_compare($link, "cn=userNotAvailable,dc=my-domain,dc=com", "sn", "testSN1"),
+       ldap_error($link),
+       ldap_errno($link)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECTF--
+Warning: Wrong parameter count for ldap_compare() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_compare() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_compare() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_compare() in %s on line %d
+NULL
+
+Warning: ldap_compare(): Compare: No such object in %s on line %d
+int(-1)
+string(14) "No such object"
+int(32)
+===DONE===
diff --git a/ext/ldap/tests/ldap_connect_basic.phpt b/ext/ldap/tests/ldap_connect_basic.phpt
new file mode 100644 (file)
index 0000000..26133a6
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+ldap_connect() - Basic connection
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+var_dump($link);
+?>
+===DONE===
+--EXPECTF--
+resource(%d) of type (ldap link)
+===DONE===
diff --git a/ext/ldap/tests/ldap_connect_error.phpt b/ext/ldap/tests/ldap_connect_error.phpt
new file mode 100644 (file)
index 0000000..fa28fcf
--- /dev/null
@@ -0,0 +1,31 @@
+--TEST--
+ldap_connect() - Connection errors
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--INI--
+ldap.max_links=1
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+// too many arguments
+var_dump(ldap_connect(null, null, null));
+var_dump(ldap_connect("ldap://$host:$port/dc=my-domain,dc=com"));
+
+$links = array();
+$links[0] = ldap_connect($host, $port);
+$links[1] = ldap_connect($host, $port);
+?>
+===DONE===
+--EXPECTF--
+Warning: ldap_connect() expects at most 2 parameters, 3 given in %s on line %d
+bool(false)
+
+Warning: ldap_connect(): Could not create session handle: %s in %s on line %d
+bool(false)
+
+Warning: ldap_connect(): Too many open links (1) in %s on line %d
+===DONE===
diff --git a/ext/ldap/tests/ldap_connect_variation.phpt b/ext/ldap/tests/ldap_connect_variation.phpt
new file mode 100644 (file)
index 0000000..09b07e7
--- /dev/null
@@ -0,0 +1,39 @@
+--TEST--
+ldap_connect() - Variation
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+// no hostname, no port
+$link = ldap_connect();
+var_dump($link);
+
+// no port
+$link = ldap_connect($host);
+var_dump($link);
+
+// URI
+$link = ldap_connect("ldap://$host:$port");
+var_dump($link);
+
+// URI no port
+$link = ldap_connect("ldap://$host");
+var_dump($link);
+
+// bad hostname (connect should work, not bind)
+$link = ldap_connect("nonexistent" . $host);
+var_dump($link);
+?>
+===DONE===
+--EXPECTF--
+resource(%d) of type (ldap link)
+resource(%d) of type (ldap link)
+resource(%d) of type (ldap link)
+resource(%d) of type (ldap link)
+resource(%d) of type (ldap link)
+===DONE===
diff --git a/ext/ldap/tests/ldap_count_entries_basic.phpt b/ext/ldap/tests/ldap_count_entries_basic.phpt
new file mode 100644 (file)
index 0000000..a03f059
--- /dev/null
@@ -0,0 +1,28 @@
+--TEST--
+ldap_count_entries() - Basic counting LDAP entries
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=person)");
+var_dump(ldap_count_entries($link, $result));
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECT--
+int(3)
+===DONE===
diff --git a/ext/ldap/tests/ldap_count_entries_error.phpt b/ext/ldap/tests/ldap_count_entries_error.phpt
new file mode 100644 (file)
index 0000000..c81be7b
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+ldap_count_entries() - Testing counting LDAP entries that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+var_dump(ldap_count_entries($link));
+var_dump(ldap_count_entries($link, $link));
+?>
+===DONE===
+--EXPECTF--
+Warning: Wrong parameter count for ldap_count_entries() in %s on line %d
+NULL
+
+Warning: ldap_count_entries(): supplied resource is not a valid ldap result resource in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_delete_basic.phpt b/ext/ldap/tests/ldap_delete_basic.phpt
new file mode 100644 (file)
index 0000000..1457384
--- /dev/null
@@ -0,0 +1,40 @@
+--TEST--
+ldap_delete() - Basic delete operation
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+ldap_add($link, "dc=my-domain,dc=com", array(
+       "objectClass"   => array(
+               "top",
+               "dcObject",
+               "organization"),
+       "dc"                    => "my-domain",
+       "o"                             => "my-domain",
+));
+
+var_dump(
+       ldap_delete($link, "dc=my-domain,dc=com"),
+       @ldap_search($link, "dc=my-domain,dc=com", "(o=my-domain)")
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+ldap_delete($link, "dc=my-domain,dc=com");
+?>
+--EXPECT--
+bool(true)
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_delete_error.phpt b/ext/ldap/tests/ldap_delete_error.phpt
new file mode 100644 (file)
index 0000000..34aa03d
--- /dev/null
@@ -0,0 +1,62 @@
+--TEST--
+ldap_delete() - Delete operation that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+// Too few parameters
+var_dump(ldap_delete());
+var_dump(ldap_delete($link));
+
+// Too many parameters
+var_dump(ldap_delete($link, "dc=my-domain,dc=com", "Additional data"));
+
+// Invalid DN
+var_dump(
+       ldap_delete($link, "weirdAttribute=val"),
+       ldap_error($link),
+       ldap_errno($link)
+);
+
+// Deleting unexisting data
+var_dump(
+       ldap_delete($link, "dc=my-domain,dc=com"),
+       ldap_error($link),
+       ldap_errno($link)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+?>
+--EXPECTF--
+Warning: Wrong parameter count for ldap_delete() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_delete() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_delete() in %s on line %d
+NULL
+
+Warning: ldap_delete(): Delete: Invalid DN syntax in %s on line %d
+bool(false)
+string(17) "Invalid DN syntax"
+int(34)
+
+Warning: ldap_delete(): Delete: No such object in %s on line %d
+bool(false)
+string(14) "No such object"
+int(32)
+===DONE===
diff --git a/ext/ldap/tests/ldap_err2str_basic.phpt b/ext/ldap/tests/ldap_err2str_basic.phpt
new file mode 100644 (file)
index 0000000..0ecad03
--- /dev/null
@@ -0,0 +1,15 @@
+--TEST--
+ldap_err2str() - Basic error number to string conversion
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+var_dump(ldap_err2str(2));
+?>
+===DONE===
+--EXPECT--
+string(14) "Protocol error"
+===DONE===
diff --git a/ext/ldap/tests/ldap_err2str_error.phpt b/ext/ldap/tests/ldap_err2str_error.phpt
new file mode 100644 (file)
index 0000000..103df75
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+ldap_err2str() - Incorrect usage of number to string conversion
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+// Too few args
+var_dump(ldap_err2str());
+
+// Too many args
+var_dump(ldap_err2str(1, "Additional data"));
+?>
+===DONE===
+--EXPECTF--
+Warning: Wrong parameter count for ldap_err2str() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_err2str() in %s on line %d
+NULL
+===DONE===
diff --git a/ext/ldap/tests/ldap_errno_basic.phpt b/ext/ldap/tests/ldap_errno_basic.phpt
new file mode 100644 (file)
index 0000000..4b02ac6
--- /dev/null
@@ -0,0 +1,30 @@
+--TEST--
+ldap_errno() - Basic ldap_errno() operation
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+@ldap_add($link, "badDN dc=my-domain,dc=com", array(
+       "objectClass"   => array(
+               "top",
+               "dcObject",
+               "organization"),
+       "dc"                    => "my-domain",
+       "o"                             => "my-domain",
+));
+
+var_dump(
+       ldap_errno($link)
+);
+?>
+===DONE===
+--EXPECT--
+int(34)
+===DONE===
diff --git a/ext/ldap/tests/ldap_errno_error.phpt b/ext/ldap/tests/ldap_errno_error.phpt
new file mode 100644 (file)
index 0000000..686cd84
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+ldap_errno() - ldap_errno() operation that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+// Too few parameters
+var_dump(ldap_errno());
+
+// Too many parameters
+var_dump(ldap_errno(null, null));
+?>
+===DONE===
+--EXPECTF--
+Warning: Wrong parameter count for ldap_errno() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_errno() in %s on line %d
+NULL
+===DONE===
diff --git a/ext/ldap/tests/ldap_error_basic.phpt b/ext/ldap/tests/ldap_error_basic.phpt
new file mode 100644 (file)
index 0000000..64e4ef6
--- /dev/null
@@ -0,0 +1,30 @@
+--TEST--
+ldap_error() - Basic ldap_error() operation
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+@ldap_add($link, "badDN dc=my-domain,dc=com", array(
+       "objectClass"   => array(
+               "top",
+               "dcObject",
+               "organization"),
+       "dc"                    => "my-domain",
+       "o"                             => "my-domain",
+));
+
+var_dump(
+       ldap_error($link)
+);
+?>
+===DONE===
+--EXPECT--
+string(17) "Invalid DN syntax"
+===DONE===
diff --git a/ext/ldap/tests/ldap_error_error.phpt b/ext/ldap/tests/ldap_error_error.phpt
new file mode 100644 (file)
index 0000000..8f0bf2d
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+ldap_error() - ldap_error() operation that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+// Too few parameters
+var_dump(ldap_error());
+
+// Too many parameters
+var_dump(ldap_error(null, null));
+?>
+===DONE===
+--EXPECTF--
+Warning: Wrong parameter count for ldap_error() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_error() in %s on line %d
+NULL
+===DONE===
diff --git a/ext/ldap/tests/ldap_first_attribute_basic.phpt b/ext/ldap/tests/ldap_first_attribute_basic.phpt
new file mode 100644 (file)
index 0000000..8e506fa
--- /dev/null
@@ -0,0 +1,31 @@
+--TEST--
+ldap_first_attribute() - Basic ldap_first_attribute test
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=organization)");
+$entry = ldap_first_entry($link, $result);
+var_dump(
+       ldap_first_attribute($link, $entry)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECT--
+string(11) "objectClass"
+===DONE===
diff --git a/ext/ldap/tests/ldap_first_attribute_error.phpt b/ext/ldap/tests/ldap_first_attribute_error.phpt
new file mode 100644 (file)
index 0000000..e6df3fd
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+ldap_first_attribute() - Testing ldap_first_attribute() that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+var_dump(ldap_first_attribute($link));
+var_dump(ldap_first_attribute($link, $link));
+?>
+===DONE===
+--EXPECTF--
+Warning: Wrong parameter count for ldap_first_attribute() in %s on line %d
+NULL
+
+Warning: ldap_first_attribute(): supplied resource is not a valid ldap result entry resource in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_first_entry_basic.phpt b/ext/ldap/tests/ldap_first_entry_basic.phpt
new file mode 100644 (file)
index 0000000..9b65822
--- /dev/null
@@ -0,0 +1,37 @@
+--TEST--
+ldap_first_entry() - Basic ldap_first_entry test
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=person)");
+var_dump(
+       $entry = ldap_first_entry($link, $result),
+       ldap_get_values($link, $entry, 'sn')
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECTF--
+resource(%d) of type (ldap result entry)
+array(2) {
+  [0]=>
+  string(7) "testSN%d"
+  ["count"]=>
+  int(1)
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_first_entry_error.phpt b/ext/ldap/tests/ldap_first_entry_error.phpt
new file mode 100644 (file)
index 0000000..f4d91c4
--- /dev/null
@@ -0,0 +1,27 @@
+--TEST--
+ldap_first_entry() - Testing ldap_first_entry() that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+var_dump(ldap_first_entry($link));
+var_dump(ldap_first_entry($link, $link, "Additional data"));
+var_dump(ldap_first_entry($link, $link));
+?>
+===DONE===
+--EXPECTF--
+Warning: Wrong parameter count for ldap_first_entry() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_first_entry() in %s on line %d
+NULL
+
+Warning: ldap_first_entry(): supplied resource is not a valid ldap result resource in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_first_reference_basic.phpt b/ext/ldap/tests/ldap_first_reference_basic.phpt
new file mode 100644 (file)
index 0000000..d783489
--- /dev/null
@@ -0,0 +1,43 @@
+--TEST--
+ldap_first_reference() - Basic ldap_first_reference test
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+ldap_add($link, "cn=userref,dc=my-domain,dc=com", array(
+        "objectClass" => array("extensibleObject", "referral"),
+        "cn" => "userref",
+        "ref" => "cn=userA,dc=my-domain,dc=com",
+));
+ldap_set_option($link, LDAP_OPT_DEREF, LDAP_DEREF_NEVER);
+$result = ldap_search($link, "dc=my-domain,dc=com", "(cn=*)");
+var_dump($ref = ldap_first_reference($link, $result));
+$refs = null;
+ldap_parse_reference($link, $ref, $refs);
+var_dump($refs);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+// Referral can only be removed with Manage DSA IT Control
+ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, array(array("oid" => "2.16.840.1.113730.3.4.2")));
+ldap_delete($link, "cn=userref,dc=my-domain,dc=com");
+remove_dummy_data($link);
+?>
+--EXPECTF--
+resource(%d) of type (ldap result entry)
+array(1) {
+  [0]=>
+  string(28) "cn=userA,dc=my-domain,dc=com"
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_first_reference_error.phpt b/ext/ldap/tests/ldap_first_reference_error.phpt
new file mode 100644 (file)
index 0000000..fc36dd9
--- /dev/null
@@ -0,0 +1,27 @@
+--TEST--
+ldap_first_reference() - Testing ldap_first_reference() that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+var_dump(ldap_first_reference($link));
+var_dump(ldap_first_reference($link, $link, "Additional data"));
+var_dump(ldap_first_reference($link, $link));
+?>
+===DONE===
+--EXPECTF--
+Warning: Wrong parameter count for ldap_first_reference() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_first_reference() in %s on line %d
+NULL
+
+Warning: ldap_first_reference(): supplied resource is not a valid ldap result resource in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_free_result_basic.phpt b/ext/ldap/tests/ldap_free_result_basic.phpt
new file mode 100644 (file)
index 0000000..33e47d6
--- /dev/null
@@ -0,0 +1,28 @@
+--TEST--
+ldap_free_result() - Basic ldap_free_result tests
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=person)");
+var_dump(ldap_free_result($result));
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECT--
+bool(true)
+===DONE===
diff --git a/ext/ldap/tests/ldap_free_result_error.phpt b/ext/ldap/tests/ldap_free_result_error.phpt
new file mode 100644 (file)
index 0000000..e2a1444
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+ldap_free_result() - Testing ldap_free_result() that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+var_dump(ldap_free_result($link));
+var_dump(ldap_free_result($link, "Additional data"));
+?>
+===DONE===
+--EXPECTF--
+Warning: ldap_free_result(): supplied resource is not a valid ldap result resource in %s on line %d
+bool(false)
+
+Warning: Wrong parameter count for ldap_free_result() in %s on line %d
+NULL
+===DONE===
diff --git a/ext/ldap/tests/ldap_get_attributes_basic.phpt b/ext/ldap/tests/ldap_get_attributes_basic.phpt
new file mode 100644 (file)
index 0000000..82074c5
--- /dev/null
@@ -0,0 +1,65 @@
+--TEST--
+ldap_get_attributes() - Basic ldap_get_attributes test
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=organization)");
+$entry = ldap_first_entry($link, $result);
+var_dump(
+       ldap_get_attributes($link, $entry)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECT--
+array(7) {
+  ["objectClass"]=>
+  array(4) {
+    ["count"]=>
+    int(3)
+    [0]=>
+    string(3) "top"
+    [1]=>
+    string(8) "dcObject"
+    [2]=>
+    string(12) "organization"
+  }
+  [0]=>
+  string(11) "objectClass"
+  ["dc"]=>
+  array(2) {
+    ["count"]=>
+    int(1)
+    [0]=>
+    string(9) "my-domain"
+  }
+  [1]=>
+  string(2) "dc"
+  ["o"]=>
+  array(2) {
+    ["count"]=>
+    int(1)
+    [0]=>
+    string(9) "my-domain"
+  }
+  [2]=>
+  string(1) "o"
+  ["count"]=>
+  int(3)
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_get_attributes_error.phpt b/ext/ldap/tests/ldap_get_attributes_error.phpt
new file mode 100644 (file)
index 0000000..2c7f3ce
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+ldap_get_attributes() - Testing ldap_get_attributes() that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+var_dump(ldap_get_attributes($link));
+var_dump(ldap_get_attributes($link, $link));
+?>
+===DONE===
+--EXPECTF--
+Warning: Wrong parameter count for ldap_get_attributes() in %s on line %d
+NULL
+
+Warning: ldap_get_attributes(): supplied resource is not a valid ldap result entry resource in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_get_dn_basic.phpt b/ext/ldap/tests/ldap_get_dn_basic.phpt
new file mode 100644 (file)
index 0000000..e70e7bf
--- /dev/null
@@ -0,0 +1,31 @@
+--TEST--
+ldap_get_dn() - Basic ldap_get_dn test
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=organization)");
+$entry = ldap_first_entry($link, $result);
+var_dump(
+       ldap_get_dn($link, $entry)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECT--
+string(19) "dc=my-domain,dc=com"
+===DONE===
diff --git a/ext/ldap/tests/ldap_get_dn_error.phpt b/ext/ldap/tests/ldap_get_dn_error.phpt
new file mode 100644 (file)
index 0000000..59460c2
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+ldap_get_dn() - Testing ldap_get_dn() that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+var_dump(ldap_get_dn($link));
+var_dump(ldap_get_dn($link, $link));
+?>
+===DONE===
+--EXPECTF--
+Warning: Wrong parameter count for ldap_get_dn() in %s on line %d
+NULL
+
+Warning: ldap_get_dn(): supplied resource is not a valid ldap result entry resource in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_get_entries_basic.phpt b/ext/ldap/tests/ldap_get_entries_basic.phpt
new file mode 100644 (file)
index 0000000..90dbb26
--- /dev/null
@@ -0,0 +1,74 @@
+--TEST--
+ldap_get_entries() - Basic modify operation
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+
+var_dump(
+       ldap_get_entries(
+               $link,
+               ldap_search($link, "dc=my-domain,dc=com", "(o=my-domain)")
+       )
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECT--
+array(2) {
+  ["count"]=>
+  int(1)
+  [0]=>
+  array(8) {
+    ["objectclass"]=>
+    array(4) {
+      ["count"]=>
+      int(3)
+      [0]=>
+      string(3) "top"
+      [1]=>
+      string(8) "dcObject"
+      [2]=>
+      string(12) "organization"
+    }
+    [0]=>
+    string(11) "objectclass"
+    ["dc"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(9) "my-domain"
+    }
+    [1]=>
+    string(2) "dc"
+    ["o"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(9) "my-domain"
+    }
+    [2]=>
+    string(1) "o"
+    ["count"]=>
+    int(3)
+    ["dn"]=>
+    string(19) "dc=my-domain,dc=com"
+  }
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_get_entries_error.phpt b/ext/ldap/tests/ldap_get_entries_error.phpt
new file mode 100644 (file)
index 0000000..e51850e
--- /dev/null
@@ -0,0 +1,33 @@
+--TEST--
+ldap_get_entries() - ldap_get_entries() operation that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+
+// Too few parameters
+var_dump(ldap_get_entries($link));
+
+// Too many parameters
+var_dump(ldap_get_entries($link, $link, "Additional data"));
+
+// Bad parameter
+var_dump(ldap_get_entries($link, "string"));
+?>
+===DONE===
+--EXPECTF--
+Warning: Wrong parameter count for ldap_get_entries() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_get_entries() in %s on line %d
+NULL
+
+Warning: ldap_get_entries(): supplied argument is not a valid ldap result resource in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_get_entries_variation.phpt b/ext/ldap/tests/ldap_get_entries_variation.phpt
new file mode 100644 (file)
index 0000000..92c4974
--- /dev/null
@@ -0,0 +1,33 @@
+--TEST--
+Test ldap_get_entries() function - variation: used on empty search
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+
+var_dump(
+       ldap_get_entries(
+               $link,
+               ldap_search($link, "dc=my-domain,dc=com", "(o=my-unexisting-domain)")
+       )
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECT--
+NULL
+===DONE===
diff --git a/ext/ldap/tests/ldap_get_option_basic.phpt b/ext/ldap/tests/ldap_get_option_basic.phpt
new file mode 100644 (file)
index 0000000..3136a5a
--- /dev/null
@@ -0,0 +1,25 @@
+--TEST--
+ldap_get_option() - Basic ldap_get_option() operation
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+$option = null;
+ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
+
+var_dump(
+       ldap_get_option($link, LDAP_OPT_PROTOCOL_VERSION, $option),
+       $option
+);
+?>
+===DONE===
+--EXPECT--
+bool(true)
+int(3)
+===DONE===
diff --git a/ext/ldap/tests/ldap_get_option_error.phpt b/ext/ldap/tests/ldap_get_option_error.phpt
new file mode 100644 (file)
index 0000000..4208a48
--- /dev/null
@@ -0,0 +1,40 @@
+--TEST--
+ldap_get_option() - ldap_get_option() operation that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+$option = null;
+
+// Too few parameters
+var_dump(ldap_get_option());
+var_dump(ldap_get_option($link));
+var_dump(ldap_get_option($link, LDAP_OPT_PROTOCOL_VERSION));
+
+// Too many parameters
+var_dump(
+       ldap_get_option($link, LDAP_OPT_PROTOCOL_VERSION, $option, "Additional data"),
+       $option
+);
+?>
+===DONE===
+--EXPECTF--
+Warning: Wrong parameter count for ldap_get_option() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_get_option() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_get_option() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_get_option() in %s on line %d
+NULL
+NULL
+===DONE===
diff --git a/ext/ldap/tests/ldap_get_option_variation.phpt b/ext/ldap/tests/ldap_get_option_variation.phpt
new file mode 100644 (file)
index 0000000..9e5a993
--- /dev/null
@@ -0,0 +1,61 @@
+--TEST--
+ldap_get_option() - More ldap_get_option() operations
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+$option = null;
+
+$controls = array(
+       array("oid" => "1.2.752.58.10.1", "iscritical" => true),
+       array("oid" => "1.2.752.58.1.10", "value" => "magic"),
+);
+
+ldap_set_option($link, LDAP_OPT_DEREF, LDAP_DEREF_NEVER);
+ldap_set_option($link, LDAP_OPT_SIZELIMIT, 123);
+ldap_set_option($link, LDAP_OPT_TIMELIMIT, 33);
+ldap_set_option($link, LDAP_OPT_REFERRALS, false);
+ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, $controls);
+ldap_set_option($link, LDAP_OPT_CLIENT_CONTROLS, $controls);
+ldap_set_option($link, LDAP_OPT_RESTART, false);
+
+var_dump(
+       ldap_get_option($link, LDAP_OPT_DEREF, $option),
+       $option,
+       ldap_get_option($link, LDAP_OPT_SIZELIMIT, $option),
+       $option,
+       ldap_get_option($link, LDAP_OPT_TIMELIMIT, $option),
+       $option,
+       ldap_get_option($link, LDAP_OPT_REFERRALS, $option),
+       $option,
+       ldap_get_option($link, LDAP_OPT_RESTART, $option),
+       $option,
+       ldap_get_option($link, LDAP_OPT_SERVER_CONTROLS, $option),
+       $option,
+       ldap_get_option($link, LDAP_OPT_CLIENT_CONTROLS, $option),
+       $option
+);
+?>
+===DONE===
+--EXPECT--
+bool(true)
+int(0)
+bool(true)
+int(123)
+bool(true)
+int(33)
+bool(true)
+int(0)
+bool(true)
+int(0)
+bool(false)
+int(0)
+bool(false)
+int(0)
+===DONE===
diff --git a/ext/ldap/tests/ldap_get_values_len_basic.phpt b/ext/ldap/tests/ldap_get_values_len_basic.phpt
new file mode 100644 (file)
index 0000000..ed84614
--- /dev/null
@@ -0,0 +1,36 @@
+--TEST--
+ldap_get_values_len() - Basic ldap_get_values_len test
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=organization)");
+$entry = ldap_first_entry($link, $result);
+var_dump(
+       ldap_get_values_len($link, $entry, "o")
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECT--
+array(2) {
+  [0]=>
+  string(9) "my-domain"
+  ["count"]=>
+  int(1)
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_get_values_len_error.phpt b/ext/ldap/tests/ldap_get_values_len_error.phpt
new file mode 100644 (file)
index 0000000..c163cc2
--- /dev/null
@@ -0,0 +1,45 @@
+--TEST--
+ldap_get_values_len() - Testing ldap_get_values_len() that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=organization)");
+$entry = ldap_first_entry($link, $result);
+
+// Too few parameters
+var_dump(ldap_get_values_len($link));
+var_dump(ldap_get_values_len($link, $entry));
+var_dump(ldap_get_values_len($link, $entry, "weirdAttribute", "Additional data"));
+
+var_dump(ldap_get_values_len($link, $entry, "inexistantAttribute"));
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECTF--
+Warning: Wrong parameter count for ldap_get_values_len() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_get_values_len() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_get_values_len() in %s on line %d
+NULL
+
+Warning: ldap_get_values_len(): Cannot get the value(s) of attribute %s in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_list_basic.phpt b/ext/ldap/tests/ldap_list_basic.phpt
new file mode 100644 (file)
index 0000000..1993f30
--- /dev/null
@@ -0,0 +1,150 @@
+--TEST--
+ldap_list() test
+--CREDITS--
+Davide Mendolia <idaf1er@gmail.com>
+Patrick Allaert <patrickallaert@php.net>
+Belgian PHP Testfest 2009
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifbindfailure.inc');
+?>
+--FILE--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+var_dump(
+       $result = ldap_list($link, "dc=my-domain,dc=com", "(objectClass=person)"),
+       ldap_get_entries($link, $result)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECTF--
+resource(%d) of type (ldap result)
+array(3) {
+  ["count"]=>
+  int(2)
+  [0]=>
+  array(14) {
+    ["objectclass"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(6) "person"
+    }
+    [0]=>
+    string(11) "objectclass"
+    ["cn"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(5) "userA"
+    }
+    [1]=>
+    string(2) "cn"
+    ["sn"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(7) "testSN1"
+    }
+    [2]=>
+    string(2) "sn"
+    ["userpassword"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(4) "oops"
+    }
+    [3]=>
+    string(12) "userpassword"
+    ["telephonenumber"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(14) "xx-xx-xx-xx-xx"
+    }
+    [4]=>
+    string(15) "telephonenumber"
+    ["description"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(6) "user A"
+    }
+    [5]=>
+    string(11) "description"
+    ["count"]=>
+    int(6)
+    ["dn"]=>
+    string(28) "cn=userA,dc=my-domain,dc=com"
+  }
+  [1]=>
+  array(12) {
+    ["objectclass"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(6) "person"
+    }
+    [0]=>
+    string(11) "objectclass"
+    ["cn"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(5) "userB"
+    }
+    [1]=>
+    string(2) "cn"
+    ["sn"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(7) "testSN2"
+    }
+    [2]=>
+    string(2) "sn"
+    ["userpassword"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(15) "oopsIDitItAgain"
+    }
+    [3]=>
+    string(12) "userpassword"
+    ["description"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(6) "user B"
+    }
+    [4]=>
+    string(11) "description"
+    ["count"]=>
+    int(5)
+    ["dn"]=>
+    string(28) "cn=userB,dc=my-domain,dc=com"
+  }
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_list_error.phpt b/ext/ldap/tests/ldap_list_error.phpt
new file mode 100644 (file)
index 0000000..f1e5680
--- /dev/null
@@ -0,0 +1,35 @@
+--TEST--
+ldap_list() - operation that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+include "connect.inc";
+
+$link = ldap_connect($host, $port);
+
+// Too few parameters
+var_dump(ldap_list());
+var_dump(ldap_list($link));
+var_dump(ldap_list($link, $link));
+
+// Too many parameters
+var_dump(ldap_list($link, "dc=my-domain,dc=com", "(objectClass=*)", array(), 0, 0, 0, 0 , "Additional data"));
+?>
+===DONE===
+--EXPECTF--
+Warning: Wrong parameter count for ldap_list() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_list() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_list() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_list() in %s on line %d
+NULL
+===DONE===
diff --git a/ext/ldap/tests/ldap_mod_add_basic.phpt b/ext/ldap/tests/ldap_mod_add_basic.phpt
new file mode 100644 (file)
index 0000000..8c8164c
--- /dev/null
@@ -0,0 +1,90 @@
+--TEST--
+ldap_mod_add() - Basic modify operation
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+
+$entry = array(
+       "description"   => "Domain description",
+);
+
+var_dump(
+       ldap_mod_add($link, "dc=my-domain,dc=com", $entry),
+       ldap_get_entries(
+               $link,
+               ldap_search($link, "dc=my-domain,dc=com", "(Description=Domain description)")
+       )
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+remove_dummy_data($link);
+?>
+--EXPECT--
+bool(true)
+array(2) {
+  ["count"]=>
+  int(1)
+  [0]=>
+  array(10) {
+    ["objectclass"]=>
+    array(4) {
+      ["count"]=>
+      int(3)
+      [0]=>
+      string(3) "top"
+      [1]=>
+      string(8) "dcObject"
+      [2]=>
+      string(12) "organization"
+    }
+    [0]=>
+    string(11) "objectclass"
+    ["dc"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(9) "my-domain"
+    }
+    [1]=>
+    string(2) "dc"
+    ["o"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(9) "my-domain"
+    }
+    [2]=>
+    string(1) "o"
+    ["description"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(18) "Domain description"
+    }
+    [3]=>
+    string(11) "description"
+    ["count"]=>
+    int(4)
+    ["dn"]=>
+    string(19) "dc=my-domain,dc=com"
+  }
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_mod_add_error.phpt b/ext/ldap/tests/ldap_mod_add_error.phpt
new file mode 100644 (file)
index 0000000..560d4ca
--- /dev/null
@@ -0,0 +1,83 @@
+--TEST--
+ldap_mod_add() - ldap_mod_add() operations that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+// Too few parameters
+var_dump(ldap_mod_add());
+var_dump(ldap_mod_add($link));
+var_dump(ldap_mod_add($link, "dc=my-domain,dc=com"));
+
+// Too many parameters
+var_dump(ldap_mod_add($link, "dc=my-domain,dc=com", array(), "Additional data"));
+
+// DN not found
+var_dump(ldap_mod_add($link, "dc=my-domain,dc=com", array()));
+
+// Invalid DN
+var_dump(ldap_mod_add($link, "weirdAttribute=val", array()));
+
+$entry = array(
+       "objectClass"   => array(
+               "top",
+               "dcObject",
+               "organization"),
+       "dc"                    => "my-domain",
+       "o"                             => "my-domain",
+);
+
+ldap_add($link, "dc=my-domain,dc=com", $entry);
+
+$entry2 = $entry;
+$entry2["dc"] = "Wrong Domain";
+
+var_dump(ldap_mod_add($link, "dc=my-domain,dc=com", $entry2));
+
+$entry2 = $entry;
+$entry2["weirdAttribute"] = "weirdVal";
+
+var_dump(ldap_mod_add($link, "dc=my-domain,dc=com", $entry2));
+?>
+===DONE===
+--CLEAN--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+ldap_delete($link, "dc=my-domain,dc=com");
+?>
+--EXPECTF--
+Warning: Wrong parameter count for ldap_mod_add() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_mod_add() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_mod_add() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_mod_add() in %s on line %d
+NULL
+
+Warning: ldap_mod_add(): Modify: No such object in %s on line %d
+bool(false)
+
+Warning: ldap_mod_add(): Modify: Invalid DN syntax in %s on line %d
+bool(false)
+
+Warning: ldap_mod_add(): Modify: Type or value exists in %s on line %d
+bool(false)
+
+Warning: ldap_mod_add(): Modify: Undefined attribute type in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_mod_del_basic.phpt b/ext/ldap/tests/ldap_mod_del_basic.phpt
new file mode 100644 (file)
index 0000000..0d002bd
--- /dev/null
@@ -0,0 +1,40 @@
+--TEST--
+ldap_mod_del() - Basic modify operation
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+
+$entry = array(
+       "description" => "user A"
+);
+
+var_dump(
+       ldap_mod_del($link, "cn=userA,dc=my-domain,dc=com", $entry),
+       ldap_get_entries(
+               $link,
+               ldap_search($link, "dc=my-domain,dc=com", "(description=user A)")
+       )
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+remove_dummy_data($link);
+?>
+--EXPECT--
+bool(true)
+NULL
+===DONE===
diff --git a/ext/ldap/tests/ldap_mod_del_error.phpt b/ext/ldap/tests/ldap_mod_del_error.phpt
new file mode 100644 (file)
index 0000000..29efeeb
--- /dev/null
@@ -0,0 +1,62 @@
+--TEST--
+ldap_mod_del() - ldap_mod_del() operations that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+// Too few parameters
+var_dump(ldap_mod_del());
+var_dump(ldap_mod_del($link));
+var_dump(ldap_mod_del($link, "dc=my-domain,dc=com"));
+
+// Too many parameters
+var_dump(ldap_mod_del($link, "dc=my-domain,dc=com", array(), "Additional data"));
+
+// DN not found
+var_dump(ldap_mod_del($link, "dc=my-domain,dc=com", array()));
+
+// Invalid DN
+var_dump(ldap_mod_del($link, "weirdAttribute=val", array()));
+
+// Invalid attributes
+var_dump(ldap_mod_del($link, "dc=my-domain,dc=com", array('dc')));
+?>
+===DONE===
+--CLEAN--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+ldap_delete($link, "dc=my-domain,dc=com");
+?>
+--EXPECTF--
+Warning: Wrong parameter count for ldap_mod_del() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_mod_del() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_mod_del() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_mod_del() in %s on line %d
+NULL
+
+Warning: ldap_mod_del(): Modify: No such object in %s on line %d
+bool(false)
+
+Warning: ldap_mod_del(): Modify: Invalid DN syntax in %s on line %d
+bool(false)
+
+Warning: ldap_mod_del(): Unknown attribute in the data in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_mod_replace_basic.phpt b/ext/ldap/tests/ldap_mod_replace_basic.phpt
new file mode 100644 (file)
index 0000000..d1670ec
--- /dev/null
@@ -0,0 +1,59 @@
+--TEST--
+ldap_mod_replace() - Basic modify operation
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+
+$entry = array(
+       "description" => "user X"
+);
+
+var_dump(
+       ldap_mod_replace($link, "cn=userA,dc=my-domain,dc=com", $entry),
+       ldap_get_entries(
+               $link,
+               ldap_search($link, "dc=my-domain,dc=com", "(description=user X)", array("description"))
+       )
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+remove_dummy_data($link);
+?>
+--EXPECT--
+bool(true)
+array(2) {
+  ["count"]=>
+  int(1)
+  [0]=>
+  array(4) {
+    ["description"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(6) "user X"
+    }
+    [0]=>
+    string(11) "description"
+    ["count"]=>
+    int(1)
+    ["dn"]=>
+    string(28) "cn=userA,dc=my-domain,dc=com"
+  }
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_mod_replace_error.phpt b/ext/ldap/tests/ldap_mod_replace_error.phpt
new file mode 100644 (file)
index 0000000..20fee86
--- /dev/null
@@ -0,0 +1,62 @@
+--TEST--
+ldap_mod_replace() - ldap_mod_replace() operations that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+// Too few parameters
+var_dump(ldap_mod_replace());
+var_dump(ldap_mod_replace($link));
+var_dump(ldap_mod_replace($link, "dc=my-domain,dc=com"));
+
+// Too many parameters
+var_dump(ldap_mod_replace($link, "dc=my-domain,dc=com", array(), "Additional data"));
+
+// DN not found
+var_dump(ldap_mod_replace($link, "dc=my-domain,dc=com", array()));
+
+// Invalid DN
+var_dump(ldap_mod_replace($link, "weirdAttribute=val", array()));
+
+// Invalid attributes
+var_dump(ldap_mod_replace($link, "dc=my-domain,dc=com", array('dc')));
+?>
+===DONE===
+--CLEAN--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+ldap_delete($link, "dc=my-domain,dc=com");
+?>
+--EXPECTF--
+Warning: Wrong parameter count for ldap_mod_replace() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_mod_replace() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_mod_replace() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_mod_replace() in %s on line %d
+NULL
+
+Warning: ldap_mod_replace(): Modify: No such object in %s on line %d
+bool(false)
+
+Warning: ldap_mod_replace(): Modify: Invalid DN syntax in %s on line %d
+bool(false)
+
+Warning: ldap_mod_replace(): Unknown attribute in the data in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_modify_basic.phpt b/ext/ldap/tests/ldap_modify_basic.phpt
new file mode 100644 (file)
index 0000000..74bd831
--- /dev/null
@@ -0,0 +1,96 @@
+--TEST--
+ldap_modify() - Basic modify operation
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+
+$entry = array(
+       "objectClass"   => array(
+               "top",
+               "dcObject",
+               "organization"),
+       "dc"            => "my-domain",
+       "o"             => "my-domain",
+       "description"   => "Domain description",
+);
+
+var_dump(
+       ldap_modify($link, "dc=my-domain,dc=com", $entry),
+       ldap_get_entries(
+               $link,
+               ldap_search($link, "dc=my-domain,dc=com", "(Description=Domain description)")
+       )
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+remove_dummy_data($link);
+?>
+--EXPECT--
+bool(true)
+array(2) {
+  ["count"]=>
+  int(1)
+  [0]=>
+  array(10) {
+    ["objectclass"]=>
+    array(4) {
+      ["count"]=>
+      int(3)
+      [0]=>
+      string(3) "top"
+      [1]=>
+      string(8) "dcObject"
+      [2]=>
+      string(12) "organization"
+    }
+    [0]=>
+    string(11) "objectclass"
+    ["dc"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(9) "my-domain"
+    }
+    [1]=>
+    string(2) "dc"
+    ["o"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(9) "my-domain"
+    }
+    [2]=>
+    string(1) "o"
+    ["description"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(18) "Domain description"
+    }
+    [3]=>
+    string(11) "description"
+    ["count"]=>
+    int(4)
+    ["dn"]=>
+    string(19) "dc=my-domain,dc=com"
+  }
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_modify_error.phpt b/ext/ldap/tests/ldap_modify_error.phpt
new file mode 100644 (file)
index 0000000..ca417b5
--- /dev/null
@@ -0,0 +1,83 @@
+--TEST--
+ldap_modify() - Modify operations that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+// Too few parameters
+var_dump(ldap_modify());
+var_dump(ldap_modify($link));
+var_dump(ldap_modify($link, "dc=my-domain,dc=com"));
+
+// Too many parameters
+var_dump(ldap_modify($link, "dc=my-domain,dc=com", array(), "Additional data"));
+
+// DN not found
+var_dump(ldap_modify($link, "dc=my-domain,dc=com", array()));
+
+// Invalid DN
+var_dump(ldap_modify($link, "weirdAttribute=val", array()));
+
+$entry = array(
+       "objectClass"   => array(
+               "top",
+               "dcObject",
+               "organization"),
+       "dc"                    => "my-domain",
+       "o"                             => "my-domain",
+);
+
+ldap_add($link, "dc=my-domain,dc=com", $entry);
+
+$entry2 = $entry;
+$entry2["dc"] = "Wrong Domain";
+
+var_dump(ldap_modify($link, "dc=my-domain,dc=com", $entry2));
+
+$entry2 = $entry;
+$entry2["weirdAttribute"] = "weirdVal";
+
+var_dump(ldap_modify($link, "dc=my-domain,dc=com", $entry2));
+?>
+===DONE===
+--CLEAN--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+ldap_delete($link, "dc=my-domain,dc=com");
+?>
+--EXPECTF--
+Warning: Wrong parameter count for ldap_modify() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_modify() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_modify() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_modify() in %s on line %d
+NULL
+
+Warning: ldap_modify(): Modify: No such object in %s on line %d
+bool(false)
+
+Warning: ldap_modify(): Modify: Invalid DN syntax in %s on line %d
+bool(false)
+
+Warning: ldap_modify(): Modify: Naming violation in %s on line %d
+bool(false)
+
+Warning: ldap_modify(): Modify: Undefined attribute type in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_next_attribute_basic.phpt b/ext/ldap/tests/ldap_next_attribute_basic.phpt
new file mode 100644 (file)
index 0000000..0fab78a
--- /dev/null
@@ -0,0 +1,36 @@
+--TEST--
+ldap_next_attribute() - Basic ldap_next_attribute test
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=organization)");
+$entry = ldap_first_entry($link, $result);
+$attribute = ldap_first_attribute($link, $entry);
+var_dump(
+       ldap_next_attribute($link, $entry),
+       ldap_next_attribute($link, $entry),
+       ldap_next_attribute($link, $entry)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECTF--
+string(%d) "%s"
+string(%d) "%s"
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_next_attribute_error.phpt b/ext/ldap/tests/ldap_next_attribute_error.phpt
new file mode 100644 (file)
index 0000000..2c23224
--- /dev/null
@@ -0,0 +1,40 @@
+--TEST--
+ldap_next_attribute() - Testing ldap_next_attribute() that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=organization)");
+$entry = ldap_first_entry($link, $result);
+var_dump(
+       ldap_next_attribute($link),
+       ldap_next_attribute($link, $link),
+       ldap_next_attribute($link, $entry)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECTF--
+Warning: Wrong parameter count for ldap_next_attribute() %s on line %d
+
+Warning: ldap_next_attribute(): supplied resource is not a valid ldap result entry resource in %s on line %d
+
+Warning: ldap_next_attribute(): called before calling ldap_first_attribute() or no attributes found in result entry in %s on line %d
+NULL
+bool(false)
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_next_entry_basic.phpt b/ext/ldap/tests/ldap_next_entry_basic.phpt
new file mode 100644 (file)
index 0000000..3209df6
--- /dev/null
@@ -0,0 +1,40 @@
+--TEST--
+ldap_next_entry() - Basic ldap_first_entry test
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+$result = ldap_list($link, "dc=my-domain,dc=com", "(objectClass=person)");
+$entry = ldap_first_entry($link, $result);
+var_dump(
+       $entry = ldap_next_entry($link, $entry),
+       ldap_get_values($link, $entry, 'sn'),
+       $entry = ldap_next_entry($link, $entry)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECTF--
+resource(%d) of type (ldap result entry)
+array(2) {
+  [0]=>
+  string(7) "testSN%d"
+  ["count"]=>
+  int(1)
+}
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_next_entry_error.phpt b/ext/ldap/tests/ldap_next_entry_error.phpt
new file mode 100644 (file)
index 0000000..89bf1f0
--- /dev/null
@@ -0,0 +1,27 @@
+--TEST--
+ldap_next_entry() - Testing ldap_next_entry() that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+var_dump(ldap_next_entry($link));
+var_dump(ldap_next_entry($link, $link, "Additional data"));
+var_dump(ldap_next_entry($link, $link));
+?>
+===DONE===
+--EXPECTF--
+Warning: Wrong parameter count for ldap_next_entry() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_next_entry() in %s on line %d
+NULL
+
+Warning: ldap_next_entry(): supplied resource is not a valid ldap result entry resource in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_next_reference_basic.phpt b/ext/ldap/tests/ldap_next_reference_basic.phpt
new file mode 100644 (file)
index 0000000..d0fa31d
--- /dev/null
@@ -0,0 +1,49 @@
+--TEST--
+ldap_next_reference() - Basic ldap_next_reference test
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+ldap_add($link, "cn=userref,dc=my-domain,dc=com", array(
+        "objectClass" => array("extensibleObject", "referral"),
+        "cn" => "userref",
+        "ref" => "cn=userA,dc=my-domain,dc=com",
+));
+ldap_add($link, "cn=userref2,dc=my-domain,dc=com", array(
+        "objectClass" => array("extensibleObject", "referral"),
+        "cn" => "userref2",
+        "ref" => "cn=userB,dc=my-domain,dc=com",
+));
+ldap_set_option($link, LDAP_OPT_DEREF, LDAP_DEREF_NEVER);
+$result = ldap_search($link, "dc=my-domain,dc=com", "(cn=*)");
+$ref = ldap_first_reference($link, $result);
+var_dump($ref2 = ldap_next_reference($link, $ref));
+ldap_parse_reference($link, $ref2, $refs);
+var_dump($refs);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+// Referral can only be removed with Manage DSA IT Control
+ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, array(array("oid" => "2.16.840.1.113730.3.4.2")));
+ldap_delete($link, "cn=userref,dc=my-domain,dc=com");
+ldap_delete($link, "cn=userref2,dc=my-domain,dc=com");
+remove_dummy_data($link);
+?>
+--EXPECTF--
+resource(%d) of type (ldap result entry)
+array(1) {
+  [0]=>
+  string(28) "cn=userB,dc=my-domain,dc=com"
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_next_reference_error.phpt b/ext/ldap/tests/ldap_next_reference_error.phpt
new file mode 100644 (file)
index 0000000..5cde899
--- /dev/null
@@ -0,0 +1,27 @@
+--TEST--
+ldap_next_reference() - Testing ldap_next_reference() that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+var_dump(ldap_next_reference($link));
+var_dump(ldap_next_reference($link, $link, "Additional data"));
+var_dump(ldap_next_reference($link, $link));
+?>
+===DONE===
+--EXPECTF--
+Warning: Wrong parameter count for ldap_next_reference() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_next_reference() in %s on line %d
+NULL
+
+Warning: ldap_next_reference(): supplied resource is not a valid ldap result entry resource in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_parse_reference_basic.phpt b/ext/ldap/tests/ldap_parse_reference_basic.phpt
new file mode 100644 (file)
index 0000000..2bacd42
--- /dev/null
@@ -0,0 +1,45 @@
+--TEST--
+ldap_parse_reference() - Basic ldap_parse_reference test
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+ldap_add($link, "cn=userref,dc=my-domain,dc=com", array(
+        "objectClass" => array("extensibleObject", "referral"),
+        "cn" => "userref",
+        "ref" => "cn=userA,dc=my-domain,dc=com",
+));
+ldap_set_option($link, LDAP_OPT_DEREF, LDAP_DEREF_NEVER);
+$result = ldap_search($link, "dc=my-domain,dc=com", "(cn=*)");
+$ref = ldap_first_reference($link, $result);
+$refs = null;
+var_dump(
+       ldap_parse_reference($link, $ref, $refs),
+       $refs
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+// Referral can only be removed with Manage DSA IT Control
+ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, array(array("oid" => "2.16.840.1.113730.3.4.2")));
+ldap_delete($link, "cn=userref,dc=my-domain,dc=com");
+remove_dummy_data($link);
+?>
+--EXPECTF--
+bool(true)
+array(1) {
+  [0]=>
+  string(28) "cn=userA,dc=my-domain,dc=com"
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_parse_reference_error.phpt b/ext/ldap/tests/ldap_parse_reference_error.phpt
new file mode 100644 (file)
index 0000000..104d5d3
--- /dev/null
@@ -0,0 +1,31 @@
+--TEST--
+ldap_parse_reference() - ldap_parse_reference() operations that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+$link = ldap_connect($host, $port);
+$refs = null;
+var_dump(
+       ldap_parse_reference($link, $link),
+       ldap_parse_reference($link, $link, $refs),
+       ldap_parse_reference($link, $refs, $refs, "Additional data"),
+       $refs
+);
+?>
+===DONE===
+--EXPECTF--
+Warning: Wrong parameter count for ldap_parse_reference() in %s on line %d
+
+Warning: ldap_parse_reference(): supplied resource is not a valid ldap result entry resource in %s on line %d
+
+Warning: Wrong parameter count for ldap_parse_reference() in %s on line %d
+NULL
+bool(false)
+NULL
+NULL
+===DONE===
diff --git a/ext/ldap/tests/ldap_parse_result_basic.phpt b/ext/ldap/tests/ldap_parse_result_basic.phpt
new file mode 100644 (file)
index 0000000..1646d59
--- /dev/null
@@ -0,0 +1,47 @@
+--TEST--
+ldap_parse_result() - Basic ldap_parse_result test
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+ldap_add($link, "cn=userref,dc=my-domain,dc=com", array(
+        "objectClass" => array("extensibleObject", "referral"),
+        "cn" => "userref",
+        "ref" => "cn=userA,dc=my-domain,dc=com",
+));
+$result = ldap_search($link, "cn=userref,dc=my-domain,dc=com", "(cn=user*)");
+$errcode = $dn = $errmsg = $refs =  null;
+var_dump(
+       ldap_parse_result($link, $result, $errcode, $dn, $errmsg, $refs),
+       $errcode, $dn, $errmsg, $refs
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+// Referral can only be removed with Manage DSA IT Control
+ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, array(array("oid" => "2.16.840.1.113730.3.4.2")));
+ldap_delete($link, "cn=userref,dc=my-domain,dc=com");
+remove_dummy_data($link);
+?>
+--EXPECT--
+bool(true)
+int(10)
+string(30) "cn=userref,dc=my-domain,dc=com"
+string(0) ""
+array(1) {
+  [0]=>
+  string(28) "cn=userA,dc=my-domain,dc=com"
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_parse_result_error.phpt b/ext/ldap/tests/ldap_parse_result_error.phpt
new file mode 100644 (file)
index 0000000..8811783
--- /dev/null
@@ -0,0 +1,17 @@
+--TEST--
+ldap_parse_result() - Testing ldap_parse_result() that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+var_dump(ldap_parse_result(null, null));
+?>
+===DONE===
+--EXPECTF--
+Warning: Wrong parameter count for ldap_parse_result() in %s on line %d
+NULL
+===DONE===
diff --git a/ext/ldap/tests/ldap_read_basic.phpt b/ext/ldap/tests/ldap_read_basic.phpt
new file mode 100644 (file)
index 0000000..04d03d9
--- /dev/null
@@ -0,0 +1,75 @@
+--TEST--
+ldap_read() test
+--CREDITS--
+Davide Mendolia <idaf1er@gmail.com>
+Patrick Allaert <patrickallaert@php.net>
+Belgian PHP Testfest 2009
+--SKIPIF--
+<?php 
+require_once('skipif.inc'); 
+require_once('skipifbindfailure.inc');
+?>
+--FILE--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+var_dump(
+       $result = ldap_read($link, "dc=my-domain,dc=com", "(dc=*)"),
+       ldap_get_entries($link, $result)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECTF--
+resource(%d) of type (ldap result)
+array(2) {
+  ["count"]=>
+  int(1)
+  [0]=>
+  array(8) {
+    ["objectclass"]=>
+    array(4) {
+      ["count"]=>
+      int(3)
+      [0]=>
+      string(3) "top"
+      [1]=>
+      string(8) "dcObject"
+      [2]=>
+      string(12) "organization"
+    }
+    [0]=>
+    string(11) "objectclass"
+    ["dc"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(9) "my-domain"
+    }
+    [1]=>
+    string(2) "dc"
+    ["o"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(9) "my-domain"
+    }
+    [2]=>
+    string(1) "o"
+    ["count"]=>
+    int(3)
+    ["dn"]=>
+    string(19) "dc=my-domain,dc=com"
+  }
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_read_error.phpt b/ext/ldap/tests/ldap_read_error.phpt
new file mode 100644 (file)
index 0000000..10c0e29
--- /dev/null
@@ -0,0 +1,35 @@
+--TEST--
+ldap_read() - operation that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+include "connect.inc";
+
+$link = ldap_connect($host, $port);
+
+// Too few parameters
+var_dump(ldap_read());
+var_dump(ldap_read($link));
+var_dump(ldap_read($link, $link));
+
+// Too many parameters
+var_dump(ldap_read($link, "dc=my-domain,dc=com", "(objectClass=*)", array(), 0, 0, 0, 0 , "Additional data"));
+?>
+===DONE===
+--EXPECTF--
+Warning: Wrong parameter count for ldap_read() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_read() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_read() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_read() in %s on line %d
+NULL
+===DONE===
diff --git a/ext/ldap/tests/ldap_rename_basic.phpt b/ext/ldap/tests/ldap_rename_basic.phpt
new file mode 100644 (file)
index 0000000..135769d
--- /dev/null
@@ -0,0 +1,62 @@
+--TEST--
+ldap_rename() - Basic ldap_rename test
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+var_dump(
+       ldap_rename($link, "cn=userA,dc=my-domain,dc=com", "cn=userZ", "dc=my-domain,dc=com", true)
+);
+$result = ldap_search($link, "dc=my-domain,dc=com", "(cn=userA)", array("cn", "sn"));
+$result = ldap_search($link, "dc=my-domain,dc=com", "(cn=userZ)", array("cn", "sn"));
+var_dump(ldap_get_entries($link, $result));
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+ldap_rename($link, "cn=userZ,dc=my-domain,dc=com", "cn=userA", "dc=my-domain,dc=com", true);
+remove_dummy_data($link);
+?>
+--EXPECT--
+bool(true)
+array(2) {
+  ["count"]=>
+  int(1)
+  [0]=>
+  array(6) {
+    ["sn"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(7) "testSN1"
+    }
+    [0]=>
+    string(2) "sn"
+    ["cn"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(5) "userZ"
+    }
+    [1]=>
+    string(2) "cn"
+    ["count"]=>
+    int(2)
+    ["dn"]=>
+    string(28) "cn=userZ,dc=my-domain,dc=com"
+  }
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_rename_error.phpt b/ext/ldap/tests/ldap_rename_error.phpt
new file mode 100644 (file)
index 0000000..ac088de
--- /dev/null
@@ -0,0 +1,21 @@
+--TEST--
+ldap_rename() - Testing ldap_rename() that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+var_dump(ldap_rename($link));
+var_dump(ldap_rename($link, "cn=userNotFound,dc=my-domain,dc=com", "cn=userZ", "dc=my-domain,dc=com", true));
+?>
+===DONE===
+--EXPECTF--
+Warning: Wrong parameter count for ldap_rename() in %s on line %d
+NULL
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_sasl_bind_basic.phpt b/ext/ldap/tests/ldap_sasl_bind_basic.phpt
new file mode 100644 (file)
index 0000000..6ed14a5
--- /dev/null
@@ -0,0 +1,20 @@
+--TEST--
+ldap_sasl_bind() - Basic anonymous binding
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php if (!function_exists("ldap_sasl_bind")) die("skip LDAP extension not compiled with SASL support"); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
+var_dump(ldap_sasl_bind($link, null, $passwd, 'DIGEST-MD5', 'realm', $sasl_user));
+?>
+===DONE===
+--EXPECT--
+bool(true)
+===DONE===
diff --git a/ext/ldap/tests/ldap_sasl_bind_error.phpt b/ext/ldap/tests/ldap_sasl_bind_error.phpt
new file mode 100644 (file)
index 0000000..180066b
--- /dev/null
@@ -0,0 +1,53 @@
+--TEST--
+ldap_sasl_bind() - Binding that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+<?php if (!function_exists("ldap_sasl_bind")) die("skip LDAP extension not compiled with SASL support"); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
+
+// Invalid parameter count
+var_dump(ldap_sasl_bind());
+
+// Invalid DN
+var_dump(ldap_sasl_bind($link, "Invalid DN", $passwd, 'DIGEST-MD5', 'realm', $sasl_user));
+
+// Invalid user
+var_dump(ldap_sasl_bind($link, null, "ThisIsNotCorrect$passwd", 'DIGEST-MD5', "realm", "invalid$sasl_user"));
+
+// Invalid password
+var_dump(ldap_sasl_bind($link, null, "ThisIsNotCorrect$passwd", 'DIGEST-MD5', "realm", $sasl_user));
+
+var_dump(ldap_sasl_bind($link, null, $passwd, 'DIGEST-MD5', "realm", "Manager", "test"));
+
+// Invalid DN syntax
+var_dump(ldap_sasl_bind($link, "unexistingProperty=weirdValue,$user", $passwd));
+?>
+===DONE===
+--EXPECTF--
+Warning: ldap_sasl_bind() expects at least 1 parameter, 0 given in %s on line %d
+bool(false)
+
+Warning: ldap_sasl_bind(): Unable to bind to server: Invalid DN syntax in %s on line %d
+bool(false)
+
+Warning: ldap_sasl_bind(): Unable to bind to server: Invalid credentials in %s on line %d
+bool(false)
+
+Warning: ldap_sasl_bind(): Unable to bind to server: Invalid credentials in %s on line %d
+bool(false)
+
+Warning: ldap_sasl_bind(): Unable to bind to server: Insufficient access in %s on line %d
+bool(false)
+
+Warning: ldap_sasl_bind(): Unable to bind to server: Invalid DN syntax in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_search_basic.phpt b/ext/ldap/tests/ldap_search_basic.phpt
new file mode 100644 (file)
index 0000000..e6cebf2
--- /dev/null
@@ -0,0 +1,194 @@
+--TEST--
+ldap_search() test
+--CREDITS--
+Davide Mendolia <idaf1er@gmail.com>
+Patrick Allaert <patrickallaert@php.net>
+Belgian PHP Testfest 2009
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifbindfailure.inc');
+?>
+--FILE--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+insert_dummy_data($link);
+var_dump(
+       $result = ldap_search($link, "dc=my-domain,dc=com", "(objectClass=person)"),
+       ldap_get_entries($link, $result)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECTF--
+resource(%d) of type (ldap result)
+array(4) {
+  ["count"]=>
+  int(3)
+  [0]=>
+  array(14) {
+    ["objectclass"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(6) "person"
+    }
+    [0]=>
+    string(11) "objectclass"
+    ["cn"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(5) "userA"
+    }
+    [1]=>
+    string(2) "cn"
+    ["sn"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(7) "testSN1"
+    }
+    [2]=>
+    string(2) "sn"
+    ["userpassword"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(4) "oops"
+    }
+    [3]=>
+    string(12) "userpassword"
+    ["telephonenumber"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(14) "xx-xx-xx-xx-xx"
+    }
+    [4]=>
+    string(15) "telephonenumber"
+    ["description"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(6) "user A"
+    }
+    [5]=>
+    string(11) "description"
+    ["count"]=>
+    int(6)
+    ["dn"]=>
+    string(28) "cn=userA,dc=my-domain,dc=com"
+  }
+  [1]=>
+  array(12) {
+    ["objectclass"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(6) "person"
+    }
+    [0]=>
+    string(11) "objectclass"
+    ["cn"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(5) "userB"
+    }
+    [1]=>
+    string(2) "cn"
+    ["sn"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(7) "testSN2"
+    }
+    [2]=>
+    string(2) "sn"
+    ["userpassword"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(15) "oopsIDitItAgain"
+    }
+    [3]=>
+    string(12) "userpassword"
+    ["description"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(6) "user B"
+    }
+    [4]=>
+    string(11) "description"
+    ["count"]=>
+    int(5)
+    ["dn"]=>
+    string(28) "cn=userB,dc=my-domain,dc=com"
+  }
+  [2]=>
+  array(10) {
+    ["objectclass"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(6) "person"
+    }
+    [0]=>
+    string(11) "objectclass"
+    ["cn"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(5) "userC"
+    }
+    [1]=>
+    string(2) "cn"
+    ["sn"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(7) "testSN3"
+    }
+    [2]=>
+    string(2) "sn"
+    ["userpassword"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(17) "0r1g1na1 passw0rd"
+    }
+    [3]=>
+    string(12) "userpassword"
+    ["count"]=>
+    int(4)
+    ["dn"]=>
+    string(37) "cn=userC,cn=userB,dc=my-domain,dc=com"
+  }
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_search_error.phpt b/ext/ldap/tests/ldap_search_error.phpt
new file mode 100644 (file)
index 0000000..6a68e9d
--- /dev/null
@@ -0,0 +1,62 @@
+--TEST--
+ldap_search() - operation that should fail
+--CREDITS--
+Davide Mendolia <idaf1er@gmail.com>
+Belgian PHP Testfest 2009
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+?>
+--FILE--
+<?php
+include "connect.inc";
+
+$link = ldap_connect($host, $port);
+
+$dn = "dc=my-domain,dc=com";
+$filter = "(dc=*)";
+
+$result = ldap_search();
+var_dump($result);
+
+$result = ldap_search($link, $dn, $filter);
+var_dump($result);
+
+$result = ldap_search($link, $dn, $filter, NULL);
+var_dump($result);
+
+$result = ldap_search($link, $dn, $filter, array(1 => 'top'));
+var_dump($result);
+
+$result = ldap_search(array(), $dn, $filter, array('top'));
+var_dump($result);
+
+$result = ldap_search(array($link, $link), array($dn), $filter, array('top'));
+var_dump($result);
+
+$result = ldap_search(array($link, $link), $dn, array($filter), array('top'));
+var_dump($result);
+?>
+===DONE===
+--EXPECTF--
+Warning: Wrong parameter count for ldap_search() in %s on line %d
+NULL
+
+Warning: ldap_search(): Search: No such object in %s on line %d
+bool(false)
+
+Warning: ldap_search(): Expected Array as last element in %s on line %d
+bool(false)
+
+Warning: ldap_search(): Array initialization wrong in %s on line %d
+bool(false)
+
+Warning: ldap_search(): No links in link array in %s on line %d
+bool(false)
+
+Warning: ldap_search(): Base must either be a string, or an array with the same number of elements as the links array in %s on line %d
+bool(false)
+
+Warning: ldap_search(): Filter must either be a string, or an array with the same number of elements as the links array in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_search_variation1.phpt b/ext/ldap/tests/ldap_search_variation1.phpt
new file mode 100644 (file)
index 0000000..d56f5bd
--- /dev/null
@@ -0,0 +1,56 @@
+--TEST--
+ldap_search() test
+--CREDITS--
+Davide Mendolia <idaf1er@gmail.com>
+Patrick Allaert <patrickallaert@php.net>
+Belgian PHP Testfest 2009
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifbindfailure.inc');
+?>
+--FILE--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+
+$dn = "dc=my-domain,dc=com";
+$filter = "(dc=*)";
+var_dump(
+       $result = ldap_search($link, "dc=my-domain,dc=com", "(dc=*)", array('dc')),
+       ldap_get_entries($link, $result)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECTF--
+resource(%d) of type (ldap result)
+array(2) {
+  ["count"]=>
+  int(1)
+  [0]=>
+  array(4) {
+    ["dc"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(9) "my-domain"
+    }
+    [0]=>
+    string(2) "dc"
+    ["count"]=>
+    int(1)
+    ["dn"]=>
+    string(19) "dc=my-domain,dc=com"
+  }
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_search_variation2.phpt b/ext/ldap/tests/ldap_search_variation2.phpt
new file mode 100644 (file)
index 0000000..791c5e9
--- /dev/null
@@ -0,0 +1,80 @@
+--TEST--
+ldap_search() test
+--CREDITS--
+Davide Mendolia <idaf1er@gmail.com>
+Patrick Allaert <patrickallaert@php.net>
+Belgian PHP Testfest 2009
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifbindfailure.inc');
+?>
+--FILE--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+
+var_dump(
+       $result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=person)", array('sn'), 1),
+       ldap_get_entries($link, $result)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECTF--
+resource(%d) of type (ldap result)
+array(4) {
+  ["count"]=>
+  int(3)
+  [0]=>
+  array(4) {
+    ["sn"]=>
+    array(1) {
+      ["count"]=>
+      int(0)
+    }
+    [0]=>
+    string(2) "sn"
+    ["count"]=>
+    int(1)
+    ["dn"]=>
+    string(28) "cn=userA,dc=my-domain,dc=com"
+  }
+  [1]=>
+  array(4) {
+    ["sn"]=>
+    array(1) {
+      ["count"]=>
+      int(0)
+    }
+    [0]=>
+    string(2) "sn"
+    ["count"]=>
+    int(1)
+    ["dn"]=>
+    string(28) "cn=userB,dc=my-domain,dc=com"
+  }
+  [2]=>
+  array(4) {
+    ["sn"]=>
+    array(1) {
+      ["count"]=>
+      int(0)
+    }
+    [0]=>
+    string(2) "sn"
+    ["count"]=>
+    int(1)
+    ["dn"]=>
+    string(37) "cn=userC,cn=userB,dc=my-domain,dc=com"
+  }
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_search_variation3.phpt b/ext/ldap/tests/ldap_search_variation3.phpt
new file mode 100644 (file)
index 0000000..ab7b222
--- /dev/null
@@ -0,0 +1,108 @@
+--TEST--
+ldap_search() test
+--CREDITS--
+Davide Mendolia <idaf1er@gmail.com>
+Patrick Allaert <patrickallaert@php.net>
+Belgian PHP Testfest 2009
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifbindfailure.inc');
+?>
+--FILE--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+
+$dn = "dc=my-domain,dc=com";
+$filter = "(objectclass=person)";
+var_dump(
+       $result = ldap_search($link, $dn, $filter, array('sn'), 1, 3),
+       ldap_get_entries($link, $result)
+);
+
+var_dump(
+       $result = ldap_search($link, $dn, $filter, array('sn'), 1, 1),
+       ldap_get_entries($link, $result)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECTF--
+resource(%d) of type (ldap result)
+array(4) {
+  ["count"]=>
+  int(3)
+  [0]=>
+  array(4) {
+    ["sn"]=>
+    array(1) {
+      ["count"]=>
+      int(0)
+    }
+    [0]=>
+    string(2) "sn"
+    ["count"]=>
+    int(1)
+    ["dn"]=>
+    string(28) "cn=userA,dc=my-domain,dc=com"
+  }
+  [1]=>
+  array(4) {
+    ["sn"]=>
+    array(1) {
+      ["count"]=>
+      int(0)
+    }
+    [0]=>
+    string(2) "sn"
+    ["count"]=>
+    int(1)
+    ["dn"]=>
+    string(28) "cn=userB,dc=my-domain,dc=com"
+  }
+  [2]=>
+  array(4) {
+    ["sn"]=>
+    array(1) {
+      ["count"]=>
+      int(0)
+    }
+    [0]=>
+    string(2) "sn"
+    ["count"]=>
+    int(1)
+    ["dn"]=>
+    string(37) "cn=userC,cn=userB,dc=my-domain,dc=com"
+  }
+}
+
+Warning: ldap_search(): Partial search results returned: Sizelimit exceeded in %s on line %d
+resource(%d) of type (ldap result)
+array(2) {
+  ["count"]=>
+  int(1)
+  [0]=>
+  array(4) {
+    ["sn"]=>
+    array(1) {
+      ["count"]=>
+      int(0)
+    }
+    [0]=>
+    string(2) "sn"
+    ["count"]=>
+    int(1)
+    ["dn"]=>
+    string(28) "cn=userA,dc=my-domain,dc=com"
+  }
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_search_variation4.phpt b/ext/ldap/tests/ldap_search_variation4.phpt
new file mode 100644 (file)
index 0000000..787468e
--- /dev/null
@@ -0,0 +1,55 @@
+--TEST--
+ldap_search() test
+--CREDITS--
+Davide Mendolia <idaf1er@gmail.com>
+Patrick Allaert <patrickallaert@php.net>
+Belgian PHP Testfest 2009
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifbindfailure.inc');
+?>
+--FILE--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+
+$dn = "dc=my-domain,dc=com";
+$filter = "(objectclass=person)";
+var_dump(
+       $result = ldap_search($link, $dn, $filter, array('sn'), 1, 1, 3),
+       ldap_get_entries($link, $result)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECTF--
+Warning: ldap_search(): Partial search results returned: Sizelimit exceeded in %s on line %d
+resource(%d) of type (ldap result)
+array(2) {
+  ["count"]=>
+  int(1)
+  [0]=>
+  array(4) {
+    ["sn"]=>
+    array(1) {
+      ["count"]=>
+      int(0)
+    }
+    [0]=>
+    string(2) "sn"
+    ["count"]=>
+    int(1)
+    ["dn"]=>
+    string(28) "cn=userA,dc=my-domain,dc=com"
+  }
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_search_variation5.phpt b/ext/ldap/tests/ldap_search_variation5.phpt
new file mode 100644 (file)
index 0000000..d50854c
--- /dev/null
@@ -0,0 +1,105 @@
+--TEST--
+ldap_search() test
+--CREDITS--
+Davide Mendolia <idaf1er@gmail.com>
+Patrick Allaert <patrickallaert@php.net>
+Belgian PHP Testfest 2009
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifbindfailure.inc');
+?>
+--FILE--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+
+$dn = "dc=my-domain,dc=com";
+$filter = "(objectclass=person)";
+var_dump(
+       $result = ldap_search($link, $dn, $filter, array('sn'), 1, 1, 3, LDAP_DEREF_SEARCHING),
+       ldap_get_entries($link, $result)
+);
+var_dump(
+       $result = ldap_search($link, $dn, $filter, array('sn'), 1, 1, 3, LDAP_DEREF_FINDING),
+       ldap_get_entries($link, $result)
+);
+var_dump(
+       $result = ldap_search($link, $dn, $filter, array('sn'), 1, 1, 3, LDAP_DEREF_ALWAYS),
+       ldap_get_entries($link, $result)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECTF--
+Warning: ldap_search(): Partial search results returned: Sizelimit exceeded in %s on line %d
+resource(%d) of type (ldap result)
+array(2) {
+  ["count"]=>
+  int(1)
+  [0]=>
+  array(4) {
+    ["sn"]=>
+    array(1) {
+      ["count"]=>
+      int(0)
+    }
+    [0]=>
+    string(2) "sn"
+    ["count"]=>
+    int(1)
+    ["dn"]=>
+    string(28) "cn=userA,dc=my-domain,dc=com"
+  }
+}
+
+Warning: ldap_search(): Partial search results returned: Sizelimit exceeded in %s on line %d
+resource(%d) of type (ldap result)
+array(2) {
+  ["count"]=>
+  int(1)
+  [0]=>
+  array(4) {
+    ["sn"]=>
+    array(1) {
+      ["count"]=>
+      int(0)
+    }
+    [0]=>
+    string(2) "sn"
+    ["count"]=>
+    int(1)
+    ["dn"]=>
+    string(28) "cn=userA,dc=my-domain,dc=com"
+  }
+}
+
+Warning: ldap_search(): Partial search results returned: Sizelimit exceeded in %s on line %d
+resource(%d) of type (ldap result)
+array(2) {
+  ["count"]=>
+  int(1)
+  [0]=>
+  array(4) {
+    ["sn"]=>
+    array(1) {
+      ["count"]=>
+      int(0)
+    }
+    [0]=>
+    string(2) "sn"
+    ["count"]=>
+    int(1)
+    ["dn"]=>
+    string(28) "cn=userA,dc=my-domain,dc=com"
+  }
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_search_variation6.phpt b/ext/ldap/tests/ldap_search_variation6.phpt
new file mode 100644 (file)
index 0000000..a29e452
--- /dev/null
@@ -0,0 +1,230 @@
+--TEST--
+ldap_search() test
+--CREDITS--
+Davide Mendolia <idaf1er@gmail.com>
+Patrick Allaert <patrickallaert@php.net>
+Belgian PHP Testfest 2009
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifbindfailure.inc');
+?>
+--FILE--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+
+$dn = "dc=my-domain,dc=com";
+$filter = "(objectclass=person)";
+
+var_dump(
+       $result = ldap_search(array($link, $link), $dn, $filter),
+       $result0 = ldap_get_entries($link, $result[0]),
+       ldap_get_entries($link, $result[1]) === $result0
+);
+var_dump(
+       $result = ldap_search(array($link, $link), null, $filter),
+       ldap_get_entries($link, $result[0]),
+       ldap_get_entries($link, $result[1])
+);
+var_dump(
+       $result = ldap_search(array($link, $link), null, array($filter, $filter)),
+       ldap_get_entries($link, $result[0]),
+       ldap_get_entries($link, $result[1])
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+remove_dummy_data($link);
+?>
+--EXPECTF--
+array(2) {
+  [0]=>
+  resource(%d) of type (ldap result)
+  [1]=>
+  resource(%d) of type (ldap result)
+}
+array(4) {
+  ["count"]=>
+  int(3)
+  [0]=>
+  array(14) {
+    ["objectclass"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(6) "person"
+    }
+    [0]=>
+    string(11) "objectclass"
+    ["cn"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(5) "userA"
+    }
+    [1]=>
+    string(2) "cn"
+    ["sn"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(7) "testSN1"
+    }
+    [2]=>
+    string(2) "sn"
+    ["userpassword"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(4) "oops"
+    }
+    [3]=>
+    string(12) "userpassword"
+    ["telephonenumber"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(14) "xx-xx-xx-xx-xx"
+    }
+    [4]=>
+    string(15) "telephonenumber"
+    ["description"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(6) "user A"
+    }
+    [5]=>
+    string(11) "description"
+    ["count"]=>
+    int(6)
+    ["dn"]=>
+    string(28) "cn=userA,dc=my-domain,dc=com"
+  }
+  [1]=>
+  array(12) {
+    ["objectclass"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(6) "person"
+    }
+    [0]=>
+    string(11) "objectclass"
+    ["cn"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(5) "userB"
+    }
+    [1]=>
+    string(2) "cn"
+    ["sn"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(7) "testSN2"
+    }
+    [2]=>
+    string(2) "sn"
+    ["userpassword"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(15) "oopsIDitItAgain"
+    }
+    [3]=>
+    string(12) "userpassword"
+    ["description"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(6) "user B"
+    }
+    [4]=>
+    string(11) "description"
+    ["count"]=>
+    int(5)
+    ["dn"]=>
+    string(28) "cn=userB,dc=my-domain,dc=com"
+  }
+  [2]=>
+  array(10) {
+    ["objectclass"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(6) "person"
+    }
+    [0]=>
+    string(11) "objectclass"
+    ["cn"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(5) "userC"
+    }
+    [1]=>
+    string(2) "cn"
+    ["sn"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(7) "testSN3"
+    }
+    [2]=>
+    string(2) "sn"
+    ["userpassword"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(17) "0r1g1na1 passw0rd"
+    }
+    [3]=>
+    string(12) "userpassword"
+    ["count"]=>
+    int(4)
+    ["dn"]=>
+    string(37) "cn=userC,cn=userB,dc=my-domain,dc=com"
+  }
+}
+bool(true)
+array(2) {
+  [0]=>
+  resource(%d) of type (ldap result)
+  [1]=>
+  resource(%d) of type (ldap result)
+}
+NULL
+NULL
+array(2) {
+  [0]=>
+  resource(%d) of type (ldap result)
+  [1]=>
+  resource(%d) of type (ldap result)
+}
+NULL
+NULL
+===DONE===
diff --git a/ext/ldap/tests/ldap_set_option_basic.phpt b/ext/ldap/tests/ldap_set_option_basic.phpt
new file mode 100644 (file)
index 0000000..de25e59
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+ldap_set_option() - Basic ldap_set_option() operation
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+$option = null;
+
+var_dump(ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version));
+ldap_get_option($link, LDAP_OPT_PROTOCOL_VERSION, $option);
+var_dump($option);
+?>
+===DONE===
+--EXPECT--
+bool(true)
+int(3)
+===DONE===
diff --git a/ext/ldap/tests/ldap_set_option_error.phpt b/ext/ldap/tests/ldap_set_option_error.phpt
new file mode 100644 (file)
index 0000000..e9ff5ab
--- /dev/null
@@ -0,0 +1,66 @@
+--TEST--
+ldap_set_option() - ldap_set_option() operation that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+$controls = array(
+       array(
+               array("xid" => "1.2.752.58.10.1", "iscritical" => true),
+               array("xid" => "1.2.752.58.1.10", "value" => "magic"),
+       ),
+       array(
+               array("oid" => "1.2.752.58.10.1", "iscritical" => true),
+               array("oid" => "1.2.752.58.1.10", "value" => "magic"),
+               "weird"
+       ),
+       array(
+       ),
+);
+
+// Too few parameters
+var_dump(ldap_set_option());
+var_dump(ldap_set_option($link));
+var_dump(ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION));
+
+// Too many parameters
+var_dump(ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, 3, "Additional data"));
+
+var_dump(ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, 10));
+
+foreach ($controls as $control)
+       var_dump(ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, $control));
+
+var_dump(ldap_set_option($link, 999999, 999999));
+?>
+===DONE===
+--EXPECTF--
+Warning: Wrong parameter count for ldap_set_option() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_set_option() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_set_option() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_set_option() in %s on line %d
+NULL
+bool(false)
+
+Warning: ldap_set_option(): Control must have an oid key in %s on line %d
+bool(false)
+
+Warning: ldap_set_option(): The array value must contain only arrays, where each array is a control in %s on line %d
+bool(false)
+
+Warning: ldap_set_option(): Expected non-empty array value for this option in %s on line %d
+bool(false)
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_set_option_variation.phpt b/ext/ldap/tests/ldap_set_option_variation.phpt
new file mode 100644 (file)
index 0000000..1bbfe1f
--- /dev/null
@@ -0,0 +1,77 @@
+--TEST--
+ldap_set_option() - More ldap_set_option() operations
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+$option = null;
+
+$controls = array(
+       array("oid" => "1.2.752.58.10.1", "iscritical" => true),
+       array("oid" => "1.2.752.58.1.10", "value" => "magic"),
+);
+
+var_dump(ldap_set_option($link, LDAP_OPT_DEREF, LDAP_DEREF_ALWAYS));
+ldap_get_option($link, LDAP_OPT_DEREF, $option);
+var_dump(
+       $option === LDAP_DEREF_ALWAYS,
+       ldap_set_option($link, LDAP_OPT_SIZELIMIT, 123)
+);
+ldap_get_option($link, LDAP_OPT_SIZELIMIT, $option);
+var_dump(
+       $option,
+       ldap_set_option($link, LDAP_OPT_TIMELIMIT, 33)
+);
+ldap_get_option($link, LDAP_OPT_TIMELIMIT, $option);
+var_dump(
+       $option,
+       ldap_set_option($link, LDAP_OPT_REFERRALS, true)
+);
+ldap_get_option($link, LDAP_OPT_REFERRALS, $option);
+var_dump(
+       (bool) $option,
+       ldap_set_option($link, LDAP_OPT_RESTART, false)
+);
+ldap_get_option($link, LDAP_OPT_RESTART, $option);
+var_dump(
+       (bool) $option,
+       ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, $controls)
+);
+ldap_get_option($link, LDAP_OPT_SERVER_CONTROLS, $option);
+var_dump(
+       $option,
+       ldap_set_option($link, LDAP_OPT_CLIENT_CONTROLS, $controls)
+);
+ldap_get_option($link, LDAP_OPT_CLIENT_CONTROLS, $option);
+var_dump(
+       $option,
+       ldap_set_option($link, LDAP_OPT_MATCHED_DN, "dc=test,dc=com")
+);
+ldap_get_option($link, LDAP_OPT_MATCHED_DN, $option);
+var_dump($option);
+?>
+===DONE===
+--EXPECT--
+bool(true)
+bool(true)
+bool(true)
+int(123)
+bool(true)
+int(33)
+bool(true)
+bool(true)
+bool(true)
+bool(false)
+bool(true)
+int(0)
+bool(true)
+int(0)
+bool(true)
+string(14) "dc=test,dc=com"
+===DONE===
diff --git a/ext/ldap/tests/ldap_set_rebind_proc_basic.phpt b/ext/ldap/tests/ldap_set_rebind_proc_basic.phpt
new file mode 100644 (file)
index 0000000..428b8d8
--- /dev/null
@@ -0,0 +1,34 @@
+--TEST--
+ldap_set_rebind_proc() - Basic ldap_set_rebind_proc test
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+function rebind_proc ($ds, $ldap_url) {
+  global $user;
+  global $passwd;
+  global $protocol_version;
+
+  // required by most modern LDAP servers, use LDAPv3
+  ldap_set_option($a, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
+
+  if (!ldap_bind($a, $user, $passwd)) {
+        print "Cannot bind";
+  }
+}
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+var_dump(ldap_set_rebind_proc($link, "rebind_proc"));
+var_dump(ldap_set_rebind_proc($link, ""));
+?>
+===DONE===
+--EXPECT--
+bool(true)
+bool(true)
+===DONE===
diff --git a/ext/ldap/tests/ldap_set_rebind_proc_error.phpt b/ext/ldap/tests/ldap_set_rebind_proc_error.phpt
new file mode 100644 (file)
index 0000000..3b4cd69
--- /dev/null
@@ -0,0 +1,40 @@
+--TEST--
+ldap_set_rebind_proc() - Testing ldap_set_rebind_proc() that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+function rebind_proc ($ds, $ldap_url) {
+  global $user;
+  global $passwd;
+  global $protocol_version;
+
+  // required by most modern LDAP servers, use LDAPv3
+  ldap_set_option($a, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
+
+  if (!ldap_bind($a, $user, $passwd)) {
+        print "Cannot bind";
+  }
+}
+
+$link = ldap_connect($host, $port);
+var_dump(ldap_set_rebind_proc($link));
+var_dump(ldap_set_rebind_proc($link, "rebind_proc", "Additional data"));
+var_dump(ldap_set_rebind_proc($link, "rebind_proc_inexistant"));
+?>
+===DONE===
+--EXPECTF--
+Warning: ldap_set_rebind_proc() expects exactly 2 parameters, 1 given in %s on line %d
+bool(false)
+
+Warning: ldap_set_rebind_proc() expects exactly 2 parameters, 3 given in %s on line %d
+bool(false)
+
+Warning: ldap_set_rebind_proc(): Two arguments expected for 'rebind_proc_inexistant' to be a valid callback in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_sort_basic.phpt b/ext/ldap/tests/ldap_sort_basic.phpt
new file mode 100644 (file)
index 0000000..f6ee5d1
--- /dev/null
@@ -0,0 +1,200 @@
+--TEST--
+ldap_sort() - Basic ldap_sort test
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+ldap_add($link, "cn=userC,dc=my-domain,dc=com", array(
+       "objectclass" => "person",
+       "cn" => "userC",
+       "sn" => "zzz",
+       "userPassword" => "oops",
+       "description" => "a user",
+));
+ldap_add($link, "cn=userD,dc=my-domain,dc=com", array(
+       "objectclass" => "person",
+       "cn" => "userD",
+       "sn" => "aaa",
+       "userPassword" => "oops",
+       "description" => "another user",
+));
+ldap_add($link, "cn=userE,dc=my-domain,dc=com", array(
+       "objectclass" => "person",
+       "cn" => "userE",
+       "sn" => "a",
+       "userPassword" => "oops",
+       "description" => "yet another user",
+));
+$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=person)", array("sn", "description"));
+var_dump(
+       ldap_sort($link, $result, "sn"),
+       ldap_get_entries($link, $result)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+ldap_delete($link, "cn=userC,dc=my-domain,dc=com");
+ldap_delete($link, "cn=userD,dc=my-domain,dc=com");
+ldap_delete($link, "cn=userE,dc=my-domain,dc=com");
+remove_dummy_data($link);
+?>
+--EXPECT--
+bool(true)
+array(7) {
+  ["count"]=>
+  int(6)
+  [0]=>
+  array(6) {
+    ["sn"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(1) "a"
+    }
+    [0]=>
+    string(2) "sn"
+    ["description"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(16) "yet another user"
+    }
+    [1]=>
+    string(11) "description"
+    ["count"]=>
+    int(2)
+    ["dn"]=>
+    string(28) "cn=userE,dc=my-domain,dc=com"
+  }
+  [1]=>
+  array(6) {
+    ["sn"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(3) "aaa"
+    }
+    [0]=>
+    string(2) "sn"
+    ["description"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(12) "another user"
+    }
+    [1]=>
+    string(11) "description"
+    ["count"]=>
+    int(2)
+    ["dn"]=>
+    string(28) "cn=userD,dc=my-domain,dc=com"
+  }
+  [2]=>
+  array(6) {
+    ["sn"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(7) "testSN1"
+    }
+    [0]=>
+    string(2) "sn"
+    ["description"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(6) "user A"
+    }
+    [1]=>
+    string(11) "description"
+    ["count"]=>
+    int(2)
+    ["dn"]=>
+    string(28) "cn=userA,dc=my-domain,dc=com"
+  }
+  [3]=>
+  array(6) {
+    ["sn"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(7) "testSN2"
+    }
+    [0]=>
+    string(2) "sn"
+    ["description"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(6) "user B"
+    }
+    [1]=>
+    string(11) "description"
+    ["count"]=>
+    int(2)
+    ["dn"]=>
+    string(28) "cn=userB,dc=my-domain,dc=com"
+  }
+  [4]=>
+  array(4) {
+    ["sn"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(7) "testSN3"
+    }
+    [0]=>
+    string(2) "sn"
+    ["count"]=>
+    int(1)
+    ["dn"]=>
+    string(37) "cn=userC,cn=userB,dc=my-domain,dc=com"
+  }
+  [5]=>
+  array(6) {
+    ["sn"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(3) "zzz"
+    }
+    [0]=>
+    string(2) "sn"
+    ["description"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(6) "a user"
+    }
+    [1]=>
+    string(11) "description"
+    ["count"]=>
+    int(2)
+    ["dn"]=>
+    string(28) "cn=userC,dc=my-domain,dc=com"
+  }
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_sort_error.phpt b/ext/ldap/tests/ldap_sort_error.phpt
new file mode 100644 (file)
index 0000000..6eb4090
--- /dev/null
@@ -0,0 +1,35 @@
+--TEST--
+ldap_sort() - Testing ldap_sort() that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+var_dump(ldap_sort($link));
+var_dump(ldap_sort($link, $link));
+var_dump(ldap_sort($link, $link, $link, $link));
+var_dump(ldap_sort($link, $link, $link));
+var_dump(ldap_sort($link, $link, "sn"));
+?>
+===DONE===
+--EXPECTF--
+Warning: ldap_sort() expects exactly 3 parameters, 1 given in %s on line %d
+bool(false)
+
+Warning: ldap_sort() expects exactly 3 parameters, 2 given in %s on line %d
+bool(false)
+
+Warning: ldap_sort() expects exactly 3 parameters, 4 given in %s on line %d
+bool(false)
+
+Warning: ldap_sort() expects parameter 3 to be %binary_string_optional%, resource given in %s on line %d
+bool(false)
+
+Warning: ldap_sort(): Supplied resource is not a valid ldap result resource in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_sort_variation.phpt b/ext/ldap/tests/ldap_sort_variation.phpt
new file mode 100644 (file)
index 0000000..e1affe8
--- /dev/null
@@ -0,0 +1,200 @@
+--TEST--
+ldap_sort() - Basic ldap_sort test
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+insert_dummy_data($link);
+ldap_add($link, "cn=userC,dc=my-domain,dc=com", array(
+       "objectclass" => "person",
+       "cn" => "userC",
+       "sn" => "zzz",
+       "userPassword" => "oops",
+       "description" => "a user",
+));
+ldap_add($link, "cn=userD,dc=my-domain,dc=com", array(
+       "objectclass" => "person",
+       "cn" => "userD",
+       "sn" => "aaa",
+       "userPassword" => "oops",
+       "description" => "another user",
+));
+ldap_add($link, "cn=userE,dc=my-domain,dc=com", array(
+       "objectclass" => "person",
+       "cn" => "userE",
+       "sn" => "a",
+       "userPassword" => "oops",
+       "description" => "yet another user",
+));
+$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=person)", array("sn", "description"));
+var_dump(
+       ldap_sort($link, $result, "description"),
+       ldap_get_entries($link, $result)
+);
+?>
+===DONE===
+--CLEAN--
+<?php
+include "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+ldap_delete($link, "cn=userC,dc=my-domain,dc=com");
+ldap_delete($link, "cn=userD,dc=my-domain,dc=com");
+ldap_delete($link, "cn=userE,dc=my-domain,dc=com");
+remove_dummy_data($link);
+?>
+--EXPECT--
+bool(true)
+array(7) {
+  ["count"]=>
+  int(6)
+  [0]=>
+  array(4) {
+    ["sn"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(7) "testSN3"
+    }
+    [0]=>
+    string(2) "sn"
+    ["count"]=>
+    int(1)
+    ["dn"]=>
+    string(37) "cn=userC,cn=userB,dc=my-domain,dc=com"
+  }
+  [1]=>
+  array(6) {
+    ["sn"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(3) "zzz"
+    }
+    [0]=>
+    string(2) "sn"
+    ["description"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(6) "a user"
+    }
+    [1]=>
+    string(11) "description"
+    ["count"]=>
+    int(2)
+    ["dn"]=>
+    string(28) "cn=userC,dc=my-domain,dc=com"
+  }
+  [2]=>
+  array(6) {
+    ["sn"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(3) "aaa"
+    }
+    [0]=>
+    string(2) "sn"
+    ["description"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(12) "another user"
+    }
+    [1]=>
+    string(11) "description"
+    ["count"]=>
+    int(2)
+    ["dn"]=>
+    string(28) "cn=userD,dc=my-domain,dc=com"
+  }
+  [3]=>
+  array(6) {
+    ["sn"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(7) "testSN1"
+    }
+    [0]=>
+    string(2) "sn"
+    ["description"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(6) "user A"
+    }
+    [1]=>
+    string(11) "description"
+    ["count"]=>
+    int(2)
+    ["dn"]=>
+    string(28) "cn=userA,dc=my-domain,dc=com"
+  }
+  [4]=>
+  array(6) {
+    ["sn"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(7) "testSN2"
+    }
+    [0]=>
+    string(2) "sn"
+    ["description"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(6) "user B"
+    }
+    [1]=>
+    string(11) "description"
+    ["count"]=>
+    int(2)
+    ["dn"]=>
+    string(28) "cn=userB,dc=my-domain,dc=com"
+  }
+  [5]=>
+  array(6) {
+    ["sn"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(1) "a"
+    }
+    [0]=>
+    string(2) "sn"
+    ["description"]=>
+    array(2) {
+      ["count"]=>
+      int(1)
+      [0]=>
+      string(16) "yet another user"
+    }
+    [1]=>
+    string(11) "description"
+    ["count"]=>
+    int(2)
+    ["dn"]=>
+    string(28) "cn=userE,dc=my-domain,dc=com"
+  }
+}
+===DONE===
diff --git a/ext/ldap/tests/ldap_start_tls_basic.phpt b/ext/ldap/tests/ldap_start_tls_basic.phpt
new file mode 100644 (file)
index 0000000..3ae50be
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--
+ldap_start_tls() - Basic ldap_start_tls test
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
+var_dump(ldap_start_tls($link));
+?>
+===DONE===
+--EXPECT--
+bool(true)
+===DONE===
diff --git a/ext/ldap/tests/ldap_start_tls_error.phpt b/ext/ldap/tests/ldap_start_tls_error.phpt
new file mode 100644 (file)
index 0000000..a09b7f1
--- /dev/null
@@ -0,0 +1,27 @@
+--TEST--
+ldap_start_tls() - Binding that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect($host, $port);
+ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
+
+// Invalid parameter count
+var_dump(ldap_start_tls());
+var_dump(ldap_start_tls($link, $link));
+?>
+===DONE===
+--EXPECTF--
+Warning: Wrong parameter count for ldap_start_tls() in %s on line %d
+NULL
+
+Warning: Wrong parameter count for ldap_start_tls() in %s on line %d
+NULL
+===DONE===
diff --git a/ext/ldap/tests/ldap_unbind_basic.phpt b/ext/ldap/tests/ldap_unbind_basic.phpt
new file mode 100644 (file)
index 0000000..addfac5
--- /dev/null
@@ -0,0 +1,20 @@
+--TEST--
+ldap_unbind() - Basic ldap_unbind() operation
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+var_dump(ldap_unbind($link));
+?>
+===DONE===
+--EXPECT--
+bool(true)
+===DONE===
diff --git a/ext/ldap/tests/ldap_unbind_error.phpt b/ext/ldap/tests/ldap_unbind_error.phpt
new file mode 100644 (file)
index 0000000..19b4ad5
--- /dev/null
@@ -0,0 +1,42 @@
+--TEST--
+ldap_unbind() - ldap_unbind() operations that should fail
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+
+// Too few parameters
+var_dump(ldap_unbind());
+
+// Too many parameters
+var_dump(ldap_unbind($link, "Additional data"));
+
+// Bad parameter
+var_dump(ldap_unbind("string"));
+
+// unbind twice
+var_dump(ldap_unbind($link));
+var_dump(ldap_unbind($link));
+?>
+===DONE===
+--EXPECTF--
+Warning: ldap_unbind() expects exactly 1 parameter, 0 given in %s on line %d
+bool(false)
+
+Warning: ldap_unbind() expects exactly 1 parameter, 2 given in %s on line %d
+bool(false)
+
+Warning: ldap_unbind() expects parameter 1 to be resource, %unicode_string_optional% given in %s on line %d
+bool(false)
+bool(true)
+
+Warning: ldap_unbind(): %d is not a valid ldap link resource in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/ldap/tests/ldap_unbind_variation.phpt b/ext/ldap/tests/ldap_unbind_variation.phpt
new file mode 100644 (file)
index 0000000..377018c
--- /dev/null
@@ -0,0 +1,34 @@
+--TEST--
+ldap_unbind() - Variation of ldap_unbind() function using ldap_set_rebind_proc()
+--CREDITS--
+Patrick Allaert <patrickallaert@php.net>
+# Belgian PHP Testfest 2009
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifbindfailure.inc'); ?>
+--FILE--
+<?php
+require "connect.inc";
+
+function rebind_proc ($ds, $ldap_url) {
+       global $user;
+       global $passwd;
+       global $protocol_version;
+       
+       // required by most modern LDAP servers, use LDAPv3
+       ldap_set_option($a, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
+       
+       if (!ldap_bind($a, $user, $passwd)) {
+               print "Cannot bind";
+       }
+}
+
+$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
+ldap_set_rebind_proc($link, "rebind_proc");
+
+var_dump(ldap_unbind($link));
+?>
+===DONE===
+--EXPECT--
+bool(true)
+===DONE===