xref: /PHP-8.0/ext/ldap/tests/ldap_add_error.phpt (revision 36cdbd05)
1--TEST--
2ldap_add() - Add operation that should fail
3--CREDITS--
4Patrick Allaert <patrickallaert@php.net>
5# Belgian PHP Testfest 2009
6--SKIPIF--
7<?php require_once('skipif.inc'); ?>
8<?php require_once('skipifbindfailure.inc'); ?>
9--FILE--
10<?php
11require "connect.inc";
12
13$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
14
15var_dump(ldap_add($link, "$base", array()));
16
17// Invalid DN
18var_dump(
19    ldap_add($link, "weirdAttribute=val", array(
20        "weirdAttribute"			=> "val",
21    )),
22    ldap_error($link),
23    ldap_errno($link)
24);
25
26// Duplicate entry
27for ($i = 0; $i < 2; $i++)
28    var_dump(
29    ldap_add($link, "dc=my-domain,$base", array(
30      "objectClass"	=> array(
31        "top",
32        "dcObject",
33        "organization"),
34      "dc"			=> "my-domain",
35      "o"				=> "my-domain",
36    ))
37    );
38var_dump(ldap_error($link), ldap_errno($link));
39
40// Wrong array indexes
41try {
42    ldap_add($link, "dc=my-domain2,dc=com", array(
43        "objectClass"	=> array(
44            0	=> "top",
45            2	=> "dcObject",
46            5	=> "organization"),
47        "dc"			=> "my-domain",
48        "o"				=> "my-domain",
49    ));
50    /* Is this correct behaviour to still have "Already exists" as error/errno?
51    ,
52    ldap_error($link),
53    ldap_errno($link)
54    */
55} catch (ValueError $exception) {
56    echo $exception->getMessage() . "\n";
57}
58
59// Invalid attribute
60var_dump(
61    ldap_add($link, "$base", array(
62        "objectClass"	=> array(
63            "top",
64            "dcObject",
65            "organization"),
66        "dc"			=> "my-domain",
67        "o"				=> "my-domain",
68        "weirdAttr"		=> "weirdVal",
69    )),
70    ldap_error($link),
71    ldap_errno($link)
72);
73
74var_dump(
75    ldap_add($link, "$base", array(array( "Oops"
76    )))
77    /* Is this correct behaviour to still have "Undefined attribute type" as error/errno?
78    ,
79    ldap_error($link),
80    ldap_errno($link)
81    */
82);
83?>
84--CLEAN--
85<?php
86require "connect.inc";
87
88$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
89
90ldap_delete($link, "dc=my-domain,$base");
91?>
92--EXPECTF--
93Warning: ldap_add(): Add: Protocol error in %s on line %d
94bool(false)
95
96Warning: ldap_add(): Add: Invalid DN syntax in %s on line %d
97bool(false)
98string(17) "Invalid DN syntax"
99int(34)
100bool(true)
101
102Warning: ldap_add(): Add: Already exists in %s on line %d
103bool(false)
104string(14) "Already exists"
105int(68)
106ldap_add(): Argument #3 ($entry) must contain arrays with consecutive integer indices starting from 0
107
108Warning: ldap_add(): Add: Undefined attribute type in %s on line %d
109bool(false)
110string(24) "Undefined attribute type"
111int(17)
112
113Warning: ldap_add(): Unknown attribute in the data in %s on line %d
114bool(false)
115