Skip to content

Commit

Permalink
Add behat tests form combination update with specific shops
Browse files Browse the repository at this point in the history
  • Loading branch information
jolelievre committed Dec 19, 2024
1 parent 59aafc6 commit f7916eb
Show file tree
Hide file tree
Showing 6 changed files with 234 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public function getByShopConstraint(CombinationId $combinationId, ShopConstraint
// Find first shop IDs that is both in the specified list and the valid associated shops
$validShopIds = array_map(fn (ShopId $shopId) => $shopId->getValue(), $associatedShopIds);
foreach ($shopConstraint->getShopIds() as $shopId) {
if (in_array($shopId, $validShopIds)) {
if (in_array($shopId->getValue(), $validShopIds)) {
$defaultShopId = $shopId;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

use Behat\Gherkin\Node\TableNode;
use PHPUnit\Framework\Assert;
use PrestaShop\Decimal\DecimalNumber;
use PrestaShop\PrestaShop\Core\Domain\Product\Combination\CombinationAttributeInformation;
use PrestaShop\PrestaShop\Core\Domain\Product\Combination\QueryResult\EditableCombinationForListing;
use PrestaShop\PrestaShop\Core\Search\Filters\ProductCombinationFilters;
Expand Down Expand Up @@ -287,9 +288,8 @@ private function assertListedCombinationsProperties(array $expectedDataRows, arr
$editableCombinationForListing->isDefault(),
'Unexpected default combination'
);
Assert::assertEquals(
$expectedCombination['impact on price'],
(string) $editableCombinationForListing->getImpactOnPrice(),
Assert::assertTrue(
$editableCombinationForListing->getImpactOnPrice()->equals(new DecimalNumber($expectedCombination['impact on price'])),
'Unexpected combination impact on price'
);
Assert::assertSame(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use PrestaShop\PrestaShop\Core\Domain\Product\Combination\Command\GenerateProductCombinationsCommand;
use PrestaShop\PrestaShop\Core\Domain\Product\Combination\Exception\CannotGenerateCombinationException;
use PrestaShop\PrestaShop\Core\Domain\Product\Exception\InvalidProductTypeException;
use PrestaShop\PrestaShop\Core\Domain\Shop\ValueObject\ShopCollection;
use PrestaShop\PrestaShop\Core\Domain\Shop\ValueObject\ShopConstraint;
use Product;
use Tests\Integration\Behaviour\Features\Context\Util\PrimitiveUtils;
Expand Down Expand Up @@ -67,6 +68,22 @@ public function generateCombinationsForShop(string $shopReference, string $produ
);
}

/**
* @When I generate combinations for product :productReference in shops :shopReferences using following attributes:
*
* @param string $shopReferences
* @param string $productReference
* @param TableNode $table
*/
public function generateCombinationsForShopCollection(string $shopReferences, string $productReference, TableNode $table): void
{
$this->generateCombinations(
$productReference,
$table,
ShopCollection::shops($this->referencesToIds($shopReferences))
);
}

/**
* @When I generate combinations for product :productReference in all shops using following attributes:
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use Behat\Gherkin\Node\TableNode;
use DateTime;
use PrestaShop\PrestaShop\Core\Domain\Product\Combination\Command\UpdateCombinationCommand;
use PrestaShop\PrestaShop\Core\Domain\Shop\ValueObject\ShopCollection;
use PrestaShop\PrestaShop\Core\Domain\Shop\ValueObject\ShopConstraint;
use Tests\Integration\Behaviour\Features\Context\Util\PrimitiveUtils;

Expand Down Expand Up @@ -67,6 +68,22 @@ public function updateCombinationForShop(string $combinationReference, TableNode
);
}

/**
* @When I update combination ":combinationReference" with following values for shops ":shopReferences":
*
* @param string $combinationReference
* @param string $shopReferences
* @param TableNode $tableNode
*/
public function updateCombinationForShopCollection(string $combinationReference, TableNode $tableNode, string $shopReferences): void
{
$this->updateCombination(
$combinationReference,
$tableNode,
ShopCollection::shops($this->referencesToIds($shopReferences))
);
}

/**
* @When I update combination ":combinationReference" with following values for all shops:
*
Expand Down Expand Up @@ -106,6 +123,20 @@ public function setDefaultCombinationForShop(string $combinationReference, strin
);
}

/**
* @When I set combination ":combinationReference" as default for shops ":shopReference"
*
* @param string $combinationReference
* @param string $shopReferences
*/
public function setDefaultCombinationForShopCollection(string $combinationReference, string $shopReferences): void
{
$this->setDefaultCombination(
$combinationReference,
ShopCollection::shops($this->referencesToIds($shopReferences))
);
}

/**
* @When I set combination ":combinationReference" as default for all shops
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use Behat\Gherkin\Node\TableNode;
use PrestaShop\PrestaShop\Core\Domain\Product\Combination\Command\UpdateCombinationStockAvailableCommand;
use PrestaShop\PrestaShop\Core\Domain\Product\Stock\Exception\ProductStockConstraintException;
use PrestaShop\PrestaShop\Core\Domain\Shop\ValueObject\ShopCollection;
use PrestaShop\PrestaShop\Core\Domain\Shop\ValueObject\ShopConstraint;

class UpdateCombinationStockFeatureContext extends AbstractCombinationFeatureContext
Expand Down Expand Up @@ -63,6 +64,21 @@ public function updateStockForShop(
);
}

/**
* @When I update combination :combinationReference stock for shops :shopReferences with following details:
*/
public function updateStockForShopCollection(
string $combinationReference,
string $shopReferences,
TableNode $tableNode
): void {
$this->updateStockAvailable(
$combinationReference,
$tableNode->getRowsHash(),
ShopCollection::shops($this->referencesToIds($shopReferences))
);
}

/**
* @When I update combination ":combinationReference" stock for all shops with following details:
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# ./vendor/bin/behat -c tests/Integration/Behaviour/behat.yml -s product --tags combinations-shop-collection
@restore-products-before-feature
@clear-cache-before-feature
@restore-shops-after-feature
@restore-languages-after-feature
@reset-img-after-feature
@clear-cache-after-feature
@product-multishop
@combinations-shop-collection
Feature: Edit combinations with specific list of shops.
As a BO user I want to be able to edit combinations for specific shops.

Background:
Given I enable multishop feature
And language with iso code "en" is the default one
And language "english" with locale "en-US" exists
And language "french" with locale "fr-FR" exists
And attribute group "Size" named "Size" in en language exists
And attribute group "Color" named "Color" in en language exists
And attribute "S" named "S" in en language exists
And attribute "M" named "M" in en language exists
And attribute "L" named "L" in en language exists
And attribute "White" named "White" in en language exists
And attribute "Black" named "Black" in en language exists
And attribute "Blue" named "Blue" in en language exists
And attribute "Yellow" named "Yellow" in en language exists
And manufacturer studioDesign named "Studio Design" exists
And manufacturer graphicCorner named "Graphic Corner" exists
And following image types should be applicable to products:
| reference | name | width | height |
| cartDefault | cart_default | 125 | 125 |
| homeDefault | home_default | 250 | 250 |
| largeDefault | large_default | 800 | 800 |
| mediumDefault | medium_default | 452 | 452 |
| smallDefault | small_default | 98 | 98 |
And shop "shop1" with name "test_shop" exists
And shop group "default_shop_group" with name "Default" exists
And I add a shop "shop2" with name "test_second_shop" and color "red" for the group "default_shop_group"
And I add a shop group "test_second_shop_group" with name "Test second shop group" and color "green"
And I add a shop "shop3" with name "test_third_shop" and color "blue" for the group "test_second_shop_group"
And I add a shop "shop4" with name "test_shop_without_url" and color "blue" for the group "test_second_shop_group"
And I associate attribute group "Size" with shops "shop1,shop2,shop3,shop4"
And I associate attribute group "Color" with shops "shop1,shop2,shop3,shop4"
And I associate attribute "S" with shops "shop1,shop2,shop3,shop4"
And I associate attribute "M" with shops "shop1,shop2,shop3,shop4"
And I associate attribute "L" with shops "shop1,shop2,shop3,shop4"
And I associate attribute "White" with shops "shop1,shop2,shop3,shop4"
And I associate attribute "Black" with shops "shop1,shop2,shop3,shop4"
And I associate attribute "Blue" with shops "shop1,shop2,shop3,shop4"
And I associate attribute "Yellow" with shops "shop1,shop2,shop3,shop4"
And single shop context is loaded
And language "french" with locale "fr-FR" exists
And I add product "product" to shop "shop1" with following information:
| name[en-US] | magic staff |
| type | standard |
And default shop for product product is shop1
And I set following shops for product "product":
| source shop | shop1 |
| shops | shop1,shop2,shop3,shop4 |
Then product product is associated to shops "shop1,shop2,shop3,shop4"
And product "product" should have no images

Scenario: I can generate combinations for specific shops and edit them
Given I add product "product" with following information:
| name[en-US] | universal T-shirt |
| type | combinations |
And product product type should be combinations
And default shop for product product is shop1
And I set following shops for product "product":
| source shop | shop1 |
| shops | shop1,shop2,shop3,shop4 |
Then product product is associated to shops "shop1,shop2,shop3,shop4"
When I generate combinations for product product in shops "shop1,shop3" using following attributes:
| Size | [L] |
| Color | [White,Black,Yellow] |
Then product "product" should have the following combinations for shops "shop1,shop3":
| id reference | combination name | reference | attributes | impact on price | quantity | is default |
| productLWhite | Size - L, Color - White | | [Size:L,Color:White] | 0 | 0 | true |
| productLBlack | Size - L, Color - Black | | [Size:L,Color:Black] | 0 | 0 | false |
| productLYellow | Size - L, Color - Yellow | | [Size:L,Color:Yellow] | 0 | 0 | false |
And product "product" should have no combinations for shops "shop2,shop4"
When I generate combinations for product product in shops "shop2,shop3" using following attributes:
| Size | [L,M] |
| Color | [Black,Blue] |
Then product "product" should have the following combinations for shop "shop1":
| id reference | combination name | reference | attributes | impact on price | quantity | is default |
| productLWhite | Size - L, Color - White | | [Size:L,Color:White] | 0 | 0 | true |
| productLBlack | Size - L, Color - Black | | [Size:L,Color:Black] | 0 | 0 | false |
| productLYellow | Size - L, Color - Yellow | | [Size:L,Color:Yellow] | 0 | 0 | false |
And product "product" should have the following combinations for shop "shop2":
| id reference | combination name | reference | attributes | impact on price | quantity | is default |
| productLBlack | Size - L, Color - Black | | [Size:L,Color:Black] | 0 | 0 | true |
| productLBlue | Size - L, Color - Blue | | [Size:L,Color:Blue] | 0 | 0 | false |
| productMBlack | Size - M, Color - Black | | [Size:M,Color:Black] | 0 | 0 | false |
| productMBlue | Size - M, Color - Blue | | [Size:M,Color:Blue] | 0 | 0 | false |
And product "product" should have the following combinations for shop "shop3":
| id reference | combination name | reference | attributes | impact on price | quantity | is default |
| productLWhite | Size - L, Color - White | | [Size:L,Color:White] | 0 | 0 | true |
| productLBlack | Size - L, Color - Black | | [Size:L,Color:Black] | 0 | 0 | false |
| productLYellow | Size - L, Color - Yellow | | [Size:L,Color:Yellow] | 0 | 0 | false |
| productLBlue | Size - L, Color - Blue | | [Size:L,Color:Blue] | 0 | 0 | false |
| productMBlack | Size - M, Color - Black | | [Size:M,Color:Black] | 0 | 0 | false |
| productMBlue | Size - M, Color - Blue | | [Size:M,Color:Blue] | 0 | 0 | false |
And product "product" should have no combinations for shops "shop4"
# Update default combinations on two shops
When I set combination "productLYellow" as default for shops "shop1,shop3"
And I set combination "productLBlue" as default for shops "shop2"
Then product "product" should have the following combinations for shop "shop1":
| id reference | combination name | reference | attributes | impact on price | quantity | is default |
| productLWhite | Size - L, Color - White | | [Size:L,Color:White] | 0 | 0 | false |
| productLBlack | Size - L, Color - Black | | [Size:L,Color:Black] | 0 | 0 | false |
| productLYellow | Size - L, Color - Yellow | | [Size:L,Color:Yellow] | 0 | 0 | true |
And product "product" should have the following combinations for shop "shop2":
| id reference | combination name | reference | attributes | impact on price | quantity | is default |
| productLBlack | Size - L, Color - Black | | [Size:L,Color:Black] | 0 | 0 | false |
| productLBlue | Size - L, Color - Blue | | [Size:L,Color:Blue] | 0 | 0 | true |
| productMBlack | Size - M, Color - Black | | [Size:M,Color:Black] | 0 | 0 | false |
| productMBlue | Size - M, Color - Blue | | [Size:M,Color:Blue] | 0 | 0 | false |
And product "product" should have the following combinations for shop "shop3":
| id reference | combination name | reference | attributes | impact on price | quantity | is default |
| productLWhite | Size - L, Color - White | | [Size:L,Color:White] | 0 | 0 | false |
| productLBlack | Size - L, Color - Black | | [Size:L,Color:Black] | 0 | 0 | false |
| productLYellow | Size - L, Color - Yellow | | [Size:L,Color:Yellow] | 0 | 0 | true |
| productLBlue | Size - L, Color - Blue | | [Size:L,Color:Blue] | 0 | 0 | false |
| productMBlack | Size - M, Color - Black | | [Size:M,Color:Black] | 0 | 0 | false |
| productMBlue | Size - M, Color - Blue | | [Size:M,Color:Blue] | 0 | 0 | false |
And product "product" should have no combinations for shops "shop4"
# Update infos for shop2 and shop3
When I update combination "productLBlack" with following values for shops "shop2,shop3":
| reference | ABC |
| ean13 | 978020137962 |
| isbn | 978-3-16-148410-0 |
| mpn | mpn1 |
| upc | 72527273070 |
| impact on weight | 17.25 |
| eco tax | 0.5 |
| impact on price | 10.50 |
| impact on unit price | 0.5 |
| wholesale price | 20 |
| minimal quantity | 10 |
| low stock threshold | 10 |
| low stock alert is enabled | true |
| available date | 2021-10-10 |
# But update quantity for shop1 and shop2
When I update combination "productLBlack" stock for shops "shop1,shop2" with following details:
| fixed quantity | 10 |
Then product "product" should have the following combinations for shop "shop1":
| id reference | combination name | reference | attributes | impact on price | quantity | is default |
| productLWhite | Size - L, Color - White | | [Size:L,Color:White] | 0 | 0 | false |
| productLBlack | Size - L, Color - Black | ABC | [Size:L,Color:Black] | 0 | 10 | false |
| productLYellow | Size - L, Color - Yellow | | [Size:L,Color:Yellow] | 0 | 0 | true |
And product "product" should have the following combinations for shop "shop2":
| id reference | combination name | reference | attributes | impact on price | quantity | is default |
| productLBlack | Size - L, Color - Black | ABC | [Size:L,Color:Black] | 10.5 | 10 | false |
| productLBlue | Size - L, Color - Blue | | [Size:L,Color:Blue] | 0 | 0 | true |
| productMBlack | Size - M, Color - Black | | [Size:M,Color:Black] | 0 | 0 | false |
| productMBlue | Size - M, Color - Blue | | [Size:M,Color:Blue] | 0 | 0 | false |
And product "product" should have the following combinations for shop "shop3":
| id reference | combination name | reference | attributes | impact on price | quantity | is default |
| productLWhite | Size - L, Color - White | | [Size:L,Color:White] | 0 | 0 | false |
| productLBlack | Size - L, Color - Black | ABC | [Size:L,Color:Black] | 10.50 | 0 | false |
| productLYellow | Size - L, Color - Yellow | | [Size:L,Color:Yellow] | 0 | 0 | true |
| productLBlue | Size - L, Color - Blue | | [Size:L,Color:Blue] | 0 | 0 | false |
| productMBlack | Size - M, Color - Black | | [Size:M,Color:Black] | 0 | 0 | false |
| productMBlue | Size - M, Color - Blue | | [Size:M,Color:Blue] | 0 | 0 | false |
And product "product" should have no combinations for shops "shop4"

0 comments on commit f7916eb

Please sign in to comment.