@@ -133,6 +133,39 @@ public function testAddTermsToEntity(): void
133133 self ::assertEquals ([1 , 6 , 1 , 2 ], array_column ($ termsProduct , 'count ' ));
134134 }
135135
136+ public function testAddDuplicateTermsToEntityDoesNotDuplicateThem (): void
137+ {
138+ $ hoodieTerms = $ this ->repository ->findBy ([
139+ new PostRelationshipCondition (Product::class, [
140+ 'post_status ' => new Operand (['publish ' , 'private ' ], Operand::OPERATOR_IN ),
141+ 'sku ' => 'super-forces-hoodie ' ,
142+ ]),
143+ ]);
144+
145+ $ product = $ this ->manager ->getRepository (Product::class)
146+ ->find (16 )
147+ ;
148+
149+ $ termsProduct = $ this ->repository ->findBy ([
150+ new PostRelationshipCondition (Product::class, [
151+ 'id ' => $ product ->id ,
152+ ]),
153+ ]);
154+
155+ self ::assertEquals (['simple ' , 'Hoodies ' ], array_column ($ termsProduct , 'name ' ));
156+
157+ $ this ->repository ->addTermsToEntity ($ product , $ hoodieTerms );
158+
159+ $ termsProduct = $ this ->repository ->findBy ([
160+ new PostRelationshipCondition (Product::class, [
161+ 'id ' => $ product ->id ,
162+ ]),
163+ ]);
164+
165+ self ::assertEquals (['simple ' , 'Hoodies ' , 'MegaBrand ' ], array_column ($ termsProduct , 'name ' ));
166+ self ::assertEquals ([15 , 5 , 2 ], array_column ($ termsProduct , 'count ' ));
167+ }
168+
136169 public function testAddTermsToEntityWithoutTermTaxonomyIdAreIgnored (): void
137170 {
138171 $ hoodieTerms = array_map (
0 commit comments