|
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\Page\Admin\Order; |
|
13
|
|
|
|
|
14
|
|
|
use Behat\Mink\Element\NodeElement; |
|
15
|
|
|
use Behat\Mink\Exception\ElementNotFoundException; |
|
16
|
|
|
use Sylius\Behat\Page\Admin\Crud\UpdatePage as BaseUpdatePage; |
|
17
|
|
|
use Sylius\Component\Addressing\Model\AddressInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @author Grzegorz Sadowski <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
class UpdatePage extends BaseUpdatePage implements UpdatePageInterface |
|
23
|
|
|
{ |
|
24
|
|
|
const TYPE_BILLING = 'billing'; |
|
25
|
|
|
const TYPE_SHIPPING = 'shipping'; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* {@inheritdoc} |
|
29
|
|
|
*/ |
|
30
|
|
|
public function specifyBillingAddress(AddressInterface $address) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->specifyAddress($address, UpdatePage::TYPE_BILLING); |
|
|
|
|
|
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* {@inheritdoc} |
|
37
|
|
|
*/ |
|
38
|
|
|
public function specifyShippingAddress(AddressInterface $address) |
|
39
|
|
|
{ |
|
40
|
|
|
$this->specifyAddress($address, UpdatePage::TYPE_SHIPPING); |
|
|
|
|
|
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* {@inheritdoc} |
|
45
|
|
|
*/ |
|
46
|
|
|
private function specifyAddress(AddressInterface $address, $addressType) |
|
47
|
|
|
{ |
|
48
|
|
|
$this->specifyElementValue($addressType.'_first_name', $address->getFirstName()); |
|
49
|
|
|
$this->specifyElementValue($addressType.'_last_name', $address->getLastName()); |
|
50
|
|
|
$this->specifyElementValue($addressType.'_street', $address->getStreet()); |
|
51
|
|
|
$this->specifyElementValue($addressType.'_city', $address->getCity()); |
|
52
|
|
|
$this->specifyElementValue($addressType.'_postcode', $address->getPostcode()); |
|
53
|
|
|
|
|
54
|
|
|
$this->chooseCountry($address->getCountryCode(), $addressType); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* {@inheritdoc} |
|
59
|
|
|
* |
|
60
|
|
|
* @throws ElementNotFoundException |
|
61
|
|
|
*/ |
|
62
|
|
|
public function checkValidationMessageFor($element, $message) |
|
|
|
|
|
|
63
|
|
|
{ |
|
64
|
|
|
$foundElement = $this->getFieldElement($element); |
|
65
|
|
|
if (null === $foundElement) { |
|
66
|
|
|
throw new ElementNotFoundException($this->getSession(), 'Validation message', 'css', '.sylius-validation-error'); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
$validationMessage = $foundElement->find('css', '.sylius-validation-error'); |
|
70
|
|
|
if (null === $validationMessage) { |
|
71
|
|
|
throw new ElementNotFoundException($this->getSession(), 'Validation message', 'css', '.sylius-validation-error'); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return $message === $validationMessage->getText(); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* {@inheritdoc} |
|
79
|
|
|
*/ |
|
80
|
|
|
protected function getDefinedElements() |
|
81
|
|
|
{ |
|
82
|
|
|
return array_merge(parent::getDefinedElements(), [ |
|
83
|
|
|
'billing_city' => '#sylius_order_billingAddress_city', |
|
84
|
|
|
'billing_country' => '#sylius_order_billingAddress_countryCode', |
|
85
|
|
|
'billing_first_name' => '#sylius_order_billingAddress_firstName', |
|
86
|
|
|
'billing_last_name' => '#sylius_order_billingAddress_lastName', |
|
87
|
|
|
'billing_postcode' => '#sylius_order_billingAddress_postcode', |
|
88
|
|
|
'billing_street' => '#sylius_order_billingAddress_street', |
|
89
|
|
|
'shipping_city' => '#sylius_order_shippingAddress_city', |
|
90
|
|
|
'shipping_country' => '#sylius_order_shippingAddress_countryCode', |
|
91
|
|
|
'shipping_first_name' => '#sylius_order_shippingAddress_firstName', |
|
92
|
|
|
'shipping_last_name' => '#sylius_order_shippingAddress_lastName', |
|
93
|
|
|
'shipping_postcode' => '#sylius_order_shippingAddress_postcode', |
|
94
|
|
|
'shipping_street' => '#sylius_order_shippingAddress_street', |
|
95
|
|
|
]); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @param string $elementName |
|
100
|
|
|
* @param string $value |
|
101
|
|
|
* |
|
102
|
|
|
* @throws ElementNotFoundException |
|
103
|
|
|
*/ |
|
104
|
|
|
private function specifyElementValue($elementName, $value) |
|
105
|
|
|
{ |
|
106
|
|
|
$this->getElement($elementName)->setValue($value); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @param string $country |
|
111
|
|
|
* @param string $addressType |
|
112
|
|
|
* |
|
113
|
|
|
* @throws ElementNotFoundException |
|
114
|
|
|
*/ |
|
115
|
|
|
private function chooseCountry($country, $addressType) |
|
116
|
|
|
{ |
|
117
|
|
|
$this->getElement($addressType.'_country')->selectOption((null !== $country) ? $country : 'Select'); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @param string $element |
|
122
|
|
|
* |
|
123
|
|
|
* @return NodeElement|null |
|
124
|
|
|
* |
|
125
|
|
|
* @throws ElementNotFoundException |
|
126
|
|
|
*/ |
|
127
|
|
|
private function getFieldElement($element) |
|
|
|
|
|
|
128
|
|
|
{ |
|
129
|
|
|
$element = $this->getElement($element); |
|
130
|
|
|
while (null !== $element && !($element->hasClass('field'))) { |
|
131
|
|
|
$element = $element->getParent(); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
return $element; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
} |
|
138
|
|
|
|
This check looks for accesses to local static members using the fully qualified name instead of
self::.While this is perfectly valid, the fully qualified name of
Certificate::TRIPLEDES_CBCcould just as well be replaced byself::TRIPLEDES_CBC. Referencing local members withself::assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.