From e5bdf6ce31113c39458c0a9049faef3300544185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Randy=20=C4=8Cupi=C4=87?= Date: Fri, 26 Jan 2024 12:31:42 +0100 Subject: [PATCH 1/2] Don't show products which are disabled --- lib/Item/ValueConverter/ProductValueConverter.php | 2 +- tests/lib/Item/Stubs/Product.php | 4 ++-- tests/lib/Item/ValueConverter/ProductValueConverterTest.php | 6 ++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/Item/ValueConverter/ProductValueConverter.php b/lib/Item/ValueConverter/ProductValueConverter.php index 5c95e74..8742e8a 100644 --- a/lib/Item/ValueConverter/ProductValueConverter.php +++ b/lib/Item/ValueConverter/ProductValueConverter.php @@ -39,7 +39,7 @@ public function getName(object $object): string public function getIsVisible(object $object): bool { - return true; + return $object->isEnabled(); } public function getObject(object $object): ProductInterface diff --git a/tests/lib/Item/Stubs/Product.php b/tests/lib/Item/Stubs/Product.php index dbcd1ba..a157799 100644 --- a/tests/lib/Item/Stubs/Product.php +++ b/tests/lib/Item/Stubs/Product.php @@ -8,7 +8,7 @@ final class Product extends BaseProduct { - public function __construct(int $id, string $name, ?string $slug = null) + public function __construct(int $id, string $name, ?string $slug = null, bool $enabled = true) { parent::__construct(); @@ -16,7 +16,7 @@ public function __construct(int $id, string $name, ?string $slug = null) $this->currentLocale = 'en'; $this->setName($name); - $this->setSlug($slug); + $this->setEnabled($enabled); } } diff --git a/tests/lib/Item/ValueConverter/ProductValueConverterTest.php b/tests/lib/Item/ValueConverter/ProductValueConverterTest.php index 919fcbf..8fdefd6 100644 --- a/tests/lib/Item/ValueConverter/ProductValueConverterTest.php +++ b/tests/lib/Item/ValueConverter/ProductValueConverterTest.php @@ -74,6 +74,12 @@ public function testGetIsVisible(): void new ProductStub(42, 'Product name'), ), ); + + self::assertFalse( + $this->valueConverter->getIsVisible( + new ProductStub(42, 'Product name', null, false), + ), + ); } public function testGetObject(): void From c1ab34cf3634525aea39589988e5c69e334e2744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Randy=20=C4=8Cupi=C4=87?= Date: Fri, 26 Jan 2024 13:08:59 +0100 Subject: [PATCH 2/2] Create separate test for disabled product --- tests/lib/Item/ValueConverter/ProductValueConverterTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/lib/Item/ValueConverter/ProductValueConverterTest.php b/tests/lib/Item/ValueConverter/ProductValueConverterTest.php index 8fdefd6..0fff412 100644 --- a/tests/lib/Item/ValueConverter/ProductValueConverterTest.php +++ b/tests/lib/Item/ValueConverter/ProductValueConverterTest.php @@ -74,7 +74,10 @@ public function testGetIsVisible(): void new ProductStub(42, 'Product name'), ), ); + } + public function testGetIsVisibleReturnsFalse(): void + { self::assertFalse( $this->valueConverter->getIsVisible( new ProductStub(42, 'Product name', null, false),