1--TEST--
2ldap_search() test with sort and VLV controls
3--CREDITS--
4Côme Chilliet <mcmic@php.net>
5--SKIPIF--
6<?php
7require_once('skipif.inc');
8require_once('skipifbindfailure.inc');
9require_once('skipifcontrol.inc');
10skipifunsupportedcontrol(LDAP_CONTROL_SORTREQUEST);
11skipifunsupportedcontrol(LDAP_CONTROL_VLVREQUEST);
12?>
13--FILE--
14<?php
15include "connect.inc";
16
17$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
18insert_dummy_data($link, $base);
19
20/* First test with only SORT control */
21var_dump(
22	$result = ldap_search($link, $base, '(cn=*)', array('cn'), 0, 0, 0, LDAP_DEREF_NEVER,
23		[
24			[
25				'oid' => LDAP_CONTROL_SORTREQUEST,
26				'iscritical' => TRUE,
27				'value' => [
28					['attr' => 'cn', 'oid' => '2.5.13.3' /* caseIgnoreOrderingMatch */, 'reverse' => TRUE]
29				]
30			]
31		]
32	),
33	ldap_get_entries($link, $result),
34	ldap_parse_result($link, $result, $errcode , $matcheddn , $errmsg , $referrals, $controls),
35	$errcode,
36	$errmsg,
37	$controls
38);
39
40/* Then with VLV control */
41var_dump(
42	$result = ldap_search($link, $base, '(cn=*)', array('cn'), 0, 0, 0, LDAP_DEREF_NEVER,
43		[
44			[
45				'oid' => LDAP_CONTROL_SORTREQUEST,
46				'iscritical' => TRUE,
47				'value' => [
48					['attr' => 'cn', 'oid' => '2.5.13.3' /* caseIgnoreOrderingMatch */, 'reverse' => TRUE]
49				]
50			],
51			[
52				'oid' => LDAP_CONTROL_VLVREQUEST,
53				'iscritical' => TRUE,
54				'value' => [
55					'before'	=> 0, // Return 0 entry before target
56					'after'		=> 1, // Return 1 entry after target
57					'offset'	=> 2, // Target entry is the second one
58					'count'		=> 0, // We have no idea how many entries there are
59				]
60			]
61		]
62	),
63	ldap_get_entries($link, $result),
64	ldap_parse_result($link, $result, $errcode , $matcheddn , $errmsg , $referrals, $controls),
65	array_keys($controls),
66	$controls[LDAP_CONTROL_SORTRESPONSE],
67	$controls[LDAP_CONTROL_VLVRESPONSE]['value']['target'],
68	$controls[LDAP_CONTROL_VLVRESPONSE]['value']['count'],
69	$controls[LDAP_CONTROL_VLVRESPONSE]['value']['errcode'],
70	bin2hex($controls[LDAP_CONTROL_VLVRESPONSE]['value']['context'])
71);
72?>
73===DONE===
74--CLEAN--
75<?php
76include "connect.inc";
77
78$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
79remove_dummy_data($link, $base);
80?>
81--EXPECTF--
82resource(%d) of type (ldap result)
83array(4) {
84  ["count"]=>
85  int(3)
86  [0]=>
87  array(4) {
88    ["cn"]=>
89    array(2) {
90      ["count"]=>
91      int(1)
92      [0]=>
93      string(5) "userC"
94    }
95    [0]=>
96    string(2) "cn"
97    ["count"]=>
98    int(1)
99    ["dn"]=>
100    string(%d) "cn=userC,cn=userB,%s"
101  }
102  [1]=>
103  array(4) {
104    ["cn"]=>
105    array(2) {
106      ["count"]=>
107      int(1)
108      [0]=>
109      string(5) "userB"
110    }
111    [0]=>
112    string(2) "cn"
113    ["count"]=>
114    int(1)
115    ["dn"]=>
116    string(%d) "cn=userB,%s"
117  }
118  [2]=>
119  array(4) {
120    ["cn"]=>
121    array(2) {
122      ["count"]=>
123      int(1)
124      [0]=>
125      string(5) "userA"
126    }
127    [0]=>
128    string(2) "cn"
129    ["count"]=>
130    int(1)
131    ["dn"]=>
132    string(%d) "cn=userA,%s"
133  }
134}
135bool(true)
136int(0)
137string(0) ""
138array(1) {
139  ["1.2.840.113556.1.4.474"]=>
140  array(2) {
141    ["oid"]=>
142    string(22) "1.2.840.113556.1.4.474"
143    ["value"]=>
144    array(1) {
145      ["errcode"]=>
146      int(0)
147    }
148  }
149}
150resource(%d) of type (ldap result)
151array(3) {
152  ["count"]=>
153  int(2)
154  [0]=>
155  array(4) {
156    ["cn"]=>
157    array(2) {
158      ["count"]=>
159      int(1)
160      [0]=>
161      string(5) "userB"
162    }
163    [0]=>
164    string(2) "cn"
165    ["count"]=>
166    int(1)
167    ["dn"]=>
168    string(%d) "cn=userB,%s"
169  }
170  [1]=>
171  array(4) {
172    ["cn"]=>
173    array(2) {
174      ["count"]=>
175      int(1)
176      [0]=>
177      string(5) "userA"
178    }
179    [0]=>
180    string(2) "cn"
181    ["count"]=>
182    int(1)
183    ["dn"]=>
184    string(%d) "cn=userA,%s"
185  }
186}
187bool(true)
188array(2) {
189  [0]=>
190  string(22) "1.2.840.113556.1.4.474"
191  [1]=>
192  string(24) "2.16.840.1.113730.3.4.10"
193}
194array(2) {
195  ["oid"]=>
196  string(22) "1.2.840.113556.1.4.474"
197  ["value"]=>
198  array(1) {
199    ["errcode"]=>
200    int(0)
201  }
202}
203int(2)
204int(3)
205int(0)
206string(%d) "%s"
207===DONE===
208