From 097854376e7a607f80e2b02935943635efba4925 Mon Sep 17 00:00:00 2001 From: Roman Havrylko <70894038+romanhavrylko@users.noreply.github.com> Date: Wed, 20 Jul 2022 13:40:02 +0200 Subject: [PATCH] CC-16898 Added server-side validation for product category filters. (#9491) CC-16898 Fixed missing server-side validation for product category filters. --- composer.json | 1 + .../Business/ProductSearchFacade.php | 12 +++++ .../Business/ProductSearchFacadeInterface.php | 10 ++++ .../Persistence/ProductSearchRepository.php | 14 +++++ .../ProductSearchRepositoryInterface.php | 5 ++ .../GetAllProductAttributeKeysTest.php | 53 +++++++++++++++++++ .../_support/ProductSearchBusinessTester.php | 18 +++++++ .../Zed/ProductSearch/codeception.yml | 3 ++ 8 files changed, 116 insertions(+) create mode 100644 tests/SprykerTest/Zed/ProductSearch/Business/ProductSearchFacade/GetAllProductAttributeKeysTest.php diff --git a/composer.json b/composer.json index d82786b..7863651 100644 --- a/composer.json +++ b/composer.json @@ -28,6 +28,7 @@ "spryker/application": "*", "spryker/code-sniffer": "*", "spryker/config": "*", + "spryker/product-attribute": "*", "spryker/propel": "*", "spryker/testify": "*", "spryker/zed-navigation": "*" diff --git a/src/Spryker/Zed/ProductSearch/Business/ProductSearchFacade.php b/src/Spryker/Zed/ProductSearch/Business/ProductSearchFacade.php index 591f73b..691094c 100644 --- a/src/Spryker/Zed/ProductSearch/Business/ProductSearchFacade.php +++ b/src/Spryker/Zed/ProductSearch/Business/ProductSearchFacade.php @@ -438,4 +438,16 @@ public function expandProductConcreteTransfersWithIsSearchable(array $productCon ->createProductConcreteSearchReader() ->expandProductConcreteTransfersWithIsSearchable($productConcreteTransfers); } + + /** + * {@inheritDoc} + * + * @api + * + * @return array + */ + public function getAllProductAttributeKeys(): array + { + return $this->getRepository()->getAllProductAttributeKeys(); + } } diff --git a/src/Spryker/Zed/ProductSearch/Business/ProductSearchFacadeInterface.php b/src/Spryker/Zed/ProductSearch/Business/ProductSearchFacadeInterface.php index a574065..403ec34 100644 --- a/src/Spryker/Zed/ProductSearch/Business/ProductSearchFacadeInterface.php +++ b/src/Spryker/Zed/ProductSearch/Business/ProductSearchFacadeInterface.php @@ -353,4 +353,14 @@ public function isProductConcreteSearchable($idProductConcrete, ?LocaleTransfer * @return array<\Generated\Shared\Transfer\ProductConcreteTransfer> */ public function expandProductConcreteTransfersWithIsSearchable(array $productConcreteTransfers): array; + + /** + * Specification: + * - Gets all product attribute keys from Persistence. + * + * @api + * + * @return array + */ + public function getAllProductAttributeKeys(): array; } diff --git a/src/Spryker/Zed/ProductSearch/Persistence/ProductSearchRepository.php b/src/Spryker/Zed/ProductSearch/Persistence/ProductSearchRepository.php index 5e8ee36..abebc01 100644 --- a/src/Spryker/Zed/ProductSearch/Persistence/ProductSearchRepository.php +++ b/src/Spryker/Zed/ProductSearch/Persistence/ProductSearchRepository.php @@ -7,8 +7,10 @@ namespace Spryker\Zed\ProductSearch\Persistence; +use Orm\Zed\Product\Persistence\Map\SpyProductAttributeKeyTableMap; use Orm\Zed\ProductSearch\Persistence\Map\SpyProductSearchTableMap; use Spryker\Zed\Kernel\Persistence\AbstractRepository; +use Spryker\Zed\PropelOrm\Business\Model\Formatter\PropelArraySetFormatter; /** * @method \Spryker\Zed\ProductSearch\Persistence\ProductSearchPersistenceFactory getFactory() @@ -54,4 +56,16 @@ public function getProductSearchEntitiesCountGroupedByIdProductAndIdLocale(array return $result; } + + /** + * @return array + */ + public function getAllProductAttributeKeys(): array + { + return $this->getFactory() + ->createProductAttributeKeyQuery() + ->addSelectColumn(SpyProductAttributeKeyTableMap::COL_KEY) + ->setFormatter(new PropelArraySetFormatter()) + ->find(); + } } diff --git a/src/Spryker/Zed/ProductSearch/Persistence/ProductSearchRepositoryInterface.php b/src/Spryker/Zed/ProductSearch/Persistence/ProductSearchRepositoryInterface.php index 546da48..7388003 100644 --- a/src/Spryker/Zed/ProductSearch/Persistence/ProductSearchRepositoryInterface.php +++ b/src/Spryker/Zed/ProductSearch/Persistence/ProductSearchRepositoryInterface.php @@ -25,4 +25,9 @@ public function getProductSearchEntitiesCountGroupedByIdProductAndIdLocale( array $productIds, array $localeIds ): array; + + /** + * @return array + */ + public function getAllProductAttributeKeys(): array; } diff --git a/tests/SprykerTest/Zed/ProductSearch/Business/ProductSearchFacade/GetAllProductAttributeKeysTest.php b/tests/SprykerTest/Zed/ProductSearch/Business/ProductSearchFacade/GetAllProductAttributeKeysTest.php new file mode 100644 index 0000000..bd99298 --- /dev/null +++ b/tests/SprykerTest/Zed/ProductSearch/Business/ProductSearchFacade/GetAllProductAttributeKeysTest.php @@ -0,0 +1,53 @@ +tester->ensureProductAttributeKeyTableIsEmpty(); + + $expectedProductAttributeKeys = []; + $expectedCount = 3; + for ($i = 0; $i < $expectedCount; $i++) { + $expectedProductAttributeKeys[] = $this->tester->haveProductAttributeKeyEntity()->getKey(); + } + + // Act + $productAttributeKeys = $this->tester->getFacade()->getAllProductAttributeKeys(); + + // Assert + $this->assertCount($expectedCount, $productAttributeKeys); + $this->assertEmpty(array_diff($expectedProductAttributeKeys, $productAttributeKeys)); + } +} diff --git a/tests/SprykerTest/Zed/ProductSearch/_support/ProductSearchBusinessTester.php b/tests/SprykerTest/Zed/ProductSearch/_support/ProductSearchBusinessTester.php index 8a681f6..7b70048 100644 --- a/tests/SprykerTest/Zed/ProductSearch/_support/ProductSearchBusinessTester.php +++ b/tests/SprykerTest/Zed/ProductSearch/_support/ProductSearchBusinessTester.php @@ -8,6 +8,7 @@ namespace SprykerTest\Zed\ProductSearch; use Codeception\Actor; +use Orm\Zed\Product\Persistence\SpyProductAttributeKeyQuery; /** * @method void wantToTest($text) @@ -20,10 +21,27 @@ * @method void lookForwardTo($achieveValue) * @method void comment($description) * @method \Codeception\Lib\Friend haveFriend($name, $actorClass = null) + * @method \Spryker\Zed\ProductSearch\Business\ProductSearchFacadeInterface getFacade() * * @SuppressWarnings(PHPMD) */ class ProductSearchBusinessTester extends Actor { use _generated\ProductSearchBusinessTesterActions; + + /** + * @return void + */ + public function ensureProductAttributeKeyTableIsEmpty(): void + { + $this->ensureDatabaseTableIsEmpty($this->createProductAttributeKeyQuery()); + } + + /** + * @return \Orm\Zed\Product\Persistence\SpyProductAttributeKeyQuery + */ + protected function createProductAttributeKeyQuery(): SpyProductAttributeKeyQuery + { + return SpyProductAttributeKeyQuery::create(); + } } diff --git a/tests/SprykerTest/Zed/ProductSearch/codeception.yml b/tests/SprykerTest/Zed/ProductSearch/codeception.yml index 9940b69..ad9eba8 100644 --- a/tests/SprykerTest/Zed/ProductSearch/codeception.yml +++ b/tests/SprykerTest/Zed/ProductSearch/codeception.yml @@ -23,6 +23,9 @@ suites: - \SprykerTest\Shared\Testify\Helper\LocatorHelper - \SprykerTest\Shared\Testify\Helper\DependencyHelper - \SprykerTest\Shared\Propel\Helper\TransactionHelper + - \SprykerTest\Shared\Testify\Helper\DataCleanupHelper + - \SprykerTest\Shared\Testify\Helper\TableRelationsCleanupHelper + - \SprykerTest\Zed\ProductAttribute\Helper\ProductAttributeDataHelper Persistence: path: Persistence