@@ -762,31 +762,43 @@ public function test_nested_or_filter()
762762 {
763763 $ b = $ this ->newBuilder ();
764764
765- // orFilter wraps the nested query in an OrGroup
766- // Since where() creates an AndGroup, the result is OrGroup(AndGroup(...))
765+ // orFilter combines the filters inside with OR
767766 $ query = $ b ->orFilter (function ($ query ) {
768767 $ query ->where ([
769768 'one ' => 'one ' ,
770769 'two ' => 'two ' ,
771770 ]);
772771 })->getUnescapedQuery ();
773772
774- $ this ->assertEquals ('(|(&(one=one)(two=two))) ' , $ query );
773+ $ this ->assertEquals ('(|(one=one)(two=two)) ' , $ query );
774+ }
775+
776+ public function test_nested_or_filter_with_where_equals ()
777+ {
778+ $ b = $ this ->newBuilder ();
779+
780+ // orFilter with whereEquals should combine with OR, not AND
781+ $ query = $ b ->orFilter (function ($ query ) {
782+ $ query ->whereEquals ('foo ' , '1 ' );
783+ $ query ->whereEquals ('foo ' , '2 ' );
784+ })->getUnescapedQuery ();
785+
786+ $ this ->assertEquals ('(|(foo=1)(foo=2)) ' , $ query );
775787 }
776788
777789 public function test_nested_and_filter ()
778790 {
779791 $ b = $ this ->newBuilder ();
780792
781- // andFilter wraps the nested query in an AndGroup
793+ // andFilter combines the filters inside with AND
782794 $ query = $ b ->andFilter (function ($ query ) {
783795 $ query ->where ([
784796 'one ' => 'one ' ,
785797 'two ' => 'two ' ,
786798 ]);
787799 })->getUnescapedQuery ();
788800
789- $ this ->assertEquals ('(&(&( one=one)(two=two) )) ' , $ query );
801+ $ this ->assertEquals ('(&(one=one)(two=two)) ' , $ query );
790802 }
791803
792804 public function test_nested_not_filter ()
@@ -820,7 +832,7 @@ public function test_nested_filters()
820832 ]);
821833 })->getUnescapedQuery ();
822834
823- $ this ->assertEquals ('(&(|(&( one=one)(two=two))) (&(&( one=one)(two=two) ))) ' , $ query );
835+ $ this ->assertEquals ('(&(|(one=one)(two=two))(&(one=one)(two=two))) ' , $ query );
824836 }
825837
826838 public function test_nested_filters_with_non_nested ()
@@ -842,7 +854,32 @@ public function test_nested_filters_with_non_nested()
842854 'six ' => 'six ' ,
843855 ])->getUnescapedQuery ();
844856
845- $ this ->assertEquals ('(&(|(&(one=one)(two=two)))(&(&(three=three)(four=four)))(five=five)(six=six)) ' , $ query );
857+ $ this ->assertEquals ('(&(|(one=one)(two=two))(&(three=three)(four=four))(five=five)(six=six)) ' , $ query );
858+ }
859+
860+ public function test_deeply_nested_filters ()
861+ {
862+ $ b = $ this ->newBuilder ();
863+
864+ // Complex query: enabled AND (user with verified OR service with trusted)
865+ $ query = $ b ->andFilter (function ($ query ) {
866+ $ query ->whereEquals ('enabled ' , 'true ' );
867+ $ query ->orFilter (function ($ q ) {
868+ $ q ->andFilter (function ($ inner ) {
869+ $ inner ->whereEquals ('type ' , 'user ' );
870+ $ inner ->whereEquals ('verified ' , 'true ' );
871+ });
872+ $ q ->andFilter (function ($ inner ) {
873+ $ inner ->whereEquals ('type ' , 'service ' );
874+ $ inner ->whereEquals ('trusted ' , 'true ' );
875+ });
876+ });
877+ })->getUnescapedQuery ();
878+
879+ $ this ->assertEquals (
880+ '(&(enabled=true)(|(&(type=user)(verified=true))(&(type=service)(trusted=true)))) ' ,
881+ $ query
882+ );
846883 }
847884
848885 public function test_nested_builder_is_nested ()
0 commit comments