Skip to content

Commit 0ba54e5

Browse files
committedNov 8, 2016
[Behat] Extracted setup AddressBookContext
1 parent 3033d3d commit 0ba54e5

File tree

13 files changed

+147
-60
lines changed

13 files changed

+147
-60
lines changed
 

‎features/account/customer_account/address_book/setting_default_address.feature

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ Feature: Marking an address as default
2121
Given I am browsing my address book
2222
When I set the address of "Lucifer Morningstar" as default
2323
Then I should be notified that the address has been set as default
24-
And it should be marked as my default address
2524
And I should have 1 address in my address book
25+
And address "Lucifer Morningstar", "Seaside Fwy", "90802", "Los Angeles", "United States", "Arkansas" should be marked as my default address
2626

2727
@ui
2828
Scenario: Only one address can be default
29-
Given I am browsing my address book
30-
And my default address is of "Lucifer Morningstar"
29+
Given my default address is of "Lucifer Morningstar"
30+
And I am browsing my address book
3131
When I set the address of "Archangelo Prime" as default
3232
Then I should be notified that the address has been set as default
33-
And the address of "Archangelo Prime" should be marked as my default
33+
And address "Archangelo Prime", "Mountain Av", "90640", "Isla del Muerte", "United States" should be marked as my default address
3434
And the address assigned to "Lucifer Morningstar" should be in my book

‎features/user/managing_customers/seeing_customer_details.feature

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Feature: Seeing customer's details
1818

1919
@ui
2020
Scenario: Seeing customer's addresses
21-
Given his default address is "Hobbiton", "Bag End", "1", "New Zealand" for "Frodo Baggins"
21+
Given their default address is "Hobbiton", "Bag End", "1", "New Zealand" for "Frodo Baggins"
2222
When I view details of the customer "f.baggins@shire.me"
2323
Then his default address should be "Frodo Baggins, Bag End, Hobbiton, NEW ZEALAND 1"
2424

‎features/user/managing_customers/seeing_province_created_manually_on_customer_details_page.feature

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ Feature: Seeing a province on customer's details
88
Scenario: Seeing customer's addresses
99
Given I am logged in as an administrator
1010
And the store has customer "f.baggins@shire.me" with name "Frodo Baggins" since "2011-01-10 21:00"
11-
And his default address is "Frodo Baggins", "Bag End", "12-1321", "Hobbiton", "United Kingdom", "East of England"
11+
And their default address is "Frodo Baggins", "Bag End", "12-1321", "Hobbiton", "United Kingdom", "East of England"
1212
When I view details of the customer "f.baggins@shire.me"
1313
Then the province in the default address should be "East of England"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Sylius package.
5+
*
6+
* (c) Paweł Jędrzejewski
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Sylius\Behat\Context\Setup;
13+
14+
use Behat\Behat\Context\Context;
15+
use Doctrine\Common\Persistence\ObjectManager;
16+
use Sylius\Component\Core\Model\AddressInterface;
17+
use Sylius\Component\Core\Model\CustomerInterface;
18+
use Sylius\Component\Core\Model\ShopUserInterface;
19+
use Sylius\Component\Core\Repository\AddressRepositoryInterface;
20+
use Webmozart\Assert\Assert;
21+
22+
/**
23+
* @author Jan Góralski <jan.goralski@lakion.com>
24+
*/
25+
final class AddressBookContext implements Context
26+
{
27+
/**
28+
* @var AddressRepositoryInterface
29+
*/
30+
private $addressRepository;
31+
32+
/**
33+
* @var ObjectManager
34+
*/
35+
private $customerManager;
36+
37+
/**
38+
* @param AddressRepositoryInterface $addressRepository
39+
* @param ObjectManager $customerManager
40+
*/
41+
public function __construct(AddressRepositoryInterface $addressRepository, ObjectManager $customerManager)
42+
{
43+
$this->addressRepository = $addressRepository;
44+
$this->customerManager = $customerManager;
45+
}
46+
47+
/**
48+
* @Given /^(their) default (address is "(?:[^"]+)", "(?:[^"]+)", "(?:[^"]+)", "(?:[^"]+)" for "(?:[^"]+)")$/
49+
* @Given /^(their) default (address is "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)")$/
50+
*/
51+
public function theirDefaultAddressIs(CustomerInterface $customer, AddressInterface $address)
52+
{
53+
$this->setDefaultAddressOfCustomer($customer, $address);
54+
}
55+
56+
/**
57+
* @Given /^(my) default address is of "([^"]+)"$/
58+
*/
59+
public function myDefaultAddressIsOf(ShopUserInterface $user, $fullName)
60+
{
61+
list($firstName, $lastName) = explode(' ', $fullName);
62+
63+
/** @var AddressInterface $address */
64+
$address = $this->addressRepository->findOneBy(['firstName' => $firstName, 'lastName' => $lastName]);
65+
Assert::notNull($address, sprintf('The address of "%s" has not been found.', $fullName));
66+
67+
/** @var CustomerInterface $customer */
68+
$customer = $user->getCustomer();
69+
70+
$this->setDefaultAddressOfCustomer($customer, $address);
71+
}
72+
73+
/**
74+
* @Given /^(I) have an (address "[^"]+", "[^"]+", "[^"]+", "[^"]+", "[^"]+"(?:|, "[^"]+")) in my address book$/
75+
*/
76+
public function iHaveAnAddressInAddressBook(ShopUserInterface $user, AddressInterface $address)
77+
{
78+
/** @var CustomerInterface $customer */
79+
$customer = $user->getCustomer();
80+
81+
$this->addAddressToCustomer($customer, $address);
82+
}
83+
84+
/**
85+
* @Given /^(this customer) has an (address "[^"]+", "[^"]+", "[^"]+", "[^"]+", "[^"]+"(?:|, "[^"]+")) in their address book$/
86+
*/
87+
public function thisCustomerHasAnAddressInAddressBook(CustomerInterface $customer, AddressInterface $address)
88+
{
89+
$this->addAddressToCustomer($customer, $address);
90+
}
91+
92+
/**
93+
* @param CustomerInterface $customer
94+
* @param AddressInterface $address
95+
*/
96+
private function addAddressToCustomer(CustomerInterface $customer, AddressInterface $address)
97+
{
98+
$customer->addAddress($address);
99+
100+
$this->customerManager->flush();
101+
}
102+
103+
/**
104+
* @param CustomerInterface $customer
105+
* @param AddressInterface $address
106+
*/
107+
private function setDefaultAddressOfCustomer(CustomerInterface $customer, AddressInterface $address)
108+
{
109+
$customer->setDefaultAddress($address);
110+
111+
$this->customerManager->flush();
112+
}
113+
}

‎src/Sylius/Behat/Context/Setup/CustomerContext.php

-34
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
use Behat\Behat\Context\Context;
1515
use Doctrine\Common\Persistence\ObjectManager;
1616
use Sylius\Behat\Service\SharedStorageInterface;
17-
use Sylius\Component\Core\Model\AddressInterface;
1817
use Sylius\Component\Core\Model\CustomerInterface;
19-
use Sylius\Component\Core\Model\ShopUserInterface;
2018
use Sylius\Component\Core\Repository\CustomerRepositoryInterface;
2119
use Sylius\Component\Customer\Model\CustomerGroupInterface;
2220
use Sylius\Component\Resource\Factory\FactoryInterface;
@@ -155,17 +153,6 @@ public function thereIsAdministratorIdentifiedByEmailAndPassword($name, $email,
155153
$this->createCustomerWithUserAccount($email, $password, true, $firstName, $lastName, 'ROLE_ADMINISTRATION_ACCESS');
156154
}
157155

158-
/**
159-
* @Given /^(his) default (address is "(?:[^"]+)", "(?:[^"]+)", "(?:[^"]+)", "(?:[^"]+)" for "(?:[^"]+)")$/
160-
* @Given /^(his) default (address is "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)")$/
161-
*/
162-
public function heHasDefaultAddress(CustomerInterface $customer, AddressInterface $address)
163-
{
164-
$customer->setDefaultAddress($address);
165-
166-
$this->customerManager->flush();
167-
}
168-
169156
/**
170157
* @Given /^(the customer) subscribed to the newsletter$/
171158
*/
@@ -176,27 +163,6 @@ public function theCustomerSubscribedToTheNewsletter(CustomerInterface $customer
176163
$this->customerManager->flush();
177164
}
178165

179-
/**
180-
* @Given /^(I) have an (address "[^"]+", "[^"]+", "[^"]+", "[^"]+", "[^"]+"(?:|, "[^"]+")) in my address book$/
181-
*/
182-
public function iHaveAnAddressInAddressBook(ShopUserInterface $user, AddressInterface $address)
183-
{
184-
/** @var CustomerInterface $customer */
185-
$customer = $user->getCustomer();
186-
187-
$this->thisCustomerHasAnAddressInAddressBook($customer, $address);
188-
}
189-
190-
/**
191-
* @Given /^(this customer) has an (address "[^"]+", "[^"]+", "[^"]+", "[^"]+", "[^"]+"(?:|, "[^"]+")) in their address book$/
192-
*/
193-
public function thisCustomerHasAnAddressInAddressBook(CustomerInterface $customer, AddressInterface $address)
194-
{
195-
$customer->addAddress($address);
196-
197-
$this->customerManager->flush();
198-
}
199-
200166
/**
201167
* @Given /^(this customer) verified their email$/
202168
*/

‎src/Sylius/Behat/Context/Transform/CustomerContext.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function getOrCreateCustomerByEmail($email)
7171
}
7272

7373
/**
74-
* @Transform /^(he|his|she|her|the customer of my account)$/
74+
* @Transform /^(he|his|she|her|their|the customer of my account)$/
7575
*/
7676
public function getLastCustomer()
7777
{

‎src/Sylius/Behat/Context/Ui/Shop/AddressBookContext.php

+9-10
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function __construct(
9494
}
9595

9696
/**
97-
* @Given /^I am editing the address of "([^"]+)"$/
97+
* @Given I am editing the address of :fullName
9898
*/
9999
public function iEditAddressOf($fullName)
100100
{
@@ -105,7 +105,6 @@ public function iEditAddressOf($fullName)
105105
}
106106

107107
/**
108-
* @Given my default address is of :fullName
109108
* @When I set the address of :fullName as default
110109
*/
111110
public function iSetTheAddressOfAsDefault($fullName)
@@ -209,12 +208,12 @@ public function iDeleteTheAddress($fullname)
209208
/**
210209
* @When /^I try to edit the address of "([^"]+)"$/
211210
*/
212-
public function iTryToEdit($fullName)
211+
public function iTryToEditTheAddressOf($fullName)
213212
{
214-
$this->sharedStorage->set('full_name', $fullName);
215-
216213
$address = $this->getAddressOf($fullName);
217214

215+
$this->sharedStorage->set('full_name', sprintf('%s %s', $address->getFirstName(), $address->getLastName()));
216+
218217
$this->addressBookUpdatePage->tryToOpen(['id' => $address->getId()]);
219218
}
220219

@@ -377,17 +376,17 @@ public function iShouldHaveNoDefaultAddress()
377376
}
378377

379378
/**
380-
* @Then /^the address of "([^"]+)" should be marked as my default$/
381-
* @Then /^(it) should be marked as my default address$/
379+
* @Then /^(address "[^"]+", "[^"]+", "[^"]+", "[^"]+", "[^"]+"(?:|, "[^"]+")) should be marked as my default address$/
382380
*/
383-
public function itShouldBeMarkedAsMyDefaultAddress($fullName)
381+
public function addressShouldBeMarkedAsMyDefaultAddress(AddressInterface $address)
384382
{
385383
$actualFullName = $this->addressBookIndexPage->getFullNameOfDefaultAddress();
384+
$expectedFullName = sprintf('%s %s', $address->getFirstName(), $address->getLastName());
386385

387386
Assert::same(
388-
$fullName,
387+
$expectedFullName,
389388
$actualFullName,
390-
sprintf('The default address should be of "%s", but is of "%s".', $fullName, $actualFullName)
389+
sprintf('The default address should be of "%s", but is of "%s".', $expectedFullName, $actualFullName)
391390
);
392391
}
393392

‎src/Sylius/Behat/Page/Shop/Account/AddressBook/IndexPage.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function getFullNameOfDefaultAddress()
117117
*/
118118
private function getAddressOf($fullName)
119119
{
120-
return $this->getElement('addresses')->find('css', sprintf('div:contains("%s")', $fullName));
120+
return $this->getElement('addresses')->find('css', sprintf('div.address:contains("%s")', $fullName));
121121
}
122122

123123
/**

‎src/Sylius/Behat/Resources/config/services/contexts/setup.xml

+13-7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,19 @@
1313

1414
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
1515
<services>
16+
<service id="sylius.behat.context.setup.address_book" class="Sylius\Behat\Context\Setup\AddressBookContext" scope="scenario">
17+
<argument type="service" id="__symfony__.sylius.repository.address" />
18+
<argument type="service" id="__symfony__.sylius.manager.customer" />
19+
<tag name="fob.context_service" />
20+
</service>
21+
22+
<service id="sylius.behat.context.setup.admin_user" class="Sylius\Behat\Context\Setup\AdminUserContext" scope="scenario">
23+
<argument type="service" id="__symfony__.sylius.behat.shared_storage" />
24+
<argument type="service" id="__symfony__.sylius.fixture.example_factory.admin_user" />
25+
<argument type="service" id="__symfony__.sylius.repository.admin_user" />
26+
<tag name="fob.context_service" />
27+
</service>
28+
1629
<service id="sylius.behat.context.setup.channel" class="Sylius\Behat\Context\Setup\ChannelContext">
1730
<argument type="service" id="sylius.behat.shared_storage" />
1831
<argument type="service" id="__symfony__.sylius.behat.factory.default_united_states_channel" />
@@ -242,13 +255,6 @@
242255
<tag name="fob.context_service" />
243256
</service>
244257

245-
<service id="sylius.behat.context.setup.admin_user" class="Sylius\Behat\Context\Setup\AdminUserContext">
246-
<argument type="service" id="sylius.behat.shared_storage" />
247-
<argument type="service" id="__symfony__.sylius.fixture.example_factory.admin_user" />
248-
<argument type="service" id="__symfony__.sylius.repository.admin_user" />
249-
<tag name="fob.context_service" />
250-
</service>
251-
252258
<service id="sylius.behat.context.setup.zone" class="Sylius\Behat\Context\Setup\ZoneContext">
253259
<argument type="service" id="sylius.behat.shared_storage" />
254260
<argument type="service" id="__symfony__.sylius.repository.zone" />

‎src/Sylius/Behat/Resources/config/suites/ui/account/address_book.yml

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ default:
1212
- sylius.behat.context.transform.shared_storage
1313
- sylius.behat.context.transform.user
1414

15+
- sylius.behat.context.setup.address_book
1516
- sylius.behat.context.setup.channel
1617
- sylius.behat.context.setup.customer
1718
- sylius.behat.context.setup.geographical

‎src/Sylius/Behat/Resources/config/suites/ui/checkout/checkout.yml

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ default:
2121
- sylius.behat.context.transform.user
2222
- sylius.behat.context.transform.zone
2323

24+
- sylius.behat.context.setup.address_book
2425
- sylius.behat.context.setup.admin_user
2526
- sylius.behat.context.setup.channel
2627
- sylius.behat.context.setup.currency

‎src/Sylius/Behat/Resources/config/suites/ui/user/managing_customers.yml

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ default:
1212
- sylius.behat.context.transform.customer_group
1313
- sylius.behat.context.transform.shared_storage
1414

15+
- sylius.behat.context.setup.address_book
1516
- sylius.behat.context.setup.channel
1617
- sylius.behat.context.setup.customer
1718
- sylius.behat.context.setup.customer_group

‎src/Sylius/Bundle/ShopBundle/Resources/views/Account/AddressBook/_item.html.twig

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="eight wide column">
2-
<div class="ui segment">
2+
<div class="ui segment address">
33
<div class="ui stackable two column grid">
44
<div class="column">
55
{% include '@SyliusShop/Common/_address.html.twig' with {'address': address} %}

0 commit comments

Comments
 (0)