diff --git a/features/account/registering.feature b/features/account/registering.feature deleted file mode 100644 index 9c43c843fe..0000000000 --- a/features/account/registering.feature +++ /dev/null @@ -1,33 +0,0 @@ -@customer_account -Feature: Account registration - In order to order products - As a visitor - I need to be able to create an account in the store - - Background: - Given the store operates on a single channel in "France" - - @ui - Scenario: Registering a new account with minimum information - Given I want to register a new account - When I specify first name with "Saul" - And I specify last name with "Goodman" - And I specify email with "goodman@gmail.com" - And I specify password with "heisenberg" - And I confirm this password - And I register this account - Then I should be notified that new account has been successfully created - And I should be logged in - - @ui - Scenario: Registering a new account with all details - Given I want to register a new account - When I specify first name with "Saul" - And I specify last name with "Goodman" - And I specify email with "goodman@gmail.com" - And I specify password with "heisenberg" - And I confirm this password - And I specify phone number with "123456789" - And I register this account - Then I should be notified that new account has been successfully created - And I should be logged in diff --git a/features/account/registration.feature b/features/account/registration.feature new file mode 100644 index 0000000000..44261be898 --- /dev/null +++ b/features/account/registration.feature @@ -0,0 +1,49 @@ +@customer_registration +Feature: Account registration + In order to make future purchases with ease + As a Visitor + I need to be able to create an account in the store + + Background: + Given the store operates on a single channel in "France" + + @ui + Scenario: Registering a new account with minimum information + Given I want to register a new account + When I specify the first name as "Saul" + And I specify the last name as "Goodman" + And I specify the email as "goodman@gmail.com" + And I specify the password as "heisenberg" + And I confirm this password + And I register this account + Then I should be notified that new account has been successfully created + And I should be logged in + And my email should be "goodman@gmail.com" + + @ui + Scenario: Registering a new account with all details + Given I want to register a new account + When I specify the first name as "Saul" + And I specify the last name as "Goodman" + And I specify the email as "goodman@gmail.com" + And I specify the password as "heisenberg" + And I confirm this password + And I specify the phone number as "123456789" + And I register this account + Then I should be notified that new account has been successfully created + And I should be logged in + And my email should be "goodman@gmail.com" + + @ui + Scenario: Registering a guest account + Given there is a customer "goodman@gmail.com" that placed an order "#001" + And I want to register a new account + When I specify the first name as "Saul" + And I specify the last name as "Goodman" + And I specify the email as "goodman@gmail.com" + And I specify the password as "heisenberg" + And I confirm this password + And I register this account + Then I should be notified that new account has been successfully created + And I should be logged in + And my email should be "goodman@gmail.com" diff --git a/features/account/registering_validation.feature b/features/account/registration_validation.feature similarity index 50% rename from features/account/registering_validation.feature rename to features/account/registration_validation.feature index 881757390e..7d2a95c1a5 100644 --- a/features/account/registering_validation.feature +++ b/features/account/registration_validation.feature @@ -1,8 +1,8 @@ -@customer_account +@customer_registration Feature: Account registration In order to avoid making mistakes when registering account - As a visitor - I need to be able to create an account in the store + As a Visitor + I want to be prevented from creating an account without required fields Background: Given the store operates on a single channel in "France" @@ -11,63 +11,63 @@ Feature: Account registration Scenario: Trying to register a new account with email that has been already used Given there is user "goodman@gmail.com" identified by "heisenberg" And I want to register a new account - When I specify email with "goodman@gmail.com" + When I specify the email as "goodman@gmail.com" And I try to register this account - Then I should be notified that email is already used + Then I should be notified that the email is already used And I should not be logged in @ui Scenario: Trying to register a new account without specifying first name Given I want to register a new account - When I do not specify first name - And I specify last name with "Goodman" - And I specify email with "goodman@gmail.com" - And I specify password with "heisenberg" + When I do not specify the first name + And I specify the last name as "Goodman" + And I specify the email as "goodman@gmail.com" + And I specify the password as "heisenberg" And I try to register this account - Then I should be notified that first name is required + Then I should be notified that the first name is required And I should not be logged in @ui Scenario: Trying to register a new account without specifying last name Given I want to register a new account - When I do not specify last name - And I specify first name with "Saul" - And I specify email with "goodman@gmail.com" - And I specify password with "heisenberg" + When I do not specify the last name + And I specify the first name as "Saul" + And I specify the email as "goodman@gmail.com" + And I specify the password as "heisenberg" And I confirm this password And I try to register this account - Then I should be notified that last name is required + Then I should be notified that the last name is required And I should not be logged in @ui Scenario: Trying to register a new account without specifying password Given I want to register a new account - When I do not specify password - And I specify first name with "Saul" - And I specify last name with "Goodman" - And I specify email with "goodman@gmail.com" + When I do not specify the password + And I specify the first name as "Saul" + And I specify the last name as "Goodman" + And I specify the email as "goodman@gmail.com" And I try to register this account - Then I should be notified that password is required + Then I should be notified that the password is required And I should not be logged in @ui Scenario: Trying to register a new account without confirming password Given I want to register a new account - When I specify first name with "Saul" - Then I specify last name with "Goodman" - And I specify email with "goodman@gmail.com" - And I specify password with "heisenberg" - And I do not confirm password + When I specify the first name as "Saul" + Then I specify the last name as "Goodman" + And I specify the email as "goodman@gmail.com" + And I specify the password as "heisenberg" + And I do not confirm the password And I try to register this account - Then I should be notified that password do not match + Then I should be notified that the password do not match And I should not be logged in @ui Scenario: Trying to register a new account without specifying email Given I want to register a new account - When I do not specify email - And I specify first name with "Saul" - And I specify last name with "Goodman" + When I do not specify the email + And I specify the first name as "Saul" + And I specify the last name as "Goodman" And I try to register this account - Then I should be notified that email is required + Then I should be notified that the email is required And I should not be logged in diff --git a/features/account/sign_in.feature b/features/account/sign_in.feature index 5b1bd14bd4..8b5e7a2ff9 100644 --- a/features/account/sign_in.feature +++ b/features/account/sign_in.feature @@ -1,7 +1,7 @@ -@customer_account +@customer_login Feature: Sign in to the store - In order to view my - As a visitor + In order to view my orders + As a Visitor I want to be able to log in to the store Background: @@ -11,15 +11,16 @@ Feature: Sign in to the store @ui Scenario: Sign in with email and password Given I want to log in - When I specify email with "ted@example.com" - And I specify password with "bear" + When I specify the user name as "ted@example.com" + And I specify the password as "bear" And I log in Then I should be logged in @ui Scenario: Sign in with bad credentials Given I want to log in - When I specify email with "bear@example.com" - And I specify password with "pswd" + When I specify the user name as "bear@example.com" + And I specify the password as "pswd" And I log in Then I should be notified about bad credentials + And I should not be logged in diff --git a/src/Sylius/Behat/Context/Ui/ChannelContext.php b/src/Sylius/Behat/Context/Ui/ChannelContext.php index ddf9093ccf..7647d5713c 100644 --- a/src/Sylius/Behat/Context/Ui/ChannelContext.php +++ b/src/Sylius/Behat/Context/Ui/ChannelContext.php @@ -13,7 +13,7 @@ namespace Sylius\Behat\Context\Ui; use Behat\Behat\Context\Context; use Sylius\Behat\Page\Admin\Channel\CreatePageInterface; -use Sylius\Behat\Page\Shop\HomePageInterface; +use Sylius\Behat\Page\Shop\LegacyHomePageInterface; use Sylius\Behat\Service\Setter\ChannelContextSetterInterface; use Sylius\Component\Channel\Repository\ChannelRepositoryInterface; use Sylius\Component\Core\Model\ChannelInterface; @@ -45,7 +45,7 @@ final class ChannelContext implements Context private $channelCreatePage; /** - * @var HomePageInterface + * @var LegacyHomePageInterface */ private $homePage; @@ -54,14 +54,14 @@ final class ChannelContext implements Context * @param ChannelContextSetterInterface $channelContextSetter * @param ChannelRepositoryInterface $channelRepository * @param CreatePageInterface $channelCreatePage - * @param HomePageInterface $homePage + * @param LegacyHomePageInterface $homePage */ public function __construct( SharedStorageInterface $sharedStorage, ChannelContextSetterInterface $channelContextSetter, ChannelRepositoryInterface $channelRepository, CreatePageInterface $channelCreatePage, - HomePageInterface $homePage + LegacyHomePageInterface $homePage ) { $this->sharedStorage = $sharedStorage; $this->channelContextSetter = $channelContextSetter; diff --git a/src/Sylius/Behat/Context/Ui/Shop/AccountContext.php b/src/Sylius/Behat/Context/Ui/Shop/AccountContext.php index a08d2dfd30..72e436cbe2 100644 --- a/src/Sylius/Behat/Context/Ui/Shop/AccountContext.php +++ b/src/Sylius/Behat/Context/Ui/Shop/AccountContext.php @@ -16,29 +16,13 @@ use Sylius\Behat\NotificationType; use Sylius\Behat\Page\Shop\Account\DashboardPageInterface; use Sylius\Behat\Page\Shop\Account\ProfileUpdatePageInterface; use Sylius\Behat\Service\NotificationCheckerInterface; -use Sylius\Behat\Page\Shop\Account\LoginPageInterface; -use Sylius\Behat\Page\Shop\Account\RegisterPageInterface; -use Sylius\Behat\Page\Shop\ShopHomePageInterface; -use Sylius\Behat\Service\Resolver\CurrentPageResolverInterface; -use Sylius\Component\Core\Test\Services\SharedStorageInterface; use Webmozart\Assert\Assert; /** * @author Grzegorz Sadowski - * @author Arkadiusz Krakowiak */ final class AccountContext implements Context { - /** - * @var SharedStorageInterface - */ - private $sharedStorage; - - /** - * @var CurrentPageResolverInterface - */ - private $currentPageResolver; - /** * @var NotificationCheckerInterface */ @@ -55,48 +39,18 @@ final class AccountContext implements Context private $profileUpdatePage; /** - * @var LoginPageInterface - */ - private $loginPage; - - /** - * @var RegisterPageInterface - */ - private $registerPage; - - /** - * @var ShopHomePageInterface - */ - private $shopHomePage; - - /** - * @param SharedStorageInterface $sharedStorage - * @param CurrentPageResolverInterface $currentPageResolver * @param NotificationCheckerInterface $notificationChecker * @param DashboardPageInterface $dashboardPage * @param ProfileUpdatePageInterface $profileUpdatePage - * @param LoginPageInterface $loginPage - * @param RegisterPageInterface $registerPage - * @param ShopHomePageInterface $shopHomePage */ public function __construct( - SharedStorageInterface $sharedStorage, - CurrentPageResolverInterface $currentPageResolver, NotificationCheckerInterface $notificationChecker, DashboardPageInterface $dashboardPage, - ProfileUpdatePageInterface $profileUpdatePage, - LoginPageInterface $loginPage, - RegisterPageInterface $registerPage, - ShopHomePageInterface $shopHomePage + ProfileUpdatePageInterface $profileUpdatePage ) { - $this->sharedStorage = $sharedStorage; - $this->currentPageResolver = $currentPageResolver; $this->notificationChecker = $notificationChecker; $this->dashboardPage = $dashboardPage; $this->profileUpdatePage = $profileUpdatePage; - $this->loginPage = $loginPage; - $this->registerPage = $registerPage; - $this->shopHomePage = $shopHomePage; } /** @@ -107,30 +61,13 @@ final class AccountContext implements Context $this->profileUpdatePage->open(); } - /** - * @Given I want to log in - */ - public function iWantToLogIn() - { - $this->loginPage->open(); - } - - /** - * @Given I want to register a new account - */ - public function iWantToRegisterANewAccount() - { - $this->registerPage->open(); - } - /** * @When I specify the first name as :firstName * @When I remove the first name */ public function iSpecifyTheFirstName($firstName = null) { - $currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->profileUpdatePage, $this->registerPage]); - $currentPage->specifyFirstName($firstName); + $this->profileUpdatePage->specifyFirstName($firstName); } /** @@ -139,8 +76,7 @@ final class AccountContext implements Context */ public function iSpecifyTheLastName($lastName = null) { - $currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->profileUpdatePage, $this->registerPage]); - $currentPage->specifyLastName($lastName); + $this->profileUpdatePage->specifyLastName($lastName); } /** @@ -149,43 +85,7 @@ final class AccountContext implements Context */ public function iSpecifyTheEmail($email = null) { - $currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->profileUpdatePage, $this->registerPage]); - $currentPage->specifyEmail($email); - } - - /** - * @When I specify password with :password - * @When I do not specify password - */ - public function iSpecifyPasswordWith($password = null) - { - $currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->loginPage, $this->registerPage]); - $currentPage->specifyPassword($password); - $this->sharedStorage->set('password', $password); - } - - /** - * @When /^I confirm (this password)$/ - */ - public function iConfirmThisPassword($password) - { - $this->registerPage->verifyPassword($password); - } - - /** - * @When I do not confirm password - */ - public function iDoNotConfirmPassword() - { - $this->registerPage->verifyPassword(null); - } - - /** - * @When I specify phone number with :phoneNumber - */ - public function iSpecifyPhoneNumberWith($phoneNumber) - { - $this->registerPage->specifyPhoneNumber($phoneNumber); + $this->profileUpdatePage->specifyEmail($email); } /** @@ -197,23 +97,6 @@ final class AccountContext implements Context $this->profileUpdatePage->saveChanges(); } - /** - * @When I log in - */ - public function iLogIn() - { - $this->loginPage->logIn(); - } - - /** - * @When I register this account - * @When I try to register this account - */ - public function iRegister() - { - $this->registerPage->register(); - } - /** * @Then I should be notified that it has been successfully edited */ @@ -250,47 +133,6 @@ final class AccountContext implements Context ); } - /** - * @Then I should be notified that new account has been successfully created - */ - public function iShouldBeNotifiedThatNewAccountHasBeenSuccessfullyCreated() - { - $this->notificationChecker->checkNotification('Customer has been successfully created.', NotificationType::success()); - } - - /** - * @Then I should be logged in - */ - public function iShouldBeLoggedIn() - { - Assert::true( - $this->shopHomePage->hasLogoutButton(), - 'I should be on home page and, also i should be able to sign out.' - ); - } - - /** - * @Then I should not be logged in - */ - public function iShouldNotBeLoggedIn() - { - Assert::false( - $this->shopHomePage->hasLogoutButton(), - 'I should not be logged in.' - ); - } - - /** - * @Then I should be notified about bad credentials - */ - public function iShouldBeNotifiedAboutBadCredentials() - { - Assert::true( - $this->loginPage->hasValidationErrorWith('Error Invalid credentials.'), - 'I should see validation error.' - ); - } - /** * @Then /^I should be notified that the ([^"]+) is required$/ */ @@ -315,23 +157,14 @@ final class AccountContext implements Context $this->assertFieldValidationMessage('email', 'This email is already used.'); } - /** - * @Then I should be notified that password do not match - */ - public function iShouldBeNotifiedThatPasswordDoNotMatch() - { - $this->assertFieldValidationMessage('password', "The entered passwords don't match"); - } - /** * @param string $element * @param string $expectedMessage */ private function assertFieldValidationMessage($element, $expectedMessage) { - $currentPage = $this->currentPageResolver->getCurrentPageWithForm($this->profileUpdatePage, $this->registerPage); Assert::true( - $currentPage->checkValidationMessageFor($element, $expectedMessage), + $this->profileUpdatePage->checkValidationMessageFor($element, $expectedMessage), sprintf('The %s should be required.', $element) ); } diff --git a/src/Sylius/Behat/Context/Ui/Shop/LoginContext.php b/src/Sylius/Behat/Context/Ui/Shop/LoginContext.php new file mode 100644 index 0000000000..647181eaf0 --- /dev/null +++ b/src/Sylius/Behat/Context/Ui/Shop/LoginContext.php @@ -0,0 +1,110 @@ + + */ +class LoginContext implements Context +{ + /** + * @var LoginPageInterface + */ + private $loginPage; + + /** + * @var HomePageInterface + */ + private $homePage; + + /** + * @param LoginPageInterface $loginPage + * @param HomePageInterface $homePage + */ + public function __construct(LoginPageInterface $loginPage, HomePageInterface $homePage) + { + $this->loginPage = $loginPage; + $this->homePage = $homePage; + } + + /** + * @Given I want to log in + */ + public function iWantToLogIn() + { + $this->loginPage->open(); + } + + /** + * @When I specify the user name as :userName + * @When I do not specify the user name + */ + public function iSpecifyTheUserName($userName = null) + { + $this->loginPage->specifyUserName($userName); + } + + /** + * @When I specify the password as :password + * @When I do not specify the password + */ + public function iSpecifyThePasswordAs($password = null) + { + $this->loginPage->specifyPassword($password); + } + + /** + * @When I log in + */ + public function iLogIn() + { + $this->loginPage->logIn(); + } + + /** + * @Then I should be logged in + */ + public function iShouldBeLoggedIn() + { + Assert::true( + $this->homePage->hasLogoutButton(), + 'I should be on home page and, also i should be able to sign out.' + ); + } + + /** + * @Then I should not be logged in + */ + public function iShouldNotBeLoggedIn() + { + Assert::false( + $this->homePage->hasLogoutButton(), + 'I should not be logged in.' + ); + } + + /** + * @Then I should be notified about bad credentials + */ + public function iShouldBeNotifiedAboutBadCredentials() + { + Assert::true( + $this->loginPage->hasValidationErrorWith('Error Invalid credentials.'), + 'I should see validation error.' + ); + } +} diff --git a/src/Sylius/Behat/Context/Ui/Shop/RegistrationContext.php b/src/Sylius/Behat/Context/Ui/Shop/RegistrationContext.php new file mode 100644 index 0000000000..dcd30c4e4a --- /dev/null +++ b/src/Sylius/Behat/Context/Ui/Shop/RegistrationContext.php @@ -0,0 +1,240 @@ + + */ +class RegistrationContext implements Context +{ + /** + * @var CurrentPageResolverInterface + */ + private $currentPageResolver; + + /** + * @var DashboardPageInterface + */ + private $dashboardPage; + + /** + * @var HomePageInterface + */ + private $homePage; + + /** + * @var NotificationCheckerInterface + */ + private $notificationChecker; + + /** + * @var RegisterPageInterface + */ + private $registerPage; + + /** + * @var SharedStorageInterface + */ + private $sharedStorage; + + /** + * @param CurrentPageResolverInterface $currentPageResolver + * @param DashboardPageInterface $dashboardPage + * @param HomePageInterface $homePage + * @param NotificationCheckerInterface $notificationChecker + * @param RegisterPageInterface $registerPage + * @param SharedStorageInterface $sharedStorage + */ + public function __construct( + CurrentPageResolverInterface $currentPageResolver, + DashboardPageInterface $dashboardPage, + HomePageInterface $homePage, + NotificationCheckerInterface $notificationChecker, + RegisterPageInterface $registerPage, + SharedStorageInterface $sharedStorage + ) { + $this->currentPageResolver = $currentPageResolver; + $this->dashboardPage = $dashboardPage; + $this->homePage = $homePage; + $this->notificationChecker = $notificationChecker; + $this->registerPage = $registerPage; + $this->sharedStorage = $sharedStorage; + } + + /** + * @Given I want to register a new account + */ + public function iWantToRegisterANewAccount() + { + $this->registerPage->open(); + } + + /** + * @When I specify the first name as :firstName + * @When I do not specify the first name + */ + public function iSpecifyTheFirstName($firstName = null) + { + $this->registerPage->specifyFirstName($firstName); + } + + /** + * @When I specify the last name as :lastName + * @When I do not specify the last name + */ + public function iSpecifyTheLastName($lastName = null) + { + $this->registerPage->specifyLastName($lastName); + } + + /** + * @When I specify the email as :email + * @When I do not specify the email + */ + public function iSpecifyTheEmail($email = null) + { + $this->registerPage->specifyEmail($email); + } + + /** + * @When I specify the password as :password + * @When I do not specify the password + */ + public function iSpecifyThePasswordAs($password = null) + { + $this->registerPage->specifyPassword($password); + $this->sharedStorage->set('password', $password); + } + + /** + * @When /^I confirm (this password)$/ + */ + public function iConfirmThisPassword($password) + { + $this->registerPage->verifyPassword($password); + } + + /** + * @Given I do not confirm the password + */ + public function iDoNotConfirmPassword() + { + $this->registerPage->verifyPassword(null); + } + + /** + * @When I specify the phone number as :phoneNumber + */ + public function iSpecifyThePhoneNumberAS($phoneNumber) + { + $this->registerPage->specifyPhoneNumber($phoneNumber); + } + + /** + * @When I register this account + * @When I try to register this account + */ + public function iRegisterThisAccount() + { + $this->registerPage->register(); + } + + /** + * @Then my email should be :email + * @Then my email should still be :email + */ + public function myEmailShouldBe($email) + { + $this->dashboardPage->open(); + + Assert::true( + $this->dashboardPage->hasCustomerEmail($email), + sprintf('Cannot find customer email "%s".', $email) + ); + } + + /** + * @Then /^I should be notified that the ([^"]+) is required$/ + */ + public function iShouldBeNotifiedThatElementIsRequired($element) + { + $this->assertFieldValidationMessage($element, sprintf('Please enter your %s.', $element)); + } + + /** + * @Then I should be notified that the email is already used + */ + public function iShouldBeNotifiedThatTheEmailIsAlreadyUsed() + { + $this->assertFieldValidationMessage('email', 'This email is already used.'); + } + + /** + * @Then I should be notified that the password do not match + */ + public function iShouldBeNotifiedThatThePasswordDoNotMatch() + { + $this->assertFieldValidationMessage('password', 'The entered passwords don\'t match'); + } + + /** + * @Then I should be notified that new account has been successfully created + */ + public function iShouldBeNotifiedThatNewAccountHasBeenSuccessfullyCreated() + { + $this->notificationChecker->checkNotification('Customer has been successfully created.', NotificationType::success()); + } + + /** + * @Then I should be logged in + */ + public function iShouldBeLoggedIn() + { + Assert::true( + $this->homePage->hasLogoutButton(), + 'I should be on home page and, also i should be able to sign out.' + ); + } + + /** + * @Then I should not be logged in + */ + public function iShouldNotBeLoggedIn() + { + Assert::false( + $this->homePage->hasLogoutButton(), + 'I should not be logged in.' + ); + } + + /** + * @param string $element + * @param string $expectedMessage + */ + private function assertFieldValidationMessage($element, $expectedMessage) + { + Assert::true( + $this->registerPage->checkValidationMessageFor($element, $expectedMessage), + sprintf('The %s should be required.', $element) + ); + } +} diff --git a/src/Sylius/Behat/Context/Ui/ThemeContext.php b/src/Sylius/Behat/Context/Ui/ThemeContext.php index ae00c0c6a2..d32650132b 100644 --- a/src/Sylius/Behat/Context/Ui/ThemeContext.php +++ b/src/Sylius/Behat/Context/Ui/ThemeContext.php @@ -14,7 +14,7 @@ namespace Sylius\Behat\Context\Ui; use Behat\Behat\Context\Context; use Sylius\Behat\Page\Admin\Channel\IndexPageInterface; use Sylius\Behat\Page\Admin\Channel\UpdatePageInterface; -use Sylius\Behat\Page\Shop\HomePageInterface; +use Sylius\Behat\Page\Shop\LegacyHomePageInterface; use Sylius\Bundle\ThemeBundle\Model\ThemeInterface; use Sylius\Component\Core\Model\ChannelInterface; use Sylius\Component\Core\Test\Services\SharedStorageInterface; @@ -40,7 +40,7 @@ final class ThemeContext implements Context private $channelUpdatePage; /** - * @var HomePageInterface + * @var LegacyHomePageInterface */ private $homePage; @@ -48,13 +48,13 @@ final class ThemeContext implements Context * @param SharedStorageInterface $sharedStorage * @param IndexPageInterface $channelIndexPage * @param UpdatePageInterface $channelUpdatePage - * @param HomePageInterface $homePage + * @param LegacyHomePageInterface $homePage */ public function __construct( SharedStorageInterface $sharedStorage, IndexPageInterface $channelIndexPage, UpdatePageInterface $channelUpdatePage, - HomePageInterface $homePage + LegacyHomePageInterface $homePage ) { $this->sharedStorage = $sharedStorage; $this->channelIndexPage = $channelIndexPage; diff --git a/src/Sylius/Behat/Context/Ui/UserContext.php b/src/Sylius/Behat/Context/Ui/UserContext.php index 1011ead78c..4461a3aa3d 100644 --- a/src/Sylius/Behat/Context/Ui/UserContext.php +++ b/src/Sylius/Behat/Context/Ui/UserContext.php @@ -14,7 +14,7 @@ namespace Sylius\Behat\Context\Ui; use Behat\Behat\Context\Context; use Behat\Mink\Exception\ElementNotFoundException; use Sylius\Behat\Page\Admin\Customer\ShowPageInterface; -use Sylius\Behat\Page\Shop\User\LoginPageInterface; +use Sylius\Behat\Page\Shop\Account\LoginPageInterface; use Sylius\Behat\Page\Shop\User\RegisterPageInterface; use Sylius\Component\Core\Test\Services\SharedStorageInterface; use Sylius\Component\User\Repository\UserRepositoryInterface; @@ -40,6 +40,11 @@ final class UserContext implements Context */ private $customerShowPage; + /** + * @var LoginPageInterface + */ + private $loginPage; + /** * @var RegisterPageInterface */ @@ -49,20 +54,34 @@ final class UserContext implements Context * @param SharedStorageInterface $sharedStorage * @param UserRepositoryInterface $userRepository * @param ShowPageInterface $customerShowPage + * @param LoginPageInterface $loginPage * @param RegisterPageInterface $registerPage */ public function __construct( SharedStorageInterface $sharedStorage, UserRepositoryInterface $userRepository, ShowPageInterface $customerShowPage, + LoginPageInterface $loginPage, RegisterPageInterface $registerPage ) { $this->sharedStorage = $sharedStorage; $this->userRepository = $userRepository; $this->customerShowPage = $customerShowPage; + $this->loginPage = $loginPage; $this->registerPage = $registerPage; } + /** + * @Given I log in as :email with :password password + */ + public function iLogInAsWithPassword($email, $password) + { + $this->loginPage->open(); + $this->loginPage->specifyUserName($email); + $this->loginPage->specifyPassword($password); + $this->loginPage->logIn(); + } + /** * @When I try to register again with email :email */ diff --git a/src/Sylius/Behat/Page/Shop/Account/LoginPage.php b/src/Sylius/Behat/Page/Shop/Account/LoginPage.php index 6d5f25bf3e..e1d53ce2d5 100644 --- a/src/Sylius/Behat/Page/Shop/Account/LoginPage.php +++ b/src/Sylius/Behat/Page/Shop/Account/LoginPage.php @@ -34,17 +34,17 @@ class LoginPage extends SymfonyPage implements LoginPageInterface /** * {@inheritdoc} */ - public function specifyEmail($email) + public function specifyPassword($password) { - $this->getDocument()->fillField('Email', $email); + $this->getDocument()->fillField('Password', $password); } /** * {@inheritdoc} */ - public function specifyPassword($password) + public function specifyUserName($userName) { - $this->getDocument()->fillField('Password', $password); + $this->getDocument()->fillField('Username', $userName); } /** diff --git a/src/Sylius/Behat/Page/Shop/Account/LoginPageInterface.php b/src/Sylius/Behat/Page/Shop/Account/LoginPageInterface.php index 1798770515..3a12268c74 100644 --- a/src/Sylius/Behat/Page/Shop/Account/LoginPageInterface.php +++ b/src/Sylius/Behat/Page/Shop/Account/LoginPageInterface.php @@ -27,13 +27,13 @@ interface LoginPageInterface extends SymfonyPageInterface public function logIn(); - /** - * @param string $email - */ - public function specifyEmail($email); - /** * @param string $password */ public function specifyPassword($password); + + /** + * @param string $userName + */ + public function specifyUserName($userName); } diff --git a/src/Sylius/Behat/Page/Shop/Account/RegisterPage.php b/src/Sylius/Behat/Page/Shop/Account/RegisterPage.php index a9da78e247..6d1a828c40 100644 --- a/src/Sylius/Behat/Page/Shop/Account/RegisterPage.php +++ b/src/Sylius/Behat/Page/Shop/Account/RegisterPage.php @@ -19,7 +19,6 @@ use Sylius\Behat\Page\SymfonyPage; */ class RegisterPage extends SymfonyPage implements RegisterPageInterface { - /** * {@inheritdoc} * @@ -27,12 +26,12 @@ class RegisterPage extends SymfonyPage implements RegisterPageInterface */ public function checkValidationMessageFor($element, $message) { - $foundedElement = $this->getFieldElement($element); - if (null === $foundedElement) { + $foundElement = $this->getFieldElement($element); + if (null === $foundElement) { throw new ElementNotFoundException($this->getSession(), 'Validation message', 'css', '.form-error'); } - return $message === $foundedElement->find('css', '.form-error')->getText(); + return $message === $foundElement->find('css', '.form-error')->getText(); } /** @@ -40,7 +39,7 @@ class RegisterPage extends SymfonyPage implements RegisterPageInterface */ public function getRouteName() { - return 'sylius_shop_account_registration'; + return 'sylius_shop_registration'; } public function register() diff --git a/src/Sylius/Behat/Page/Shop/HomePage.php b/src/Sylius/Behat/Page/Shop/HomePage.php index 79847a2dfa..62b1a9d130 100644 --- a/src/Sylius/Behat/Page/Shop/HomePage.php +++ b/src/Sylius/Behat/Page/Shop/HomePage.php @@ -21,16 +21,26 @@ class HomePage extends SymfonyPage implements HomePageInterface /** * {@inheritdoc} */ - public function getContents() + public function getRouteName() { - return $this->getDocument()->getContent(); + return 'sylius_shop_homepage'; } /** * {@inheritdoc} */ - public function getRouteName() + public function hasLogoutButton() { - return 'sylius_homepage'; + return $this->getElement('right_menu')->hasLink('Logout'); + } + + /** + * {@inheritdoc} + */ + protected function getDefinedElements() + { + return array_merge(parent::getDefinedElements(),[ + 'right_menu' => '.right.item', + ]); } } diff --git a/src/Sylius/Behat/Page/Shop/HomePageInterface.php b/src/Sylius/Behat/Page/Shop/HomePageInterface.php index 8fc10f50eb..781eb946a2 100644 --- a/src/Sylius/Behat/Page/Shop/HomePageInterface.php +++ b/src/Sylius/Behat/Page/Shop/HomePageInterface.php @@ -11,15 +11,15 @@ namespace Sylius\Behat\Page\Shop; -use Sylius\Behat\Page\PageInterface; +use Sylius\Behat\Page\SymfonyPageInterface; /** - * @author Łukasz Chruściel + * @author Arkadiusz Krakowiak */ -interface HomePageInterface extends PageInterface +interface HomePageInterface extends SymfonyPageInterface { /** - * @return string + * @return bool */ - public function getContents(); + public function hasLogoutButton(); } diff --git a/src/Sylius/Behat/Page/Shop/ShopHomePage.php b/src/Sylius/Behat/Page/Shop/LegacyHomePage.php similarity index 54% rename from src/Sylius/Behat/Page/Shop/ShopHomePage.php rename to src/Sylius/Behat/Page/Shop/LegacyHomePage.php index 1df04eaf02..c270a044c2 100644 --- a/src/Sylius/Behat/Page/Shop/ShopHomePage.php +++ b/src/Sylius/Behat/Page/Shop/LegacyHomePage.php @@ -16,31 +16,21 @@ use Sylius\Behat\Page\SymfonyPage; /** * @author Arkadiusz Krakowiak */ -class ShopHomePage extends SymfonyPage implements ShopHomePageInterface +class LegacyHomePage extends SymfonyPage implements LegacyHomePageInterface { + /** + * {@inheritdoc} + */ + public function getContents() + { + return $this->getDocument()->getContent(); + } + /** * {@inheritdoc} */ public function getRouteName() { - return 'sylius_shop_homepage'; - } - - /** - * {@inheritdoc} - */ - public function hasLogoutButton() - { - return $this->getElement('right_menu')->hasLink('Logout'); - } - - /** - * {@inheritdoc} - */ - protected function getDefinedElements() - { - return array_merge(parent::getDefinedElements(),[ - 'right_menu' => '.right.item', - ]); + return 'sylius_homepage'; } } diff --git a/src/Sylius/Behat/Page/Shop/ShopHomePageInterface.php b/src/Sylius/Behat/Page/Shop/LegacyHomePageInterface.php similarity index 55% rename from src/Sylius/Behat/Page/Shop/ShopHomePageInterface.php rename to src/Sylius/Behat/Page/Shop/LegacyHomePageInterface.php index 60d41561a1..d9be6455e5 100644 --- a/src/Sylius/Behat/Page/Shop/ShopHomePageInterface.php +++ b/src/Sylius/Behat/Page/Shop/LegacyHomePageInterface.php @@ -11,15 +11,15 @@ namespace Sylius\Behat\Page\Shop; -use Sylius\Behat\Page\SymfonyPageInterface; +use Sylius\Behat\Page\PageInterface; /** - * @author Arkadiusz Krakowiak + * @author Łukasz Chruściel */ -interface ShopHomePageInterface extends SymfonyPageInterface +interface LegacyHomePageInterface extends PageInterface { /** - * @return bool + * @return string */ - public function hasLogoutButton(); + public function getContents(); } diff --git a/src/Sylius/Behat/Resources/config/services/contexts/ui.xml b/src/Sylius/Behat/Resources/config/services/contexts/ui.xml index 8cc99b6a0b..91ac915b06 100644 --- a/src/Sylius/Behat/Resources/config/services/contexts/ui.xml +++ b/src/Sylius/Behat/Resources/config/services/contexts/ui.xml @@ -41,7 +41,9 @@ Sylius\Behat\Context\Ui\Shop\AccountContext Sylius\Behat\Context\Ui\Shop\CartContext + Sylius\Behat\Context\Ui\Shop\LoginContext Sylius\Behat\Context\Ui\Shop\ProductContext + Sylius\Behat\Context\Ui\Shop\RegistrationContext @@ -198,7 +200,7 @@ - + @@ -235,7 +237,7 @@ - + @@ -243,19 +245,15 @@ + - - - - - @@ -267,9 +265,25 @@ + + + + + + + + + + + + + + + + diff --git a/src/Sylius/Behat/Resources/config/services/pages/shop.xml b/src/Sylius/Behat/Resources/config/services/pages/shop.xml index d8e9579091..b3ef543d10 100644 --- a/src/Sylius/Behat/Resources/config/services/pages/shop.xml +++ b/src/Sylius/Behat/Resources/config/services/pages/shop.xml @@ -19,20 +19,20 @@ - Sylius\Behat\Page\Shop\HomePage Sylius\Behat\Page\Shop\Cart\SummaryPage + Sylius\Behat\Page\Shop\HomePage + Sylius\Behat\Page\Shop\LegacyHomePage Sylius\Behat\Page\Shop\Product\ShowPage Sylius\Behat\Page\Shop\Order\OrderPaymentsPage - Sylius\Behat\Page\Shop\ShopHomePage - + + - diff --git a/src/Sylius/Behat/Resources/config/services/pages/shop/user.xml b/src/Sylius/Behat/Resources/config/services/pages/shop/user.xml index e24359d164..d50b8849c5 100644 --- a/src/Sylius/Behat/Resources/config/services/pages/shop/user.xml +++ b/src/Sylius/Behat/Resources/config/services/pages/shop/user.xml @@ -13,12 +13,10 @@ - Sylius\Behat\Page\Shop\User\LoginPage Sylius\Behat\Page\Shop\User\RegisterPage - diff --git a/src/Sylius/Behat/Resources/config/suites.yml b/src/Sylius/Behat/Resources/config/suites.yml index 0e3ba5e069..270c2c9698 100644 --- a/src/Sylius/Behat/Resources/config/suites.yml +++ b/src/Sylius/Behat/Resources/config/suites.yml @@ -39,6 +39,8 @@ imports: - suites/legacy/user.yml - suites/ui/account/customer.yml + - suites/ui/account/login.yml + - suites/ui/account/registration.yml - suites/ui/addressing/managing_countries.yml - suites/ui/addressing/managing_zones.yml - suites/ui/cart/shopping_cart.yml diff --git a/src/Sylius/Behat/Resources/config/suites/ui/account/customer.yml b/src/Sylius/Behat/Resources/config/suites/ui/account/customer.yml index 0e53d27400..c8aaaaac78 100644 --- a/src/Sylius/Behat/Resources/config/suites/ui/account/customer.yml +++ b/src/Sylius/Behat/Resources/config/suites/ui/account/customer.yml @@ -10,6 +10,8 @@ default: - sylius.behat.context.transform.shared_storage - sylius.behat.context.setup.channel + - sylius.behat.context.setup.customer + - sylius.behat.context.setup.security - sylius.behat.context.setup.user - sylius.behat.context.ui.shop.account diff --git a/src/Sylius/Behat/Resources/config/suites/ui/account/login.yml b/src/Sylius/Behat/Resources/config/suites/ui/account/login.yml new file mode 100644 index 0000000000..fead8ee8e1 --- /dev/null +++ b/src/Sylius/Behat/Resources/config/suites/ui/account/login.yml @@ -0,0 +1,15 @@ +# This file is part of the Sylius package. +# (c) Paweł Jędrzejewski + +default: + suites: + ui_customer_login: + contexts_as_services: + - sylius.behat.context.hook.doctrine_orm + + - sylius.behat.context.setup.channel + - sylius.behat.context.setup.user + + - sylius.behat.context.ui.shop.login + filters: + tags: "@customer_login && @ui" diff --git a/src/Sylius/Behat/Resources/config/suites/ui/account/customer_account.yml b/src/Sylius/Behat/Resources/config/suites/ui/account/registration.yml similarity index 56% rename from src/Sylius/Behat/Resources/config/suites/ui/account/customer_account.yml rename to src/Sylius/Behat/Resources/config/suites/ui/account/registration.yml index 04e3adf98e..c82e8a20ed 100644 --- a/src/Sylius/Behat/Resources/config/suites/ui/account/customer_account.yml +++ b/src/Sylius/Behat/Resources/config/suites/ui/account/registration.yml @@ -3,15 +3,19 @@ default: suites: - ui_customer_account: + ui_customer_registration: contexts_as_services: - sylius.behat.context.hook.doctrine_orm + - sylius.behat.context.transform.shared_storage + - sylius.behat.context.transform.customer + - sylius.behat.context.setup.channel - sylius.behat.context.setup.customer + - sylius.behat.context.setup.order - sylius.behat.context.setup.security - sylius.behat.context.setup.user - - sylius.behat.context.ui.shop.account + - sylius.behat.context.ui.shop.registration filters: - tags: "@customer_account && @ui" + tags: "@customer_registration && @ui" diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/routing/account.yml b/src/Sylius/Bundle/ShopBundle/Resources/config/routing/account.yml index a5ec008e89..8b29a2b02e 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/config/routing/account.yml +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/routing/account.yml @@ -21,17 +21,3 @@ sylius_shop_account_profile_update: method: find arguments: [expr:service('sylius.context.customer').getCustomer().getId()] redirect: sylius_shop_account_dashboard - -sylius_shop_account_registration: - path: /register - methods: [GET, POST] - defaults: - _controller: sylius.controller.customer:createAction - _sylius: - form: sylius_customer_registration - event: register - template: SyliusShopBundle:Account:register.html.twig - permission: false - redirect: - route: sylius_shop_homepage - parameters: { email: resource.email } diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/routing/security.yml b/src/Sylius/Bundle/ShopBundle/Resources/config/routing/security.yml index 14c51b532d..cea41c2995 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/config/routing/security.yml +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/routing/security.yml @@ -5,7 +5,7 @@ sylius_shop_login: path: /login methods: [GET] defaults: - _controller: sylius.controller.user_security:loginAction + _controller: sylius.controller.security:loginAction _sylius: template: SyliusShopBundle:Account:login.html.twig @@ -17,6 +17,16 @@ sylius_shop_login_check: sylius_shop_logout: path: /logout -sylius_shop_password_resetting: - resource: @SyliusUserBundle/Resources/config/routing/password_reset.yml - prefix: /resetting +sylius_shop_registration: + path: /register + methods: [GET, POST] + defaults: + _controller: sylius.controller.customer:createAction + _sylius: + form: sylius_customer_registration + event: register + template: SyliusShopBundle:Account:register.html.twig + permission: false + redirect: + route: sylius_shop_homepage + parameters: { email: resource.email } diff --git a/src/Sylius/Bundle/ShopBundle/Resources/views/Account/login.html.twig b/src/Sylius/Bundle/ShopBundle/Resources/views/Account/login.html.twig index ef2df1c42d..22e44ceb4d 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/views/Account/login.html.twig +++ b/src/Sylius/Bundle/ShopBundle/Resources/views/Account/login.html.twig @@ -4,8 +4,8 @@ {% block content %}
- {% if error %} - {{ messages.error(error.messageKey|trans(error.messageData, 'security')) }} + {% if last_error %} + {{ messages.error(last_error.messageKey|trans(last_error.messageData, 'security')) }} {% endif %}
diff --git a/src/Sylius/Bundle/ShopBundle/Resources/views/Account/register.html.twig b/src/Sylius/Bundle/ShopBundle/Resources/views/Account/register.html.twig index 202090855f..e7a1805b0c 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/views/Account/register.html.twig +++ b/src/Sylius/Bundle/ShopBundle/Resources/views/Account/register.html.twig @@ -5,7 +5,7 @@ {% block content %}
- + {{ form_errors(form) }}
{{ form_row(form.firstName) }} diff --git a/src/Sylius/Bundle/ShopBundle/Resources/views/Homepage/_header.html.twig b/src/Sylius/Bundle/ShopBundle/Resources/views/Homepage/_header.html.twig index 8b7bb8d495..4f8672033a 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/views/Homepage/_header.html.twig +++ b/src/Sylius/Bundle/ShopBundle/Resources/views/Homepage/_header.html.twig @@ -42,8 +42,8 @@ {{ 'sylius.ui.logout'|trans }} {% else %} {{ 'sylius.ui.login'|trans }} + {{ 'sylius.ui.register'|trans }} {% endif %} - {{ 'sylius.ui.register'|trans }}
diff --git a/src/Sylius/Bundle/UserBundle/DependencyInjection/Configuration.php b/src/Sylius/Bundle/UserBundle/DependencyInjection/Configuration.php index 67488b03bb..58239c4336 100644 --- a/src/Sylius/Bundle/UserBundle/DependencyInjection/Configuration.php +++ b/src/Sylius/Bundle/UserBundle/DependencyInjection/Configuration.php @@ -223,7 +223,7 @@ class Configuration implements ConfigurationInterface ->end() ->arrayNode('registration') ->prototype('scalar')->end() - ->defaultValue(['sylius']) + ->defaultValue(['sylius', 'sylius_user_registration']) ->end() ->end() ->end() diff --git a/src/Sylius/Bundle/UserBundle/Form/Type/CustomerSimpleRegistrationType.php b/src/Sylius/Bundle/UserBundle/Form/Type/CustomerSimpleRegistrationType.php index 54ee08ca42..b5efb684ba 100644 --- a/src/Sylius/Bundle/UserBundle/Form/Type/CustomerSimpleRegistrationType.php +++ b/src/Sylius/Bundle/UserBundle/Form/Type/CustomerSimpleRegistrationType.php @@ -51,8 +51,6 @@ class CustomerSimpleRegistrationType extends AbstractResourceType ]) ->add('user', 'sylius_user_registration', [ 'label' => false, - 'validation_groups' => $this->validationGroups, - 'cascade_validation' => true, ]) ->addEventSubscriber(new CustomerRegistrationFormSubscriber($this->customerRepository)) ->addEventSubscriber(new UserRegistrationFormSubscriber()) diff --git a/src/Sylius/Bundle/UserBundle/Form/Type/UserRegistrationType.php b/src/Sylius/Bundle/UserBundle/Form/Type/UserRegistrationType.php index 74aec3acfa..1993a6508f 100644 --- a/src/Sylius/Bundle/UserBundle/Form/Type/UserRegistrationType.php +++ b/src/Sylius/Bundle/UserBundle/Form/Type/UserRegistrationType.php @@ -35,18 +35,6 @@ class UserRegistrationType extends AbstractResourceType ; } - /** - * {@inheritdoc} - */ - public function configureOptions(OptionsResolver $resolver) - { - $resolver->setDefaults([ - 'data_class' => $this->dataClass, - 'validation_groups' => $this->validationGroups, - 'cascade_validation' => true, - ]); - } - /** * {@inheritdoc} */ diff --git a/tests/Responses/Expected/customer/create_with_user_validation_fail_response.json b/tests/Responses/Expected/customer/create_with_user_validation_fail_response.json index 26910ddeaf..a3ae4c5023 100644 --- a/tests/Responses/Expected/customer/create_with_user_validation_fail_response.json +++ b/tests/Responses/Expected/customer/create_with_user_validation_fail_response.json @@ -24,13 +24,13 @@ "Please choose your gender." ] }, - "groups": {}, "phoneNumber": {}, + "groups": {}, "user": { "children": { "plainPassword": { "errors": [ - "This value should not be blank." + "Please enter your password." ] }, "enabled": {},