mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 09:02:12 +00:00
[Admin][ProductOption] Added adding product option feature
This commit is contained in:
parent
4ec65db176
commit
a6a3aba9b9
7 changed files with 180 additions and 17 deletions
|
|
@ -106,8 +106,8 @@
|
|||
<argument type="service" id="sylius.repository.product" container="symfony" />
|
||||
<argument type="service" id="sylius.factory.product" container="symfony" />
|
||||
<argument type="service" id="sylius.factory.product_variant" container="symfony" />
|
||||
<argument type="service" id="sylius.repository.product_option" container="symfony" />
|
||||
<argument type="service" id="sylius.factory.product_option" container="symfony" />
|
||||
<argument type="service" id="sylius.repository.product_option" container="symfony" />
|
||||
<argument type="service" id="doctrine.orm.entity_manager" container="symfony" />
|
||||
<tag name="sylius.behat.context" />
|
||||
</service>
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@
|
|||
<parameter key="sylius.behat.page.admin.product_attribute.create.class">Sylius\Behat\Page\Admin\Product\Attribute\CreatePage</parameter>
|
||||
<parameter key="sylius.behat.page.admin.product_attribute.index.class">%sylius.behat.page.admin.crud.index.class%</parameter>
|
||||
<parameter key="sylius.behat.page.admin.product_attribute.update.class">Sylius\Behat\Page\Admin\Product\Attribute\UpdatePage</parameter>
|
||||
<parameter key="sylius.behat.page.admin.product_option.create.class">%sylius.behat.page.admin.crud.create.class%</parameter>
|
||||
<parameter key="sylius.behat.page.admin.product_option.create.class">Sylius\Behat\Page\Admin\ProductOption\CreatePage</parameter>
|
||||
<parameter key="sylius.behat.page.admin.product_option.update.class">%sylius.behat.page.admin.crud.update.class%</parameter>
|
||||
<parameter key="sylius.behat.page.admin.product_option.index.class">%sylius.behat.page.admin.crud.index.class%</parameter>
|
||||
<parameter key="sylius.behat.page.admin.promotion.create.class">Sylius\Behat\Page\Admin\Promotion\CreatePage</parameter>
|
||||
|
|
|
|||
|
|
@ -7,10 +7,12 @@ default:
|
|||
contexts_as_services:
|
||||
- sylius.behat.context.hook.doctrine_orm
|
||||
|
||||
- sylius.behat.context.transform.locale
|
||||
- sylius.behat.context.transform.shared_storage
|
||||
|
||||
- sylius.behat.context.setup.channel
|
||||
- sylius.behat.context.setup.product
|
||||
- sylius.behat.context.setup.security
|
||||
- sylius.behat.context.setup.product_option
|
||||
|
||||
- sylius.behat.context.ui.admin.managing_product_options
|
||||
filters:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
@managing_product_options
|
||||
Feature: Adding a new product option
|
||||
In order to have different product option
|
||||
As an Administrator
|
||||
I want to be able to add a new product option to the registry
|
||||
|
||||
Background:
|
||||
Given the store operates on a single channel in "France"
|
||||
And I am logged in as an administrator
|
||||
|
||||
@ui @javascript
|
||||
Scenario: Adding a new product option with two required option values
|
||||
Given I want to create a new product option
|
||||
When I name it "T-Shirt size" in "English (United States)"
|
||||
And I specify its code as "t_shirt_size"
|
||||
And I add the option value with code "OV1" and value "S"
|
||||
And I add the option value with code "OV2" and value "M"
|
||||
And I add it
|
||||
Then I should be notified that it has been successfully created
|
||||
And the product option "T-Shirt size" should appear in the registry
|
||||
|
|
@ -13,13 +13,10 @@ namespace Sylius\Behat\Context\Ui\Admin;
|
|||
|
||||
use Behat\Behat\Context\Context;
|
||||
use Sylius\Behat\Page\Admin\Crud\IndexPageInterface;
|
||||
use Sylius\Behat\Page\Admin\Crud\CreatePageInterface;
|
||||
use Sylius\Behat\Page\Admin\ProductOption\CreatePageInterface;
|
||||
use Sylius\Behat\Page\Admin\Crud\UpdatePageInterface;
|
||||
use Sylius\Behat\Service\CurrentPageResolverInterface;
|
||||
use Sylius\Behat\Service\NotificationCheckerInterface;
|
||||
use Sylius\Behat\NotificationType;
|
||||
use Sylius\Component\Core\Model\ShippingMethodInterface;
|
||||
use Sylius\Component\Core\Test\Services\SharedStorageInterface;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
|
|
@ -29,11 +26,6 @@ final class ManagingProductOptionsContext implements Context
|
|||
{
|
||||
const RESOURCE_NAME = 'product_option';
|
||||
|
||||
/**
|
||||
* @var SharedStorageInterface
|
||||
*/
|
||||
private $sharedStorage;
|
||||
|
||||
/**
|
||||
* @var IndexPageInterface
|
||||
*/
|
||||
|
|
@ -60,7 +52,6 @@ final class ManagingProductOptionsContext implements Context
|
|||
private $notificationChecker;
|
||||
|
||||
/**
|
||||
* @param SharedStorageInterface $sharedStorage
|
||||
* @param IndexPageInterface $indexPage
|
||||
* @param CreatePageInterface $createPage
|
||||
* @param UpdatePageInterface $updatePage
|
||||
|
|
@ -68,14 +59,12 @@ final class ManagingProductOptionsContext implements Context
|
|||
* @param NotificationCheckerInterface $notificationChecker
|
||||
*/
|
||||
public function __construct(
|
||||
SharedStorageInterface $sharedStorage,
|
||||
IndexPageInterface $indexPage,
|
||||
CreatePageInterface $createPage,
|
||||
UpdatePageInterface $updatePage,
|
||||
CurrentPageResolverInterface $currentPageResolver,
|
||||
NotificationCheckerInterface $notificationChecker
|
||||
) {
|
||||
$this->sharedStorage = $sharedStorage;
|
||||
$this->indexPage = $indexPage;
|
||||
$this->createPage = $createPage;
|
||||
$this->updatePage = $updatePage;
|
||||
|
|
@ -92,9 +81,9 @@ final class ManagingProductOptionsContext implements Context
|
|||
}
|
||||
|
||||
/**
|
||||
* @When I want to browse product options
|
||||
* @When I browse product options
|
||||
*/
|
||||
public function iWantToBrowseProductOptions()
|
||||
public function iBrowseProductOptions()
|
||||
{
|
||||
$this->indexPage->open();
|
||||
}
|
||||
|
|
@ -116,4 +105,49 @@ final class ManagingProductOptionsContext implements Context
|
|||
{
|
||||
$this->updatePage->saveChanges();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I name it :name in :language
|
||||
*/
|
||||
public function iNameItInLanguage($name, $language)
|
||||
{
|
||||
$this->createPage->nameItIn($name, $language);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I specify its code as :code
|
||||
*/
|
||||
public function iSpecifyItsCodeAs($code)
|
||||
{
|
||||
$this->createPage->specifyCode($code);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I add the option value with code :code and value :value
|
||||
*/
|
||||
public function iAddTheOptionValueWithCodeAndValue($code, $value)
|
||||
{
|
||||
$this->createPage->addOptionValue($code, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should be notified that it has been successfully created
|
||||
*/
|
||||
public function iShouldBeNotifiedItHasBeenSuccessfullyCreated()
|
||||
{
|
||||
$this->notificationChecker->checkCreationNotification(self::RESOURCE_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then the product option :productOptionName should appear in the registry
|
||||
*/
|
||||
public function theProductOptionShouldAppearInTheRegistry($productOptionName)
|
||||
{
|
||||
$this->iBrowseProductOptions();
|
||||
|
||||
Assert::true(
|
||||
$this->indexPage->isResourceOnPage(['name' => $productOptionName]),
|
||||
sprintf('The shipping method with name %s has not been found.', $productOptionName)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
70
src/Sylius/Behat/Page/Admin/ProductOption/CreatePage.php
Normal file
70
src/Sylius/Behat/Page/Admin/ProductOption/CreatePage.php
Normal 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\ProductOption;
|
||||
|
||||
use Behat\Mink\Element\Element;
|
||||
use Sylius\Behat\Behaviour\SpecifiesItsCode;
|
||||
use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage;
|
||||
|
||||
/**
|
||||
* @author Grzegorz Sadowski <grzegorz.sadowski@lakion.com>
|
||||
*/
|
||||
class CreatePage extends BaseCreatePage implements CreatePageInterface
|
||||
{
|
||||
use SpecifiesItsCode;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function nameItIn($name, $language)
|
||||
{
|
||||
$this->getDocument()->fillField(
|
||||
sprintf('sylius_product_option_translations_%s_name', $language), $name
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addOptionValue($code, $value)
|
||||
{
|
||||
$this->getDocument()->clickLink('Add value');
|
||||
|
||||
$optionValueForm = $this->getLastOptionValueElement();
|
||||
|
||||
$optionValueForm->fillField('Code', $code);
|
||||
$optionValueForm->fillField('Value', $code);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getDefinedElements()
|
||||
{
|
||||
return array_merge(parent::getDefinedElements(), [
|
||||
'code' => '#sylius_product_option_code',
|
||||
'name' => '#sylius_product_option_translations_en_US_name',
|
||||
'values' => '#sylius_product_option_values',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Element
|
||||
*/
|
||||
private function getLastOptionValueElement()
|
||||
{
|
||||
$optionValues = $this->getElement('values');
|
||||
$items = $optionValues->findAll('css', 'div[data-form-collection="item"]');
|
||||
|
||||
return end($items);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
<?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\ProductOption;
|
||||
|
||||
use Sylius\Behat\Page\Admin\Crud\CreatePageInterface as BaseCreatePageInterface;
|
||||
|
||||
/**
|
||||
* @author Grzegorz Sadowski <grzegorz.sadowski@lakion.com>
|
||||
*/
|
||||
interface CreatePageInterface extends BaseCreatePageInterface
|
||||
{
|
||||
/**
|
||||
* @param string $code
|
||||
*/
|
||||
public function specifyCode($code);
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $language
|
||||
*/
|
||||
public function nameItIn($name, $language);
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @param string $value
|
||||
*/
|
||||
public function addOptionValue($code, $value);
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue