Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,40 @@ Feature: Creating a catalog promotion
And it should have "winter_sale" code and "Winter sale" name

@api @ui @javascript
Scenario: Creating a catalog promotion
Scenario: Creating an enabled catalog promotion
When I want to create a new catalog promotion
And I specify its code as "winter_sale"
And I name it "Winter sale"
And I specify its label as "Winter -50%" in "English (United States)"
And I describe it as "This promotion gives a 50% discount on all products" in "English (United States)"
And I add rule that applies on variants "PHP T-Shirt" variant and "Kotlin T-Shirt" variant
And I add action that gives "50%" percentage discount
And I make it available in channel "United States"
And I enable this catalog promotion
And I add it
Then there should be 1 new catalog promotion on the list
And it should have "winter_sale" code and "Winter sale" name
And "Winter sale" catalog promotion should apply to "PHP T-Shirt" variant and "Kotlin T-Shirt" variant
And it should have "50%" discount
And this catalog promotion should be usable
And "PHP T-Shirt" variant and "Kotlin T-Shirt" variant should be discounted

@api @ui @javascript
Scenario: Creating a disabled catalog promotion
When I want to create a new catalog promotion
And I specify its code as "winter_sale"
And I name it "Winter sale"
And I specify its label as "Winter -50%" in "English (United States)"
And I describe it as "This promotion gives a 50% discount on all products" in "English (United States)"
And I add rule that applies on variants "PHP T-Shirt" variant and "Kotlin T-Shirt" variant
And I add action that gives "50%" percentage discount
And I disable this catalog promotion
And I add it
Then there should be 1 new catalog promotion on the list
And it should have "winter_sale" code and "Winter sale" name
And "Winter sale" catalog promotion should apply to "PHP T-Shirt" variant and "Kotlin T-Shirt" variant
And it should have "50%" discount
And "PHP T-Shirt" variant and "Kotlin T-Shirt" variant should not be discounted

@api @ui
Scenario: Creating a catalog promotion for channel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ Feature: Editing catalog promotion

Background:
Given the store operates on a single channel in "United States"
And the store operates on a channel named "Europe"
And the store has a "T-Shirt" configurable product
And this product has "PHP T-Shirt" variant priced at "$20.00"
And this product has "Kotlin T-Shirt" variant priced at "$40.00"
And there is a catalog promotion with "christmas_sale" code and "Christmas sale" name
And it applies on "PHP T-Shirt" variant
And it reduces price by "30%"
And it is enabled
And I am logged in as an administrator

@api @ui
Expand All @@ -33,6 +33,7 @@ Feature: Editing catalog promotion
@api @ui
Scenario: Changing availability in channels for catalog promotion
Given the catalog promotion "Christmas sale" is available in "United States"
And the store operates on a channel named "Europe"
When I want to modify a catalog promotion "Christmas sale"
And I make it available in channel "Europe"
And I make it unavailable in channel "United States"
Expand All @@ -57,3 +58,14 @@ Feature: Editing catalog promotion
When I edit "Christmas sale" catalog promotion to have "40%" discount
Then I should be notified that it has been successfully edited
And this catalog promotion should have "40%" percentage discount

@api @ui
Scenario: Disabling catalog promotion
When I disable "Christmas sale" catalog promotion
Then "PHP T-Shirt" variant should not be discounted

@api @ui
Scenario: Enabling catalog promotion
Given this catalog promotion is disabled
When I enable "Christmas sale" catalog promotion
Then "PHP T-Shirt" variant should be discounted
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,22 @@ public function iSpecifyItsAsIn(string $field, string $value, string $localeCode
$this->client->updateRequestData($data);
}

/**
* @When I disable this catalog promotion
*/
public function iDisableCatalogPromotion(): void
{
$this->client->updateRequestData(['enabled' => false]);
}

/**
* @When I enable this catalog promotion
*/
public function iEnableThisCatalogPromotion(): void
{
$this->client->updateRequestData(['enabled' => true]);
}

/**
* @When I describe it as :description in :localeCode
*/
Expand Down Expand Up @@ -285,6 +301,22 @@ public function iEditCatalogPromotionToBeAppliedOn(CatalogPromotionInterface $ca
$this->client->update();
}

/**
* @When /^I disable ("[^"]*" catalog promotion)$/
*/
public function iDisableThisCatalogPromotion(CatalogPromotionInterface $catalogPromotion): void
{
$this->toggleCatalogPromotion($catalogPromotion, false);
}

/**
* @When /^I enable ("[^"]*" catalog promotion)$/
*/
public function iEnableCatalogPromotion(CatalogPromotionInterface $catalogPromotion): void
{
$this->toggleCatalogPromotion($catalogPromotion, true);
}

/**
* @When /^I edit ("[^"]+" catalog promotion) to have ("[^"]+") discount$/
*/
Expand Down Expand Up @@ -756,4 +788,12 @@ private function hasVariantInConfiguration(array $configuration, ProductVariantI

return false;
}

private function toggleCatalogPromotion(CatalogPromotionInterface $catalogPromotion, bool $enabled): void
{
$this->client->buildUpdateRequest($catalogPromotion->getCode());

$this->client->updateRequestData(['enabled' => $enabled]);
$this->client->update();
}
}
38 changes: 38 additions & 0 deletions src/Sylius/Behat/Context/Api/Shop/ProductVariantContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,44 @@ public function iShouldSeeThisVariantIsNotDiscounted(): void
Assert::keyNotExists($content, 'appliedPromotions');
}

/**
* @Then /^("[^"]+" variant) and ("[^"]+" variant) should be discounted$/
* @Then /^("[^"]+" variant) should be discounted$/
*/
public function variantAndVariantShouldBeDiscounted(ProductVariantInterface ...$variants): void
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it won't be better to check that in admin endpoints 🤔

{
$this->sharedStorage->set('token', null);

/** @var ProductVariantInterface $variant */
foreach ($variants as $variant) {
$content = $this->responseChecker->getResponseContent($this->client->show($variant->getCode()));
Assert::keyExists(
$content,
'appliedPromotions',
sprintf('%s variant should be discounted', $variant->getName())
);
}
}

/**
* @Then /^("[^"]+" variant) and ("[^"]+" variant) should not be discounted$/
* @Then /^("[^"]+" variant) should not be discounted$/
*/
public function variantAndVariantShouldNotBeDiscounted(ProductVariantInterface ...$variants): void
{
$this->sharedStorage->set('token', null);

/** @var ProductVariantInterface $variant */
foreach ($variants as $variant) {
$content = $this->responseChecker->getResponseContent($this->client->show($variant->getCode()));
Assert::keyNotExists(
$content,
'appliedPromotions',
sprintf('%s variant should not be discounted', $variant->getName())
);
}
}

private function findVariant(?ProductVariantInterface $variant): array
{
$response = $this->client->getLastResponse();
Expand Down
20 changes: 20 additions & 0 deletions src/Sylius/Behat/Context/Setup/CatalogPromotionContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,26 @@ public function thereIsACatalogPromotionWithCodeAndName(string $code, string $na
$this->entityManager->flush();
}

/**
* @Given /^(it) is enabled$/
*/
public function itIsEnabled(CatalogPromotionInterface $catalogPromotion): void
{
$catalogPromotion->setEnabled(true);

$this->entityManager->flush();
}

/**
* @Given /^(this catalog promotion) is disabled$/
*/
public function thisCatalogPromotionIsDisabled(CatalogPromotionInterface $catalogPromotion): void
{
$catalogPromotion->setEnabled(false);

$this->entityManager->flush();
}

/**
* @Given there are catalog promotions named :firstName and :secondName
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,22 @@ public function iDescribeItAsIn(string $description, string $localeCode): void
$this->formElement->describeIt($description, $localeCode);
}

/**
* @When I enable this catalog promotion
*/
public function iEnableCatalogPromotion(): void
{
$this->formElement->changeEnableTo(true);
}

/**
* @When I disable this catalog promotion
*/
public function iDisableThisCatalogPromotion(): void
{
$this->formElement->changeEnableTo(false);
}

/**
* @When I make it available in channel :channelName
*/
Expand Down Expand Up @@ -207,6 +223,26 @@ public function iEditCatalogPromotionToHaveDiscount(CatalogPromotionInterface $c
$this->updatePage->saveChanges();
}

/**
* @When /^I disable ("[^"]*" catalog promotion)$/
*/
public function iDisableCatalogPromotion(CatalogPromotionInterface $catalogPromotion): void
{
$this->updatePage->open(['id' => $catalogPromotion->getId()]);
$this->formElement->changeEnableTo(false);
$this->updatePage->saveChanges();
Comment thread
AdamKasp marked this conversation as resolved.
}

/**
* @When /^I enable ("[^"]*" catalog promotion)$/
*/
public function iEnableThisCatalogPromotion(CatalogPromotionInterface $catalogPromotion): void
{
$this->updatePage->open(['id' => $catalogPromotion->getId()]);
$this->formElement->changeEnableTo(true);
$this->updatePage->saveChanges();
}

/**
* @When I add for variants rule without variants configured
*/
Expand Down
29 changes: 29 additions & 0 deletions src/Sylius/Behat/Context/Ui/Shop/ProductContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,35 @@ public function iTryToOpenProductPage(ProductInterface $product, $localeCode = '
]);
}

/**
* @Then /^("[^"]+" variant) and ("[^"]+" variant) should be discounted$/
* @Then /^("[^"]+" variant) should be discounted$/
*/
public function variantAndVariantShouldBeDiscounted(ProductVariantInterface ...$variants): void
{
/** @var ProductVariantInterface $variant */
foreach ($variants as $variant) {
$this->showPage->open(['slug' => $variant->getProduct()->getTranslation('en_US')->getSlug(), '_locale' => 'en_US']);
$this->showPage->selectVariant($variant->getName());
Assert::greaterThan($this->showPage->getOriginalPrice(), $this->showPage->getPrice());
}
}

/**
* @Then /^("[^"]+" variant) and ("[^"]+" variant) should not be discounted$/
* @Then /^("[^"]+" variant) should not be discounted$/
*/
public function variantAndVariantShouldNotBeDiscounted(ProductVariantInterface ...$variants): void
{
/** @var ProductVariantInterface $variant */
foreach ($variants as $variant) {
$this->showPage->open(['slug' => $variant->getProduct()->getTranslation('en_US')->getSlug(), '_locale' => 'en_US']);
$this->showPage->selectVariant($variant->getName());

Assert::isEmpty($this->showPage->getOriginalPrice());
}
}

/**
* @When I try to reach unexistent product
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public function describeIt(string $description, string $localeCode): void
$this->getElement('description', ['%localeCode%' => $localeCode])->setValue($description);
}

public function changeEnableTo(bool $enabled): void
{
$this->getElement('enabled')->setValue($enabled);
}

public function checkChannel(string $channelName): void
{
$this->getDocument()->checkField($channelName);
Expand Down Expand Up @@ -107,6 +112,7 @@ protected function getDefinedElements(): array
'add_rule_button' => '#rules [data-form-collection="add"]',
'channel' => '#sylius_catalog_promotion_code',
'description' => '#sylius_catalog_promotion_translations_%localeCode%_description',
'enabled' => '#sylius_catalog_promotion_enabled',
'label' => '#sylius_catalog_promotion_translations_%localeCode%_label',
'last_action' => '#actions [data-form-collection="item"]:last-child',
'last_rule' => '#rules [data-form-collection="item"]:last-child',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public function labelIt(string $label, string $localeCode): void;

public function describeIt(string $description, string $localeCode): void;

public function changeEnableTo(bool $enabled): void;

public function checkChannel(string $channelName): void;

public function uncheckChannel(string $channelName): void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ default:
- Sylius\Behat\Context\Setup\CatalogPromotionContext

- sylius.behat.context.api.admin.managing_catalog_promotions
- sylius.behat.context.api.shop.product_variant

filters:
tags: "@managing_catalog_promotions && @api"
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ default:
- Sylius\Behat\Context\Setup\CatalogPromotionContext

- sylius.behat.context.ui.admin.notification
- sylius.behat.context.ui.shop.product
- Sylius\Behat\Context\Ui\Admin\ManagingCatalogPromotionsContext

filters:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ sylius_grid:
label: sylius.ui.channels
options:
template: '@SyliusAdmin/Grid/Field/_channels.html.twig'
enabled:
type: twig
label: sylius.ui.enabled
sortable: ~
options:
template: "@SyliusUi/Grid/Field/enabled.html.twig"
actions:
main:
create:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
{{ form_row(form.code) }}
{{ form_row(form.name) }}
{{ form_row(form.channels) }}
{{ form_row(form.enabled) }}
</div>
<div class="ui segment" id="rules">
{{ form_row(form.rules) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,6 @@ Example configuration for `percentage_discount` action type:
</property>
<property name="rules" writable="true" />
<property name="actions" writable="true" />
<property name="enabled" writable="true" />
</resource>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,10 @@
<group>admin:catalog_promotion:create</group>
<group>admin:catalog_promotion:update</group>
</attribute>
<attribute name="enabled">
<group>admin:catalog_promotion:read</group>
<group>admin:catalog_promotion:create</group>
<group>admin:catalog_promotion:update</group>
</attribute>
</class>
</serializer>
Loading