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 15// Too few parameters 16var_dump(ldap_add()); 17var_dump(ldap_add($link)); 18var_dump(ldap_add($link, "$base")); 19 20// Too many parameters 21var_dump(ldap_add($link, "$base", array(), [], "Additional data")); 22 23var_dump(ldap_add($link, "$base", array())); 24 25// Invalid DN 26var_dump( 27 ldap_add($link, "weirdAttribute=val", array( 28 "weirdAttribute" => "val", 29 )), 30 ldap_error($link), 31 ldap_errno($link) 32); 33 34// Duplicate entry 35for ($i = 0; $i < 2; $i++) 36 var_dump( 37 ldap_add($link, "dc=my-domain,$base", array( 38 "objectClass" => array( 39 "top", 40 "dcObject", 41 "organization"), 42 "dc" => "my-domain", 43 "o" => "my-domain", 44 )) 45 ); 46var_dump(ldap_error($link), ldap_errno($link)); 47 48// Wrong array indexes 49var_dump( 50 ldap_add($link, "dc=my-domain2,dc=com", array( 51 "objectClass" => array( 52 0 => "top", 53 2 => "dcObject", 54 5 => "organization"), 55 "dc" => "my-domain", 56 "o" => "my-domain", 57 )) 58 /* Is this correct behaviour to still have "Already exists" as error/errno? 59 , 60 ldap_error($link), 61 ldap_errno($link) 62 */ 63); 64 65// Invalid attribute 66var_dump( 67 ldap_add($link, "$base", array( 68 "objectClass" => array( 69 "top", 70 "dcObject", 71 "organization"), 72 "dc" => "my-domain", 73 "o" => "my-domain", 74 "weirdAttr" => "weirdVal", 75 )), 76 ldap_error($link), 77 ldap_errno($link) 78); 79 80var_dump( 81 ldap_add($link, "$base", array(array( "Oops" 82 ))) 83 /* Is this correct behaviour to still have "Undefined attribute type" as error/errno? 84 , 85 ldap_error($link), 86 ldap_errno($link) 87 */ 88); 89?> 90===DONE=== 91--CLEAN-- 92<?php 93require "connect.inc"; 94 95$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version); 96 97ldap_delete($link, "dc=my-domain,$base"); 98?> 99--EXPECTF-- 100Warning: ldap_add() expects at least 3 parameters, 0 given in %s on line %d 101NULL 102 103Warning: ldap_add() expects at least 3 parameters, 1 given in %s on line %d 104NULL 105 106Warning: ldap_add() expects at least 3 parameters, 2 given in %s on line %d 107NULL 108 109Warning: ldap_add() expects at most 4 parameters, 5 given in %s on line %d 110NULL 111 112Warning: ldap_add(): Add: Protocol error in %s on line %d 113bool(false) 114 115Warning: ldap_add(): Add: Invalid DN syntax in %s on line %d 116bool(false) 117string(17) "Invalid DN syntax" 118int(34) 119bool(true) 120 121Warning: ldap_add(): Add: Already exists in %s on line %d 122bool(false) 123string(14) "Already exists" 124int(68) 125 126Warning: ldap_add(): Value array must have consecutive indices 0, 1, ... in %s on line %d 127bool(false) 128 129Warning: ldap_add(): Add: Undefined attribute type in %s on line %d 130bool(false) 131string(24) "Undefined attribute type" 132int(17) 133 134Warning: ldap_add(): Unknown attribute in the data in %s on line %d 135bool(false) 136===DONE=== 137