Skip to content

Commit

Permalink
Merge pull request #4742 from GSadee/admin-payment-method
Browse files Browse the repository at this point in the history
[Admin][PaymentMethod] Payment method features
  • Loading branch information
Paweł Jędrzejewski committed Apr 21, 2016
2 parents fdb14b0 + 1f3e1bb commit f906b51
Show file tree
Hide file tree
Showing 29 changed files with 1,047 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/config/config_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ sylius_payment:
cc: Credit Card
test: Test
stripe: Stripe
paypal_express_checkout: Paypal Express Checkout

sylius_rbac:
authorization_checker: sylius.authorization_checker.toggleable
Expand Down
1 change: 1 addition & 0 deletions etc/behat/services/contexts/setup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
<argument type="service" id="sylius.repository.payment_method" container="symfony" />
<argument type="service" id="sylius.factory.payment_method" container="symfony" />
<argument type="service" id="sylius.payment_method_name_to_gateway_converter" container="symfony" />
<argument type="service" id="doctrine.orm.entity_manager" container="symfony" />
<tag name="sylius.behat.context" />
</service>

Expand Down
6 changes: 6 additions & 0 deletions etc/behat/services/contexts/transform.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<parameter key="sylius.behat.context.transform.lexical.class">Sylius\Behat\Context\Transform\LexicalContext</parameter>
<parameter key="sylius.behat.context.transform.locale.class">Sylius\Behat\Context\Transform\LocaleContext</parameter>
<parameter key="sylius.behat.context.transform.payment.class">Sylius\Behat\Context\Transform\PaymentContext</parameter>
<parameter key="sylius.behat.context.transform.payment_method.class">Sylius\Behat\Context\Transform\PaymentMethodContext</parameter>
<parameter key="sylius.behat.context.transform.product.class">Sylius\Behat\Context\Transform\ProductContext</parameter>
<parameter key="sylius.behat.context.transform.product_variant.class">Sylius\Behat\Context\Transform\ProductVariantContext</parameter>
<parameter key="sylius.behat.context.transform.promotion.class">Sylius\Behat\Context\Transform\PromotionContext</parameter>
Expand Down Expand Up @@ -76,6 +77,11 @@
<tag name="sylius.behat.context" />
</service>

<service id="sylius.behat.context.transform.payment_method" class="%sylius.behat.context.transform.payment_method.class%" scope="scenario">
<argument type="service" id="sylius.repository.payment_method" container="symfony" />
<tag name="sylius.behat.context" />
</service>

<service id="sylius.behat.context.transform.product" class="%sylius.behat.context.transform.product.class%" scope="scenario">
<argument type="service" id="sylius.repository.product" container="symfony" />
<tag name="sylius.behat.context" />
Expand Down
10 changes: 10 additions & 0 deletions etc/behat/services/contexts/ui.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<parameter key="sylius.behat.context.ui.admin.managing_countries.class">Sylius\Behat\Context\Ui\Admin\ManagingCountriesContext</parameter>
<parameter key="sylius.behat.context.ui.admin.managing_customers.class">Sylius\Behat\Context\Ui\Admin\ManagingCustomersContext</parameter>
<parameter key="sylius.behat.context.ui.admin.managing_locale.class">Sylius\Behat\Context\Ui\Admin\ManagingLocalesContext</parameter>
<parameter key="sylius.behat.context.ui.admin.managing_payment_methods.class">Sylius\Behat\Context\Ui\Admin\ManagingPaymentMethodsContext</parameter>
<parameter key="sylius.behat.context.ui.admin.managing_promotions.class">Sylius\Behat\Context\Ui\Admin\ManagingPromotionsContext</parameter>
<parameter key="sylius.behat.context.ui.admin.managing_shipping_methods.class">Sylius\Behat\Context\Ui\Admin\ManagingShippingMethodsContext</parameter>
<parameter key="sylius.behat.context.ui.admin.managing_tax_category.class">Sylius\Behat\Context\Ui\Admin\ManagingTaxCategoryContext</parameter>
Expand Down Expand Up @@ -57,6 +58,15 @@
<tag name="sylius.behat.context" />
</service>

<service id="sylius.behat.context.ui.admin.managing_payment_methods" class="%sylius.behat.context.ui.admin.managing_payment_methods.class%" scope="scenario">
<argument type="service" id="sylius.behat.page.admin.payment_method.create" />
<argument type="service" id="sylius.behat.page.admin.payment_method.index" />
<argument type="service" id="sylius.behat.page.admin.payment_method.update" />
<argument type="service" id="sylius.behat.current_page_resolver" />
<argument type="service" id="sylius.behat.notification_checker" />
<tag name="sylius.behat.context" />
</service>

<service id="sylius.behat.context.ui.admin.managing_promotions" class="%sylius.behat.context.ui.admin.managing_promotions.class%" scope="scenario">
<argument type="service" id="sylius.behat.page.admin.promotion.index" />
<argument type="service" id="sylius.behat.page.admin.promotion.create" />
Expand Down
12 changes: 12 additions & 0 deletions etc/behat/services/pages.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
<parameter key="sylius.behat.page.admin.locale.create.class">Sylius\Behat\Page\Admin\Locale\CreatePage</parameter>
<parameter key="sylius.behat.page.admin.locale.index.class">Sylius\Behat\Page\Admin\Locale\IndexPage</parameter>
<parameter key="sylius.behat.page.admin.locale.update.class">Sylius\Behat\Page\Admin\Locale\UpdatePage</parameter>
<parameter key="sylius.behat.page.admin.payment_method.create.class">Sylius\Behat\Page\Admin\PaymentMethod\CreatePage</parameter>
<parameter key="sylius.behat.page.admin.payment_method.index.class">%sylius.behat.page.admin.crud.index.class%</parameter>
<parameter key="sylius.behat.page.admin.payment_method.update.class">Sylius\Behat\Page\Admin\PaymentMethod\UpdatePage</parameter>
<parameter key="sylius.behat.page.admin.product.show.class">Sylius\Behat\Page\Admin\Product\ShowPage</parameter>
<parameter key="sylius.behat.page.admin.product.index.class">Sylius\Behat\Page\Admin\Product\IndexPage</parameter>
<parameter key="sylius.behat.page.admin.promotion.create.class">Sylius\Behat\Page\Admin\Promotion\CreatePage</parameter>
Expand Down Expand Up @@ -114,6 +117,15 @@
<service id="sylius.behat.page.admin.locale.update" class="%sylius.behat.page.admin.locale.update.class%" parent="sylius.behat.page.admin.crud.update" scope="scenario" public="false">
<argument type="string">locale</argument>
</service>
<service id="sylius.behat.page.admin.payment_method.create" class="%sylius.behat.page.admin.payment_method.create.class%" parent="sylius.behat.page.admin.crud.create" scope="scenario" public="false">
<argument type="string">payment_method</argument>
</service>
<service id="sylius.behat.page.admin.payment_method.index" class="%sylius.behat.page.admin.payment_method.index.class%" parent="sylius.behat.page.admin.crud.index" scope="scenario" public="false">
<argument type="string">payment_method</argument>
</service>
<service id="sylius.behat.page.admin.payment_method.update" class="%sylius.behat.page.admin.payment_method.update.class%" parent="sylius.behat.page.admin.crud.update" scope="scenario" public="false">
<argument type="string">payment_method</argument>
</service>
<service id="sylius.behat.page.admin.shipping_method.create" class="%sylius.behat.page.admin.shipping_method.create.class%" parent="sylius.behat.page.admin.crud.create" scope="scenario" public="false">
<argument type="string">shipping_method</argument>
</service>
Expand Down
1 change: 1 addition & 0 deletions etc/behat/suites.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ imports:
- suites/ui/checkout.yml
- suites/ui/customer/managing_customers.yml
- suites/ui/locale.yml
- suites/ui/payment/managing_payment_methods.yml
- suites/ui/product.yml
- suites/ui/promotion.yml
- suites/ui/promotion/managing_promotions.yml
Expand Down
20 changes: 20 additions & 0 deletions etc/behat/suites/ui/payment/managing_payment_methods.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This file is part of the Sylius package.
# (c) Paweł Jędrzejewski

default:
suites:
ui_managing_payment_methods:
contexts_as_services:
- sylius.behat.context.hook.doctrine_orm

- sylius.behat.context.setup.channel
- sylius.behat.context.setup.payment
- sylius.behat.context.setup.security

- sylius.behat.context.transform.locale
- sylius.behat.context.transform.payment_method
- sylius.behat.context.transform.shared_storage

- sylius.behat.context.ui.admin.managing_payment_methods
filters:
tags: "@managing_payment_methods && @ui"
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@managing_payment_methods
Feature: Adding a new payment method
In order to pay for orders in different ways
As an Administrator
I want to add a new payment method to the registry

Background:
Given the store operates on a single channel in "France"
And I am logged in as an administrator

@ui
Scenario: Adding a new payment method
Given I want to create a new payment method
When I name it "Paypal Express Checkout" in "English (United States)"
And I specify its code as "PEC"
And I choose "Paypal Express Checkout" gateway
And I add it
Then I should be notified that it has been successfully created
And the payment method "Paypal Express Checkout" should appear in the registry

@ui
Scenario: Adding a new payment method with description
Given I want to create a new payment method
When I name it "Paypal Express Checkout" in "English (United States)"
And I specify its code as "PEC"
And I choose "Paypal Express Checkout" gateway
And I describe it as "Payment method Paypal Express Checkout" in "English (United States)"
And I add it
Then I should be notified that it has been successfully created
And the payment method "Paypal Express Checkout" should appear in the registry
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@managing_payment_methods
Feature: Browsing payment methods
In order to see all payment methods in the store
As an Administrator
I want to be able to browse payment methods

Background:
And I am logged in as an administrator

@ui
Scenario: Browsing defined payment methods
Given the store has a payment method "Offline" with a code "OFF"
And the store has a payment method "PayPal Express Checkout" with a code "PEC"
When I browse payment methods
Then I should see 2 payment methods in the list
And the payment method "PayPal Express Checkout" should be in the registry
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@managing_payment_methods
Feature: Deleting payment methods
In order to remove test, obsolete or incorrect payment methods
As an Administrator
I want to be able to delete a payment method

Background:
And I am logged in as an administrator

@ui
Scenario: Deleted payment method should disappear from the registry
Given the store has a payment method "Offline" with a code "offline"
When I delete the "Offline" payment method
Then I should be notified that it has been successfully deleted
And this payment method should no longer exist in the registry
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
@managing_payment_methods
Feature: Editing payment methods
In order to change which payment methods are available in my store
As an Administrator
I want to be able to edit payment method

Background:
Given the store has a payment method "Offline" with a code "offline"
And I am logged in as an administrator

@ui
Scenario: Renaming the payment method
Given I want to modify the "Offline" payment method
When I rename it to "Cash on delivery" in "English (United States)"
And I save my changes
Then I should be notified that it has been successfully edited
And this payment method name should be "Cash on delivery"

@ui
Scenario: Modifying payment method gateway
Given I want to modify the "Offline" payment method
When I choose "Paypal Express Checkout" gateway
And I save my changes
Then I should be notified that it has been successfully edited
And this payment method gateway should be "paypal_express_checkout"

@ui
Scenario: Disabling payment method
Given I want to modify the "Offline" payment method
When I disable it
And I save my changes
Then I should be notified that it has been successfully edited
And this payment method should be disabled

@ui
Scenario: Enabling payment method
Given the payment method "Offline" is disabled
And I want to modify the "Offline" payment method
When I enable it
And I save my changes
Then I should be notified that it has been successfully edited
And this payment method should be enabled

@ui
Scenario: Seeing disabled code field while editing payment method
When I want to modify the "Offline" payment method
Then the code field should be disabled
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@managing_payment_methods
Feature: Payment method unique code validation
In order to uniquely identify payment methods
As an Administrator
I want to be prevented from adding two payment methods with the same code

Background:
Given the store operates on a single channel in "France"
And the store has a payment method "Offline" with a code "offline"
And I am logged in as an administrator

@ui
Scenario: Trying to add payment method with taken code
Given I want to create a new payment method
When I name it "Paypal Express Checkout" in "English (United States)"
And I specify its code as "offline"
And I choose "Offline" gateway
And I try to add it
Then I should be notified that payment method with this code already exists
And there should still be only one payment method with code "offline"
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
@managing_payment_methods
Feature: Payment method validation
In order to avoid making mistakes when managing a payment method
As an Administrator
I want to be prevented from adding it without specifying required fields

Background:
Given the store operates on a single channel in "France"
And the store has a payment method "Offline" with a code "offline"
And I am logged in as an administrator

@ui
Scenario: Trying to add a new payment method without specifying its code
Given I want to create a new payment method
When I name it "Paypal Express Checkout" in "English (United States)"
But I do not specify its code
And I choose "Paypal Express Checkout" gateway
And I add it
Then I should be notified that code is required
And the payment method with name "Paypal Express Checkout" should not be added

@ui
Scenario: Trying to add a new payment method without specifying its name
Given I want to create a new payment method
When I specify its code as "PEC"
And I choose "Paypal Express Checkout" gateway
But I do not name it
And I add it
Then I should be notified that name is required
And the payment method with code "PEC" should not be added

@ui
Scenario: Trying to remove name from an existing payment method
Given I want to modify the "Offline" payment method
When I remove its name from "English (United States)" translation
And I try to save my changes
Then I should be notified that name is required
And this payment method should still be named "Offline"
51 changes: 50 additions & 1 deletion src/Sylius/Behat/Context/Setup/PaymentContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@
namespace Sylius\Behat\Context\Setup;

use Behat\Behat\Context\Context;
use Doctrine\Common\Persistence\ObjectManager;
use Sylius\Bundle\CoreBundle\Test\Services\PaymentMethodNameToGatewayConverterInterface;
use Sylius\Component\Core\Test\Services\SharedStorageInterface;
use Sylius\Component\Payment\Model\PaymentMethodInterface;
use Sylius\Component\Payment\Repository\PaymentMethodRepositoryInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;

/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
* @author Łukasz Chruściel <lukasz.chrusciel@lakion.com>
* @author Grzegorz Sadowski <grzegorz.sadowski@lakion.com>
*/
final class PaymentContext implements Context
{
Expand All @@ -43,22 +46,30 @@ final class PaymentContext implements Context
*/
private $paymentMethodNameToGatewayConverter;

/**
* @var ObjectManager
*/
private $objectManager;

/**
* @param SharedStorageInterface $sharedStorage
* @param PaymentMethodRepositoryInterface $paymentMethodRepository
* @param FactoryInterface $paymentMethodFactory
* @param PaymentMethodNameToGatewayConverterInterface $paymentMethodNameToGatewayConverter
* @param ObjectManager $objectManager
*/
public function __construct(
SharedStorageInterface $sharedStorage,
PaymentMethodRepositoryInterface $paymentMethodRepository,
FactoryInterface $paymentMethodFactory,
PaymentMethodNameToGatewayConverterInterface $paymentMethodNameToGatewayConverter
PaymentMethodNameToGatewayConverterInterface $paymentMethodNameToGatewayConverter,
ObjectManager $objectManager
) {
$this->sharedStorage = $sharedStorage;
$this->paymentMethodRepository = $paymentMethodRepository;
$this->paymentMethodFactory = $paymentMethodFactory;
$this->paymentMethodNameToGatewayConverter = $paymentMethodNameToGatewayConverter;
$this->objectManager = $objectManager;
}

/**
Expand All @@ -78,4 +89,42 @@ public function storeAllowsPaying($paymentMethodName)

$this->paymentMethodRepository->add($paymentMethod);
}

/**
* @Given the store has a payment method :paymentMethodName with a code :paymentMethodCode
*/
public function theStoreHasAPaymentMethodWithACode($paymentMethodName, $paymentMethodCode)
{
$paymentMethod = $this->createPaymentMethodFromNameAndCode($paymentMethodName, $paymentMethodCode);

$this->sharedStorage->set('payment_method', $paymentMethod);
$this->paymentMethodRepository->add($paymentMethod);
}

/**
* @Given the payment method :paymentMethod is disabled
*/
public function theStoreHasAPaymentMethodDisabled(PaymentMethodInterface $paymentMethod)
{
$paymentMethod->disable();

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

/**
* @param string $name
* @param string $code
*
* @return PaymentMethodInterface
*/
private function createPaymentMethodFromNameAndCode($name, $code)
{
/** @var PaymentMethodInterface $paymentMethod */
$paymentMethod = $this->paymentMethodFactory->createNew();
$paymentMethod->setName($name);
$paymentMethod->setCode($code);
$paymentMethod->setGateway($this->paymentMethodNameToGatewayConverter->convert($name));

return $paymentMethod;
}
}
Loading

0 comments on commit f906b51

Please sign in to comment.