Skip to content

Commit

Permalink
[Shop] Change customer id and address id to order token in routing
Browse files Browse the repository at this point in the history
  • Loading branch information
GSadee committed Aug 24, 2018
1 parent c290959 commit 616bef8
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 32 deletions.
6 changes: 2 additions & 4 deletions features/checkout/registering_account_after_checkout.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Feature: Registering a new account after checkout

Background:
Given the store operates on a single channel in "United States"
And on this channel account verification is not required
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
Expand All @@ -21,6 +20,5 @@ Feature: Registering a new account after checkout
And I specify a password as "sylius"
And I confirm this password
And I register this account
Then I should be notified that new account has been successfully created
And my email should be "[email protected]"
And I should be logged in
And I verify my account using link sent to "[email protected]"
Then I should be able to log in as "[email protected]" with "sylius" password
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,25 @@
namespace Sylius\Behat\Context\Ui\Shop\Checkout;

use Behat\Behat\Context\Context;
use Sylius\Behat\NotificationType;
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;
use Sylius\Behat\Service\NotificationCheckerInterface;
use Sylius\Behat\Service\SharedStorageInterface;
use Sylius\Component\Core\Model\CustomerInterface;
use Webmozart\Assert\Assert;

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

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

/** @var RegisterPageInterface */
private $registerPage;

Expand All @@ -40,22 +45,29 @@ class RegistrationAfterCheckoutContext implements Context
/** @var HomePageInterface */
private $homePage;

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

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

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

Expand Down Expand Up @@ -85,14 +97,14 @@ public function iRegisterThisAccount(): void
}

/**
* @Then I should be notified that new account has been successfully created
* @When I verify my account using link sent to :customer
*/
public function iShouldBeNotifiedThatNewAccountHasBeenSuccessfullyCreated(): void
public function iVerifyMyAccountUsingLink(CustomerInterface $customer): void
{
$this->notificationChecker->checkNotification(
'Thank you for registering, check your email to verify your account.',
NotificationType::success()
);
$user = $customer->getUser();
Assert::notNull($user, 'No account for given customer');

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

/**
Expand All @@ -106,20 +118,15 @@ public function theRegistrationFormShouldBePrefilledWithEmail(string $email): vo
}

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

Assert::true($this->dashboardPage->hasCustomerEmail($email));
}
$this->loginPage->open();
$this->loginPage->specifyUsername($email);
$this->loginPage->specifyPassword($password);
$this->loginPage->logIn();

/**
* @Then I should be logged in
*/
public function iShouldBeLoggedIn(): void
{
Assert::true($this->homePage->hasLogoutButton());
}
}
2 changes: 2 additions & 0 deletions src/Sylius/Behat/Resources/config/services/contexts/ui.xml
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,12 @@

<service id="sylius.behat.context.ui.shop.checkout.registration_after_checkout" class="Sylius\Behat\Context\Ui\Shop\Checkout\RegistrationAfterCheckoutContext">
<argument type="service" id="sylius.behat.shared_storage" />
<argument type="service" id="sylius.behat.page.shop.account.login" />
<argument type="service" id="sylius.behat.page.shop.account.register" />
<argument type="service" id="sylius.behat.page.shop.order.thank_you" />
<argument type="service" id="sylius.behat.page.shop.account.dashboard" />
<argument type="service" id="sylius.behat.page.shop.home" />
<argument type="service" id="sylius.behat.page.shop.account.verify" />
<argument type="service" id="sylius.behat.notification_checker" />
<tag name="fob.context_service" />
</service>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ default:
- sylius.behat.context.transform.country
- sylius.behat.context.transform.channel
- sylius.behat.context.transform.currency
- sylius.behat.context.transform.customer
- sylius.behat.context.transform.lexical
- sylius.behat.context.transform.locale
- sylius.behat.context.transform.order
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ sylius_shop_register:
flash: sylius.customer.register

sylius_shop_register_after_checkout:
path: /register-after-checkout
path: /register-after-checkout/{tokenValue}
methods: [GET]
defaults:
_controller: sylius.controller.customer:createAction
Expand All @@ -43,8 +43,7 @@ sylius_shop_register_after_checkout:
factory:
method: ['expr:service("sylius.factory.customer_after_checkout")', 'createAfterCheckout']
arguments:
- 'expr:service("sylius.repository.customer").find($customerId)'
- 'expr:service("sylius.repository.address").find($addressId)'
- 'expr:service("sylius.repository.order").findOneByTokenValue($tokenValue)'
template: "@SyliusShop/register.html.twig"
event: register
redirect:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{% endif %}

{% if order.customer.user is null %}
<a href="{{ path('sylius_shop_register_after_checkout', {'customerId': order.customer.id, 'addressId': order.billingAddress.id}) }}" class="ui large green button">
<a href="{{ path('sylius_shop_register_after_checkout', {'tokenValue': order.tokenValue}) }}" class="ui large green button">
<i class="signup icon"></i>
{{ 'sylius.ui.create_an_account'|trans }}
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

namespace Sylius\Component\Core\Factory;

use Sylius\Component\Core\Model\AddressInterface;
use Sylius\Component\Core\Model\CustomerInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;

final class CustomerAfterCheckoutFactory implements CustomerAfterCheckoutFactoryInterface
Expand All @@ -35,8 +35,11 @@ public function createNew(): CustomerInterface
return $customer;
}

public function createAfterCheckout(CustomerInterface $guest, AddressInterface $address): CustomerInterface
public function createAfterCheckout(OrderInterface $order): CustomerInterface
{
$guest = $order->getCustomer();
$address = $order->getBillingAddress();

$customer = $this->createNew();
$customer->setEmail($guest->getEmail());
$customer->setFirstName($address->getFirstName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

namespace Sylius\Component\Core\Factory;

use Sylius\Component\Core\Model\AddressInterface;
use Sylius\Component\Core\Model\CustomerInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;

interface CustomerAfterCheckoutFactoryInterface extends FactoryInterface
{
public function createAfterCheckout(CustomerInterface $guest, AddressInterface $address): CustomerInterface;
public function createAfterCheckout(OrderInterface $order): CustomerInterface;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Sylius\Component\Core\Factory\CustomerAfterCheckoutFactoryInterface;
use Sylius\Component\Core\Model\AddressInterface;
use Sylius\Component\Core\Model\CustomerInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;

final class CustomerAfterCheckoutFactorySpec extends ObjectBehavior
Expand Down Expand Up @@ -46,10 +47,15 @@ function it_creates_a_new_customer(FactoryInterface $baseCustomerFactory, Custom
function it_creates_a_new_customer_after_checkout(
FactoryInterface $baseCustomerFactory,
CustomerInterface $guest,
OrderInterface $order,
AddressInterface $address,
CustomerInterface $customer
): void {
$order->getCustomer()->willReturn($guest);
$order->getBillingAddress()->willReturn($address);

$guest->getEmail()->willReturn('[email protected]');

$address->getFirstName()->willReturn('John');
$address->getLastName()->willReturn('Doe');
$address->getPhoneNumber()->willReturn('666777888');
Expand All @@ -61,6 +67,6 @@ function it_creates_a_new_customer_after_checkout(
$customer->setLastName('Doe')->shouldBeCalled();
$customer->setPhoneNumber('666777888')->shouldBeCalled();

$this->createAfterCheckout($guest, $address)->shouldReturn($customer);
$this->createAfterCheckout($order)->shouldReturn($customer);
}
}

0 comments on commit 616bef8

Please sign in to comment.