Skip to content

Commit

Permalink
CC-16898 Added server-side validation for product category filters. (…
Browse files Browse the repository at this point in the history
…#9491)

CC-16898 Fixed missing server-side validation for product category filters.
  • Loading branch information
romanhavrylko committed Jul 20, 2022
1 parent c36f751 commit 0978543
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 0 deletions.
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -28,6 +28,7 @@
"spryker/application": "*",
"spryker/code-sniffer": "*",
"spryker/config": "*",
"spryker/product-attribute": "*",
"spryker/propel": "*",
"spryker/testify": "*",
"spryker/zed-navigation": "*"
Expand Down
12 changes: 12 additions & 0 deletions src/Spryker/Zed/ProductSearch/Business/ProductSearchFacade.php
Expand Up @@ -438,4 +438,16 @@ public function expandProductConcreteTransfersWithIsSearchable(array $productCon
->createProductConcreteSearchReader()
->expandProductConcreteTransfersWithIsSearchable($productConcreteTransfers);
}

/**
* {@inheritDoc}
*
* @api
*
* @return array<string>
*/
public function getAllProductAttributeKeys(): array
{
return $this->getRepository()->getAllProductAttributeKeys();
}
}
Expand Up @@ -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<string>
*/
public function getAllProductAttributeKeys(): array;
}
Expand Up @@ -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()
Expand Down Expand Up @@ -54,4 +56,16 @@ public function getProductSearchEntitiesCountGroupedByIdProductAndIdLocale(array

return $result;
}

/**
* @return array<string>
*/
public function getAllProductAttributeKeys(): array
{
return $this->getFactory()
->createProductAttributeKeyQuery()
->addSelectColumn(SpyProductAttributeKeyTableMap::COL_KEY)
->setFormatter(new PropelArraySetFormatter())
->find();
}
}
Expand Up @@ -25,4 +25,9 @@ public function getProductSearchEntitiesCountGroupedByIdProductAndIdLocale(
array $productIds,
array $localeIds
): array;

/**
* @return array<string>
*/
public function getAllProductAttributeKeys(): array;
}
@@ -0,0 +1,53 @@
<?php

/**
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace SprykerTest\Zed\ProductSearch\Business\ProductSearchFacade;

use Codeception\Test\Unit;
use SprykerTest\Zed\ProductSearch\ProductSearchBusinessTester;

/**
* Auto-generated group annotations
*
* @group SprykerTest
* @group Zed
* @group ProductSearch
* @group Business
* @group ProductSearchFacade
* @group GetAllProductAttributeKeysTest
*
* Add your own group annotations below this line
*/
class GetAllProductAttributeKeysTest extends Unit
{
/**
* @var \SprykerTest\Zed\ProductSearch\ProductSearchBusinessTester
*/
protected ProductSearchBusinessTester $tester;

/**
* @return void
*/
public function testGetAllProductAttributeKeysShouldReturnAttributeKeys(): void
{
// Arrange
$this->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));
}
}
Expand Up @@ -8,6 +8,7 @@
namespace SprykerTest\Zed\ProductSearch;

use Codeception\Actor;
use Orm\Zed\Product\Persistence\SpyProductAttributeKeyQuery;

/**
* @method void wantToTest($text)
Expand All @@ -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();
}
}
3 changes: 3 additions & 0 deletions tests/SprykerTest/Zed/ProductSearch/codeception.yml
Expand Up @@ -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
Expand Down

0 comments on commit 0978543

Please sign in to comment.