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\Ui\Shop; |
13
|
|
|
|
14
|
|
|
use Behat\Behat\Context\Context; |
15
|
|
|
use Sylius\Behat\NotificationType; |
16
|
|
|
use Sylius\Behat\Page\Shop\Account\AddressBook\CreatePageInterface; |
17
|
|
|
use Sylius\Behat\Page\Shop\Account\AddressBook\IndexPageInterface; |
18
|
|
|
use Sylius\Behat\Service\NotificationCheckerInterface; |
19
|
|
|
use Sylius\Component\Core\Model\AddressInterface; |
20
|
|
|
use Webmozart\Assert\Assert; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @author Anna Walasek <[email protected]> |
24
|
|
|
* @author Jan Góralski <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
final class AddressBookContext implements Context |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var IndexPageInterface |
30
|
|
|
*/ |
31
|
|
|
private $addressBookIndexPage; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var CreatePageInterface |
35
|
|
|
*/ |
36
|
|
|
private $addressBookCreatePage; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var NotificationCheckerInterface |
40
|
|
|
*/ |
41
|
|
|
private $notificationChecker; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param IndexPageInterface $addressBookIndexPage |
45
|
|
|
* @param CreatePageInterface $addressBookCreatePage |
46
|
|
|
* @param NotificationCheckerInterface $notificationChecker |
47
|
|
|
*/ |
48
|
|
|
public function __construct( |
49
|
|
|
IndexPageInterface $addressBookIndexPage, |
50
|
|
|
CreatePageInterface $addressBookCreatePage, |
51
|
|
|
NotificationCheckerInterface $notificationChecker |
52
|
|
|
) { |
53
|
|
|
$this->addressBookIndexPage = $addressBookIndexPage; |
54
|
|
|
$this->addressBookCreatePage = $addressBookCreatePage; |
55
|
|
|
$this->notificationChecker = $notificationChecker; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @When I browse my address book |
60
|
|
|
*/ |
61
|
|
|
public function iBrowseMyAddresses() |
62
|
|
|
{ |
63
|
|
|
$this->addressBookIndexPage->open(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @Given I want to add a new address to my address book |
68
|
|
|
*/ |
69
|
|
|
public function iWantToAddANewAddressToMyAddressBook() |
70
|
|
|
{ |
71
|
|
|
$this->addressBookCreatePage->open(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @When /^I specify the (address as "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)")$/ |
76
|
|
|
*/ |
77
|
|
|
public function iSpecifyItsDataAs(AddressInterface $address) |
78
|
|
|
{ |
79
|
|
|
$this->addressBookCreatePage->fillAddressData($address); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @When I add it |
84
|
|
|
*/ |
85
|
|
|
public function iAddIt() |
86
|
|
|
{ |
87
|
|
|
$this->addressBookCreatePage->saveAddress(); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @When I delete the :fullName address |
92
|
|
|
*/ |
93
|
|
|
public function iDeleteTheAddress($fullname) |
94
|
|
|
{ |
95
|
|
|
$this->addressBookIndexPage->deleteAddress($fullname); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @Then I should be notified that it has been successfully deleted |
100
|
|
|
*/ |
101
|
|
|
public function iShouldBeNotifiedAboutSuccessfulDelete() |
102
|
|
|
{ |
103
|
|
|
$this->notificationChecker->checkNotification('Address has been successfully deleted.', NotificationType::success()); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @Then I should see a single address in my book |
108
|
|
|
*/ |
109
|
|
|
public function iShouldSeeASingleAddressInTheList() |
110
|
|
|
{ |
111
|
|
|
$this->assertAddressesCountOnPage(1); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @Then this address should be assigned to :fullName |
116
|
|
|
* @Then the address assigned to :fullName should appear in my book |
117
|
|
|
*/ |
118
|
|
|
public function thisAddressShouldHavePersonFirstNameAndLastName($fullName) |
119
|
|
|
{ |
120
|
|
|
Assert::true( |
121
|
|
|
$this->addressBookIndexPage->hasAddressOf($fullName), |
122
|
|
|
sprintf('An address of "%s" should be on the list.', $fullName) |
123
|
|
|
); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @Then there should be no addresses |
128
|
|
|
*/ |
129
|
|
|
public function thereShouldBeNoAddresses() |
130
|
|
|
{ |
131
|
|
|
Assert::true( |
132
|
|
|
$this->addressBookIndexPage->hasNoAddresses(), |
133
|
|
|
'There should be no addresses on the list.' |
134
|
|
|
); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @Then I should not see the address assigned to :fullName |
139
|
|
|
*/ |
140
|
|
|
public function iShouldNotSeeAddressOf($fullName) |
141
|
|
|
{ |
142
|
|
|
Assert::false( |
143
|
|
|
$this->addressBookIndexPage->hasAddressOf($fullName), |
144
|
|
|
sprintf('The address of "%s" should not be on the list.', $fullName) |
145
|
|
|
); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @Then /^I should(?:| still) have (\d+) address(?:|es) in my address book$/ |
150
|
|
|
*/ |
151
|
|
|
public function iShouldHaveAddresses($count) |
152
|
|
|
{ |
153
|
|
|
$this->addressBookIndexPage->open(); |
154
|
|
|
|
155
|
|
|
$this->assertAddressesCountOnPage((int) $count); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @Then I should be notified that it has been successfully added |
160
|
|
|
*/ |
161
|
|
|
public function iShouldBeNotifiedThatAddressHasBeenSuccessfullyAdded() |
162
|
|
|
{ |
163
|
|
|
$this->notificationChecker->checkNotification('has been successfully added.', NotificationType::success()); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @param int $expectedCount |
168
|
|
|
* |
169
|
|
|
* @throws \InvalidArgumentException |
170
|
|
|
*/ |
171
|
|
|
private function assertAddressesCountOnPage($expectedCount) |
172
|
|
|
{ |
173
|
|
|
$actualCount = $this->addressBookIndexPage->getAddressesCount(); |
174
|
|
|
|
175
|
|
|
Assert::same( |
176
|
|
|
$expectedCount, |
177
|
|
|
$actualCount, |
178
|
|
|
sprintf( |
179
|
|
|
'There should be %d addresses on the list, but %d addresses has been found.', |
180
|
|
|
$expectedCount, |
181
|
|
|
$actualCount |
182
|
|
|
) |
183
|
|
|
); |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
|