33namespace LdapRecord \Tests \Unit \Query ;
44
55use DateTime ;
6+ use InvalidArgumentException ;
67use LdapRecord \Connection ;
78use LdapRecord \Container ;
89use LdapRecord \LdapRecordException ;
@@ -109,7 +110,7 @@ public function test_add_filter()
109110
110111 public function test_adding_filter_with_invalid_bindings_throws_exception ()
111112 {
112- $ this ->expectException (\ InvalidArgumentException::class);
113+ $ this ->expectException (InvalidArgumentException::class);
113114
114115 // Missing 'value' key.
115116 $ this ->newBuilder ()->addFilter ('and ' , [
@@ -120,7 +121,7 @@ public function test_adding_filter_with_invalid_bindings_throws_exception()
120121
121122 public function test_adding_invalid_filter_type_throws_exception ()
122123 {
123- $ this ->expectException (\ InvalidArgumentException::class);
124+ $ this ->expectException (InvalidArgumentException::class);
124125
125126 $ this ->newBuilder ()->addFilter ('non-existent ' , [
126127 'field ' => 'cn ' ,
@@ -467,7 +468,7 @@ public function test_or_where_ends_with()
467468
468469 public function test_where_invalid_operator ()
469470 {
470- $ this ->expectException (\ InvalidArgumentException::class);
471+ $ this ->expectException (InvalidArgumentException::class);
471472
472473 $ b = $ this ->newBuilder ();
473474
@@ -476,7 +477,7 @@ public function test_where_invalid_operator()
476477
477478 public function test_or_where_invalid_operator ()
478479 {
479- $ this ->expectException (\ InvalidArgumentException::class);
480+ $ this ->expectException (InvalidArgumentException::class);
480481
481482 $ b = $ this ->newBuilder ();
482483
@@ -1025,6 +1026,80 @@ public function test_get()
10251026 $ this ->assertEquals ($ result , $ b ->get ());
10261027 }
10271028
1029+ public function test_order_by ()
1030+ {
1031+ $ b = $ this ->newBuilder ();
1032+
1033+ $ b ->orderBy ('foo ' , 'asc ' );
1034+
1035+ $ this ->assertEquals ($ b ->controls , [
1036+ LDAP_CONTROL_SORTREQUEST => [
1037+ 'oid ' => LDAP_CONTROL_SORTREQUEST ,
1038+ 'isCritical ' => true ,
1039+ 'value ' => [
1040+ [
1041+ 'attr ' => 'foo ' ,
1042+ 'reverse ' => false ,
1043+ ],
1044+ ],
1045+ ],
1046+ ]);
1047+ }
1048+
1049+ public function test_order_by_desc ()
1050+ {
1051+ $ b = $ this ->newBuilder ();
1052+
1053+ $ b ->orderByDesc ('foo ' );
1054+
1055+ $ this ->assertEquals ($ b ->controls , [
1056+ LDAP_CONTROL_SORTREQUEST => [
1057+ 'oid ' => LDAP_CONTROL_SORTREQUEST ,
1058+ 'isCritical ' => true ,
1059+ 'value ' => [
1060+ [
1061+ 'attr ' => 'foo ' ,
1062+ 'reverse ' => true ,
1063+ ],
1064+ ],
1065+ ],
1066+ ]);
1067+ }
1068+
1069+ public function test_order_by_with_options ()
1070+ {
1071+ $ b = $ this ->newBuilder ();
1072+
1073+ $ b ->orderBy ('foo ' , 'asc ' , [
1074+ 'oid ' => $ oid = '2.5.13.2 ' ,
1075+ ]);
1076+
1077+ $ this ->assertEquals ($ b ->controls , [
1078+ LDAP_CONTROL_SORTREQUEST => [
1079+ 'oid ' => LDAP_CONTROL_SORTREQUEST ,
1080+ 'isCritical ' => true ,
1081+ 'value ' => [
1082+ [
1083+ 'attr ' => 'foo ' ,
1084+ 'reverse ' => false ,
1085+ 'oid ' => $ oid ,
1086+ ],
1087+ ],
1088+ ],
1089+ ]);
1090+ }
1091+
1092+ public function test_has_order_by ()
1093+ {
1094+ $ b = $ this ->newBuilder ();
1095+
1096+ $ this ->assertFalse ($ b ->hasOrderBy ());
1097+
1098+ $ b ->orderBy ('foo ' , 'asc ' );
1099+
1100+ $ this ->assertTrue ($ b ->hasOrderBy ());
1101+ }
1102+
10281103 public function test_first ()
10291104 {
10301105 $ b = $ this ->newBuilder ();
0 commit comments