[Behat] Add create feature

This commit is contained in:
Arminek 2016-04-20 13:52:45 +02:00
parent 64ba9b29ff
commit 1738bd594d
19 changed files with 489 additions and 4 deletions

View file

@ -23,6 +23,8 @@
<parameter key="sylius.behat.context.ui.admin.managing_product_options.class">Sylius\Behat\Context\Ui\Admin\ManagingProductOptionsContext</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_taxons.class">Sylius\Behat\Context\Ui\Admin\ManagingTaxonsContext</parameter>
<parameter key="sylius.behat.context.ui.admin.managing_tax_category.class">Sylius\Behat\Context\Ui\Admin\ManagingTaxCategoryContext</parameter>
<parameter key="sylius.behat.context.ui.admin.managing_tax_categories.class">Sylius\Behat\Context\Ui\Admin\ManagingTaxCategoriesContext</parameter>
<parameter key="sylius.behat.context.ui.admin.managing_tax_rate.class">Sylius\Behat\Context\Ui\Admin\ManagingTaxRateContext</parameter>
<parameter key="sylius.behat.context.ui.admin.managing_zones.class">Sylius\Behat\Context\Ui\Admin\ManagingZonesContext</parameter>
@ -128,6 +130,14 @@
<tag name="sylius.behat.context" />
</service>
<service id="sylius.behat.context.ui.admin.managing_taxons" class="%sylius.behat.context.ui.admin.managing_taxons.class%" scope="scenario">
<argument type="service" id="sylius.behat.page.admin.taxon.create" />
<argument type="service" id="sylius.behat.page.admin.taxon.index" />
<argument type="service" id="sylius.behat.page.admin.taxon.update" />
<argument type="service" id="sylius.behat.notification_checker" />
<tag name="sylius.behat.context" />
</service>
<service id="sylius.behat.context.ui.admin.managing_tax_categories" class="%sylius.behat.context.ui.admin.managing_tax_categories.class%" scope="scenario">
<argument type="service" id="sylius.behat.page.admin.tax_category.index" />
<argument type="service" id="sylius.behat.page.admin.tax_category.create" />

View file

@ -67,6 +67,9 @@
<parameter key="sylius.behat.page.admin.shipping_method.create.class">Sylius\Behat\Page\Admin\ShippingMethod\CreatePage</parameter>
<parameter key="sylius.behat.page.admin.shipping_method.index.class">%sylius.behat.page.admin.crud.index.class%</parameter>
<parameter key="sylius.behat.page.admin.shipping_method.update.class">Sylius\Behat\Page\Admin\ShippingMethod\UpdatePage</parameter>
<parameter key="sylius.behat.page.admin.taxon.create.class">Sylius\Behat\Page\Admin\Taxon\CreatePage</parameter>
<parameter key="sylius.behat.page.admin.taxon.index.class">%sylius.behat.page.admin.crud.index.class%</parameter>
<parameter key="sylius.behat.page.admin.taxon.update.class">Sylius\Behat\Page\Admin\Taxon\UpdatePage</parameter>
<parameter key="sylius.behat.page.admin.tax_category.create.class">Sylius\Behat\Page\Admin\TaxCategory\CreatePage</parameter>
<parameter key="sylius.behat.page.admin.tax_category.index.class">%sylius.behat.page.admin.crud.index.class%</parameter>
<parameter key="sylius.behat.page.admin.tax_category.update.class">Sylius\Behat\Page\Admin\TaxCategory\UpdatePage</parameter>
@ -169,6 +172,15 @@
<service id="sylius.behat.page.admin.shipping_method.update" class="%sylius.behat.page.admin.shipping_method.update.class%" parent="sylius.behat.page.admin.crud.update" scope="scenario" public="false">
<argument type="string">shipping_method</argument>
</service>
<service id="sylius.behat.page.admin.taxon.create" class="%sylius.behat.page.admin.taxon.create.class%" parent="sylius.behat.page.admin.crud.create" scope="scenario" public="false">
<argument type="string">taxon</argument>
</service>
<service id="sylius.behat.page.admin.taxon.index" class="%sylius.behat.page.admin.taxon.index.class%" parent="sylius.behat.page.admin.crud.index" scope="scenario" public="false">
<argument type="string">taxon</argument>
</service>
<service id="sylius.behat.page.admin.taxon.update" class="%sylius.behat.page.admin.taxon.update.class%" parent="sylius.behat.page.admin.crud.update" scope="scenario" public="false">
<argument type="string">taxon</argument>
</service>
<service id="sylius.behat.page.admin.tax_category.create" class="%sylius.behat.page.admin.tax_category.create.class%" parent="sylius.behat.page.admin.crud.create" scope="scenario" public="false">
<argument type="string">tax_category</argument>
</service>

View file

@ -57,6 +57,7 @@ imports:
- suites/ui/taxation/applying_taxes.yml
- suites/ui/taxation/managing_tax_categories.yml
- suites/ui/taxation/managing_tax_rates.yml
- suites/ui/taxonomy/managing_taxons.yml
- suites/ui/user/managing_customers.yml
- suites/ui/user/managing_users.yml
- suites/ui/user/registering.yml

View file

@ -0,0 +1,19 @@
# This file is part of the Sylius package.
# (c) Paweł Jędrzejewski
default:
suites:
ui_managing_taxons:
contexts_as_services:
- sylius.behat.context.hook.doctrine_orm
- sylius.behat.context.transform.locale
- sylius.behat.context.transform.taxon
- sylius.behat.context.setup.channel
- sylius.behat.context.setup.security
- sylius.behat.context.setup.taxonomy
- sylius.behat.context.ui.admin.managing_taxons
filters:
tags: "@managing_taxons && @ui"

View file

@ -1,4 +1,4 @@
@managing_taxonomy
@managing_taxons
Feature: Adding a new taxon
In order to categorize my merchandise
As an Administrator
@ -6,11 +6,35 @@ Feature: Adding a new taxon
Background:
Given the store operates on a single channel in "France"
And I am logged in as an administrator
@ui
Scenario: Adding a new taxon
Given I want to create a new taxon
When I specify its code as "CATEGORY"
And I name it "Category" in "English (United States)"
When I specify its code as "t-shirts"
And I name it "T-Shirts" in "English (United States)"
And I add it
Then I should be notified that it has been successfully created
And the "Category" taxon should appear in the registry
And the "T-Shirts" taxon should appear in the registry
@ui
Scenario: Adding a new taxon with permalink and description
Given I want to create a new taxon
When I specify its code as "category"
And I name it "Category" in "English (United States)"
And I specify its permalink as "category" in "English (United States)"
And I describe it as "Main taxonomy for products." in "English (United States)"
And I add it
Then I should be notified that it has been successfully created
And the "Category" taxon with "category" permalink and "Main taxonomy for products." description should appear in the registry
@ui
Scenario: Adding a new taxon with parent taxon
Given the store classifies its products as "Category"
And I want to create a new taxon
When I specify its code as "stickers"
And I name it "Stickers" in "English (United States)"
And I choose "Category" as a parent taxon
And I add it
Then I should be notified that it has been successfully created
And the "Stickers" taxon with "Category" parent taxon should appear in the registry

View file

@ -35,6 +35,9 @@ final class TaxonContext implements Context
/**
* @Transform /^classified as "([^"]+)"$/
* @Transform /^belongs to "([^"]+)"$/
* @Transform /^"([^"]+)" taxon$/
* @Transform /^"([^"]+)" as a parent taxon$/
* @Transform /^"([^"]+)" parent taxon$/
*/
public function getTaxonByName($taxonName)
{

View file

@ -0,0 +1,168 @@
<?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\IndexPageInterface;
use Sylius\Behat\Page\Admin\Taxon\CreatePageInterface;
use Sylius\Behat\Page\Admin\Taxon\UpdatePageInterface;
use Sylius\Behat\Service\NotificationCheckerInterface;
use Sylius\Component\Core\Model\TaxonInterface;
use Webmozart\Assert\Assert;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
final class ManagingTaxonsContext implements Context
{
const RESOURCE_NAME = 'taxon';
/**
* @var CreatePageInterface
*/
private $createPage;
/**
* @var IndexPageInterface
*/
private $indexPage;
/**
* @var UpdatePageInterface
*/
private $updatePage;
/**
* @var NotificationCheckerInterface
*/
private $notificationChecker;
/**
* @param CreatePageInterface $createPage
* @param IndexPageInterface $indexPage
* @param UpdatePageInterface $updatePage
* @param NotificationCheckerInterface $notificationChecker
*/
public function __construct(
CreatePageInterface $createPage,
IndexPageInterface $indexPage,
UpdatePageInterface $updatePage,
NotificationCheckerInterface $notificationChecker
) {
$this->createPage = $createPage;
$this->indexPage = $indexPage;
$this->updatePage = $updatePage;
$this->notificationChecker = $notificationChecker;
}
/**
* @Given I want to create a new taxon
*/
public function iWantToCreateANewTaxon()
{
$this->createPage->open();
}
/**
* @When I specify its code as :code
*/
public function iSpecifyItsCodeAs($code)
{
$this->createPage->specifyCode($code);
}
/**
* @When I name it :name in :language
* @When I rename it to :name in :language
*/
public function iNameItIn($name, $language)
{
$this->createPage->nameIt($name, $language);
}
/**
* @When I specify its permalink as :permalink in :language
*/
public function iSpecifyItsPermalinkAs($permalink, $language)
{
$this->createPage->specifyPermalink($permalink, $language);
}
/**
* @When I describe it as :description in :language
*/
public function iDescribeItAs($description, $language)
{
$this->createPage->describeItAs($description, $language);
}
/**
* @Given /^I choose ("[^"]+" as a parent taxon)$/
*/
public function iChooseAsAParentTaxon(TaxonInterface $taxon)
{
$this->createPage->chooseParent($taxon);
}
/**
* @When I add it
* @When I try to add it
*/
public function iAddIt()
{
$this->createPage->create();
}
/**
* @Then I should be notified that it has been successfully created
*/
public function iShouldBeNotifiedItHasBeenSuccessfullyCreated()
{
$this->notificationChecker->checkCreationNotification(self::RESOURCE_NAME);
}
/**
* @Then /^the ("[^"]+" taxon) should appear in the registry$/
*/
public function theTaxonShouldAppearInTheRegistry(TaxonInterface $taxon)
{
$this->indexPage->open();
Assert::true(
$this->indexPage->isResourceOnPage(['code' => $taxon->getCode()]),
sprintf('Taxon %s should be in the registry', $taxon->getName())
);
}
/**
* @Then /^the ("[^"]+" taxon) with "([^"]*)" permalink and "([^"]*)" description should appear in the registry$/
*/
public function theTaxonWithPermalinkAndDescriptionShouldAppearInTheRegistry(TaxonInterface $taxon, $permalink, $description)
{
$this->updatePage->open(['id' => $taxon->getId()]);
Assert::true(
$this->updatePage->hasResourceValues(['code' => $taxon->getCode(), 'permalink' => $permalink, 'description' => $description]),
sprintf('Taxon %s should have %s permalink and %s description.', $taxon->getName(), $permalink, $description)
);
}
/**
* @Then /^the ("[^"]+" taxon) with ("[^"]+" parent taxon) should appear in the registry$/
*/
public function theTaxonWithParentTaxonShouldAppearInTheRegistry(TaxonInterface $taxon, TaxonInterface $parentTaxon)
{
$this->updatePage->open(['id' => $taxon->getId()]);
Assert::true(
$this->updatePage->hasResourceValues(['parent' => $parentTaxon->getId()]),
sprintf('Taxon %s should have %s parent taxon', $taxon->getName(), $parentTaxon->getName())
);
}
}

View file

@ -0,0 +1,70 @@
<?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\Page\Admin\Taxon;
use Sylius\Behat\Behaviour\SpecifiesItsCode;
use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage;
use Sylius\Component\Core\Model\TaxonInterface;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
class CreatePage extends BaseCreatePage implements CreatePageInterface
{
use SpecifiesItsCode;
/**
* {@inheritdoc}
*/
public function chooseParent(TaxonInterface $taxon)
{
$this->getElement('parent')->selectOption($taxon->getName(), false);
}
/**
* {@inheritdoc}
*/
public function describeItAs($description, $languageCode)
{
$this->getDocument()->fillField(sprintf('sylius_taxon_translations_%s_description', $languageCode), $description);
}
/**
* {@inheritdoc}
*/
public function nameIt($name, $languageCode)
{
$this->getDocument()->fillField(sprintf('sylius_taxon_translations_%s_name', $languageCode), $name);
}
/**
* {@inheritdoc}
*/
public function specifyPermalink($permalink, $languageCode)
{
$this->getDocument()->fillField(sprintf('sylius_taxon_translations_%s_permalink', $languageCode), $permalink);
}
/**
* {@inheritdoc}
*/
protected function getDefinedElements()
{
return array_merge(parent::getDefinedElements(), [
'code' => '#sylius_taxon_code',
'name' => '#sylius_taxon_translations_en_US_name',
'parent' => '#sylius_taxon_parent',
'permalink' => '#sylius_taxon_translations_en_US_permalink',
'description' => '#sylius_taxon_translations_en_US_description',
]);
}
}

View file

@ -0,0 +1,49 @@
<?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\Page\Admin\Taxon;
use Sylius\Behat\Page\Admin\Crud\CreatePageInterface as BaseCreatePageInterface;
use Sylius\Component\Core\Model\TaxonInterface;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
interface CreatePageInterface extends BaseCreatePageInterface
{
/**
* @param string $description
* @param string $languageCode
*/
public function describeItAs($description, $languageCode);
/**
* @param TaxonInterface $taxon
*/
public function chooseParent(TaxonInterface $taxon);
/**
* @param string $name
* @param string $languageCode
*/
public function nameIt($name, $languageCode);
/**
* @param string $code
*/
public function specifyCode($code);
/**
* @param string $permalink
* @param string $languageCode
*/
public function specifyPermalink($permalink, $languageCode);
}

View file

@ -0,0 +1,34 @@
<?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\Page\Admin\Taxon;
use Sylius\Behat\Page\Admin\Crud\UpdatePage as BaseUpdatePage;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
{
/**
* {@inheritdoc}
*/
protected function getDefinedElements()
{
return array_merge(parent::getDefinedElements(), [
'code' => '#sylius_taxon_code',
'name' => '#sylius_taxon_translations_en_US_name',
'parent' => '#sylius_taxon_parent',
'permalink' => '#sylius_taxon_translations_en_US_permalink',
'description' => '#sylius_taxon_translations_en_US_description',
]);
}
}

View file

@ -0,0 +1,22 @@
<?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\Page\Admin\Taxon;
use Sylius\Behat\Page\Admin\Crud\UpdatePageInterface as BaseUpdatePageInterface;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
interface UpdatePageInterface extends BaseUpdatePageInterface
{
}

View file

@ -166,5 +166,11 @@ final class MainMenuBuilder extends AbstractAdminMenuBuilder
->setLabel('sylius.menu.admin.main.catalog.product_options')
->setLabelAttribute('icon', 'options')
;
$catalogSubMenu
->addChild('taxons', ['route' => 'sylius_admin_taxon_create'])
->setLabel('sylius.menu.admin.main.assortment.taxons')
->setLabelAttribute('icon', 'folder')
;
}
}

View file

@ -9,6 +9,7 @@ imports:
- { resource: "@SyliusAdminBundle/Resources/config/grids/product_option.yml" }
- { resource: "@SyliusAdminBundle/Resources/config/grids/promotion.yml" }
- { resource: "@SyliusAdminBundle/Resources/config/grids/shipping_method.yml" }
- { resource: "@SyliusAdminBundle/Resources/config/grids/taxon.yml" }
- { resource: "@SyliusAdminBundle/Resources/config/grids/tax_category.yml" }
- { resource: "@SyliusAdminBundle/Resources/config/grids/tax_rate.yml" }
- { resource: "@SyliusAdminBundle/Resources/config/grids/zone.yml" }

View file

@ -0,0 +1,21 @@
sylius_grid:
grids:
sylius_admin_taxon:
driver:
name: doctrine/orm
options:
class: "%sylius.model.taxon.class%"
fields:
code:
type: string
label: sylius.ui.code
name:
type: string
label: sylius.ui.name
actions:
main:
create:
type: create
item:
update:
type: update

View file

@ -43,6 +43,9 @@ sylius_admin_security:
sylius_admin_shipping_method:
resource: "@SyliusAdminBundle/Resources/config/routing/shipping_method.yml"
sylius_admin_taxon:
resource: "@SyliusAdminBundle/Resources/config/routing/taxon.yml"
sylius_admin_tax_category:
resource: "@SyliusAdminBundle/Resources/config/routing/tax_category.yml"

View file

@ -0,0 +1,16 @@
sylius_admin_taxon:
resource: |
alias: sylius.taxon
section: admin
templates: SyliusAdminBundle:Crud
except: ['show', 'delete']
redirect: update
grid: sylius_admin_taxon
vars:
all:
subheader: sylius.ui.manage_taxons
templates:
form: SyliusAdminBundle:Taxon:_form.html.twig
index:
icon: folder
type: sylius.resource

View file

@ -5,6 +5,7 @@ sylius:
catalog:
header: Catalog
product_options: Product options
taxons: Taxons
configuration:
channels: Channels
countries: Countries

View file

@ -0,0 +1,23 @@
<div class="ui two column stackable grid">
<div class="column">
<div class="ui segment">
{{ form_errors(form) }}
<div class="one field">
{{ form_row(form.code) }}
</div>
<div class="one field">
{{ form_row(form.parent) }}
</div>
</div>
</div>
<div class="column">
<div class="ui segment">
{% for locale, translationForm in form.translations %}
<h4 class="ui dividing header"><i class="{{ locale|slice(3, 2)|lower }} flag"></i> {{ locale|sylius_locale_name }}</h4>
{{ form_row(translationForm.name) }}
{{ form_row(translationForm.permalink) }}
{{ form_row(translationForm.description) }}
{% endfor %}
</div>
</div>
</div>

View file

@ -58,6 +58,8 @@ sylius:
manage_payment_method: Manage payment methods
manage_product_option: Manage product option
manage_shipping_destinations: Manage shipping destinations
manage_taxons: Manage taxons of your products
manage_taxation_of_your_products: Manage taxation of your products
manage_shipping_methods_for_your_store: Manage shipping methods for your store
manage_taxation_of_your_products: Manage taxation of your products
new: New