Skip to content

Commit

Permalink
SUPESC-654 Fixed product lists data publishing issue (#9914)
Browse files Browse the repository at this point in the history
SUPESC-654 Fixed product lists data publishing issue
  • Loading branch information
DmitryLymarenko authored Feb 2, 2023
1 parent 0afd11d commit f2cf0c5
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,17 @@ public function getCategoryWhitelistIdsByIdProductAbstract(int $idProductAbstrac
*/
public function getProductBlacklistIdsByIdProduct(int $idProduct): array
{
return array_unique(
array_merge(
$this->productListRepository->getProductConcreteProductListIdsForType(
$idProduct,
SpyProductListTableMap::COL_TYPE_BLACKLIST,
),
$this->productListRepository->getProductConcreteProductListIdsRelatedToCategoriesForType(
$idProduct,
SpyProductListTableMap::COL_TYPE_BLACKLIST,
return array_values(
array_unique(
array_merge(
$this->productListRepository->getProductConcreteProductListIdsForType(
$idProduct,
SpyProductListTableMap::COL_TYPE_BLACKLIST,
),
$this->productListRepository->getProductConcreteProductListIdsRelatedToCategoriesForType(
$idProduct,
SpyProductListTableMap::COL_TYPE_BLACKLIST,
),
),
),
);
Expand All @@ -152,15 +154,17 @@ public function getProductBlacklistIdsByIdProduct(int $idProduct): array
*/
public function getProductWhitelistIdsByIdProduct(int $idProduct): array
{
return array_unique(
array_merge(
$this->productListRepository->getProductConcreteProductListIdsForType(
$idProduct,
SpyProductListTableMap::COL_TYPE_WHITELIST,
),
$this->productListRepository->getProductConcreteProductListIdsRelatedToCategoriesForType(
$idProduct,
SpyProductListTableMap::COL_TYPE_WHITELIST,
return array_values(
array_unique(
array_merge(
$this->productListRepository->getProductConcreteProductListIdsForType(
$idProduct,
SpyProductListTableMap::COL_TYPE_WHITELIST,
),
$this->productListRepository->getProductConcreteProductListIdsRelatedToCategoriesForType(
$idProduct,
SpyProductListTableMap::COL_TYPE_WHITELIST,
),
),
),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?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\ProductList\Business\ProductList;

use Codeception\Test\Unit;
use Spryker\Zed\ProductList\Business\ProductList\ProductListReader;
use Spryker\Zed\ProductList\Business\ProductList\ProductListReaderInterface;
use Spryker\Zed\ProductList\Business\ProductListCategoryRelation\ProductListCategoryRelationReaderInterface;
use Spryker\Zed\ProductList\Business\ProductListProductConcreteRelation\ProductListProductConcreteRelationReaderInterface;
use Spryker\Zed\ProductList\Dependency\Facade\ProductListToProductFacadeInterface;
use Spryker\Zed\ProductList\Persistence\ProductListRepositoryInterface;

/**
* Auto-generated group annotations
*
* @group SprykerTest
* @group Zed
* @group ProductList
* @group Business
* @group ProductList
* @group ProductListReaderTest
* Add your own group annotations below this line
*/
class ProductListReaderTest extends Unit
{
/**
* @dataProvider productListIdsDataProvider
*
* @param array<int> $productListIdsByProduct
* @param array<int> $productListIdsByCategory
*
* @return void
*/
public function testGetProductWhitelistIdsByIdProductReturnsIndexedArray(
array $productListIdsByProduct,
array $productListIdsByCategory
): void {
// Arrange
$productListReader = $this->createProductListReader($productListIdsByProduct, $productListIdsByCategory);

// Act
$productListIds = $productListReader->getProductWhitelistIdsByIdProduct(1);

// Assert
$this->assertTrue(
array_values($productListIds) === $productListIds,
);
}

/**
* @dataProvider productListIdsDataProvider
*
* @param array<int> $productListIdsByProduct
* @param array<int> $productListIdsByCategory
*
* @return void
*/
public function testGetProductBlacklistIdsByIdProductReturnsIndexedArray(
array $productListIdsByProduct,
array $productListIdsByCategory
): void {
// Arrange
$productListReader = $this->createProductListReader($productListIdsByProduct, $productListIdsByCategory);

// Act
$productListIds = $productListReader->getProductBlacklistIdsByIdProduct(1);

// Assert
$this->assertTrue(
array_values($productListIds) === $productListIds,
);
}

/**
* @return array<array>
*/
protected function productListIdsDataProvider(): array
{
return [
[
[1, 2, 3], [4, 5, 6],
],

[
[1, 2, 3], [2, 5, 6],
],
];
}

/**
* @param array<int> $productListIdsByProduct
* @param array<int> $productListIdsByCategory
*
* @return \Spryker\Zed\ProductList\Business\ProductList\ProductListReaderInterface
*/
protected function createProductListReader(
array $productListIdsByProduct,
array $productListIdsByCategory
): ProductListReaderInterface {
$productListRepositoryMock = $this->getMockBuilder(ProductListRepositoryInterface::class)->getMock();
$productListRepositoryMock->method('getProductConcreteProductListIdsForType')->willReturn($productListIdsByProduct);
$productListRepositoryMock->method('getProductConcreteProductListIdsRelatedToCategoriesForType')->willReturn($productListIdsByCategory);

$productListCategoryRelationReaderMock = $this->getMockBuilder(ProductListCategoryRelationReaderInterface::class)->getMock();
$productListProductConcreteRelationReaderMock = $this->getMockBuilder(ProductListProductConcreteRelationReaderInterface::class)->getMock();
$productListToProductFacade = $this->getMockBuilder(ProductListToProductFacadeInterface::class)->getMock();

return new ProductListReader(
$productListRepositoryMock,
$productListCategoryRelationReaderMock,
$productListProductConcreteRelationReaderMock,
$productListToProductFacade,
);
}
}

0 comments on commit f2cf0c5

Please sign in to comment.