[Behat] Add editing feature

This commit is contained in:
Arminek 2016-04-25 13:23:47 +02:00
parent 4c08b8f80c
commit 39c4f6ecc0
5 changed files with 216 additions and 1 deletions

View file

@ -0,0 +1,53 @@
@managing_taxons
Feature: Editing a taxon
In order to change categorization of my merchandise
As an Administrator
I want to be able to edit a taxon
Background:
Given the store operates on a single channel in "France"
And the store classifies its products as "T-Shirts" and "Accessories"
And I am logged in as an administrator
@ui
Scenario: Renaming a taxon
Given I want to modify the "T-Shirts" taxon
When I rename it to "Stickers" in "English (United States)"
And I save my changes
Then I should be notified that it has been successfully edited
And this taxon name should be "Stickers"
@ui
Scenario: Changing description
Given I want to modify the "T-Shirts" taxon
When I rename it to "Stickers" in "English (United States)"
And I change its description to "Main taxonomy for stickers" in "English (United States)"
And I save my changes
Then I should be notified that it has been successfully edited
And this taxon description should be "Main taxonomy for stickers"
@ui
Scenario: Changing permalink
Given I want to modify the "T-Shirts" taxon
When I rename it to "Stickers" in "English (United States)"
And I change its description to "Main taxonomy for stickers" in "English (United States)"
And I change its permalink to "stickers" in "English (United States)"
And I save my changes
Then I should be notified that it has been successfully edited
And this taxon permalink should be "stickers"
@ui
Scenario: Changing parent taxon
Given I want to modify the "T-Shirts" taxon
When I rename it to "Stickers" in "English (United States)"
And I change its description to "Main taxonomy for stickers" in "English (United States)"
And I change its permalink to "stickers" in "English (United States)"
And I change its parent taxon to "Accessories"
And I save my changes
Then I should be notified that it has been successfully edited
And this taxon should belongs to "Accessories"
@ui
Scenario: Seeing a disabled code field when editing a taxon
Given I want to modify the "T-Shirts" taxon
Then the code field should be disabled

View file

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

View file

@ -72,6 +72,14 @@ final class ManagingTaxonsContext implements Context
$this->createPage->open();
}
/**
* @Given /^I want to modify the ("[^"]+" taxon)$/
*/
public function iWantToModifyATaxon(TaxonInterface $taxon)
{
$this->updatePage->open(['id' => $taxon->getId()]);
}
/**
* @When I specify its code as :code
*/
@ -82,13 +90,28 @@ final class ManagingTaxonsContext implements Context
/**
* @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 rename it to :name in :language
*/
public function iRenameItIn($name, $language)
{
$this->updatePage->nameIt($name, $language);
}
/**
* @When I change its description to :description in :language
*/
public function iChangeItsDescriptionToIn($description, $language)
{
$this->updatePage->describeItAs($description, $language);
}
/**
* @When I specify its permalink as :permalink in :language
*/
@ -97,6 +120,14 @@ final class ManagingTaxonsContext implements Context
$this->createPage->specifyPermalink($permalink, $language);
}
/**
* @When I change its permalink to :permalink in :language
*/
public function iChangeItsPermalinkToIn($permalink, $language)
{
$this->updatePage->specifyPermalink($permalink, $language);
}
/**
* @When I describe it as :description in :language
*/
@ -113,6 +144,14 @@ final class ManagingTaxonsContext implements Context
$this->createPage->chooseParent($taxon);
}
/**
* @Given /^I change its (parent taxon to "[^"]+")$/
*/
public function iChangeItsParentTaxonTo(TaxonInterface $taxon)
{
$this->updatePage->chooseParent($taxon);
}
/**
* @When I add it
* @When I try to add it
@ -122,6 +161,15 @@ final class ManagingTaxonsContext implements Context
$this->createPage->create();
}
/**
* @When I save my changes
* @When I try to save my changes
*/
public function iSaveMyChanges()
{
$this->updatePage->saveChanges();
}
/**
* @Then I should be notified that it has been successfully created
*/
@ -130,6 +178,14 @@ final class ManagingTaxonsContext implements Context
$this->notificationChecker->checkCreationNotification(self::RESOURCE_NAME);
}
/**
* @Then I should be notified that it has been successfully edited
*/
public function iShouldBeNotifiedAboutSuccessfulEdition()
{
$this->notificationChecker->checkEditionNotification(self::RESOURCE_NAME);
}
/**
* @Then /^the ("[^"]+" taxon) should appear in the registry$/
*/
@ -165,4 +221,37 @@ final class ManagingTaxonsContext implements Context
sprintf('Taxon %s should have %s parent taxon', $taxon->getName(), $parentTaxon->getName())
);
}
/**
* @Then this taxon :element should be :value
*/
public function thisTaxonElementShouldBe($element, $value)
{
Assert::true(
$this->updatePage->hasResourceValues([$element => $value]),
sprintf('Taxon with %s should have %s value', $element, $value)
);
}
/**
* @Then the code field should be disabled
*/
public function theCodeFiledShouldBeDisabled()
{
Assert::true(
$this->updatePage->isCodeDisabled(),
'Code field should be disabled but it is not'
);
}
/**
* @Then /^this taxon should (belongs to "[^"]+")$/
*/
public function thisTaxonShouldBelongsTo(TaxonInterface $taxon)
{
Assert::true(
$this->updatePage->hasResourceValues(['parent' => $taxon->getId()]),
sprintf('Current taxon should have %s parent taxon', $taxon->getName())
);
}
}

View file

@ -11,13 +11,58 @@
namespace Sylius\Behat\Page\Admin\Taxon;
use Behat\Mink\Element\NodeElement;
use Sylius\Behat\Behaviour\ChecksCodeImmutability;
use Sylius\Behat\Page\Admin\Crud\UpdatePage as BaseUpdatePage;
use Sylius\Component\Core\Model\TaxonInterface;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
{
use ChecksCodeImmutability;
/**
* {@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);
}
/**
* @return NodeElement
*/
protected function getCodeElement()
{
return $this->getElement('code');
}
/**
* {@inheritdoc}
*/

View file

@ -12,11 +12,38 @@
namespace Sylius\Behat\Page\Admin\Taxon;
use Sylius\Behat\Page\Admin\Crud\UpdatePageInterface as BaseUpdatePageInterface;
use Sylius\Component\Core\Model\TaxonInterface;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
interface UpdatePageInterface extends BaseUpdatePageInterface
{
/**
* @param string $description
* @param string $languageCode
*/
public function describeItAs($description, $languageCode);
/**
* @param TaxonInterface $taxon
*/
public function chooseParent(TaxonInterface $taxon);
/**
* @return bool
*/
public function isCodeDisabled();
/**
* @param string $name
* @param string $languageCode
*/
public function nameIt($name, $languageCode);
/**
* @param string $permalink
* @param string $languageCode
*/
public function specifyPermalink($permalink, $languageCode);
}