Skip to content

Commit

Permalink
test: add a test to check that remove unrelated terms from entity works
Browse files Browse the repository at this point in the history
  • Loading branch information
williarin committed Aug 5, 2022
1 parent fa33098 commit 049107a
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/Test/Bridge/Repository/TermRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,39 @@ public function testRemoveTermsFromEntity(): void
self::assertEquals(['simple'], array_column($terms, 'name'));
}

public function testRemoveTermsFromEntityWhichDoesNotHaveThemDoesNothing(): void
{
$product = $this->manager->getRepository(Product::class)
->findOneBySku('super-forces-hoodie')
;

$terms = $this->repository->findBy([
new PostRelationshipCondition(Product::class, [
'id' => $product->id,
]),
]);

self::assertEquals(['simple', 'Hoodies', 'MegaBrand'], array_column($terms, 'name'));

$unrelatedTerms = $this->repository->findBy([
new PostRelationshipCondition(Product::class, [
'id' => 37,
]),
]);

self::assertEquals(['external', 'Decor'], array_column($unrelatedTerms, 'name'));

$this->repository->removeTermsFromEntity($product, $unrelatedTerms);

$terms = $this->repository->findBy([
new PostRelationshipCondition(Product::class, [
'id' => $product->id,
]),
]);

self::assertEquals(['simple', 'Hoodies', 'MegaBrand'], array_column($terms, 'name'));
}

public function testRemoveTermsFromEntityWithoutTermTaxonomyIdAreIgnored(): void
{
$product = $this->manager->getRepository(Product::class)
Expand Down

0 comments on commit 049107a

Please sign in to comment.