[Admin][PaymentMethod] Fixes after PR review

This commit is contained in:
Grzegorz Sadowski 2016-04-20 12:31:57 +02:00
parent 4a65bf0512
commit 1f3e1bba94
16 changed files with 128 additions and 197 deletions

View file

@ -20,7 +20,6 @@
<parameter key="sylius.behat.context.setup.locale.class">Sylius\Behat\Context\Setup\LocaleContext</parameter>
<parameter key="sylius.behat.context.setup.order.class">Sylius\Behat\Context\Setup\OrderContext</parameter>
<parameter key="sylius.behat.context.setup.payment.class">Sylius\Behat\Context\Setup\PaymentContext</parameter>
<parameter key="sylius.behat.context.setup.payment_method.class">Sylius\Behat\Context\Setup\PaymentMethodContext</parameter>
<parameter key="sylius.behat.context.setup.product.class">Sylius\Behat\Context\Setup\ProductContext</parameter>
<parameter key="sylius.behat.context.setup.product_review.class">Sylius\Behat\Context\Setup\ProductReviewContext</parameter>
<parameter key="sylius.behat.context.setup.promotion.class">Sylius\Behat\Context\Setup\PromotionContext</parameter>
@ -94,14 +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" />
<tag name="sylius.behat.context" />
</service>
<service id="sylius.behat.context.setup.payment_method" class="%sylius.behat.context.setup.payment_method.class%" scope="scenario">
<argument type="service" id="sylius.behat.shared_storage" 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="sylius.repository.payment_method" container="symfony" />
<argument type="service" id="doctrine.orm.entity_manager" container="symfony" />
<tag name="sylius.behat.context" />
</service>

View file

@ -7,13 +7,13 @@ default:
contexts_as_services:
- sylius.behat.context.hook.doctrine_orm
- sylius.behat.context.transform.shared_storage
- sylius.behat.context.transform.payment_method
- sylius.behat.context.transform.locale
- sylius.behat.context.setup.channel
- sylius.behat.context.setup.payment
- sylius.behat.context.setup.security
- sylius.behat.context.setup.payment_method
- 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:

View file

@ -5,12 +5,12 @@ Feature: Browsing payment methods
I want to be able to browse payment methods
Background:
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"
And I am logged in as an administrator
@ui
Scenario: Browsing defined payment methods
When I want to browse 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

View file

@ -5,11 +5,11 @@ Feature: Deleting payment methods
I want to be able to delete a 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: Deleted payment method should disappear from the registry
When I delete payment method "Offline"
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

View file

@ -10,39 +10,38 @@ Feature: Editing payment methods
@ui
Scenario: Renaming the payment method
Given I want to modify a payment method "Offline"
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 about successful edition
Then I should be notified that it has been successfully edited
And this payment method name should be "Cash on delivery"
@ui
Scenario: Changing gateway
Given I want to modify a payment method "Offline"
When I rename it to "Paypal Express Checkout" in "English (United States)"
And I choose "Paypal Express Checkout" gateway
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 about successful edition
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 a payment method "Offline"
Given I want to modify the "Offline" payment method
When I disable it
And I save my changes
Then I should be notified about successful edition
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 store has a payment method "Offline" disabled
And I want to modify a payment method "Offline"
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 about successful edition
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 a payment method "Offline"
When I want to modify the "Offline" payment method
Then the code field should be disabled

View file

@ -31,7 +31,7 @@ Feature: Payment method validation
@ui
Scenario: Trying to remove name from an existing payment method
Given I want to modify a payment method "Offline"
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

View file

@ -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
{
@ -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;
}
/**
@ -78,4 +89,42 @@ final class PaymentContext implements Context
$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;
}
}

View file

@ -1,101 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Behat\Context\Setup;
use Behat\Behat\Context\Context;
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>
*/
final class PaymentMethodContext implements Context
{
/**
* @var SharedStorageInterface
*/
private $sharedStorage;
/**
* @var FactoryInterface
*/
private $paymentMethodFactory;
/**
* @var PaymentMethodNameToGatewayConverterInterface
*/
private $paymentMethodNameToGatewayConverter;
/**
* @var PaymentMethodRepositoryInterface
*/
private $paymentMethodRepository;
/**
* @param SharedStorageInterface $sharedStorage
* @param FactoryInterface $paymentMethodFactory
* @param PaymentMethodNameToGatewayConverterInterface $paymentMethodNameToGatewayConverter
* @param PaymentMethodRepositoryInterface $paymentMethodRepository
*/
public function __construct(
SharedStorageInterface $sharedStorage,
FactoryInterface $paymentMethodFactory,
PaymentMethodNameToGatewayConverterInterface $paymentMethodNameToGatewayConverter,
PaymentMethodRepositoryInterface $paymentMethodRepository
) {
$this->sharedStorage = $sharedStorage;
$this->paymentMethodFactory = $paymentMethodFactory;
$this->paymentMethodNameToGatewayConverter = $paymentMethodNameToGatewayConverter;
$this->paymentMethodRepository = $paymentMethodRepository;
}
/**
* @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 store has a (payment method "([^"]*)") disabled$/
*/
public function theStoreHasAPaymentMethodDisabled(PaymentMethodInterface $paymentMethod)
{
$paymentMethod->disable();
$this->paymentMethodRepository->add($paymentMethod);
}
/**
* @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;
}
}

View file

@ -34,7 +34,7 @@ final class PaymentMethodContext implements Context
}
/**
* @Transform payment method :name
* @Transform :paymentMethod
*/
public function getPaymentMethodByName($name)
{

View file

@ -75,7 +75,7 @@ final class ManagingPaymentMethodsContext implements Context
}
/**
* @Given /^I want to modify a (payment method "([^"]*)")$/
* @Given I want to modify the :paymentMethod payment method
*/
public function iWantToModifyAPaymentMethod(PaymentMethodInterface $paymentMethod)
{
@ -128,7 +128,7 @@ final class ManagingPaymentMethodsContext implements Context
}
/**
* @When /^I delete (payment method "([^"]*)")$/
* @When I delete the :paymentMethod payment method
*/
public function iDeletePaymentMethod(PaymentMethodInterface $paymentMethod)
{
@ -147,7 +147,7 @@ final class ManagingPaymentMethodsContext implements Context
}
/**
* @Then I should be notified about successful edition
* @Then I should be notified that it has been successfully edited
*/
public function iShouldBeNotifiedAboutSuccessfulEdition()
{
@ -155,18 +155,18 @@ final class ManagingPaymentMethodsContext implements Context
}
/**
* @Then this payment method :element should be :paymentMethodName
* @Then this payment method :element should be :value
*/
public function thisPaymentMethodNameShouldBe($element, $value)
public function thisPaymentMethodElementShouldBe($element, $value)
{
Assert::true(
$this->updatePage->hasResourceValues([$element => $value]),
sprintf('Payment method should have %s %s', $value, $element)
sprintf('Payment method %s should be %s', $element, $value)
);
}
/**
* @Given /^I want to create a new payment method$/
* @Given I want to create a new payment method
*/
public function iWantToCreateANewPaymentMethod()
{
@ -202,7 +202,7 @@ final class ManagingPaymentMethodsContext implements Context
/**
* @Then I should be notified that it has been successfully created
*/
public function iShouldBeNotifiedItHasBeenSuccessfulCreation()
public function iShouldBeNotifiedItHasBeenSuccessfullyCreated()
{
$this->notificationChecker->checkCreationNotification(self::RESOURCE_NAME);
}
@ -222,9 +222,9 @@ final class ManagingPaymentMethodsContext implements Context
}
/**
* @When /^I want to browse payment methods$/
* @When I browse payment methods
*/
public function iWantToBrowsePaymentMethods()
public function iBrowsePaymentMethods()
{
$this->indexPage->open();
}
@ -236,9 +236,10 @@ final class ManagingPaymentMethodsContext implements Context
{
$foundRows = $this->indexPage->countItems();
Assert::true(
((int) $amount) === $foundRows,
sprintf('%s rows with payment methods should appear on page, %s rows has been found', $amount, $foundRows)
Assert::eq(
((int) $amount),
$foundRows,
'%2$s rows with payment methods should appear on page, %s rows has been found'
);
}
@ -255,7 +256,7 @@ final class ManagingPaymentMethodsContext implements Context
*/
public function thePaymentMethodWithElementValueShouldNotBeAdded($element, $value)
{
$this->iWantToBrowsePaymentMethods();
$this->iBrowsePaymentMethods();
Assert::false(
$this->indexPage->isResourceOnPage([$element => $value]),
@ -268,15 +269,13 @@ final class ManagingPaymentMethodsContext implements Context
*/
public function thisShippingMethodNameShouldBe(PaymentMethodInterface $paymentMethod, $paymentMethodName)
{
$this->iWantToBrowsePaymentMethods();
$this->iBrowsePaymentMethods();
Assert::true(
$this->indexPage->isResourceOnPage(
[
'code' => $paymentMethod->getCode(),
'name' => $paymentMethodName,
]
),
$this->indexPage->isResourceOnPage([
'code' => $paymentMethod->getCode(),
'name' => $paymentMethodName,
]),
sprintf('Payment method name %s has not been assigned properly.', $paymentMethodName)
);
}
@ -296,7 +295,7 @@ final class ManagingPaymentMethodsContext implements Context
}
/**
* @Then /^the code field should be disabled$/
* @Then the code field should be disabled
*/
public function theCodeFieldShouldBeDisabled()
{
@ -309,7 +308,7 @@ final class ManagingPaymentMethodsContext implements Context
/**
* @Then this payment method should be enabled
*/
public function thisCountryShouldBeEnabled()
public function thisPaymentMethodShouldBeEnabled()
{
Assert::true(
$this->updatePage->isPaymentMethodEnabled(),
@ -320,7 +319,7 @@ final class ManagingPaymentMethodsContext implements Context
/**
* @Then this payment method should be disabled
*/
public function thisCountryShouldBeDisabled()
public function thisPaymentMethodShouldBeDisabled()
{
Assert::false(
$this->updatePage->isPaymentMethodEnabled(),
@ -331,7 +330,7 @@ final class ManagingPaymentMethodsContext implements Context
/**
* @Then I should be notified that it has been successfully deleted
*/
public function iShouldBeNotifiedAboutSuccessfulDeletion()
public function iShouldBeNotifiedThatItHasBeenSuccessfullyDeleted()
{
$this->notificationChecker->checkDeletionNotification(self::RESOURCE_NAME);
}
@ -363,11 +362,11 @@ final class ManagingPaymentMethodsContext implements Context
*/
public function thereShouldStillBeOnlyOnePaymentMethodWith($element, $code)
{
$this->iWantToBrowsePaymentMethods();
$this->iBrowsePaymentMethods();
Assert::true(
$this->indexPage->isResourceOnPage([$element => $code]),
sprintf('Payment method with %s %s cannot be founded.', $element, $code)
sprintf('Payment method with %s %s cannot be found.', $element, $code)
);
}
}

View file

@ -23,14 +23,18 @@ use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage;
*/
class CreatePage extends BaseCreatePage implements CreatePageInterface
{
use ChecksCodeImmutability, Toggles, SpecifiesItsCode;
use ChecksCodeImmutability;
use Toggles;
use SpecifiesItsCode;
/**
* {@inheritdoc}
*/
public function nameIt($name, $language)
public function nameIt($name, $languageCode)
{
$this->getDocument()->fillField(sprintf('sylius_payment_method_translations_%s_name', $language), $name);
$this->getDocument()->fillField(
sprintf('sylius_payment_method_translations_%s_name', $languageCode), $name
);
}
/**
@ -44,9 +48,11 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface
/**
* {@inheritdoc}
*/
public function describeIt($description, $language)
public function describeIt($description, $languageCode)
{
$this->getDocument()->fillField(sprintf('sylius_payment_method_translations_%s_description', $language), $description);
$this->getDocument()->fillField(
sprintf('sylius_payment_method_translations_%s_description', $languageCode), $description
);
}
/**
@ -58,9 +64,7 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface
}
/**
* @return NodeElement
*
* @throws ElementNotFoundException
* {@inheritdoc}
*/
protected function getCodeElement()
{
@ -68,9 +72,7 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface
}
/**
* @return NodeElement
*
* @throws ElementNotFoundException
* {@inheritdoc}
*/
protected function getToggleableElement()
{

View file

@ -23,9 +23,9 @@ interface CreatePageInterface extends BaseCreatePageInterface
/**
* @param string $name
* @param string $language
* @param string $languageCode
*/
public function nameIt($name, $language);
public function nameIt($name, $languageCode);
/**
* @param string $code
@ -39,9 +39,9 @@ interface CreatePageInterface extends BaseCreatePageInterface
/**
* @param string $description
* @param string $language
* @param string $languageCode
*/
public function describeIt($description, $language);
public function describeIt($description, $languageCode);
/**
* @return bool

View file

@ -22,13 +22,8 @@ use Sylius\Behat\Page\Admin\Crud\UpdatePage as BaseUpdatePage;
*/
class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
{
use ChecksCodeImmutability, Toggles;
/**
* @var array
*/
protected $elements = [
];
use ChecksCodeImmutability;
use Toggles;
/**
* {@inheritdoc}
@ -41,9 +36,9 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
/**
* {@inheritdoc}
*/
public function nameIt($name, $language)
public function nameIt($name, $languageCode)
{
$this->getDocument()->fillField(sprintf('sylius_payment_method_translations_%s_name', $language), $name);
$this->getDocument()->fillField(sprintf('sylius_payment_method_translations_%s_name', $languageCode), $name);
}
/**
@ -55,9 +50,7 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
}
/**
* @return NodeElement
*
* @throws ElementNotFoundException
* {@inheritdoc}
*/
protected function getCodeElement()
{
@ -65,9 +58,7 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
}
/**
* @return NodeElement
*
* @throws ElementNotFoundException
* {@inheritdoc}
*/
protected function getToggleableElement()
{

View file

@ -38,7 +38,7 @@ interface UpdatePageInterface extends BaseUpdatePageInterface
/**
* @param string $name
* @param string $language
* @param string $languageCode
*/
public function nameIt($name, $language);
public function nameIt($name, $languageCode);
}

View file

@ -198,6 +198,7 @@ sylius_payment:
choice: Sylius\Bundle\CoreBundle\Form\Type\Payment\PaymentMethodChoiceType
gateways:
offline: Offline
paypal_express_checkout: Paypal Express Checkout
sylius_payum: ~

View file

@ -40,8 +40,7 @@ sylius:
manage_country: Manage country
manage_customer: Manage customers
manage_languages_available_in_the_store: Manage languages available in the store
manage_locale: Manage locale
manage_payment_method: Manage payment method
manage_payment_method: Manage payment methods
manage_shipping_destinations: Manage shipping destinations
manage_shipping_methods_for_your_store: Manage shipping methods for your store
manage_taxation_of_your_products: Manage taxation of your products