[CustomerGroup] Implement CRUD for CustomerGroup entity

This commit is contained in:
Grzegorz Sadowski 2016-10-06 12:44:15 +02:00
parent 5e3a1dcdc9
commit 08b3bd7058
26 changed files with 563 additions and 12 deletions

View file

@ -7,7 +7,7 @@ Feature: Adding a new customer group
Background:
Given I am logged in as an administrator
@ui @todo
@ui
Scenario: Adding a new customer group
Given I want to create a new customer group
When I specify its name as "Retail"

View file

@ -9,8 +9,8 @@ Feature: Browsing customer groups
And the store has a customer group "Wholesale"
And I am logged in as an administrator
@ui @todo
@ui
Scenario: Browsing customer groups in the store
When I want to see all customer groups in the store
When I want to browse customer groups of the store
Then I should see 2 customer groups in the list
And I should see the customer group "Retail" in the list

View file

@ -7,17 +7,17 @@ Feature: Customer group validation
Background:
Given I am logged in as an administrator
@ui @todo
@ui
Scenario: Trying to add a new customer group without a name
Given I want to create a new customer group
When I try to add it
Then I should be notified that name is required
@ui @todo
@ui
Scenario: Trying to remove name from an existing customer group
Given the store has a customer group "Retail"
And I want to edit this customer group
When I remove its name
And I try to save my changes
Then I should be notified that name is required
And the customer group "Retail" should still have this name
And this customer group should still be named "Retail"

View file

@ -8,9 +8,9 @@ Feature: Editing a customer group
Given the store has a customer group "Retail"
And I am logged in as an administrator
@ui @todo
@ui
Scenario: Changing name of an existing customer group
And I want to edit this customer group
When I want to edit this customer group
And I specify its name as "Wholesale"
And I save my changes
Then I should be notified that it has been successfully edited

View file

@ -0,0 +1,75 @@
<?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\Behat\Service\SharedStorageInterface;
use Sylius\Component\Customer\Model\CustomerGroupInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
/**
* @author Grzegorz Sadowski <grzegorz.sadowski@lakion.com>
*/
final class CustomerGroupContext implements Context
{
/**
* @var SharedStorageInterface
*/
private $sharedStorage;
/**
* @var RepositoryInterface
*/
private $customerGroupRepository;
/**
* @var FactoryInterface
*/
private $customerGroupFactory;
/**
* @param SharedStorageInterface $sharedStorage
* @param RepositoryInterface $customerGroupRepository
* @param FactoryInterface $customerGroupFactory
*/
public function __construct(
SharedStorageInterface $sharedStorage,
RepositoryInterface $customerGroupRepository,
FactoryInterface $customerGroupFactory
) {
$this->sharedStorage = $sharedStorage;
$this->customerGroupRepository = $customerGroupRepository;
$this->customerGroupFactory = $customerGroupFactory;
}
/**
* @Given the store has a customer group :name
*/
public function theStoreHasACustomerGroup($name)
{
$this->createCustomerGroup($name);
}
/**
* @param string $name
*/
private function createCustomerGroup($name)
{
/** @var CustomerGroupInterface $customerGroup */
$customerGroup = $this->customerGroupFactory->createNew();
$customerGroup->setName(ucfirst($name));
$this->sharedStorage->set('customer_group', $customerGroup);
$this->customerGroupRepository->add($customerGroup);
}
}

View file

@ -0,0 +1,47 @@
<?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\Resource\Repository\RepositoryInterface;
use Webmozart\Assert\Assert;
/**
* @author Grzegorz Sadowski <grzegorz.sadowski@lakion.com>
*/
final class CustomerGroupContext implements Context
{
/**
* @var RepositoryInterface
*/
private $customerGroupRepository;
/**
* @param RepositoryInterface $customerGroupRepository
*/
public function __construct(RepositoryInterface $customerGroupRepository)
{
$this->customerGroupRepository = $customerGroupRepository;
}
/**
* @Transform :customerGroup
*/
public function getCustomerGroupByName($customerGroupName)
{
$customerGroup = $this->customerGroupRepository->findOneBy(['name' => $customerGroupName]);
Assert::notNull($customerGroup, sprintf('Cannot find customer group with name %s', $customerGroupName));
return $customerGroup;
}
}

View file

@ -0,0 +1,172 @@
<?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\CustomerGroup\CreatePageInterface;
use Sylius\Behat\Page\Admin\CustomerGroup\UpdatePageInterface;
use Sylius\Component\Customer\Model\CustomerGroupInterface;
use Webmozart\Assert\Assert;
/**
* @author Grzegorz Sadowski <grzegorz.sadowski@lakion.com>
*/
final class ManagingCustomerGroupsContext implements Context
{
/**
* @var CreatePageInterface
*/
private $createPage;
/**
* @var IndexPageInterface
*/
private $indexPage;
/**
* @var UpdatePageInterface
*/
private $updatePage;
/**
* @param CreatePageInterface $createPage
* @param IndexPageInterface $indexPage
* @param UpdatePageInterface $updatePage
*/
public function __construct(
CreatePageInterface $createPage,
IndexPageInterface $indexPage,
UpdatePageInterface $updatePage
) {
$this->createPage = $createPage;
$this->indexPage = $indexPage;
$this->updatePage = $updatePage;
}
/**
* @Given I want to create a new customer group
*/
public function iWantToCreateANewCustomerGroup()
{
$this->createPage->open();
}
/**
* @When I specify its name as :name
* @When I remove its name
*/
public function iSpecifyItsNameAs($name = null)
{
$this->createPage->nameIt($name);
}
/**
* @When I add it
* @When I try to add it
*/
public function iAddIt()
{
$this->createPage->create();
}
/**
* @Then the customer group :customerGroup should appear in the store
*/
public function theCustomerGroupShouldAppearInTheStore(CustomerGroupInterface $customerGroup)
{
$this->indexPage->open();
Assert::true(
$this->indexPage->isSingleResourceOnPage(['name' => $customerGroup->getName()]),
sprintf('Customer group with name %s should exist but it does not.', $customerGroup->getName())
);
}
/**
* @When /^I want to edit (this customer group)$/
* @When I want to edit the customer group :customerGroup
*/
public function iWantToEditThisCustomerGroup(CustomerGroupInterface $customerGroup)
{
$this->updatePage->open(['id' => $customerGroup->getId()]);
}
/**
* @When I save my changes
* @When I try to save my changes
*/
public function iSaveMyChanges()
{
$this->updatePage->saveChanges();
}
/**
* @Then this customer group with name :name should appear in the store
* @Then I should see the customer group :name in the list
*
*/
public function thisCustomerGroupWithNameShouldAppearInTheStore($name)
{
$this->indexPage->open();
Assert::true(
$this->indexPage->isSingleResourceOnPage(['name' => $name]),
sprintf('The customer group with a name %s should exist, but it does not.', $name)
);
}
/**
* @When I want to browse customer groups of the store
*/
public function iWantToBrowseCustomerGroupsOfTheStore()
{
$this->indexPage->open();
}
/**
* @Then /^I should see (\d+) customer groups in the list$/
*/
public function iShouldSeeCustomerGroupsInTheList($amountOfCustomerGroups)
{
Assert::same(
(int) $amountOfCustomerGroups,
$this->indexPage->countItems(),
sprintf('Amount of customer groups should be equal %s, but is not.', $amountOfCustomerGroups)
);
}
/**
* @Then /^(this customer group) should still be named "([^"]+)"$/
*/
public function thisChannelNameShouldBe(CustomerGroupInterface $customerGroup, $customerGroupName)
{
$this->iWantToBrowseCustomerGroupsOfTheStore();
Assert::true(
$this->indexPage->isSingleResourceOnPage(['name' => $customerGroup->getName()]
),
sprintf('Customer group name %s has not been assigned properly.', $customerGroupName)
);
}
/**
* @Then I should be notified that name is required
*/
public function iShouldBeNotifiedThatNameIsRequired()
{
Assert::same(
$this->updatePage->getValidationMessage('name'),
'Please enter a customer group name.'
);
}
}

View file

@ -0,0 +1,38 @@
<?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\CustomerGroup;
use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage;
/**
* @author Grzegorz Sadowski <grzegorz.sadowski@lakion.com>
*/
class CreatePage extends BaseCreatePage implements CreatePageInterface
{
/**
* {@inheritdoc}
*/
public function nameIt($name)
{
$this->getElement('name')->setValue($name);
}
/**
* {@inheritdoc}
*/
protected function getDefinedElements()
{
return array_merge(parent::getDefinedElements(), [
'name' => '#sylius_customer_group_name',
]);
}
}

View file

@ -0,0 +1,25 @@
<?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\CustomerGroup;
use Sylius\Behat\Page\Admin\Crud\CreatePageInterface as BaseCreatePageInterface;
/**
* @author Grzegorz Sadowski <grzegorz.sadowski@lakion.com>
*/
interface CreatePageInterface extends BaseCreatePageInterface
{
/**
* @param string $name
*/
public function nameIt($name);
}

View file

@ -0,0 +1,38 @@
<?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\CustomerGroup;
use Sylius\Behat\Page\Admin\Crud\UpdatePage as BaseUpdatePage;
/**
* @author Grzegorz Sadowski <grzegorz.sadowski@lakion.com>
*/
class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
{
/**
* {@inheritdoc}
*/
public function nameIt($name)
{
$this->getElement('name')->setValue($name);
}
/**
* {@inheritdoc}
*/
protected function getDefinedElements()
{
return array_merge(parent::getDefinedElements(), [
'name' => '#sylius_customer_group_name',
]);
}
}

View file

@ -0,0 +1,25 @@
<?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\CustomerGroup;
use Sylius\Behat\Page\Admin\Crud\UpdatePageInterface as BaseUpdatePageInterface;
/**
* @author Grzegorz Sadowski <grzegorz.sadowski@lakion.com>
*/
interface UpdatePageInterface extends BaseUpdatePageInterface
{
/**
* @param string $name
*/
public function nameIt($name);
}

View file

@ -42,6 +42,13 @@
<tag name="sylius.behat.context" />
</service>
<service id="sylius.behat.context.setup.customer_group" class="Sylius\Behat\Context\Setup\CustomerGroupContext" scope="scenario">
<argument type="service" id="sylius.behat.shared_storage" />
<argument type="service" id="sylius.repository.customer_group" container="symfony" />
<argument type="service" id="sylius.factory.customer_group" container="symfony" />
<tag name="sylius.behat.context" />
</service>
<service id="sylius.behat.context.setup.geographical" class="Sylius\Behat\Context\Setup\GeographicalContext" scope="scenario">
<argument type="service" id="sylius.behat.shared_storage" />
<argument type="service" id="sylius.factory.country" container="symfony" />

View file

@ -48,6 +48,11 @@
<tag name="sylius.behat.context" />
</service>
<service id="sylius.behat.context.transform.customer_group" class="Sylius\Behat\Context\Transform\CustomerGroupContext" scope="scenario">
<argument type="service" id="sylius.repository.customer_group" container="symfony" />
<tag name="sylius.behat.context" />
</service>
<service id="sylius.behat.context.transform.date_time" class="Sylius\Behat\Context\Transform\DateTimeContext" scope="scenario">
<tag name="sylius.behat.context" />
</service>

View file

@ -73,6 +73,13 @@
<tag name="sylius.behat.context" />
</service>
<service id="sylius.behat.context.ui.admin.managing_customer_groups" class="Sylius\Behat\Context\Ui\Admin\ManagingCustomerGroupsContext" scope="scenario">
<argument type="service" id="sylius.behat.page.admin.customer_group.create" />
<argument type="service" id="sylius.behat.page.admin.customer_group.index" />
<argument type="service" id="sylius.behat.page.admin.customer_group.update" />
<tag name="sylius.behat.context" />
</service>
<service id="sylius.behat.context.ui.admin.managing_locales" class="Sylius\Behat\Context\Ui\Admin\ManagingLocalesContext" scope="scenario">
<argument type="service" id="sylius.behat.page.admin.locale.create" />
<argument type="service" id="sylius.behat.page.admin.locale.index" />

View file

@ -20,6 +20,7 @@
<import resource="admin/country.xml" />
<import resource="admin/currency.xml" />
<import resource="admin/customer.xml" />
<import resource="admin/customer_group.xml" />
<import resource="admin/locale.xml" />
<import resource="admin/order.xml" />
<import resource="admin/payment_method.xml" />

View file

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<parameters>
<parameter key="sylius.behat.page.admin.customer_group.create.class">Sylius\Behat\Page\Admin\CustomerGroup\CreatePage</parameter>
<parameter key="sylius.behat.page.admin.customer_group.index.class">%sylius.behat.page.admin.crud.index.class%</parameter>
<parameter key="sylius.behat.page.admin.customer_group.update.class">Sylius\Behat\Page\Admin\CustomerGroup\UpdatePage</parameter>
</parameters>
<services>
<service id="sylius.behat.page.admin.customer_group.create" class="%sylius.behat.page.admin.customer_group.create.class%" parent="sylius.behat.page.admin.crud.create" scope="scenario" public="false">
<argument type="string">customer_group</argument>
</service>
<service id="sylius.behat.page.admin.customer_group.index" class="%sylius.behat.page.admin.customer_group.index.class%" parent="sylius.behat.page.admin.crud.index" scope="scenario" public="false">
<argument type="string">customer_group</argument>
</service>
<service id="sylius.behat.page.admin.customer_group.update" class="%sylius.behat.page.admin.customer_group.update.class%" parent="sylius.behat.page.admin.crud.update" scope="scenario" public="false">
<argument type="string">customer_group</argument>
</service>
</services>
</container>

View file

@ -56,5 +56,6 @@ imports:
- suites/ui/taxation/managing_tax_rates.yml
- suites/ui/taxonomy/managing_taxons.yml
- suites/ui/user/managing_administrators.yml
- suites/ui/user/managing_customer_groups.yml
- suites/ui/user/managing_customers.yml
- suites/ui/user/managing_users.yml

View file

@ -0,0 +1,19 @@
# This file is part of the Sylius package.
# (c) Paweł Jędrzejewski
default:
suites:
ui_managing_customer_groups:
contexts_as_services:
- sylius.behat.context.hook.doctrine_orm
- sylius.behat.context.transform.customer_group
- sylius.behat.context.transform.shared_storage
- sylius.behat.context.setup.admin_security
- sylius.behat.context.setup.customer_group
- sylius.behat.context.ui.admin.managing_customer_groups
- sylius.behat.context.ui.admin.notification
filters:
tags: "@managing_customer_groups && @ui"

View file

@ -90,6 +90,12 @@ final class MainMenuBuilder extends AbstractAdminMenuBuilder
->setLabel('sylius.menu.admin.main.customers.customers')
->setLabelAttribute('icon', 'users')
;
$customerSubMenu
->addChild('groups', ['route' => 'sylius_admin_customer_group_index'])
->setLabel('sylius.menu.admin.main.customers.groups')
->setLabelAttribute('icon', 'archive')
;
}
/**

View file

@ -4,6 +4,7 @@ imports:
- { resource: "@SyliusAdminBundle/Resources/config/grids/country.yml" }
- { resource: "@SyliusAdminBundle/Resources/config/grids/currency.yml" }
- { resource: "@SyliusAdminBundle/Resources/config/grids/customer.yml" }
- { resource: "@SyliusAdminBundle/Resources/config/grids/customer_group.yml" }
- { resource: "@SyliusAdminBundle/Resources/config/grids/locale.yml" }
- { resource: "@SyliusAdminBundle/Resources/config/grids/order.yml" }
- { resource: "@SyliusAdminBundle/Resources/config/grids/payment_method.yml" }

View file

@ -0,0 +1,28 @@
sylius_grid:
grids:
sylius_admin_customer_group:
driver:
name: doctrine/orm
options:
class: "%sylius.model.customer_group.class%"
sorting:
name:
path: name
direction: asc
fields:
name:
type: string
label: sylius.ui.name
filters:
name:
type: string
label: sylius.ui.name
actions:
main:
create:
type: create
item:
update:
type: update
delete:
type: delete

View file

@ -18,6 +18,9 @@ sylius_admin_currency:
sylius_admin_customer:
resource: "@SyliusAdminBundle/Resources/config/routing/customer.yml"
sylius_admin_customer_group:
resource: "@SyliusAdminBundle/Resources/config/routing/customer_group.yml"
sylius_admin_locale:
resource: "@SyliusAdminBundle/Resources/config/routing/locale.yml"

View file

@ -0,0 +1,18 @@
sylius_admin_customer_group:
resource: |
alias: sylius.customer_group
section: admin
templates: SyliusAdminBundle:Crud
except: ['show']
redirect: update
grid: sylius_admin_customer_group
permission: true
vars:
all:
header: sylius.ui.customer_groups
subheader: sylius.ui.manage_customer_groups
templates:
form: SyliusAdminBundle:CustomerGroup:_form.html.twig
index:
icon: archive
type: sylius.resource

View file

@ -25,6 +25,7 @@ sylius:
promotions: Promotions
customers:
customers: Customers
groups: Groups
header: Customer
sales:
header: Sales

View file

@ -0,0 +1,4 @@
<div class="ui segment">
{{ form_errors(form) }}
{{ form_row(form.name) }}
</div>

View file

@ -134,7 +134,6 @@ sylius:
create_country: 'Create country'
create_currency: 'Create currency'
create_customer: 'Create customer'
create_group: 'Create group'
create_imagine_block: 'Create imagine block'
create_locale: 'Create locale'
create_menu: 'Create menu'
@ -187,6 +186,7 @@ sylius:
customer_can_login_to_the_store: Customer can login to the store
customer_care: Customer Care
customer_details: 'Customer details'
customer_groups: Customer groups
customer_id: 'Customer ID'
customer_login: Customer login
customer_not_notified: 'Customer not notified'
@ -224,7 +224,6 @@ sylius:
edit_coupon: Edit coupon
edit_currency: Edit currency
edit_customer: Edit customer
edit_group: 'Edit group'
edit_locale: 'Edit locale'
edit_my_address: 'Edit my address'
edit_payment_method: Edit payment method
@ -317,7 +316,6 @@ sylius:
go: Go
go_to_dashboard: 'Go to dashboard'
grand_total: 'Grand total'
groups: Groups
guest: Guest
guest_customer: Guest customer
have_an_account_already: Have an account already
@ -385,6 +383,7 @@ sylius:
manage_coupons: Manage coupons
manage_currencies_available_in_the_store: Manage currencies available in the store
manage_customers: 'Manage customers'
manage_customer_groups: Manage groups of your customers
manage_discounts_and_promotional_campaigns: Manage discounts and promotional campaigns
manage_emails: 'Manage Emails'
manage_geographical_zones: Manage geographical zones
@ -699,7 +698,6 @@ sylius:
there_are_no_currencies_to_display: 'There are no currencies to display'
there_are_no_customers_to_display: 'There are no customers to display'
there_are_no_emails_configured: 'There are no emails configured'
there_are_no_groups_to_display: 'There are no groups to display'
there_are_no_images_for_this_product: 'There are no images for this product'
there_are_no_inventory_items_to_display: 'There are no inventory items to display'
there_are_no_inventory_units_to_display: 'There are no inventory units to display'