mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
[Behat] Add scenarios for sorting payment metods by position and their implementation
[Behat] Add scenario about viewing sorted payment method during checkout and it's implementation
This commit is contained in:
parent
9894944140
commit
c492802ef7
9 changed files with 129 additions and 11 deletions
|
|
@ -0,0 +1,25 @@
|
|||
@checkout
|
||||
Feature: Sorting payment method selection
|
||||
In order to see the most suitable payment methods first
|
||||
As a Customer
|
||||
I want to have them already sorted
|
||||
|
||||
Background:
|
||||
Given the store operates on a single channel in "United States"
|
||||
And the store has a product "Targaryen T-Shirt" priced at "$19.99"
|
||||
And the store allows shipping with "Aardvark Stagecoach"
|
||||
And the store allows paying with "Paypal Express Checkout" at position 0
|
||||
And the store allows paying with "Cash on Delivery" at position 2
|
||||
And the store allows paying with "Offline" at position 1
|
||||
And I am a logged in customer
|
||||
|
||||
@ui
|
||||
Scenario: Seeing payment methods sorted
|
||||
Given I have product "Targaryen T-Shirt" in the cart
|
||||
When I am at the checkout addressing step
|
||||
And I specify the shipping address as "Ankh Morpork", "Frost Alley", "90210", "United States" for "Jon Snow"
|
||||
And I complete the addressing step
|
||||
And I select "Aardvark Stagecoach" shipping method
|
||||
And I complete the shipping step
|
||||
Then I should have "Paypal Express Checkout" payment method available as the first choice
|
||||
And I should have "Cash on Delivery" payment method available as the last choice
|
||||
|
|
@ -16,14 +16,16 @@ Feature: Sorting listed payment methods
|
|||
And I am logged in as an administrator
|
||||
|
||||
@ui
|
||||
Scenario: Payment methods are sorted by code in ascending order by default
|
||||
When I browse payment methods
|
||||
Scenario: Payment methods can be sorted by their codes
|
||||
Given I am browsing payment methods
|
||||
When I start sorting payment methods by code
|
||||
Then I should see 3 payment methods in the list
|
||||
And the first payment method on the list should have code "cash_on_delivery"
|
||||
|
||||
@ui
|
||||
Scenario: Changing the order of sorting by code
|
||||
Scenario: Changing the order of sorting payment methods by their codes
|
||||
Given I am browsing payment methods
|
||||
And the payment methods are already sorted by code
|
||||
When I switch the way payment methods are sorted by code
|
||||
Then I should see 3 payment methods in the list
|
||||
And the first payment method on the list should have code "offline"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
@managing_payment_methods
|
||||
Feature: Sorting listed payment methods by position
|
||||
In order to change the order by which payment methods are displayed
|
||||
As an Administrator
|
||||
I want to sort payment methods by their positions
|
||||
|
||||
Background:
|
||||
Given the store operates on a single channel in "United States"
|
||||
And the store allows paying with "Paypal Express Checkout" at position 0
|
||||
And the store allows paying with "Offline" at position 1
|
||||
And the store allows paying with "Cash on Delivery" at position 2
|
||||
And I am logged in as an administrator
|
||||
|
||||
@ui
|
||||
Scenario: Payment methods are sorted by position in ascending order by default
|
||||
When I am browsing payment methods
|
||||
Then I should see 3 payment methods in the list
|
||||
And the first payment method on the list should have name "Paypal Express Checkout"
|
||||
And the last payment method on the list should have name "Cash on Delivery"
|
||||
|
||||
@ui
|
||||
Scenario: Payment method added at no position is added as the last one
|
||||
Given the store also allows paying with "Credit Card"
|
||||
When I browse payment methods
|
||||
Then the last payment method on the list should have name "Credit Card"
|
||||
|
||||
@ui
|
||||
Scenario: Payment method added at position 0 is added as the first one
|
||||
Given the store also allows paying with "Credit Card" at position 0
|
||||
When I browse payment methods
|
||||
Then the first payment method on the list should have name "Credit Card"
|
||||
|
|
@ -83,12 +83,13 @@ final class PaymentContext implements Context
|
|||
}
|
||||
|
||||
/**
|
||||
* @Given the store allows paying :paymentMethodName
|
||||
* @Given the store allows paying with :paymentMethodName
|
||||
* @Given the store (also) allows paying :paymentMethodName
|
||||
* @Given the store (also) allows paying with :paymentMethodName
|
||||
* @Given the store (also) allows paying with :paymentMethodName at position :position
|
||||
*/
|
||||
public function storeAllowsPaying($paymentMethodName)
|
||||
public function storeAllowsPaying($paymentMethodName, $position = null)
|
||||
{
|
||||
$this->createPaymentMethodFromNameAndCode($paymentMethodName, 'PM_'.$paymentMethodName, 'Payment method');
|
||||
$this->createPaymentMethod($paymentMethodName, 'PM_'.$paymentMethodName, 'Payment method', true, $position);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -96,7 +97,7 @@ final class PaymentContext implements Context
|
|||
*/
|
||||
public function theStoreHasAPaymentMethodWithACode($paymentMethodName, $paymentMethodCode)
|
||||
{
|
||||
$this->createPaymentMethodFromNameAndCode($paymentMethodName, $paymentMethodCode);
|
||||
$this->createPaymentMethod($paymentMethodName, $paymentMethodCode);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -140,7 +141,7 @@ final class PaymentContext implements Context
|
|||
*/
|
||||
public function theStoreHasPaymentMethodNotAssignedToAnyChannel($paymentMethodName)
|
||||
{
|
||||
$this->createPaymentMethodFromNameAndCode($paymentMethodName, 'PM_'.$paymentMethodName, 'Payment method', false);
|
||||
$this->createPaymentMethod($paymentMethodName, 'PM_'.$paymentMethodName, 'Payment method', false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -149,12 +150,13 @@ final class PaymentContext implements Context
|
|||
* @param bool $addForCurrentChannel
|
||||
* @param string $description
|
||||
*/
|
||||
private function createPaymentMethodFromNameAndCode($name, $code, $description = '', $addForCurrentChannel = true)
|
||||
private function createPaymentMethod($name, $code, $description = '', $addForCurrentChannel = true, $position = null)
|
||||
{
|
||||
/** @var PaymentMethodInterface $paymentMethod */
|
||||
$paymentMethod = $this->paymentMethodFactory->createNew();
|
||||
$paymentMethod->setName(ucfirst($name));
|
||||
$paymentMethod->setCode($code);
|
||||
$paymentMethod->setPosition($position);
|
||||
$paymentMethod->setGateway($this->paymentMethodNameToGatewayConverter->convert($name));
|
||||
$paymentMethod->setDescription($description);
|
||||
|
||||
|
|
|
|||
|
|
@ -234,6 +234,22 @@ final class ManagingPaymentMethodsContext implements Context
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then the last payment method on the list should have :field :value
|
||||
*/
|
||||
public function theLastPaymentMethodOnTheListShouldHave($field, $value)
|
||||
{
|
||||
$fields = $this->indexPage->getColumnFields($field);
|
||||
$actualValue = end($fields);
|
||||
|
||||
Assert::same(
|
||||
$actualValue,
|
||||
$value,
|
||||
sprintf('Expected last payment method\'s %s to be "%s", but it is "%s".', $field, $value, $actualValue)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @When I switch the way payment methods are sorted by :field
|
||||
* @When I start sorting payment methods by :field
|
||||
|
|
|
|||
|
|
@ -1340,6 +1340,28 @@ final class CheckoutContext implements Context
|
|||
Assert::true($this->addressComparator->equal($address, $this->addressPage->getPreFilledBillingAddress()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should have :paymentMethodName payment method available as the first choice
|
||||
*/
|
||||
public function iShouldHavePaymentMethodAvailableAsFirstChoice($paymentMethodName)
|
||||
{
|
||||
$paymentMethods = $this->selectPaymentPage->getPaymentMethods();
|
||||
$firstPaymentMethod = reset($paymentMethods);
|
||||
|
||||
Assert::same($paymentMethodName, $firstPaymentMethod);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should have :paymentMethodName payment method available as the last choice
|
||||
*/
|
||||
public function iShouldHavePaymentMethodAvailableAsLastChoice($paymentMethodName)
|
||||
{
|
||||
$paymentMethods = $this->selectPaymentPage->getPaymentMethods();
|
||||
$lastPaymentMethod = end($paymentMethods);
|
||||
|
||||
Assert::same($paymentMethodName, $lastPaymentMethod);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return AddressInterface
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -105,6 +105,21 @@ class SelectPaymentPage extends SymfonyPage implements SelectPaymentPageInterfac
|
|||
return $this->getElement('next_step')->hasClass('disabled');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPaymentMethods()
|
||||
{
|
||||
$inputs = $this->getSession()->getPage()->findAll('css', '#payment_methods .item .content label');
|
||||
|
||||
$paymentMethods = [];
|
||||
foreach ($inputs as $input) {
|
||||
$paymentMethods[] = trim($input->getText());
|
||||
}
|
||||
|
||||
return $paymentMethods;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -54,4 +54,9 @@ interface SelectPaymentPageInterface extends SymfonyPageInterface
|
|||
* @return bool
|
||||
*/
|
||||
public function isNextStepButtonUnavailable();
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getPaymentMethods();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
{% include '@SyliusShop/Checkout/_steps.html.twig' with {'active': 'select_payment'} %}
|
||||
<div class="ui stackable grid">
|
||||
<div class="eleven wide column">
|
||||
<div class="ui padded segment" id="shipping_methods">
|
||||
<div class="ui padded segment" id="payment_methods">
|
||||
{{ form_start(form, {'action': path('sylius_shop_checkout_select_payment'), 'attr': {'class': 'ui loadable form', 'novalidate': 'novalidate'}}) }}
|
||||
<input type="hidden" name="_method" value="PUT" />
|
||||
{% include '@SyliusShop/Checkout/SelectPayment/_form.html.twig' %}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue