diff --git a/composer.json b/composer.json index c53fec3e3c3..c605893a07b 100644 --- a/composer.json +++ b/composer.json @@ -79,6 +79,7 @@ "behat/mink-selenium2-driver": "^1.3", "friends-of-behat/context-service-extension": "^1.2", "friends-of-behat/cross-container-extension": "^1.1", + "friends-of-behat/page-object-extension": "^0.1.0", "friends-of-behat/service-container-extension": "^1.0", "friends-of-behat/symfony-extension": "^1.2.1", "friends-of-behat/variadic-extension": "^1.1", diff --git a/src/Sylius/Behat/Context/Ui/Shop/Checkout/RegistrationAfterCheckoutContext.php b/src/Sylius/Behat/Context/Ui/Shop/Checkout/RegistrationAfterCheckoutContext.php index fafd976722d..36ded06c558 100644 --- a/src/Sylius/Behat/Context/Ui/Shop/Checkout/RegistrationAfterCheckoutContext.php +++ b/src/Sylius/Behat/Context/Ui/Shop/Checkout/RegistrationAfterCheckoutContext.php @@ -14,9 +14,9 @@ namespace Sylius\Behat\Context\Ui\Shop\Checkout; use Behat\Behat\Context\Context; +use Sylius\Behat\Element\Shop\Account\RegisterElementInterface; use Sylius\Behat\Page\Shop\Account\DashboardPageInterface; use Sylius\Behat\Page\Shop\Account\LoginPageInterface; -use Sylius\Behat\Page\Shop\Account\RegisterPageInterface; use Sylius\Behat\Page\Shop\Account\VerificationPageInterface; use Sylius\Behat\Page\Shop\HomePageInterface; use Sylius\Behat\Page\Shop\Order\ThankYouPageInterface; @@ -33,9 +33,6 @@ final class RegistrationAfterCheckoutContext implements Context /** @var LoginPageInterface */ private $loginPage; - /** @var RegisterPageInterface */ - private $registerPage; - /** @var ThankYouPageInterface */ private $thankYouPage; @@ -48,26 +45,29 @@ final class RegistrationAfterCheckoutContext implements Context /** @var VerificationPageInterface */ private $verificationPage; + /** @var RegisterElementInterface */ + private $registerElement; + /** @var NotificationCheckerInterface */ private $notificationChecker; public function __construct( SharedStorageInterface $sharedStorage, LoginPageInterface $loginPage, - RegisterPageInterface $registerPage, ThankYouPageInterface $thankYouPage, DashboardPageInterface $dashboardPage, HomePageInterface $homePage, VerificationPageInterface $verificationPage, + RegisterElementInterface $registerElement, NotificationCheckerInterface $notificationChecker ) { $this->sharedStorage = $sharedStorage; $this->loginPage = $loginPage; - $this->registerPage = $registerPage; $this->thankYouPage = $thankYouPage; $this->dashboardPage = $dashboardPage; $this->homePage = $homePage; $this->verificationPage = $verificationPage; + $this->registerElement = $registerElement; $this->notificationChecker = $notificationChecker; } @@ -76,7 +76,7 @@ public function __construct( */ public function iSpecifyThePasswordAs(string $password): void { - $this->registerPage->specifyPassword($password); + $this->registerElement->specifyPassword($password); $this->sharedStorage->set('password', $password); } @@ -85,7 +85,7 @@ public function iSpecifyThePasswordAs(string $password): void */ public function iConfirmThisPassword(string $password): void { - $this->registerPage->verifyPassword($password); + $this->registerElement->verifyPassword($password); } /** @@ -93,7 +93,7 @@ public function iConfirmThisPassword(string $password): void */ public function iRegisterThisAccount(): void { - $this->registerPage->register(); + $this->registerElement->register(); } /** @@ -114,7 +114,7 @@ public function theRegistrationFormShouldBePrefilledWithEmail(string $email): vo { $this->thankYouPage->createAccount(); - Assert::same($this->registerPage->getEmail(), $email); + Assert::same($this->registerElement->getEmail(), $email); } /** diff --git a/src/Sylius/Behat/Context/Ui/Shop/CheckoutContext.php b/src/Sylius/Behat/Context/Ui/Shop/CheckoutContext.php index 85b66e34c2d..f2257d5a798 100644 --- a/src/Sylius/Behat/Context/Ui/Shop/CheckoutContext.php +++ b/src/Sylius/Behat/Context/Ui/Shop/CheckoutContext.php @@ -17,6 +17,7 @@ use Sylius\Behat\Context\Ui\Shop\Checkout\CheckoutAddressingContext; use Sylius\Behat\Context\Ui\Shop\Checkout\CheckoutPaymentContext; use Sylius\Behat\Context\Ui\Shop\Checkout\CheckoutShippingContext; +use Sylius\Behat\Element\Shop\Account\RegisterElementInterface; use Sylius\Behat\Page\Shop\Account\RegisterPageInterface; use Sylius\Behat\Page\Shop\Checkout\AddressPageInterface; use Sylius\Behat\Page\Shop\Checkout\CompletePageInterface; @@ -29,68 +30,43 @@ final class CheckoutContext implements Context { - /** - * @var AddressPageInterface - */ + /** @var AddressPageInterface */ private $addressPage; - /** - * @var SelectPaymentPageInterface - */ + /** @var SelectPaymentPageInterface */ private $selectPaymentPage; - /** - * @var SelectShippingPageInterface - */ + /** @var SelectShippingPageInterface */ private $selectShippingPage; - /** - * @var CompletePageInterface - */ + /** @var CompletePageInterface */ private $completePage; - /** - * @var RegisterPageInterface - */ + /** @var RegisterPageInterface */ private $registerPage; - /** - * @var CurrentPageResolverInterface - */ + /** @var RegisterElementInterface */ + private $registerElement; + + /** @var CurrentPageResolverInterface */ private $currentPageResolver; - /** - * @var CheckoutAddressingContext - */ + /** @var CheckoutAddressingContext */ private $addressingContext; - /** - * @var CheckoutShippingContext - */ + /** @var CheckoutShippingContext */ private $shippingContext; - /** - * @var CheckoutPaymentContext - */ + /** @var CheckoutPaymentContext */ private $paymentContext; - /** - * @param AddressPageInterface $addressPage - * @param SelectPaymentPageInterface $selectPaymentPage - * @param SelectShippingPageInterface $selectShippingPage - * @param CompletePageInterface $completePage - * @param RegisterPageInterface $registerPage - * @param CurrentPageResolverInterface $currentPageResolver - * @param CheckoutAddressingContext $addressingContext - * @param CheckoutShippingContext $shippingContext - * @param CheckoutPaymentContext $paymentContext - */ public function __construct( AddressPageInterface $addressPage, SelectPaymentPageInterface $selectPaymentPage, SelectShippingPageInterface $selectShippingPage, CompletePageInterface $completePage, RegisterPageInterface $registerPage, + RegisterElementInterface $registerElement, CurrentPageResolverInterface $currentPageResolver, CheckoutAddressingContext $addressingContext, CheckoutShippingContext $shippingContext, @@ -101,6 +77,7 @@ public function __construct( $this->selectShippingPage = $selectShippingPage; $this->completePage = $completePage; $this->registerPage = $registerPage; + $this->registerElement = $registerElement; $this->currentPageResolver = $currentPageResolver; $this->addressingContext = $addressingContext; $this->shippingContext = $shippingContext; @@ -242,11 +219,11 @@ public function theSubtotalOfItemShouldBe($item, $price) public function iRegisterWithPreviouslyUsedEmailAndPassword(string $email, string $password): void { $this->registerPage->open(); - $this->registerPage->specifyEmail($email); - $this->registerPage->specifyPassword($password); - $this->registerPage->verifyPassword($password); - $this->registerPage->specifyFirstName('Carrot'); - $this->registerPage->specifyLastName('Ironfoundersson'); - $this->registerPage->register(); + $this->registerElement->specifyEmail($email); + $this->registerElement->specifyPassword($password); + $this->registerElement->verifyPassword($password); + $this->registerElement->specifyFirstName('Carrot'); + $this->registerElement->specifyLastName('Ironfoundersson'); + $this->registerElement->register(); } } diff --git a/src/Sylius/Behat/Context/Ui/Shop/LoginContext.php b/src/Sylius/Behat/Context/Ui/Shop/LoginContext.php index cdffd1cb3ec..646cfbd14fe 100644 --- a/src/Sylius/Behat/Context/Ui/Shop/LoginContext.php +++ b/src/Sylius/Behat/Context/Ui/Shop/LoginContext.php @@ -14,6 +14,7 @@ namespace Sylius\Behat\Context\Ui\Shop; use Behat\Behat\Context\Context; +use Sylius\Behat\Element\Shop\Account\RegisterElementInterface; use Sylius\Behat\NotificationType; use Sylius\Behat\Page\Shop\Account\LoginPageInterface; use Sylius\Behat\Page\Shop\Account\RegisterPageInterface; @@ -24,49 +25,37 @@ final class LoginContext implements Context { - /** - * @var HomePageInterface - */ + /** @var HomePageInterface */ private $homePage; - /** - * @var LoginPageInterface - */ + /** @var LoginPageInterface */ private $loginPage; - /** - * @var RegisterPageInterface - */ + /** @var RegisterPageInterface */ private $registerPage; - /** - * @var ResetPasswordPageInterface - */ + /** @var ResetPasswordPageInterface */ private $resetPasswordPage; - /** - * @var NotificationCheckerInterface - */ + /** @var RegisterElementInterface */ + private $registerElement; + + /** @var NotificationCheckerInterface */ private $notificationChecker; - /** - * @param HomePageInterface $homePage - * @param LoginPageInterface $loginPage - * @param RegisterPageInterface $registerPage - * @param ResetPasswordPageInterface $resetPasswordPage - * @param NotificationCheckerInterface $notificationChecker - */ public function __construct( HomePageInterface $homePage, LoginPageInterface $loginPage, RegisterPageInterface $registerPage, ResetPasswordPageInterface $resetPasswordPage, + RegisterElementInterface $registerElement, NotificationCheckerInterface $notificationChecker ) { $this->homePage = $homePage; $this->loginPage = $loginPage; $this->registerPage = $registerPage; $this->resetPasswordPage = $resetPasswordPage; + $this->registerElement = $registerElement; $this->notificationChecker = $notificationChecker; } @@ -144,15 +133,15 @@ public function iSignInWithEmailAndPassword(string $email, string $password): vo /** * @When I register with email :email and password :password */ - public function iRegisterWithEmailAndPassword($email, $password) + public function iRegisterWithEmailAndPassword(string $email, string $password): void { $this->registerPage->open(); - $this->registerPage->specifyEmail($email); - $this->registerPage->specifyPassword($password); - $this->registerPage->verifyPassword($password); - $this->registerPage->specifyFirstName('Carrot'); - $this->registerPage->specifyLastName('Ironfoundersson'); - $this->registerPage->register(); + $this->registerElement->specifyEmail($email); + $this->registerElement->specifyPassword($password); + $this->registerElement->verifyPassword($password); + $this->registerElement->specifyFirstName('Carrot'); + $this->registerElement->specifyLastName('Ironfoundersson'); + $this->registerElement->register(); } /** diff --git a/src/Sylius/Behat/Context/Ui/Shop/RegistrationContext.php b/src/Sylius/Behat/Context/Ui/Shop/RegistrationContext.php index 4abd9ef438f..e4b6537e1cb 100644 --- a/src/Sylius/Behat/Context/Ui/Shop/RegistrationContext.php +++ b/src/Sylius/Behat/Context/Ui/Shop/RegistrationContext.php @@ -14,6 +14,7 @@ namespace Sylius\Behat\Context\Ui\Shop; use Behat\Behat\Context\Context; +use Sylius\Behat\Element\Shop\Account\RegisterElementInterface; use Sylius\Behat\NotificationType; use Sylius\Behat\Page\Shop\Account\DashboardPageInterface; use Sylius\Behat\Page\Shop\Account\LoginPageInterface; @@ -29,56 +30,33 @@ class RegistrationContext implements Context { - /** - * @var SharedStorageInterface - */ + /** @var SharedStorageInterface */ private $sharedStorage; - /** - * @var DashboardPageInterface - */ + /** @var DashboardPageInterface */ private $dashboardPage; - /** - * @var HomePageInterface - */ + /** @var HomePageInterface */ private $homePage; - /** - * @var LoginPageInterface - */ + /** @var LoginPageInterface */ private $loginPage; - /** - * @var RegisterPageInterface - */ + /** @var RegisterPageInterface */ private $registerPage; - /** - * @var VerificationPageInterface - */ + /** @var VerificationPageInterface */ private $verificationPage; - /** - * @var ProfileUpdatePageInterface - */ + /** @var ProfileUpdatePageInterface */ private $profileUpdatePage; - /** - * @var NotificationCheckerInterface - */ + /** @var RegisterElementInterface */ + private $registerElement; + + /** @var NotificationCheckerInterface */ private $notificationChecker; - /** - * @param SharedStorageInterface $sharedStorage - * @param DashboardPageInterface $dashboardPage - * @param HomePageInterface $homePage - * @param LoginPageInterface $loginPage - * @param RegisterPageInterface $registerPage - * @param VerificationPageInterface $verificationPage - * @param ProfileUpdatePageInterface $profileUpdatePage - * @param NotificationCheckerInterface $notificationChecker - */ public function __construct( SharedStorageInterface $sharedStorage, DashboardPageInterface $dashboardPage, @@ -87,6 +65,7 @@ public function __construct( RegisterPageInterface $registerPage, VerificationPageInterface $verificationPage, ProfileUpdatePageInterface $profileUpdatePage, + RegisterElementInterface $registerElement, NotificationCheckerInterface $notificationChecker ) { $this->sharedStorage = $sharedStorage; @@ -96,13 +75,14 @@ public function __construct( $this->registerPage = $registerPage; $this->verificationPage = $verificationPage; $this->profileUpdatePage = $profileUpdatePage; + $this->registerElement = $registerElement; $this->notificationChecker = $notificationChecker; } /** * @When /^I want to(?:| again) register a new account$/ */ - public function iWantToRegisterANewAccount() + public function iWantToRegisterANewAccount(): void { $this->registerPage->open(); } @@ -111,77 +91,77 @@ public function iWantToRegisterANewAccount() * @When I specify the first name as :firstName * @When I do not specify the first name */ - public function iSpecifyTheFirstName($firstName = null) + public function iSpecifyTheFirstName(?string $firstName = null): void { - $this->registerPage->specifyFirstName($firstName); + $this->registerElement->specifyFirstName($firstName); } /** * @When I specify the last name as :lastName * @When I do not specify the last name */ - public function iSpecifyTheLastName($lastName = null) + public function iSpecifyTheLastName(?string $lastName = null): void { - $this->registerPage->specifyLastName($lastName); + $this->registerElement->specifyLastName($lastName); } /** * @When I specify the email as :email * @When I do not specify the email */ - public function iSpecifyTheEmail($email = null) + public function iSpecifyTheEmail(?string $email = null): void { - $this->registerPage->specifyEmail($email); + $this->registerElement->specifyEmail($email); } /** * @When I specify the password as :password * @When I do not specify the password */ - public function iSpecifyThePasswordAs($password = null) + public function iSpecifyThePasswordAs(?string $password = null): void { - $this->registerPage->specifyPassword($password); + $this->registerElement->specifyPassword($password); $this->sharedStorage->set('password', $password); } /** * @When /^I confirm (this password)$/ */ - public function iConfirmThisPassword($password) + public function iConfirmThisPassword(string $password): void { - $this->registerPage->verifyPassword($password); + $this->registerElement->verifyPassword($password); } /** * @Given I do not confirm the password */ - public function iDoNotConfirmPassword() + public function iDoNotConfirmPassword(): void { - $this->registerPage->verifyPassword(null); + $this->registerElement->verifyPassword(null); } /** * @When I specify the phone number as :phoneNumber */ - public function iSpecifyThePhoneNumberAs($phoneNumber) + public function iSpecifyThePhoneNumberAs(string $phoneNumber): void { - $this->registerPage->specifyPhoneNumber($phoneNumber); + $this->registerElement->specifyPhoneNumber($phoneNumber); } /** * @When I register this account * @When I try to register this account */ - public function iRegisterThisAccount() + public function iRegisterThisAccount(): void { - $this->registerPage->register(); + $this->registerElement->register(); } /** * @Then my email should be :email * @Then my email should still be :email */ - public function myEmailShouldBe($email) + public function myEmailShouldBe(string $email): void { $this->dashboardPage->open(); @@ -191,7 +171,7 @@ public function myEmailShouldBe($email) /** * @Then /^I should be notified that the ([^"]+) is required$/ */ - public function iShouldBeNotifiedThatElementIsRequired($element) + public function iShouldBeNotifiedThatElementIsRequired(string $element): void { $this->assertFieldValidationMessage($element, sprintf('Please enter your %s.', $element)); } @@ -199,7 +179,7 @@ public function iShouldBeNotifiedThatElementIsRequired($element) /** * @Then I should be notified that the email is already used */ - public function iShouldBeNotifiedThatTheEmailIsAlreadyUsed() + public function iShouldBeNotifiedThatTheEmailIsAlreadyUsed(): void { $this->assertFieldValidationMessage('email', 'This email is already used.'); } @@ -207,7 +187,7 @@ public function iShouldBeNotifiedThatTheEmailIsAlreadyUsed() /** * @Then I should be notified that the password do not match */ - public function iShouldBeNotifiedThatThePasswordDoNotMatch() + public function iShouldBeNotifiedThatThePasswordDoNotMatch(): void { $this->assertFieldValidationMessage('password', 'The entered passwords don\'t match'); } @@ -216,7 +196,7 @@ public function iShouldBeNotifiedThatThePasswordDoNotMatch() * @Then I should be notified that new account has been successfully created * @Then I should be notified that my account has been created and the verification email has been sent */ - public function iShouldBeNotifiedThatNewAccountHasBeenSuccessfullyCreated() + public function iShouldBeNotifiedThatNewAccountHasBeenSuccessfullyCreated(): void { $this->notificationChecker->checkNotification( 'Thank you for registering, check your email to verify your account.', @@ -227,7 +207,7 @@ public function iShouldBeNotifiedThatNewAccountHasBeenSuccessfullyCreated() /** * @Then I should be logged in */ - public function iShouldBeLoggedIn() + public function iShouldBeLoggedIn(): void { Assert::true($this->homePage->hasLogoutButton()); } @@ -235,7 +215,7 @@ public function iShouldBeLoggedIn() /** * @Then I should not be logged in */ - public function iShouldNotBeLoggedIn() + public function iShouldNotBeLoggedIn(): void { Assert::false($this->homePage->hasLogoutButton()); } @@ -243,7 +223,7 @@ public function iShouldNotBeLoggedIn() /** * @Then I should be able to log in as :email with :password password */ - public function iShouldBeAbleToLogInAsWithPassword($email, $password) + public function iShouldBeAbleToLogInAsWithPassword(string $email, string $password): void { $this->iLogInAsWithPassword($email, $password); $this->iShouldBeLoggedIn(); @@ -252,7 +232,7 @@ public function iShouldBeAbleToLogInAsWithPassword($email, $password) /** * @Then I should not be able to log in as :email with :password password */ - public function iShouldNotBeAbleToLogInAsWithPassword($email, $password) + public function iShouldNotBeAbleToLogInAsWithPassword(string $email, string $password): void { $this->iLogInAsWithPassword($email, $password); @@ -262,7 +242,7 @@ public function iShouldNotBeAbleToLogInAsWithPassword($email, $password) /** * @When I log in as :email with :password password */ - public function iLogInAsWithPassword($email, $password) + public function iLogInAsWithPassword(string $email, string $password): void { $this->loginPage->open(); $this->loginPage->specifyUsername($email); @@ -273,21 +253,21 @@ public function iLogInAsWithPassword($email, $password) /** * @When I register with email :email and password :password */ - public function iRegisterWithEmailAndPassword($email, $password) + public function iRegisterWithEmailAndPassword(string $email, string $password): void { $this->registerPage->open(); - $this->registerPage->specifyEmail($email); - $this->registerPage->specifyPassword($password); - $this->registerPage->verifyPassword($password); - $this->registerPage->specifyFirstName('Carrot'); - $this->registerPage->specifyLastName('Ironfoundersson'); - $this->registerPage->register(); + $this->registerElement->specifyEmail($email); + $this->registerElement->specifyPassword($password); + $this->registerElement->verifyPassword($password); + $this->registerElement->specifyFirstName('Carrot'); + $this->registerElement->specifyLastName('Ironfoundersson'); + $this->registerElement->register(); } /** * @Then /^my account should be verified$/ */ - public function myAccountShouldBeVerified() + public function myAccountShouldBeVerified(): void { Assert::true($this->dashboardPage->isVerified()); } @@ -295,7 +275,7 @@ public function myAccountShouldBeVerified() /** * @When /^(I) try to verify my account using the link from this email$/ */ - public function iUseItToVerify(ShopUserInterface $user) + public function iUseItToVerify(ShopUserInterface $user): void { $this->verificationPage->verifyAccount($user->getEmailVerificationToken()); } @@ -303,7 +283,7 @@ public function iUseItToVerify(ShopUserInterface $user) /** * @When I verify my account using link sent to :customer */ - public function iVerifyMyAccount(CustomerInterface $customer) + public function iVerifyMyAccount(CustomerInterface $customer): void { $user = $customer->getUser(); Assert::notNull($user, 'No account for given customer'); @@ -314,7 +294,7 @@ public function iVerifyMyAccount(CustomerInterface $customer) /** * @When I resend the verification email */ - public function iResendVerificationEmail() + public function iResendVerificationEmail(): void { $this->dashboardPage->open(); $this->dashboardPage->pressResendVerificationEmail(); @@ -323,7 +303,7 @@ public function iResendVerificationEmail() /** * @When I use the verification link from the first email to verify */ - public function iUseVerificationLinkFromFirstEmailToVerify() + public function iUseVerificationLinkFromFirstEmailToVerify(): void { $token = $this->sharedStorage->get('verification_token'); @@ -333,7 +313,7 @@ public function iUseVerificationLinkFromFirstEmailToVerify() /** * @When I (try to )verify using :token token */ - public function iTryToVerifyUsing($token) + public function iTryToVerifyUsing(string $token): void { $this->verificationPage->verifyAccount($token); } @@ -341,7 +321,7 @@ public function iTryToVerifyUsing($token) /** * @Then /^(?:my|his|her) account should not be verified$/ */ - public function myAccountShouldNotBeVerified() + public function myAccountShouldNotBeVerified(): void { $this->dashboardPage->open(); @@ -351,7 +331,7 @@ public function myAccountShouldNotBeVerified() /** * @Then I should not be able to resend the verification email */ - public function iShouldBeUnableToResendVerificationEmail() + public function iShouldBeUnableToResendVerificationEmail(): void { $this->dashboardPage->open(); @@ -361,7 +341,7 @@ public function iShouldBeUnableToResendVerificationEmail() /** * @Then I should be notified that the verification was successful */ - public function iShouldBeNotifiedThatTheVerificationWasSuccessful() + public function iShouldBeNotifiedThatTheVerificationWasSuccessful(): void { $this->notificationChecker->checkNotification('has been successfully verified.', NotificationType::success()); } @@ -369,7 +349,7 @@ public function iShouldBeNotifiedThatTheVerificationWasSuccessful() /** * @Then I should be notified that the verification token is invalid */ - public function iShouldBeNotifiedThatTheVerificationTokenIsInvalid() + public function iShouldBeNotifiedThatTheVerificationTokenIsInvalid(): void { $this->notificationChecker->checkNotification('The verification token is invalid.', NotificationType::failure()); } @@ -377,7 +357,7 @@ public function iShouldBeNotifiedThatTheVerificationTokenIsInvalid() /** * @Then I should be notified that the verification email has been sent */ - public function iShouldBeNotifiedThatTheVerificationEmailHasBeenSent() + public function iShouldBeNotifiedThatTheVerificationEmailHasBeenSent(): void { $this->notificationChecker->checkNotification( 'An email with the verification link has been sent to your email address.', @@ -388,27 +368,23 @@ public function iShouldBeNotifiedThatTheVerificationEmailHasBeenSent() /** * @When I subscribe to the newsletter */ - public function iSubscribeToTheNewsletter() + public function iSubscribeToTheNewsletter(): void { - $this->registerPage->subscribeToTheNewsletter(); + $this->registerElement->subscribeToTheNewsletter(); } /** * @Then I should be subscribed to the newsletter */ - public function iShouldBeSubscribedToTheNewsletter() + public function iShouldBeSubscribedToTheNewsletter(): void { $this->profileUpdatePage->open(); Assert::true($this->profileUpdatePage->isSubscribedToTheNewsletter()); } - /** - * @param string $element - * @param string $expectedMessage - */ - private function assertFieldValidationMessage($element, $expectedMessage) + private function assertFieldValidationMessage(string $element, string $expectedMessage): void { - Assert::true($this->registerPage->checkValidationMessageFor($element, $expectedMessage)); + Assert::true($this->registerElement->checkValidationMessageFor($element, $expectedMessage)); } } diff --git a/src/Sylius/Behat/Element/Shop/Account/RegisterElement.php b/src/Sylius/Behat/Element/Shop/Account/RegisterElement.php new file mode 100644 index 00000000000..ceddcca12ad --- /dev/null +++ b/src/Sylius/Behat/Element/Shop/Account/RegisterElement.php @@ -0,0 +1,84 @@ +getElement(StringInflector::nameToCode($element)) + ->getParent() + ->find('css', '.sylius-validation-error') + ; + + if (null === $errorLabel) { + throw new ElementNotFoundException($this->getSession(), 'Validation message', 'css', '.sylius-validation-error'); + } + + return $message === $errorLabel->getText(); + } + + public function register(): void + { + $this->getDocument()->pressButton('Create an account'); + } + + public function specifyEmail(?string $email): void + { + $this->getDocument()->fillField('Email', $email); + } + + public function getEmail(): string + { + return $this->getElement('email')->getValue(); + } + + public function specifyFirstName(?string $firstName): void + { + $this->getDocument()->fillField('First name', $firstName); + } + + public function specifyLastName(?string $lastName): void + { + $this->getDocument()->fillField('Last name', $lastName); + } + + public function specifyPassword(?string $password): void + { + $this->getDocument()->fillField('Password', $password); + } + + public function specifyPhoneNumber(string $phoneNumber): void + { + $this->getDocument()->fillField('Phone number', $phoneNumber); + } + + public function verifyPassword(?string $password): void + { + $this->getDocument()->fillField('Verification', $password); + } + + public function subscribeToTheNewsletter(): void + { + $this->getDocument()->checkField('Subscribe to the newsletter'); + } + + protected function getDefinedElements(): array + { + return array_merge(parent::getDefinedElements(), [ + 'email' => '#sylius_customer_registration_email', + 'first_name' => '#sylius_customer_registration_firstName', + 'last_name' => '#sylius_customer_registration_lastName', + 'password' => '#sylius_customer_registration_user_plainPassword_first', + 'password_verification' => '#sylius_customer_registration_user_plainPassword_second', + 'phone_number' => '#sylius_customer_registration_phoneNumber', + ]); + } +} diff --git a/src/Sylius/Behat/Element/Shop/Account/RegisterElementInterface.php b/src/Sylius/Behat/Element/Shop/Account/RegisterElementInterface.php new file mode 100644 index 00000000000..181c2e7e984 --- /dev/null +++ b/src/Sylius/Behat/Element/Shop/Account/RegisterElementInterface.php @@ -0,0 +1,33 @@ +getElement(StringInflector::nameToCode($element)) - ->getParent() - ->find('css', '.sylius-validation-error') - ; - - if (null === $errorLabel) { - throw new ElementNotFoundException($this->getSession(), 'Validation message', 'css', '.sylius-validation-error'); - } - - return $message === $errorLabel->getText(); - } - - public function register() - { - $this->getDocument()->pressButton('Create an account'); - } - - /** - * {@inheritdoc} - */ - public function specifyEmail($email) - { - $this->getDocument()->fillField('Email', $email); - } - - public function getEmail(): string - { - return $this->getElement('email')->getValue(); - } - - /** - * {@inheritdoc} - */ - public function specifyFirstName($firstName) - { - $this->getDocument()->fillField('First name', $firstName); - } - - /** - * {@inheritdoc} - */ - public function specifyLastName($lastName) - { - $this->getDocument()->fillField('Last name', $lastName); - } - - /** - * {@inheritdoc} - */ - public function specifyPassword($password) - { - $this->getDocument()->fillField('Password', $password); - } - - /** - * {@inheritdoc} - */ - public function specifyPhoneNumber($phoneNumber) - { - $this->getDocument()->fillField('Phone number', $phoneNumber); - } - - /** - * {@inheritdoc} - */ - public function verifyPassword($password) - { - $this->getDocument()->fillField('Verification', $password); - } - - public function subscribeToTheNewsletter() - { - $this->getDocument()->checkField('Subscribe to the newsletter'); - } - - /** - * {@inheritdoc} - */ - protected function getDefinedElements() - { - return array_merge(parent::getDefinedElements(), [ - 'email' => '#sylius_customer_registration_email', - 'first_name' => '#sylius_customer_registration_firstName', - 'last_name' => '#sylius_customer_registration_lastName', - 'password_verification' => '#sylius_customer_registration_user_plainPassword_second', - 'password' => '#sylius_customer_registration_user_plainPassword_first', - 'phone_number' => '#sylius_customer_registration_phoneNumber', - ]); - } } diff --git a/src/Sylius/Behat/Page/Shop/Account/RegisterPageInterface.php b/src/Sylius/Behat/Page/Shop/Account/RegisterPageInterface.php index 03753174615..437ba1b3b1a 100644 --- a/src/Sylius/Behat/Page/Shop/Account/RegisterPageInterface.php +++ b/src/Sylius/Behat/Page/Shop/Account/RegisterPageInterface.php @@ -17,47 +17,4 @@ interface RegisterPageInterface extends SymfonyPageInterface { - /** - * @param string $element - * @param string $message - * - * @return bool - */ - public function checkValidationMessageFor($element, $message); - - public function register(); - - /** - * @param string $email - */ - public function specifyEmail($email); - - public function getEmail(): string; - - /** - * @param string $firstName - */ - public function specifyFirstName($firstName); - - /** - * @param string $lastName - */ - public function specifyLastName($lastName); - - /** - * @param string $password - */ - public function specifyPassword($password); - - /** - * @param string $phoneNumber - */ - public function specifyPhoneNumber($phoneNumber); - - /** - * @param string $password - */ - public function verifyPassword($password); - - public function subscribeToTheNewsletter(); } diff --git a/src/Sylius/Behat/Resources/config/services.xml b/src/Sylius/Behat/Resources/config/services.xml index 33c0def1d49..c2db7f6b36d 100644 --- a/src/Sylius/Behat/Resources/config/services.xml +++ b/src/Sylius/Behat/Resources/config/services.xml @@ -14,6 +14,7 @@ + diff --git a/src/Sylius/Behat/Resources/config/services/contexts/ui.xml b/src/Sylius/Behat/Resources/config/services/contexts/ui.xml index 85112167178..a879885a3b8 100644 --- a/src/Sylius/Behat/Resources/config/services/contexts/ui.xml +++ b/src/Sylius/Behat/Resources/config/services/contexts/ui.xml @@ -288,6 +288,7 @@ + @@ -337,11 +338,11 @@ - + @@ -432,6 +433,7 @@ + @@ -457,6 +459,7 @@ + diff --git a/src/Sylius/Behat/Resources/config/services/elements.xml b/src/Sylius/Behat/Resources/config/services/elements.xml new file mode 100644 index 00000000000..cfafbe56339 --- /dev/null +++ b/src/Sylius/Behat/Resources/config/services/elements.xml @@ -0,0 +1,21 @@ + + + + + + + + + diff --git a/src/Sylius/Behat/Resources/config/services/elements/shop.xml b/src/Sylius/Behat/Resources/config/services/elements/shop.xml new file mode 100644 index 00000000000..9fb30a43182 --- /dev/null +++ b/src/Sylius/Behat/Resources/config/services/elements/shop.xml @@ -0,0 +1,21 @@ + + + + + + + + + diff --git a/src/Sylius/Behat/Resources/config/services/elements/shop/account.xml b/src/Sylius/Behat/Resources/config/services/elements/shop/account.xml new file mode 100644 index 00000000000..19238829095 --- /dev/null +++ b/src/Sylius/Behat/Resources/config/services/elements/shop/account.xml @@ -0,0 +1,27 @@ + + + + + + + Sylius\Behat\Element\Shop\Account\RegisterElement + + + + + + + +