Skip to content

Commit

Permalink
Merge pull request Sylius#9656 from GSadee/registration-after-checkout
Browse files Browse the repository at this point in the history
[Shop] Registration after checkout
  • Loading branch information
pamil committed Aug 24, 2018
2 parents ec75c3f + dc9de6c commit 55d466e
Show file tree
Hide file tree
Showing 27 changed files with 719 additions and 301 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@checkout
Feature: Having registration form prefilled after checkout
In order to make future purchases with ease
As an Visitor
I want to have account registration form prefilled after placing an order

Background:
Given the store operates on a single channel in "United States"
And the store has a product "PHP T-Shirt" priced at "$19.99"
And the store ships everywhere for free
And the store allows paying offline

@ui
Scenario: Having prefilled registration form after checkout
Given I have product "PHP T-Shirt" in the cart
And I complete addressing step with email "john@example.com" and "United States" based shipping address
And I proceed with "Free" shipping method and "Offline" payment
And I confirm my order
Then I should see the thank you page
And I should be able to proceed to the registration
And the registration form should be prefilled with "john@example.com" email

@ui
Scenario: Not being able to create an account if customer is logged in
Given I am a logged in customer
And I have product "PHP T-Shirt" in the cart
And I complete addressing step with "United States" based shipping address
And I proceed with "Free" shipping method and "Offline" payment
And I confirm my order
Then I should see the thank you page
And I should not be able to proceed to the registration
24 changes: 24 additions & 0 deletions features/checkout/registering_account_after_checkout.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@checkout
Feature: Registering a new account after checkout
In order to make future purchases with ease
As an Visitor
I want to be able to create an account in the store after placing an order

Background:
Given the store operates on a single channel in "United States"
And the store has a product "PHP T-Shirt" priced at "$19.99"
And the store ships everywhere for free
And the store allows paying offline

@ui
Scenario: Registering a new account after checkout
Given I have product "PHP T-Shirt" in the cart
And I have completed addressing step with email "john@example.com" and "United States" based shipping address
And I have proceeded order with "Free" shipping method and "Offline" payment
And I have confirmed order
When I proceed to the registration
And I specify a password as "sylius"
And I confirm this password
And I register this account
And I verify my account using link sent to "john@example.com"
Then I should be able to log in as "john@example.com" with "sylius" password
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ public function iCompleteAddressingStepWithEmail($email, AddressInterface $addre
$this->iCompleteTheAddressingStep();
}

/**
* @When /^I complete addressing step with ("[^"]+" based shipping address)$/
*/
public function iCompleteAddressingStepWithBasedShippingAddress(AddressInterface $address): void
{
$this->addressPage->open();
$this->iSpecifyTheShippingAddressAs($address);
$this->iCompleteTheAddressingStep();
}

/**
* @When I specify the province name manually as :provinceName for shipping address
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Sylius\Behat\Context\Ui\Shop\Checkout;

use Behat\Behat\Context\Context;
use Sylius\Behat\Page\Shop\Account\RegisterPageInterface;
use Sylius\Behat\Page\Shop\Order\ThankYouPageInterface;
use Sylius\Component\Core\Model\PaymentMethodInterface;
use Webmozart\Assert\Assert;
Expand Down Expand Up @@ -41,6 +42,14 @@ public function iGoToOrderDetails()
$this->thankYouPage->goToOrderDetails();
}

/**
* @When I proceed to the registration
*/
public function iProceedToTheRegistration(): void
{
$this->thankYouPage->createAccount();
}

/**
* @Then I should see the thank you page
*/
Expand Down Expand Up @@ -88,4 +97,20 @@ public function iShouldNotBeAbleToChangeMyPaymentMethod()
{
Assert::false($this->thankYouPage->hasChangePaymentMethodButton());
}

/**
* @Then I should be able to proceed to the registration
*/
public function iShouldBeAbleToProceedToTheRegistration(): void
{
Assert::true($this->thankYouPage->hasRegistrationButton());
}

/**
* @Then I should not be able to proceed to the registration
*/
public function iShouldNotBeAbleToProceedToTheRegistration(): void
{
Assert::false($this->thankYouPage->hasRegistrationButton());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

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\VerificationPageInterface;
use Sylius\Behat\Page\Shop\HomePageInterface;
use Sylius\Behat\Page\Shop\Order\ThankYouPageInterface;
use Sylius\Behat\Service\NotificationCheckerInterface;
use Sylius\Behat\Service\SharedStorageInterface;
use Sylius\Component\Core\Model\CustomerInterface;
use Webmozart\Assert\Assert;

final class RegistrationAfterCheckoutContext implements Context
{
/** @var SharedStorageInterface */
private $sharedStorage;

/** @var LoginPageInterface */
private $loginPage;

/** @var ThankYouPageInterface */
private $thankYouPage;

/** @var DashboardPageInterface */
private $dashboardPage;

/** @var HomePageInterface */
private $homePage;

/** @var VerificationPageInterface */
private $verificationPage;

/** @var RegisterElementInterface */
private $registerElement;

/** @var NotificationCheckerInterface */
private $notificationChecker;

public function __construct(
SharedStorageInterface $sharedStorage,
LoginPageInterface $loginPage,
ThankYouPageInterface $thankYouPage,
DashboardPageInterface $dashboardPage,
HomePageInterface $homePage,
VerificationPageInterface $verificationPage,
RegisterElementInterface $registerElement,
NotificationCheckerInterface $notificationChecker
) {
$this->sharedStorage = $sharedStorage;
$this->loginPage = $loginPage;
$this->thankYouPage = $thankYouPage;
$this->dashboardPage = $dashboardPage;
$this->homePage = $homePage;
$this->verificationPage = $verificationPage;
$this->registerElement = $registerElement;
$this->notificationChecker = $notificationChecker;
}

/**
* @When I specify a password as :password
*/
public function iSpecifyThePasswordAs(string $password): void
{
$this->registerElement->specifyPassword($password);
$this->sharedStorage->set('password', $password);
}

/**
* @When /^I confirm (this password)$/
*/
public function iConfirmThisPassword(string $password): void
{
$this->registerElement->verifyPassword($password);
}

/**
* @When I register this account
*/
public function iRegisterThisAccount(): void
{
$this->registerElement->register();
}

/**
* @When I verify my account using link sent to :customer
*/
public function iVerifyMyAccountUsingLink(CustomerInterface $customer): void
{
$user = $customer->getUser();
Assert::notNull($user, 'No account for given customer');

$this->verificationPage->verifyAccount($user->getEmailVerificationToken());
}

/**
* @Then the registration form should be prefilled with :email email
*/
public function theRegistrationFormShouldBePrefilledWithEmail(string $email): void
{
$this->thankYouPage->createAccount();

Assert::same($this->registerElement->getEmail(), $email);
}

/**
* @Then I should be able to log in as :email with :password password
*/
public function iShouldBeAbleToLogInAsWithPassword(string $email, string $password): void
{
$this->loginPage->open();
$this->loginPage->specifyUsername($email);
$this->loginPage->specifyPassword($password);
$this->loginPage->logIn();

Assert::true($this->homePage->hasLogoutButton());
}
}
65 changes: 21 additions & 44 deletions src/Sylius/Behat/Context/Ui/Shop/CheckoutContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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();
}
}
Loading

0 comments on commit 55d466e

Please sign in to comment.