diff --git a/features/addressing/managing_countries/editing_country.feature b/features/addressing/managing_countries/editing_country.feature index ac7f5911c4..0ac4b143f2 100644 --- a/features/addressing/managing_countries/editing_country.feature +++ b/features/addressing/managing_countries/editing_country.feature @@ -25,7 +25,7 @@ Feature: Editing country Then I should be notified about successful edition And this country should be enabled - @todo + @ui Scenario: Seeing disabled code field while editing country Given the store has country "France" When I want to edit this country diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingCountriesContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingCountriesContext.php index 50c3f68e00..0c3127f9b7 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/ManagingCountriesContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingCountriesContext.php @@ -126,15 +126,13 @@ final class ManagingCountriesContext implements Context */ public function iShouldBeNotifiedAboutSuccessfulCreation() { - $doesSuccessMessageAppear = $this->notificationAccessor->hasSuccessMessage(); Assert::true( - $doesSuccessMessageAppear, + $this->notificationAccessor->hasSuccessMessage(), sprintf('Message type is not positive') ); - $doesSuccessfulCreationMessageAppear = $this->notificationAccessor->isSuccessfullyCreatedFor(self::RESOURCE_NAME); Assert::true( - $doesSuccessfulCreationMessageAppear, + $this->notificationAccessor->isSuccessfullyCreatedFor(self::RESOURCE_NAME), sprintf('Successful creation message does not appear') ); } @@ -144,15 +142,13 @@ final class ManagingCountriesContext implements Context */ public function iShouldBeNotifiedAboutSuccessfulEdition() { - $doesSuccessMessageAppear = $this->notificationAccessor->hasSuccessMessage(); Assert::true( - $doesSuccessMessageAppear, + $this->notificationAccessor->hasSuccessMessage(), 'Message type is not positive' ); - $doesSuccessfulEditionMessageAppear = $this->notificationAccessor->isSuccessfullyUpdatedFor(self::RESOURCE_NAME); Assert::true( - $doesSuccessfulEditionMessageAppear, + $this->notificationAccessor->isSuccessfullyUpdatedFor(self::RESOURCE_NAME), 'Successful edition message does not appear' ); } @@ -162,9 +158,8 @@ final class ManagingCountriesContext implements Context */ public function countryShouldAppearInTheStore(CountryInterface $country) { - $doesCountryExist = $this->countryIndexPage->isResourceOnPage(['code' => $country->getCode()]); Assert::true( - $doesCountryExist, + $this->countryIndexPage->isResourceOnPage(['code' => $country->getCode()]), sprintf('Country %s should exist but it does not', $country->getCode()) ); } @@ -174,9 +169,8 @@ final class ManagingCountriesContext implements Context */ public function thisCountryShouldBeEnabled(CountryInterface $country) { - $isCountryEnabled = $this->countryIndexPage->isCountryEnabled($country); Assert::true( - $isCountryEnabled, + $this->countryIndexPage->isCountryEnabled($country), sprintf('Country %s should be enabled but it is not', $country->getCode()) ); } @@ -201,4 +195,14 @@ final class ManagingCountriesContext implements Context expect($this->countryCreatePage)->toThrow(ElementNotFoundException::class)->during('chooseName', [$name]); } + /** + * @Then the code field should be disabled + */ + public function theCodeFieldShouldBeDisabled() + { + Assert::true( + $this->countryUpdatePage->isCodeFieldDisabled(), + 'Code field should be disabled but is not' + ); + } } diff --git a/src/Sylius/Behat/Page/Admin/Country/UpdatePage.php b/src/Sylius/Behat/Page/Admin/Country/UpdatePage.php index 68cd0a1c89..c227b37729 100644 --- a/src/Sylius/Behat/Page/Admin/Country/UpdatePage.php +++ b/src/Sylius/Behat/Page/Admin/Country/UpdatePage.php @@ -13,6 +13,7 @@ namespace Sylius\Behat\Page\Admin\Country; use Behat\Mink\Element\NodeElement; use Sylius\Behat\Page\Admin\Crud\UpdatePage as BaseUpdatePage; +use Sylius\Behat\Page\ElementNotFoundException; /** * @author Arkadiusz Krakowiak @@ -24,6 +25,7 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface */ protected $elements = [ 'enabled' => '#sylius_country_enabled', + 'code' => '#sylius_country_code', ]; /** @@ -48,6 +50,19 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface $enabled->uncheck(); } + /** + * {@inheritdoc} + */ + public function isCodeFieldDisabled() + { + try { + $codeField = $this->getElement('code'); + return $codeField->getAttribute('disabled') === 'disabled'; + } catch (ElementNotFoundException $exception) { + return false; + } + } + /** * @param NodeElement $toggleableElement * @param bool $expectedState diff --git a/src/Sylius/Behat/Page/Admin/Country/UpdatePageInterface.php b/src/Sylius/Behat/Page/Admin/Country/UpdatePageInterface.php index 8c507e6a68..8f3a4da1cd 100644 --- a/src/Sylius/Behat/Page/Admin/Country/UpdatePageInterface.php +++ b/src/Sylius/Behat/Page/Admin/Country/UpdatePageInterface.php @@ -27,4 +27,9 @@ interface UpdatePageInterface extends BaseUpdatePageInterface * @throws \RuntimeException */ public function disable(); + + /** + * @return bool + */ + public function isCodeFieldDisabled(); } diff --git a/src/Sylius/Behat/spec/Context/Ui/Admin/ManagingCountriesContextSpec.php b/src/Sylius/Behat/spec/Context/Ui/Admin/ManagingCountriesContextSpec.php index acde7a09a0..1961b88495 100644 --- a/src/Sylius/Behat/spec/Context/Ui/Admin/ManagingCountriesContextSpec.php +++ b/src/Sylius/Behat/spec/Context/Ui/Admin/ManagingCountriesContextSpec.php @@ -200,4 +200,16 @@ class ManagingCountriesContextSpec extends ObjectBehavior $this->shouldThrow(\Exception::class)->during('iShouldNotBeAbleToChoose', ['France']); } + + function it_asserts_that_country_code_field_is_disabled(UpdatePageInterface $countryUpdatePage) + { + $countryUpdatePage->isCodeFieldDisabled()->willReturn(true); + $this->theCodeFieldShouldBeDisabled(); + } + + function it_throws_not_equal_exception_if_country_code_field_is_not_disabled(UpdatePageInterface $countryUpdatePage) + { + $countryUpdatePage->isCodeFieldDisabled()->willReturn(false); + $this->shouldThrow(\InvalidArgumentException::class)->during('theCodeFieldShouldBeDisabled'); + } }