|
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\Product; |
|
13
|
|
|
|
|
14
|
|
|
use Behat\Mink\Driver\Selenium2Driver; |
|
15
|
|
|
use Behat\Mink\Element\NodeElement; |
|
16
|
|
|
use Sylius\Behat\Behaviour\SpecifiesItsCode; |
|
17
|
|
|
use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage; |
|
18
|
|
|
use Sylius\Behat\Service\SlugGenerationHelper; |
|
19
|
|
|
use Webmozart\Assert\Assert; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @author Łukasz Chruściel <[email protected]> |
|
23
|
|
|
*/ |
|
24
|
|
|
class CreateConfigurableProductPage extends BaseCreatePage implements CreateConfigurableProductPageInterface |
|
25
|
|
|
{ |
|
26
|
|
|
use SpecifiesItsCode; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* {@inheritdoc} |
|
30
|
|
|
*/ |
|
31
|
|
|
public function nameItIn($name, $localeCode) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->getDocument()->fillField( |
|
34
|
|
|
sprintf('sylius_product_translations_%s_name', $localeCode), $name |
|
35
|
|
|
); |
|
36
|
|
|
|
|
37
|
|
|
if ($this->getDriver() instanceof Selenium2Driver) { |
|
38
|
|
|
SlugGenerationHelper::waitForSlugGeneration($this->getSession(), $this->getElement('slug')); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* {@inheritdoc} |
|
44
|
|
|
*/ |
|
45
|
|
|
public function selectOption($optionName) |
|
46
|
|
|
{ |
|
47
|
|
|
$this->getDocument()->selectFieldOption('Options', $optionName); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* {@inheritdoc} |
|
52
|
|
|
*/ |
|
53
|
|
|
public function attachImage($path, $type = null) |
|
54
|
|
|
{ |
|
55
|
|
|
$this->clickTabIfItsNotActive('media'); |
|
56
|
|
|
|
|
57
|
|
|
$filesPath = $this->getParameter('files_path'); |
|
58
|
|
|
|
|
59
|
|
|
$this->getDocument()->clickLink('Add'); |
|
60
|
|
|
|
|
61
|
|
|
$imageForm = $this->getLastImageElement(); |
|
62
|
|
|
if (null !== $type) { |
|
63
|
|
|
$imageForm->fillField('Type', $type); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
$imageForm->find('css', 'input[type="file"]')->attachFile($filesPath.$path); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* {@inheritdoc} |
|
71
|
|
|
*/ |
|
72
|
|
|
protected function getDefinedElements() |
|
73
|
|
|
{ |
|
74
|
|
|
return array_merge(parent::getDefinedElements(), [ |
|
75
|
|
|
'code' => '#sylius_product_code', |
|
76
|
|
|
'images' => '#sylius_product_images', |
|
77
|
|
|
'name' => '#sylius_product_translations_en_US_name', |
|
78
|
|
|
'slug' => '#sylius_product_translations_en_US_slug', |
|
79
|
|
|
'tab' => '.menu [data-tab="%name%"]', |
|
80
|
|
|
]); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @param string $tabName |
|
85
|
|
|
*/ |
|
86
|
|
|
private function clickTabIfItsNotActive($tabName) |
|
87
|
|
|
{ |
|
88
|
|
|
$attributesTab = $this->getElement('tab', ['%name%' => $tabName]); |
|
89
|
|
|
if (!$attributesTab->hasClass('active')) { |
|
90
|
|
|
$attributesTab->click(); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @return NodeElement |
|
96
|
|
|
*/ |
|
97
|
|
|
private function getLastImageElement() |
|
98
|
|
|
{ |
|
99
|
|
|
$images = $this->getElement('images'); |
|
100
|
|
|
$items = $images->findAll('css', 'div[data-form-collection="item"]'); |
|
101
|
|
|
|
|
102
|
|
|
Assert::notEmpty($items); |
|
103
|
|
|
|
|
104
|
|
|
return end($items); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|