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