[Admin][Taxon] Implement scenarios for taxon image code validation

This commit is contained in:
Grzegorz Sadowski 2016-09-22 20:40:58 +02:00
parent ea33093a5a
commit a2f73828a4
7 changed files with 89 additions and 4 deletions

View file

@ -18,7 +18,7 @@ Feature: Changing images of an existing taxon
Then I should be notified that it has been successfully edited
And this taxon should have an image with a code "banner"
@todo
@ui
Scenario: Unable to change a code of an image
When I want to modify the "T-Shirts" taxon
Then the image code field should be disabled

View file

@ -10,7 +10,7 @@ Feature: Taxon image unique code validation within a taxon
And the "T-Shirts" taxon has an image "t-shirts.jpg" with a code "banner"
And I am logged in as an administrator
@todo
@ui @javascript
Scenario: Adding images with the same code to different taxons
When I want to modify the "Mugs" taxon
And I attach the "mugs.jpg" image with a code "banner"
@ -18,10 +18,10 @@ Feature: Taxon image unique code validation within a taxon
Then I should be notified that it has been successfully edited
And this taxon should have an image with a code "banner"
@todo
@ui @javascript
Scenario: Trying to add an image with a code that is already used by other image of this taxon
When I want to modify the "T-Shirts" taxon
And I attach the "mugs.jpg" image with a code "banner"
And I try to save my changes
Then I should be notified that the image with this code already exists
And there should still be only one image with a code "banner"
And there should still be only one image in this taxon

View file

@ -15,6 +15,7 @@ use Behat\Behat\Context\Context;
use Sylius\Behat\Page\Admin\Taxon\CreatePageInterface;
use Sylius\Behat\Page\Admin\Taxon\UpdatePageInterface;
use Sylius\Behat\Service\Resolver\CurrentPageResolverInterface;
use Sylius\Behat\Service\SharedStorageInterface;
use Sylius\Component\Core\Model\TaxonInterface;
use Webmozart\Assert\Assert;
@ -23,6 +24,11 @@ use Webmozart\Assert\Assert;
*/
final class ManagingTaxonsContext implements Context
{
/**
* @var SharedStorageInterface
*/
private $sharedStorage;
/**
* @var CreatePageInterface
*/
@ -39,15 +45,18 @@ final class ManagingTaxonsContext implements Context
private $currentPageResolver;
/**
* @param SharedStorageInterface $sharedStorage
* @param CreatePageInterface $createPage
* @param UpdatePageInterface $updatePage
* @param CurrentPageResolverInterface $currentPageResolver
*/
public function __construct(
SharedStorageInterface $sharedStorage,
CreatePageInterface $createPage,
UpdatePageInterface $updatePage,
CurrentPageResolverInterface $currentPageResolver
) {
$this->sharedStorage = $sharedStorage;
$this->createPage = $createPage;
$this->updatePage = $updatePage;
$this->currentPageResolver = $currentPageResolver;
@ -67,6 +76,8 @@ final class ManagingTaxonsContext implements Context
*/
public function iWantToModifyATaxon(TaxonInterface $taxon)
{
$this->sharedStorage->set('taxon', $taxon);
$this->updatePage->open(['id' => $taxon->getId()]);
}
@ -370,4 +381,37 @@ final class ManagingTaxonsContext implements Context
{
$this->updatePage->changeImageWithCode($code, $path);
}
/**
* @Then I should be notified that the image with this code already exists
*/
public function iShouldBeNotifiedThatTheImageWithThisCodeAlreadyExists()
{
Assert::same($this->updatePage->getValidationMessageForImage('code'), 'Image code must be unique within this taxon.');
}
/**
* @Then /^there should still be only one image in (this taxon)$/
*/
public function thereShouldStillBeOnlyOneImageInThisTaxon(TaxonInterface $taxon)
{
$this->iWantToModifyATaxon($taxon);
Assert::eq(
1,
$this->updatePage->countImages(),
'This taxon has %2$s images, but it should have only one.'
);
}
/**
* @Then the image code field should be disabled
*/
public function theImageCodeFieldShouldBeDisabled()
{
Assert::true(
$this->updatePage->isImageCodeDisabled(),
'Image code field should be disabled but it is not.'
);
}
}

View file

@ -12,6 +12,7 @@
namespace Sylius\Behat\Page\Admin\Taxon;
use Behat\Mink\Element\NodeElement;
use Behat\Mink\Exception\ElementNotFoundException;
use Sylius\Behat\Behaviour\ChecksCodeImmutability;
use Sylius\Behat\Page\Admin\Crud\UpdatePage as BaseUpdatePage;
use Sylius\Component\Core\Model\TaxonInterface;
@ -124,6 +125,29 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
$imageForm->find('css', 'input[type="file"]')->attachFile($filesPath.$path);
}
/**
* {@inheritdoc}
*/
public function getValidationMessageForImage($element)
{
$provinceForm = $this->getLastImageElement();
$foundElement = $provinceForm->find('css', '.pointing');
if (null === $foundElement) {
throw new ElementNotFoundException($this->getSession(), 'Tag', 'css', '.pointing');
}
return $foundElement->getText();
}
/**
* @return bool
*/
public function isImageCodeDisabled()
{
return 'disabled' === $this->getLastImageElement()->findField('Code')->getAttribute('disabled');
}
/**
* @return NodeElement
*/

View file

@ -11,6 +11,7 @@
namespace Sylius\Behat\Page\Admin\Taxon;
use Behat\Mink\Exception\ElementNotFoundException;
use Sylius\Behat\Page\Admin\Crud\UpdatePageInterface as BaseUpdatePageInterface;
use Sylius\Component\Core\Model\TaxonInterface;
@ -47,6 +48,11 @@ interface UpdatePageInterface extends BaseUpdatePageInterface
*/
public function specifyPermalink($permalink, $languageCode);
/**
* @return bool
*/
public function isImageCodeDisabled();
/**
* @param string $code
* @param string $path
@ -77,4 +83,13 @@ interface UpdatePageInterface extends BaseUpdatePageInterface
* @param string $path
*/
public function changeImageWithCode($code, $path);
/**
* @param string $element
*
* @return string
*
* @throws ElementNotFoundException
*/
public function getValidationMessageForImage($element);
}

View file

@ -186,6 +186,7 @@
</service>
<service id="sylius.behat.context.ui.admin.managing_taxons" class="Sylius\Behat\Context\Ui\Admin\ManagingTaxonsContext" scope="scenario">
<argument type="service" id="sylius.behat.shared_storage" />
<argument type="service" id="sylius.behat.page.admin.taxon.create" />
<argument type="service" id="sylius.behat.page.admin.taxon.update" />
<argument type="service" id="sylius.behat.current_page_resolver" />

View file

@ -8,6 +8,7 @@ default:
- sylius.behat.context.hook.doctrine_orm
- sylius.behat.context.transform.locale
- sylius.behat.context.transform.shared_storage
- sylius.behat.context.transform.taxon
- sylius.behat.context.setup.locale