Cover the scenario for allowing access for only correctly logged in users

This commit is contained in:
Kamil Grygierzec 2024-09-05 17:14:12 +02:00
parent 9833bd8ee8
commit 736c65dd8c
No known key found for this signature in database
GPG key ID: 7F54EE42DAD4B9E9
9 changed files with 163 additions and 29 deletions

View file

@ -10,12 +10,12 @@ Feature: Allowing access only for correctly logged in users
And the store allows paying Offline
And the store has "UPS" shipping method with "$20.00" fee
@api
@api @ui
Scenario: Accessing to the cart by the visitor
When the visitor adds "Stark T-Shirt" product to the cart
Then the visitor can see "Stark T-Shirt" product in the cart
@api
@api @ui
Scenario: Accessing to add address to the cart by the visitor
Given the visitor has product "Stark T-Shirt" in the cart
When the visitor specify the email as "jon.snow@example.com"
@ -23,7 +23,7 @@ Feature: Allowing access only for correctly logged in users
And the visitor completes the addressing step
Then the visitor should have checkout address step completed
@api
@api @ui
Scenario: Accessing to add shipping method to the cart by the visitor
Given the visitor has product "Stark T-Shirt" in the cart
And the visitor has specified the email as "jon.snow@example.com"
@ -32,7 +32,7 @@ Feature: Allowing access only for correctly logged in users
When the visitor proceed with "UPS" shipping method
Then the visitor should have checkout shipping method step completed
@api
@api @ui
Scenario: Accessing to add payment method to the cart by the visitor
Given the visitor has product "Stark T-Shirt" in the cart
And the visitor has specified the email as "jon.snow@example.com"
@ -42,7 +42,7 @@ Feature: Allowing access only for correctly logged in users
When the visitor proceed with "Offline" payment
Then the visitor should have checkout payment step completed
@api
@api @ui
Scenario: Accessing to complete the cart by the visitor
Given the visitor has product "Stark T-Shirt" in the cart
And the visitor has specified the email as "jon.snow@example.com"
@ -53,19 +53,19 @@ Feature: Allowing access only for correctly logged in users
When the visitor confirm his order
Then the visitor should see the thank you page
@api
@api @ui
Scenario: Accessing to increase quantity of an item in the cart by the visitor
Given the visitor has product "Stark T-Shirt" in the cart
When the visitor change product "Stark T-Shirt" quantity to 2 in his cart
Then the visitor should see product "Stark T-Shirt" with quantity 2 in his cart
@api
@api @ui
Scenario: Accessing to the cart by the logged in customer
Given the customer logged in
When the customer adds "Stark T-Shirt" product to the cart
Then the customer can see "Stark T-Shirt" product in the cart
@api
@api @ui
Scenario: Accessing to add address to the cart by the customer
Given the customer logged in
And the customer has product "Stark T-Shirt" in the cart
@ -73,17 +73,16 @@ Feature: Allowing access only for correctly logged in users
And the customer completes the addressing step
Then the customer should have checkout address step completed
@api
@api @ui
Scenario: Accessing to add shipping method to the cart by the customer
Given the customer logged in
And the customer has product "Stark T-Shirt" in the cart
And the customer has specified the email as "jon.snow@example.com"
And the customer has specified address as "Ankh Morpork", "Frost Alley", "90210", "United States" for "Jon Snow"
And the customer has completed the addressing step
When the customer proceed with "UPS" shipping method
Then the customer should have checkout shipping method step completed
@api
@api @ui
Scenario: Accessing to add payment method to the cart by the customer
Given the customer logged in
And the customer has product "Stark T-Shirt" in the cart
@ -93,7 +92,7 @@ Feature: Allowing access only for correctly logged in users
When the customer proceed with "Offline" payment
Then the customer should have checkout payment step completed
@api
@api @ui
Scenario: Accessing to complete the cart by the customer
Given the customer logged in
And the customer has product "Stark T-Shirt" in the cart
@ -104,13 +103,13 @@ Feature: Allowing access only for correctly logged in users
When the customer confirm his order
Then the customer should see the thank you page
@api
@api @ui
Scenario: Accessing to increase quantity of an item in the cart by the customer
Given the customer has product "Stark T-Shirt" in the cart
When the customer change product "Stark T-Shirt" quantity to 2 in his cart
Then the customer should see product "Stark T-Shirt" with quantity 2 in his cart
@api
@api @no-ui
Scenario: Denying access to the customers cart by the visitor
Given the customer logged in
And the customer has product "Stark T-Shirt" in the cart
@ -119,7 +118,7 @@ Feature: Allowing access only for correctly logged in users
When the visitor try to see the summary of customer's cart
Then the visitor has no access to customer's cart
@api
@api @no-ui
Scenario: Denying access to add product to the customer cart by the visitor
Given the customer logged in
And the customer has created empty cart
@ -127,7 +126,7 @@ Feature: Allowing access only for correctly logged in users
When the visitor try to add product "Stark T-Shirt" in the customer cart
Then the visitor has no access to customer's cart
@api
@api @no-ui
Scenario: Denying access to add address to the customer cart by the visitor
Given the customer logged in
And the customer has product "Stark T-Shirt" in the cart
@ -136,7 +135,7 @@ Feature: Allowing access only for correctly logged in users
And the visitor try to complete the addressing step in the customer cart
Then the visitor has no access to customer's cart
@api
@api @no-ui
Scenario: Denying access to add shipping method to the customer cart by the visitor
Given the customer logged in
And the customer has product "Stark T-Shirt" in the cart
@ -145,7 +144,7 @@ Feature: Allowing access only for correctly logged in users
And the customer logged out
Then the visitor has no access to proceed with "UPS" shipping method in the customer cart
@api
@api @no-ui
Scenario: Denying access to add payment method to the customer cart by the visitor
Given the customer logged in
And the customer has product "Stark T-Shirt" in the cart
@ -155,7 +154,7 @@ Feature: Allowing access only for correctly logged in users
And the customer logged out
Then the visitor has no access to proceed with "Offline" payment in the customer cart
@api
@api @no-ui
Scenario: Denying access to complete the customer cart by the visitor
Given the customer logged in
And the customer has product "Stark T-Shirt" in the cart
@ -166,7 +165,7 @@ Feature: Allowing access only for correctly logged in users
And the customer logged out
Then the visitor has no access to confirm the customer order
@api
@api @no-ui
Scenario: Denying to increase quantity of an item in the customer cart by the visitor
Given the customer logged in
And the customer has product "Stark T-Shirt" in the cart

View file

@ -116,6 +116,8 @@ final class CartContext implements Context
* @Given I change :productName quantity to :quantity
* @Given I change product :productName quantity to :quantity
* @Given I change product :productName quantity to :quantity in my cart
* @When the customer change product :productName quantity to :quantity in his cart
* @When the visitor change product :productName quantity to :quantity in his cart
*/
public function iChangeQuantityTo(string $productName, string $quantity): void
{
@ -298,6 +300,9 @@ final class CartContext implements Context
* @Given /^I (?:have|had) (product "[^"]+") in the cart$/
* @Given /^the customer (?:added|adds) ("[^"]+" product) to the cart$/
* @Given /^I (?:add|added) ("[^"]+" product) to the (cart)$/
* @Given /^the visitor has (product "[^"]+") in the cart$/
* @Given /^the customer has (product "[^"]+") in the cart$/
* @When /^the visitor adds ("[^"]+" product) to the cart$/
* @When I add product :product to the cart
* @When they add product :product to the cart
*/
@ -480,12 +485,26 @@ final class CartContext implements Context
/**
* @Then /^I should see "([^"]+)" with quantity (\d+) in my cart$/
* @Then /^the visitor should see product "([^"]+)" with quantity (\d+) in his cart$/
* @Then /^the customer should see product "([^"]+)" with quantity (\d+) in his cart$/
*/
public function iShouldSeeWithQuantityInMyCart(string $productName, int $quantity): void
{
Assert::same($this->summaryPage->getQuantity($productName), $quantity);
}
/**
* @Then /^the customer can see "([^"]+)" product in the cart$/
* @Then /^the visitor can see "([^"]+)" product in the cart$/
*/
public function theCustomerCanSeeProductInTheCart(string $productName): void
{
Assert::true(
$this->summaryPage->hasItemNamed($productName),
sprintf('Product with name "%s" was not found in the cart.', $productName)
);
}
/**
* @Then /^I should see(?:| also) "([^"]+)" with unit price ("[^"]+") in my cart$/
* @Then /^I should see(?:| also) "([^"]+)" with discounted unit price ("[^"]+") in my cart$/

View file

@ -36,6 +36,17 @@ final class CheckoutAddressingContext implements Context
) {
}
/**
* @Given the visitor has completed the addressing step
* @Given the customer has completed the addressing step
* @When the customer completes the addressing step
* @When the visitor completes the addressing step
*/
public function theVisitorHasCompletedTheAddressingStep(): void
{
$this->addressPage->nextStep();
}
/**
* @Given my billing address is fulfilled automatically through default address
*/
@ -174,10 +185,18 @@ final class CheckoutAddressingContext implements Context
/**
* @When /^I specify the billing (address as "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)" for "([^"]+)")$/
* @When /^I specify the billing (address for "([^"]+)" from "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)")$/
* @Given /^the customer specify the billing (address as "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)" for "([^"]+)")$/
* @Given /^the visitor specify the billing (address as "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)" for "([^"]+)")$/
* @Given /^the visitor has specified (address as "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)" for "([^"]+)")$/
* @Given /^the customer has specified (address as "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)" for "([^"]+)")$/
* @When /^I (do not specify any billing address) information$/
*/
public function iSpecifyTheBillingAddressAs(AddressInterface $address)
{
if (!$this->addressPage->isOpen()) {
$this->addressPage->open();
}
$key = sprintf(
'billing_address_%s_%s',
strtolower((string) $address->getFirstName()),
@ -228,6 +247,17 @@ final class CheckoutAddressingContext implements Context
$this->addressPage->specifyEmail($email);
}
/**
* @Given the visitor has specified the email as :email
* @Given the customer has specified the email as :email
* @When the visitor specify the email as :email
*/
public function theVisitorSpecifyTheEmail($email = null): void
{
$this->addressPage->open();
$this->addressPage->specifyEmail($email);
}
/**
* @When I specify the first and last name as :fullName for billing address
*/
@ -248,7 +278,7 @@ final class CheckoutAddressingContext implements Context
/**
* @When I go back to store
*/
public function iGoBackToStore()
public function iGoBackToStore(): void
{
$this->addressPage->backToStore();
}
@ -260,7 +290,7 @@ final class CheckoutAddressingContext implements Context
?CountryInterface $shippingCountry = null,
string $localeCode = 'en_US',
?string $email = null,
) {
): void {
$this->addressPage->open(['_locale' => $localeCode]);
$shippingAddress = $this->createDefaultAddress();
if (null !== $shippingCountry) {
@ -294,7 +324,7 @@ final class CheckoutAddressingContext implements Context
/**
* @When I specify the password as :password
*/
public function iSpecifyThePasswordAs($password)
public function iSpecifyThePasswordAs(string $password): void
{
$this->addressPage->specifyPassword($password);
}
@ -310,7 +340,7 @@ final class CheckoutAddressingContext implements Context
/**
* @When I sign in
*/
public function iSignIn()
public function iSignIn(): void
{
$this->addressPage->signIn();
}
@ -318,7 +348,7 @@ final class CheckoutAddressingContext implements Context
/**
* @Then I should have :countryName selected as country
*/
public function iShouldHaveSelectedAsCountry($countryName)
public function iShouldHaveSelectedAsCountry($countryName): void
{
Assert::same($this->addressPage->getShippingAddressCountry(), $countryName);
}
@ -383,7 +413,7 @@ final class CheckoutAddressingContext implements Context
/**
* @Then I should be able to go to the shipping step again
*/
public function iShouldBeAbleToGoToTheShippingStepAgain()
public function iShouldBeAbleToGoToTheShippingStepAgain(): void
{
$this->addressPage->nextStep();
@ -493,9 +523,18 @@ final class CheckoutAddressingContext implements Context
}
/**
* @return AddressInterface
* @Then the customer should have checkout address step completed
* @Then the visitor should have checkout address step completed
*/
private function createDefaultAddress()
public function theCustomerShouldHaveCheckoutAddressStepCompleted(): void
{
Assert::false(
$this->addressPage->isOpen(),
'Customer should have checkout address step completed, but it is not.',
);
}
private function createDefaultAddress(): AddressInterface
{
/** @var AddressInterface $address */
$address = $this->addressFactory->createNew();

View file

@ -76,6 +76,8 @@ final class CheckoutCompleteContext implements Context
/**
* @Given I have confirmed order
* @Given the visitor confirm his order
* @Given the customer confirm his order
* @When I confirm my order
* @When I try to confirm my order
*/

View file

@ -46,6 +46,10 @@ final class CheckoutPaymentContext implements Context
/**
* @Given I completed the payment step with :paymentMethodName payment method
* @Given the visitor has proceeded :paymentMethodName payment
* @Given the customer has proceeded :paymentMethodName payment
* @Given the visitor proceed with :paymentMethodName payment
* @Given the customer proceed with :paymentMethodName payment
* @When /^I choose "([^"]*)" payment method$/
*/
public function iChoosePaymentMethod(string $paymentMethodName): void
@ -177,6 +181,18 @@ final class CheckoutPaymentContext implements Context
}
}
/**
* @Then the customer should have checkout payment step completed
* @Then the visitor should have checkout payment step completed
*/
public function theCustomerShouldHaveCheckoutPaymentStepCompleted(): void
{
Assert::false(
$this->selectPaymentPage->isOpen(),
'Customer should have checkout payment step completed, but it is not.',
);
}
/**
* @Then I should not see :firstPaymentMethodName and :secondPaymentMethodName payment methods
*/

View file

@ -31,7 +31,12 @@ final class CheckoutShippingContext implements Context
}
/**
* @Given the visitor has proceeded :shippingMethodName shipping method
* @Given the customer has proceeded :shippingMethodName shipping method
* @Given the visitor proceed with :shippingMethodName shipping method
* @Given the customer proceed with :shippingMethodName shipping method
* @Given I completed the shipping step with :shippingMethodName shipping method
* @Given I have proceeded with :shippingMethodName shipping method
* @Given I have proceeded selecting :shippingMethodName shipping method
* @When I proceed with :shippingMethodName shipping method
*/
@ -53,12 +58,13 @@ final class CheckoutShippingContext implements Context
/**
* @When I try to open checkout shipping page
*/
public function iTryToOpenCheckoutShippingPage()
public function iTryToOpenCheckoutShippingPage(): void
{
$this->selectShippingPage->tryToOpen();
}
/**
* @When I try to complete the shipping step
* @When /^I(?:| try to) complete(?:|d) the shipping step$/
* @When I complete the shipping step with first shipping method
*/
@ -196,6 +202,18 @@ final class CheckoutShippingContext implements Context
Assert::same($this->selectShippingPage->getPurchaserIdentifier(), 'Checking out as ' . $email . '.');
}
/**
* @Then the customer should have checkout shipping method step completed
* @Then the visitor should have checkout shipping method step completed
*/
public function theCustomerShouldHaveCheckoutShippingMethodStepCompleted()
{
Assert::false(
$this->selectShippingPage->isOpen(),
'Customer should have checkout shipping method step completed, but it is not.',
);
}
/**
* @Then I should not be able to proceed checkout shipping step
*/

View file

@ -61,6 +61,8 @@ final class CheckoutThankYouContext implements Context
/**
* @Then I should see the thank you page
* @Then the visitor should see the thank you page
* @Then the customer should see the thank you page
*/
public function iShouldSeeTheThankYouPage()
{

View file

@ -15,6 +15,7 @@ imports:
- ui/admin/login.yml
- ui/admin/panel.yml
- ui/admin/security.yml
- ui/cart/accessing_cart.yaml
- ui/cart/shopping_cart.yml
- ui/channel/channels.yml
- ui/channel/managing_channels.yml

View file

@ -0,0 +1,38 @@
# This file is part of the Sylius package.
# (c) Sylius Sp. z o.o.
default:
suites:
ui_accessing_cart:
contexts:
- sylius.behat.context.hook.doctrine_orm
- sylius.behat.context.hook.session
- sylius.behat.context.transform.address
- sylius.behat.context.transform.cart
- sylius.behat.context.transform.lexical
- sylius.behat.context.transform.payment
- sylius.behat.context.transform.product
- sylius.behat.context.transform.shared_storage
- sylius.behat.context.transform.shipping_method
- sylius.behat.context.setup.admin_api_security
- sylius.behat.context.setup.channel
- sylius.behat.context.setup.payment
- sylius.behat.context.setup.product
- sylius.behat.context.setup.shipping
- sylius.behat.context.setup.shop_security
- sylius.behat.context.setup.user
- sylius.behat.context.ui.browser
- sylius.behat.context.ui.channel
- sylius.behat.context.ui.shop.cart
- sylius.behat.context.ui.shop.checkout.addressing
- sylius.behat.context.ui.shop.checkout.shipping
- sylius.behat.context.ui.shop.checkout.payment
- sylius.behat.context.ui.shop.checkout.thank_you
- sylius.behat.context.ui.shop.checkout.complete
- sylius.behat.context.ui.user
filters:
tags: "@accessing_cart&&@ui"