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($uri, $user, $passwd, $protocol_version); 15 16// Invalid DN 17var_dump( 18 ldap_add( 19 $link, 20 "weirdAttribute=val", 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( 31 $link, 32 "dc=my-domain,$base", 33 [ 34 "objectClass" => [ 35 "top", 36 "dcObject", 37 "organization", 38 ], 39 "dc" => "my-domain", 40 "o" => "my-domain", 41 ], 42 ) 43 ); 44} 45var_dump(ldap_error($link), ldap_errno($link)); 46 47// Invalid attribute 48var_dump( 49 ldap_add( 50 $link, 51 "dc=my-domain,$base", 52 [ 53 "objectClass" => [ 54 "top", 55 "dcObject", 56 "organization", 57 ], 58 "dc" => "my-domain", 59 "o" => "my-domain", 60 "weirdAttr" => "weirdVal", 61 ], 62 ), 63 ldap_error($link), 64 ldap_errno($link), 65); 66?> 67--CLEAN-- 68<?php 69require "connect.inc"; 70 71$link = ldap_connect_and_bind($uri, $user, $passwd, $protocol_version); 72 73ldap_delete($link, "dc=my-domain,$base"); 74?> 75--EXPECTF-- 76Warning: ldap_add(): Add: Invalid DN syntax in %s on line %d 77bool(false) 78string(17) "Invalid DN syntax" 79int(34) 80bool(true) 81 82Warning: ldap_add(): Add: Already exists in %s on line %d 83bool(false) 84string(14) "Already exists" 85int(68) 86 87Warning: ldap_add(): Add: Undefined attribute type in %s on line %d 88bool(false) 89string(24) "Undefined attribute type" 90int(17) 91