[Behat] Add setup, transformer, ui contexts configure managing payment method suite

This commit is contained in:
Arminek 2016-04-11 01:54:28 +02:00 committed by Grzegorz Sadowski
parent 602a403902
commit c211ef151f
9 changed files with 343 additions and 0 deletions

View file

@ -20,6 +20,7 @@
<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>
@ -96,6 +97,14 @@
<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" />
<tag name="sylius.behat.context" />
</service>
<service id="sylius.behat.context.setup.product" class="%sylius.behat.context.setup.product.class%" scope="scenario">
<argument type="service" id="sylius.behat.shared_storage" container="symfony" />
<argument type="service" id="sylius.repository.product" container="symfony" />

View file

@ -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>
@ -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" />

View file

@ -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_method.class">Sylius\Behat\Context\Ui\Admin\ManagingPaymentMethodContext</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>
@ -57,6 +58,15 @@
<tag name="sylius.behat.context" />
</service>
<service id="sylius.behat.context.ui.admin.managing_payment_method" class="%sylius.behat.context.ui.admin.managing_payment_method.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" />

View file

@ -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.crud.create.class%</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.crud.update.class%</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>
@ -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>

View file

@ -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

View file

@ -0,0 +1,18 @@
# This file is part of the Sylius package.
# (c) Paweł Jędrzejewski
default:
suites:
ui_payment_methods:
contexts_as_services:
- sylius.behat.context.hook.doctrine_orm
- sylius.behat.context.transform.shared_storage
- sylius.behat.context.transform.payment_method
- sylius.behat.context.setup.security
- sylius.behat.context.setup.payment_method
- sylius.behat.context.ui.admin.managing_payment_method
filters:
tags: "@managing_payment_methods && @ui"

View file

@ -0,0 +1,101 @@
<?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

@ -0,0 +1,48 @@
<?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\Transform;
use Behat\Behat\Context\Context;
use Sylius\Component\Payment\Repository\PaymentMethodRepositoryInterface;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
final class PaymentMethodContext implements Context
{
/**
* @var PaymentMethodRepositoryInterface
*/
private $paymentMethodRepository;
/**
* @param PaymentMethodRepositoryInterface $paymentMethodRepository
*/
public function __construct(PaymentMethodRepositoryInterface $paymentMethodRepository)
{
$this->paymentMethodRepository = $paymentMethodRepository;
}
/**
* @Transform payment method :name
*/
public function getPaymentMethodByName($name)
{
$paymentMethod = $this->paymentMethodRepository->findOneByName($name);
if (null === $paymentMethod) {
throw new \InvalidArgumentException('Cannot find payment method named %s', $name);
}
return $paymentMethod;
}
}

View file

@ -0,0 +1,138 @@
<?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\Ui\Admin;
use Behat\Behat\Context\Context;
use Sylius\Behat\Page\Admin\Crud\CreatePageInterface;
use Sylius\Behat\Page\Admin\Crud\IndexPageInterface;
use Sylius\Behat\Page\Admin\Crud\UpdatePageInterface;
use Sylius\Behat\Service\CurrentPageResolverInterface;
use Sylius\Behat\Service\NotificationCheckerInterface;
use Sylius\Component\Payment\Model\PaymentMethodInterface;
use Webmozart\Assert\Assert;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
final class ManagingPaymentMethodContext implements Context
{
const RESOURCE_NAME = 'payment_method';
/**
* @var CreatePageInterface
*/
private $createPage;
/**
* @var IndexPageInterface
*/
private $indexPage;
/**
* @var UpdatePageInterface
*/
private $updatePage;
/**
* @var CurrentPageResolverInterface
*/
private $currentPageResolver;
/**
* @var NotificationCheckerInterface
*/
private $notificationChecker;
/**
* @param CreatePageInterface $createPage
* @param IndexPageInterface $indexPage
* @param UpdatePageInterface $updatePage
* @param CurrentPageResolverInterface $currentPageResolver
* @param NotificationCheckerInterface $notificationChecker
*/
public function __construct(
CreatePageInterface $createPage,
IndexPageInterface $indexPage,
UpdatePageInterface $updatePage,
CurrentPageResolverInterface $currentPageResolver,
NotificationCheckerInterface $notificationChecker
) {
$this->createPage = $createPage;
$this->indexPage = $indexPage;
$this->updatePage = $updatePage;
$this->currentPageResolver = $currentPageResolver;
$this->notificationChecker = $notificationChecker;
}
/**
* @Given /^I want to modify a (payment method "([^"]*)")$/
*/
public function iWantToModifyAPaymentMethod(PaymentMethodInterface $paymentMethod)
{
$this->updatePage->open(['id' => $paymentMethod->getId()]);
}
/**
* @When I rename it to :name
*/
public function iNameItTo($name)
{
$this->updatePage->nameIt($name);
}
/**
* @When I save my changes
* @When I try to save my changes
*/
public function iSaveMyChanges()
{
$this->updatePage->saveChanges();
}
/**
* @When I choose gateway :gatewayName
*/
public function iChooseGateway($gatewayName)
{
$this->updatePage->chooseGateway($gatewayName);
}
/**
* @Then I should be notified about successful edition
*/
public function iShouldBeNotifiedAboutSuccessfulEdition()
{
$this->notificationChecker->checkEditionNotification(self::RESOURCE_NAME);
}
/**
* @Then this payment method name should be :paymentMethodName
*/
public function thisPaymentMethodNameShouldBe($paymentMethodName)
{
Assert::true(
$this->updatePage->hasResourceValues(['name' => $paymentMethodName]),
sprintf('Payment method %s should be renamed', $paymentMethodName)
);
}
/**
* @Then this payment method gateway should be :gatewayName
*/
public function thisPaymentMethodGatewayShouldBe($gatewayName)
{
Assert::true(
$this->updatePage->hasGateway($gatewayName),
sprintf('Payment method should have %s gateway', $gatewayName)
);
}
}