|
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\ProductVariant; |
|
13
|
|
|
|
|
14
|
|
|
use Behat\Mink\Element\NodeElement; |
|
15
|
|
|
use Behat\Mink\Exception\ElementNotFoundException; |
|
16
|
|
|
use Sylius\Behat\Page\SymfonyPage; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @author Łukasz Chruściel <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class GeneratePage extends SymfonyPage implements GeneratePageInterface |
|
22
|
|
|
{ |
|
23
|
|
|
public function generate() |
|
24
|
|
|
{ |
|
25
|
|
|
$this->getDocument()->pressButton('Generate'); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* {@inheritdoc} |
|
30
|
|
|
*/ |
|
31
|
|
|
public function specifyPrice($nth, $price) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->getDocument()->fillField(sprintf('sylius_product_generate_variants_variants_%s_price', $nth), $price); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* {@inheritdoc} |
|
38
|
|
|
*/ |
|
39
|
|
|
public function nameCode($nth, $code) |
|
40
|
|
|
{ |
|
41
|
|
|
$this->getDocument()->fillField(sprintf('sylius_product_generate_variants_variants_%s_code', $nth), $code); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* {@inheritdoc} |
|
46
|
|
|
*/ |
|
47
|
|
|
public function removeVariant($nth) |
|
48
|
|
|
{ |
|
49
|
|
|
$item = $this->getDocument()->find('css', sprintf('div[data-form-collection-index="%s"]', $nth)); |
|
50
|
|
|
|
|
51
|
|
|
$item->clickLink('Delete'); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* {@inheritdoc} |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getRouteName() |
|
58
|
|
|
{ |
|
59
|
|
|
return 'sylius_admin_product_variant_generate'; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* {@inheritdoc} |
|
64
|
|
|
* |
|
65
|
|
|
* @throws ElementNotFoundException |
|
66
|
|
|
*/ |
|
67
|
|
|
public function getValidationMessage($element, $position) |
|
68
|
|
|
{ |
|
69
|
|
|
$foundElement = $this->getElement($element, ['%position%' => $position]); |
|
70
|
|
|
$validatedField = $this->getValidatedField($foundElement); |
|
71
|
|
|
if (null === $validatedField) { |
|
72
|
|
|
throw new ElementNotFoundException($this->getSession(), 'Element', 'css', $foundElement); |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return $validatedField->find('css', '.sylius-validation-error')->getText(); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* {@inheritdoc} |
|
80
|
|
|
*/ |
|
81
|
|
|
protected function getDefinedElements() |
|
82
|
|
|
{ |
|
83
|
|
|
return array_merge(parent::getDefinedElements(), [ |
|
84
|
|
|
'code' => '#sylius_product_generate_variants_variants_%position%_code', |
|
85
|
|
|
'price' => '#sylius_product_generate_variants_variants_%position%_price', |
|
86
|
|
|
]); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @param NodeElement $element |
|
91
|
|
|
* |
|
92
|
|
|
* @return NodeElement |
|
|
|
|
|
|
93
|
|
|
* |
|
94
|
|
|
* @throws ElementNotFoundException |
|
95
|
|
|
*/ |
|
96
|
|
|
private function getValidatedField(NodeElement $element) |
|
97
|
|
|
{ |
|
98
|
|
|
while (null !== $element && !$element->hasClass('field')) { |
|
99
|
|
|
$element = $element->getParent(); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
return $element; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: