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
|
|
|
* @When I delete the :fullName address |
68
|
|
|
*/ |
69
|
|
|
public function iDeleteTheAddress($fullname) |
70
|
|
|
{ |
71
|
|
|
$this->addressBookIndexPage->deleteAddress($fullname); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @Then I should be notified that it has been successfully deleted |
76
|
|
|
*/ |
77
|
|
|
public function iShouldBeNotifiedAboutSuccessfulDelete() |
78
|
|
|
{ |
79
|
|
|
$this->notificationChecker->checkNotification('Address has been successfully deleted.', NotificationType::success()); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @Then I should see a single address in my book |
84
|
|
|
*/ |
85
|
|
|
public function iShouldSeeASingleAddressInTheList() |
86
|
|
|
{ |
87
|
|
|
Assert::true( |
88
|
|
|
$this->addressBookIndexPage->isSingleAddressOnList(), |
89
|
|
|
'There should be one address on the list, but it does not.' |
90
|
|
|
); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @Then this address should be assigned to :fullName |
95
|
|
|
* @Then the address assigned to :fullName should appear in my book |
96
|
|
|
*/ |
97
|
|
|
public function thisAddressShouldHavePersonFirstNameAndLastName($fullName) |
98
|
|
|
{ |
99
|
|
|
Assert::true( |
100
|
|
|
$this->addressBookIndexPage->hasAddressFullName($fullName), |
101
|
|
|
sprintf('An address of "%s" should be on the list.', $fullName) |
102
|
|
|
); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @Then There should be no addresses |
107
|
|
|
*/ |
108
|
|
|
public function thereShouldBeNoAddresses() |
109
|
|
|
{ |
110
|
|
|
Assert::true( |
111
|
|
|
$this->addressBookIndexPage->hasNoAddresses(), |
112
|
|
|
'There should be no addresses on the list.' |
113
|
|
|
); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @Then I should not see the address assigned to :fullName |
118
|
|
|
*/ |
119
|
|
|
public function iShouldNotSeeAddressOf($fullName) |
120
|
|
|
{ |
121
|
|
|
Assert::false( |
122
|
|
|
$this->addressBookIndexPage->hasAddressFullName($fullName), |
123
|
|
|
sprintf('The address of "%s" should not be on the list.', $fullName) |
124
|
|
|
); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @Given I want to add a new address to my address book |
129
|
|
|
*/ |
130
|
|
|
public function iWantToAddANewAddressToMyAddressBook() |
131
|
|
|
{ |
132
|
|
|
$this->addressBookCreatePage->open(); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @When /^I specify the (address as "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)")$/ |
137
|
|
|
*/ |
138
|
|
|
public function iSpecifyItsDataAs(AddressInterface $address) |
139
|
|
|
{ |
140
|
|
|
$this->addressBookCreatePage->fillAddressData($address); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @Then I should be notified that it has been successfully added |
145
|
|
|
*/ |
146
|
|
|
public function iShouldBeNotifiedThatAddressHasBeenSuccessfullyAdded() |
147
|
|
|
{ |
148
|
|
|
$this->notificationChecker->checkNotification('has been successfully added.', NotificationType::success()); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @When I add it |
153
|
|
|
*/ |
154
|
|
|
public function iAddIt() |
155
|
|
|
{ |
156
|
|
|
$this->addressBookCreatePage->saveAddress(); |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|