mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 09:02:12 +00:00
[Behat] Test product generation
This commit is contained in:
parent
8edeefc8e9
commit
a678d78085
5 changed files with 242 additions and 2 deletions
|
|
@ -14,6 +14,7 @@ namespace Sylius\Behat\Context\Ui\Admin;
|
|||
use Behat\Behat\Context\Context;
|
||||
use Sylius\Behat\NotificationType;
|
||||
use Sylius\Behat\Page\Admin\ProductVariant\CreatePageInterface;
|
||||
use Sylius\Behat\Page\Admin\ProductVariant\GeneratePageInterface;
|
||||
use Sylius\Behat\Page\Admin\ProductVariant\IndexPageInterface;
|
||||
use Sylius\Behat\Page\Admin\ProductVariant\UpdatePageInterface;
|
||||
use Sylius\Behat\Service\NotificationCheckerInterface;
|
||||
|
|
@ -48,6 +49,11 @@ final class ManagingProductVariantsContext implements Context
|
|||
*/
|
||||
private $updatePage;
|
||||
|
||||
/**
|
||||
* @var GeneratePageInterface
|
||||
*/
|
||||
private $generatePage;
|
||||
|
||||
/**
|
||||
* @var CurrentPageResolverInterface
|
||||
*/
|
||||
|
|
@ -63,6 +69,7 @@ final class ManagingProductVariantsContext implements Context
|
|||
* @param CreatePageInterface $createPage
|
||||
* @param IndexPageInterface $indexPage
|
||||
* @param UpdatePageInterface $updatePage
|
||||
* @param GeneratePageInterface $generatePage
|
||||
* @param CurrentPageResolverInterface $currentPageResolver
|
||||
* @param NotificationCheckerInterface $notificationChecker
|
||||
*/
|
||||
|
|
@ -71,6 +78,7 @@ final class ManagingProductVariantsContext implements Context
|
|||
CreatePageInterface $createPage,
|
||||
IndexPageInterface $indexPage,
|
||||
UpdatePageInterface $updatePage,
|
||||
GeneratePageInterface $generatePage,
|
||||
CurrentPageResolverInterface $currentPageResolver,
|
||||
NotificationCheckerInterface $notificationChecker
|
||||
) {
|
||||
|
|
@ -78,6 +86,7 @@ final class ManagingProductVariantsContext implements Context
|
|||
$this->createPage = $createPage;
|
||||
$this->indexPage = $indexPage;
|
||||
$this->updatePage = $updatePage;
|
||||
$this->generatePage = $generatePage;
|
||||
$this->currentPageResolver = $currentPageResolver;
|
||||
$this->notificationChecker = $notificationChecker;
|
||||
}
|
||||
|
|
@ -174,7 +183,7 @@ final class ManagingProductVariantsContext implements Context
|
|||
* @Then I should see :numberOfProductVariants variants in the list
|
||||
* @Then I should see :numberOfProductVariants variant in the list
|
||||
*/
|
||||
public function iShouldSeeProductsInTheList($numberOfProductVariants)
|
||||
public function iShouldSeeProductVariantsInTheList($numberOfProductVariants)
|
||||
{
|
||||
$foundRows = $this->indexPage->countItems();
|
||||
|
||||
|
|
@ -256,6 +265,22 @@ final class ManagingProductVariantsContext implements Context
|
|||
$this->assertValidationMessage('price', 'Please enter the price.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^I should be notified that price is required for the (\d)(?:st|nd|rd|th) variant$/
|
||||
*/
|
||||
public function iShouldBeNotifiedThatPriceIsRequiredForVariant($position)
|
||||
{
|
||||
Assert::same($this->generatePage->getValidationMessage('price', $position), 'Please enter the price.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^I should be notified that code is required for the (\d)(?:st|nd|rd|th) variant$/
|
||||
*/
|
||||
public function iShouldBeNotifiedThatCodeIsRequiredForVariant($position)
|
||||
{
|
||||
Assert::same($this->generatePage->getValidationMessage('code', $position), 'Please enter variant code.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I save my changes
|
||||
* @When I try to save my changes
|
||||
|
|
@ -449,6 +474,64 @@ final class ManagingProductVariantsContext implements Context
|
|||
$this->createPage->selectOption($optionName, $optionValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given /^I want to generate new variants for (this product)$/
|
||||
*/
|
||||
public function iWantToGenerateNewVariantsForThisProduct(ProductInterface $product)
|
||||
{
|
||||
$this->generatePage->open(['productId' => $product->getId()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I generate it
|
||||
* @When I try to generate it
|
||||
*/
|
||||
public function iClickGenerate()
|
||||
{
|
||||
$this->generatePage->generate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^I specify that the (\d)(?:st|nd|rd|th) variant is identified by ("[^"]+") code and costs "(?:€|£|\$)([^"]+)"$/
|
||||
*/
|
||||
public function iSpecifyThereAreVariantsIdentifiedByCodeWithCost($nthVariant, $code, $price)
|
||||
{
|
||||
$this->generatePage->nameCode($nthVariant - 1, $code);
|
||||
$this->generatePage->specifyPrice($nthVariant - 1, $price);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^I specify that the (\d)(?:st|nd|rd|th) variant is identified by ("[^"]+") code$/
|
||||
*/
|
||||
public function iSpecifyThereAreVariantsIdentifiedByCode($nthVariant, $code)
|
||||
{
|
||||
$this->generatePage->nameCode($nthVariant, $code - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^I specify that the (\d)(?:st|nd|rd|th) variant costs "(?:€|£|\$)([^"]+)"$/
|
||||
*/
|
||||
public function iSpecifyThereAreVariantsWithCost($nthVariant, $price)
|
||||
{
|
||||
$this->generatePage->specifyPrice($nthVariant, $price - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^I remove (\d)(?:st|nd|rd|th) variant from the list$/
|
||||
*/
|
||||
public function iRemoveVariantFromTheList($nthVariant)
|
||||
{
|
||||
$this->generatePage->removeVariant($nthVariant - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should be notified that it has been successfully generated
|
||||
*/
|
||||
public function iShouldBeNotifiedThatItHasBeenSuccessfullyGenerated()
|
||||
{
|
||||
$this->notificationChecker->checkNotification('Success Product variants have been successfully generated.', NotificationType::success());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $element
|
||||
* @param $message
|
||||
|
|
|
|||
104
src/Sylius/Behat/Page/Admin/ProductVariant/GeneratePage.php
Normal file
104
src/Sylius/Behat/Page/Admin/ProductVariant/GeneratePage.php
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
<?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\ProductVariant;
|
||||
|
||||
use Behat\Mink\Element\NodeElement;
|
||||
use Behat\Mink\Exception\ElementNotFoundException;
|
||||
use Sylius\Behat\Page\SymfonyPage;
|
||||
|
||||
/**
|
||||
* @author Łukasz Chruściel <lukasz.chrusciel@lakion.com>
|
||||
*/
|
||||
class GeneratePage extends SymfonyPage implements GeneratePageInterface
|
||||
{
|
||||
public function generate()
|
||||
{
|
||||
$this->getDocument()->pressButton('Generate');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function specifyPrice($nth, $price)
|
||||
{
|
||||
$this->getDocument()->fillField(sprintf('sylius_product_generate_variants_variants_%s_price', $nth), $price);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function nameCode($nth, $code)
|
||||
{
|
||||
$this->getDocument()->fillField(sprintf('sylius_product_generate_variants_variants_%s_code', $nth), $code);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function removeVariant($nth)
|
||||
{
|
||||
$item = $this->getDocument()->find('css', sprintf('div[data-form-collection-index="%s"]', $nth));
|
||||
|
||||
$item->clickLink('Delete');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRouteName()
|
||||
{
|
||||
return 'sylius_admin_product_variant_generate';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @throws ElementNotFoundException
|
||||
*/
|
||||
public function getValidationMessage($element, $position)
|
||||
{
|
||||
$foundElement = $this->getElement($element, ['%position%' => $position]);
|
||||
$validatedField = $this->getValidatedField($foundElement);
|
||||
if (null === $validatedField) {
|
||||
throw new ElementNotFoundException($this->getSession(), 'Element', 'css', $foundElement);
|
||||
}
|
||||
|
||||
return $validatedField->find('css', '.sylius-validation-error')->getText();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getDefinedElements()
|
||||
{
|
||||
return array_merge(parent::getDefinedElements(), [
|
||||
'code' => '#sylius_product_generate_variants_variants_%position%_code',
|
||||
'price' => '#sylius_product_generate_variants_variants_%position%_price',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param NodeElement $element
|
||||
*
|
||||
* @return NodeElement
|
||||
*
|
||||
* @throws ElementNotFoundException
|
||||
*/
|
||||
private function getValidatedField(NodeElement $element)
|
||||
{
|
||||
while (null !== $element && !$element->hasClass('field')) {
|
||||
$element = $element->getParent();
|
||||
}
|
||||
|
||||
return $element;
|
||||
}
|
||||
}
|
||||
|
|
@ -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\Page\Admin\ProductVariant;
|
||||
|
||||
use Sylius\Behat\Page\SymfonyPageInterface;
|
||||
|
||||
/**
|
||||
* @author Łukasz Chruściel <lukasz.chrusciel@lakion.com>
|
||||
*/
|
||||
interface GeneratePageInterface extends SymfonyPageInterface
|
||||
{
|
||||
public function generate();
|
||||
|
||||
/**
|
||||
* @param int $nth
|
||||
* @param int $price
|
||||
*/
|
||||
public function specifyPrice($nth, $price);
|
||||
|
||||
/**
|
||||
* @param int $nth
|
||||
* @param string $code
|
||||
*/
|
||||
public function nameCode($nth, $code);
|
||||
|
||||
/**
|
||||
* @param int $nth
|
||||
*/
|
||||
public function removeVariant($nth);
|
||||
|
||||
/**
|
||||
* @param string $element
|
||||
* @param int $position
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValidationMessage($element, $position);
|
||||
}
|
||||
|
|
@ -155,6 +155,7 @@
|
|||
<argument type="service" id="sylius.behat.page.admin.product_variant.create" />
|
||||
<argument type="service" id="sylius.behat.page.admin.product_variant.index" />
|
||||
<argument type="service" id="sylius.behat.page.admin.product_variant.update" />
|
||||
<argument type="service" id="sylius.behat.page.admin.product_variant.generate" />
|
||||
<argument type="service" id="sylius.behat.current_page_resolver" />
|
||||
<argument type="service" id="sylius.behat.notification_checker" />
|
||||
<tag name="fob.context_service" />
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@
|
|||
<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.product_variant.create.class">Sylius\Behat\Page\Admin\ProductVariant\CreatePage</parameter>
|
||||
<parameter key="sylius.behat.page.admin.product_variant.generate.class">Sylius\Behat\Page\Admin\ProductVariant\GeneratePage</parameter>
|
||||
<parameter key="sylius.behat.page.admin.product_variant.index.class">Sylius\Behat\Page\Admin\ProductVariant\IndexPage</parameter>
|
||||
<parameter key="sylius.behat.page.admin.product_variant.update.class">Sylius\Behat\Page\Admin\ProductVariant\UpdatePage</parameter>
|
||||
</parameters>
|
||||
|
||||
|
|
@ -21,7 +23,10 @@
|
|||
<service id="sylius.behat.page.admin.product_variant.create" class="%sylius.behat.page.admin.product_variant.create.class%" parent="sylius.behat.page.admin.crud.create" public="false">
|
||||
<argument type="string">product_variant</argument>
|
||||
</service>
|
||||
<service id="sylius.behat.page.admin.product_variant.index" class="Sylius\Behat\Page\Admin\ProductVariant\IndexPage" parent="sylius.behat.page.admin.crud.index" public="false">
|
||||
<service id="sylius.behat.page.admin.product_variant.generate" class="%sylius.behat.page.admin.product_variant.generate.class%" parent="sylius.behat.symfony_page" public="false">
|
||||
<argument type="string">product_variant</argument>
|
||||
</service>
|
||||
<service id="sylius.behat.page.admin.product_variant.index" class="%sylius.behat.page.admin.product_variant.index.class%" parent="sylius.behat.page.admin.crud.index" public="false">
|
||||
<argument type="string">product_variant</argument>
|
||||
</service>
|
||||
<service id="sylius.behat.page.admin.product_variant.update" class="%sylius.behat.page.admin.product_variant.update.class%" parent="sylius.behat.page.admin.crud.update" public="false">
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue