@@ -593,4 +593,86 @@ public function terms_are_found_using_where_json_length()
593593 $ this ->assertCount (2 , $ entries );
594594 $ this ->assertEquals (['2 ' , '5 ' ], $ entries ->map ->slug ()->all ());
595595 }
596+
597+ public function terms_are_found_using_where_has_when_max_items_1 ()
598+ {
599+ $ blueprint = Blueprint::makeFromFields (['terms_field ' => ['type ' => 'terms ' , 'max_items ' => 1 , 'taxonomies ' => ['tags ' ]]]);
600+ Blueprint::shouldReceive ('in ' )->with ('taxonomies/tags ' )->andReturn (collect (['tags ' => $ blueprint ]));
601+
602+ Taxonomy::make ('tags ' )->save ();
603+ Term::make ('a ' )->taxonomy ('tags ' )->data ([])->save ();
604+ Term::make ('b ' )->taxonomy ('tags ' )->data (['terms_field ' => 'a ' ])->save ();
605+ Term::make ('c ' )->taxonomy ('tags ' )->data (['terms_field ' => 'b ' ])->save ();
606+
607+ $ terms = Term::query ()->whereHas ('terms_field ' )->get ();
608+
609+ $ this ->assertCount (2 , $ terms );
610+ $ this ->assertEquals (['b ' , 'c ' ], $ terms ->map ->slug ->all ());
611+
612+ $ terms = Term::query ()->whereHas ('terms_field ' , function ($ subquery ) {
613+ $ subquery ->where ('title ' , 'a ' );
614+ })
615+ ->get ();
616+
617+ $ this ->assertCount (1 , $ terms );
618+ $ this ->assertEquals (['b ' ], $ terms ->map ->slug ->all ());
619+
620+ $ terms = Term::query ()->whereDoesntHave ('terms_field ' , function ($ subquery ) {
621+ $ subquery ->where ('title ' , 'a ' );
622+ })
623+ ->get ();
624+
625+ $ this ->assertCount (2 , $ terms );
626+ $ this ->assertEquals (['a ' , 'c ' ], $ terms ->map ->slug ->all ());
627+ }
628+
629+ #[Test]
630+ public function terms_are_found_using_where_has_when_max_items_not_1 ()
631+ {
632+ $ blueprint = Blueprint::makeFromFields (['terms_field ' => ['type ' => 'terms ' , 'taxonomies ' => ['tags ' ]]]);
633+ Blueprint::shouldReceive ('in ' )->with ('taxonomies/tags ' )->andReturn (collect (['tags ' => $ blueprint ]));
634+
635+ Taxonomy::make ('tags ' )->save ();
636+ Term::make ('a ' )->taxonomy ('tags ' )->data (['title ' => 'a ' ])->save ();
637+ Term::make ('b ' )->taxonomy ('tags ' )->data (['title ' => 'b ' , 'terms_field ' => ['a ' , 'c ' ]])->save ();
638+ Term::make ('c ' )->taxonomy ('tags ' )->data (['title ' => 'c ' , 'terms_field ' => ['b ' , 'a ' ]])->save ();
639+
640+ $ terms = Term::query ()->whereHas ('terms_field ' )->get ();
641+
642+ $ this ->assertCount (2 , $ terms );
643+ $ this ->assertEquals (['b ' , 'c ' ], $ terms ->map ->slug ->all ());
644+
645+ $ terms = Term::query ()->whereHas ('terms_field ' , function ($ subquery ) {
646+ $ subquery ->where ('slug ' , 'b ' );
647+ })
648+ ->get ();
649+
650+ $ this ->assertCount (1 , $ terms );
651+ $ this ->assertEquals (['c ' ], $ terms ->map ->slug ->all ());
652+
653+ $ terms = Term::query ()->whereDoesntHave ('terms_field ' , function ($ subquery ) {
654+ $ subquery ->where ('title ' , 'b ' );
655+ })
656+ ->get ();
657+
658+ $ this ->assertCount (2 , $ terms );
659+ $ this ->assertEquals (['a ' , 'b ' ], $ terms ->map ->slug ->all ());
660+ }
661+
662+ #[Test]
663+ public function terms_are_found_using_where_relation ()
664+ {
665+ $ blueprint = Blueprint::makeFromFields (['terms_field ' => ['type ' => 'terms ' , 'taxonomies ' => ['tags ' ]]]);
666+ Blueprint::shouldReceive ('in ' )->with ('taxonomies/tags ' )->andReturn (collect (['tags ' => $ blueprint ]));
667+
668+ Taxonomy::make ('tags ' )->save ();
669+ Term::make ('a ' )->taxonomy ('tags ' )->data ([])->save ();
670+ Term::make ('b ' )->taxonomy ('tags ' )->data (['terms_field ' => ['a ' , 'c ' ]])->save ();
671+ Term::make ('c ' )->taxonomy ('tags ' )->data (['terms_field ' => ['b ' , 'a ' ]])->save ();
672+
673+ $ terms = Term::query ()->whereRelation ('terms_field ' , 'slug ' , 'b ' )->get ();
674+
675+ $ this ->assertCount (1 , $ terms );
676+ $ this ->assertEquals (['c ' ], $ terms ->map ->slug ->all ());
677+ }
596678}
0 commit comments