Skip to content

Commit

Permalink
Adding scenarios for disabled type field
Browse files Browse the repository at this point in the history
  • Loading branch information
tuka217 committed Apr 25, 2016
1 parent 1d0cf48 commit 7f849e4
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 1 deletion.
1 change: 1 addition & 0 deletions etc/behat/services/contexts/ui.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
<argument type="service" id="sylius.behat.page.admin.product_attribute.create" />
<argument type="service" id="sylius.behat.page.admin.product_attribute.index" />
<argument type="service" id="sylius.behat.page.admin.product_attribute.update" />
<argument type="service" id="sylius.behat.current_page_resolver" />
<argument type="service" id="sylius.behat.notification_checker" />
<tag name="sylius.behat.context" />
</service>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ Feature: Adding a new text product attribute
And I add it
Then I should be notified that it has been successfully created
And the attribute "T-shirt brand" should appear in the store

@ui
Scenario: Seeing disabled type field while adding a product attribute
When I want to create a new text product attribute
Then the type field should be disabled
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ Feature: Text product attribute edition
Given the store has a text product attribute "T-shirt cotton brand" with code "t_shirt_brand"
When I want to edit this product attribute
Then the code field should be disabled

@ui
Scenario: Seeing disabled type field while editing a product attribute
Given the store has a text product attribute "T-shirt cotton brand" with code "t_shirt_brand"
When I want to edit this product attribute
Then the type field should be disabled
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Sylius\Behat\Page\Admin\Crud\IndexPageInterface;
use Sylius\Behat\Page\Admin\Product\Attribute\CreatePageInterface;
use Sylius\Behat\Page\Admin\Product\Attribute\UpdatePageInterface;
use Sylius\Behat\Service\CurrentPageResolverInterface;
use Sylius\Behat\Service\NotificationCheckerInterface;
use Sylius\Component\Product\Model\AttributeInterface;
use Webmozart\Assert\Assert;
Expand Down Expand Up @@ -46,21 +47,29 @@ final class ManagingProductAttributesContext implements Context
*/
private $notificationChecker;

/**
* @var CurrentPageResolverInterface
*/
private $currentPageResolver;

/**
* @param CreatePageInterface $createPage
* @param IndexPageInterface $indexPage
* @param UpdatePageInterface $updatePage
* @param CurrentPageResolverInterface $currentPageResolver
* @param NotificationCheckerInterface $notificationChecker
*/
public function __construct(
CreatePageInterface $createPage,
IndexPageInterface $indexPage,
UpdatePageInterface $updatePage,
CurrentPageResolverInterface $currentPageResolver,
NotificationCheckerInterface $notificationChecker
) {
$this->createPage = $createPage;
$this->indexPage = $indexPage;
$this->updatePage = $updatePage;
$this->currentPageResolver = $currentPageResolver;
$this->notificationChecker = $notificationChecker;
}

Expand Down Expand Up @@ -160,7 +169,20 @@ public function theCodeFieldShouldBeDisabled()
{
Assert::true(
$this->updatePage->isCodeDisabled(),
'Code should be immutable, but it does not.'
'Code field should be disabled, but it does not.'
);
}

/**
* @Then the type field should be disabled
*/
public function theTypeFieldShouldBeDisabled()
{
$currentPage = $this->currentPageResolver->getCurrentPageWithForm($this->createPage, $this->updatePage);

Assert::true(
$currentPage->isTypeDisabled(),
'Type field should be disabled, but it does not.'
);
}

Expand Down
9 changes: 9 additions & 0 deletions src/Sylius/Behat/Page/Admin/Product/Attribute/CreatePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ public function nameIt($name, $language)
$this->getDocument()->fillField(sprintf('sylius_product_attribute_translations_%s_name', $language), $name);
}

/**
* {@inheritdoc}
*/
public function isTypeDisabled()
{
return 'disabled' === $this->getElement('type')->getAttribute('disabled');
}

/**
* {@inheritdoc}
*/
Expand All @@ -37,6 +45,7 @@ protected function getDefinedElements()
return array_merge(parent::getDefinedElements(), [
'code' => '#sylius_product_attribute_code',
'name' => '#sylius_product_attribute_translations_en_US_name',
'type' => '#sylius_product_attribute_type',
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ public function specifyCode($code);
* @param string $language
*/
public function nameIt($name, $language);

/**
* @return bool
*/
public function isTypeDisabled();
}
9 changes: 9 additions & 0 deletions src/Sylius/Behat/Page/Admin/Product/Attribute/UpdatePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ public function changeName($name, $language)
$this->getDocument()->fillField(sprintf('sylius_product_attribute_translations_%s_name', $language), $name);
}

/**
* {@inheritdoc}
*/
public function isTypeDisabled()
{
return 'disabled' === $this->getElement('type')->getAttribute('disabled');
}

/**
* {@inheritdoc}
*/
Expand All @@ -44,6 +52,7 @@ protected function getDefinedElements()
{
return array_merge(parent::getDefinedElements(), [
'code' => '#sylius_product_attribute_code',
'type' => '#sylius_product_attribute_type',
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ public function changeName($name, $language);
* @return bool
*/
public function isCodeDisabled();

/**
* @return bool
*/
public function isTypeDisabled();
}

0 comments on commit 7f849e4

Please sign in to comment.