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--CLEAN--
74<?php
75include "connect.inc";
76
77$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
78remove_dummy_data($link, $base);
79?>
80--EXPECTF--
81resource(%d) of type (ldap result)
82array(4) {
83  ["count"]=>
84  int(3)
85  [0]=>
86  array(4) {
87    ["cn"]=>
88    array(2) {
89      ["count"]=>
90      int(1)
91      [0]=>
92      string(5) "userC"
93    }
94    [0]=>
95    string(2) "cn"
96    ["count"]=>
97    int(1)
98    ["dn"]=>
99    string(%d) "cn=userC,cn=userB,%s"
100  }
101  [1]=>
102  array(4) {
103    ["cn"]=>
104    array(2) {
105      ["count"]=>
106      int(1)
107      [0]=>
108      string(5) "userB"
109    }
110    [0]=>
111    string(2) "cn"
112    ["count"]=>
113    int(1)
114    ["dn"]=>
115    string(%d) "cn=userB,%s"
116  }
117  [2]=>
118  array(4) {
119    ["cn"]=>
120    array(2) {
121      ["count"]=>
122      int(1)
123      [0]=>
124      string(5) "userA"
125    }
126    [0]=>
127    string(2) "cn"
128    ["count"]=>
129    int(1)
130    ["dn"]=>
131    string(%d) "cn=userA,%s"
132  }
133}
134bool(true)
135int(0)
136string(0) ""
137array(1) {
138  ["1.2.840.113556.1.4.474"]=>
139  array(2) {
140    ["oid"]=>
141    string(22) "1.2.840.113556.1.4.474"
142    ["value"]=>
143    array(1) {
144      ["errcode"]=>
145      int(0)
146    }
147  }
148}
149resource(%d) of type (ldap result)
150array(3) {
151  ["count"]=>
152  int(2)
153  [0]=>
154  array(4) {
155    ["cn"]=>
156    array(2) {
157      ["count"]=>
158      int(1)
159      [0]=>
160      string(5) "userB"
161    }
162    [0]=>
163    string(2) "cn"
164    ["count"]=>
165    int(1)
166    ["dn"]=>
167    string(%d) "cn=userB,%s"
168  }
169  [1]=>
170  array(4) {
171    ["cn"]=>
172    array(2) {
173      ["count"]=>
174      int(1)
175      [0]=>
176      string(5) "userA"
177    }
178    [0]=>
179    string(2) "cn"
180    ["count"]=>
181    int(1)
182    ["dn"]=>
183    string(%d) "cn=userA,%s"
184  }
185}
186bool(true)
187array(2) {
188  [0]=>
189  string(22) "1.2.840.113556.1.4.474"
190  [1]=>
191  string(24) "2.16.840.1.113730.3.4.10"
192}
193array(2) {
194  ["oid"]=>
195  string(22) "1.2.840.113556.1.4.474"
196  ["value"]=>
197  array(1) {
198    ["errcode"]=>
199    int(0)
200  }
201}
202int(2)
203int(3)
204int(0)
205string(%d) "%s"
206