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