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\Taxon; |
13
|
|
|
|
14
|
|
|
use Behat\Mink\Element\NodeElement; |
15
|
|
|
use Behat\Mink\Exception\ElementNotFoundException; |
16
|
|
|
use Sylius\Behat\Behaviour\SpecifiesItsCode; |
17
|
|
|
use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage; |
18
|
|
|
use Sylius\Component\Core\Model\TaxonInterface; |
19
|
|
|
use Webmozart\Assert\Assert; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @author Arkadiusz Krakowiak <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class CreatePage extends BaseCreatePage implements CreatePageInterface |
25
|
|
|
{ |
26
|
|
|
use SpecifiesItsCode; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* {@inheritdoc} |
30
|
|
|
*/ |
31
|
|
|
public function countTaxons() |
32
|
|
|
{ |
33
|
|
|
return count($this->getLeafs()); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* {@inheritdoc} |
38
|
|
|
*/ |
39
|
|
|
public function countTaxonsByName($name) |
40
|
|
|
{ |
41
|
|
|
$matchedLeafsCounter = 0; |
42
|
|
|
$leafs = $this->getLeafs(); |
43
|
|
|
foreach ($leafs as $leaf) { |
44
|
|
|
if ($leaf->getText() === $name) { |
45
|
|
|
$matchedLeafsCounter++; |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
return $matchedLeafsCounter; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritdoc} |
54
|
|
|
*/ |
55
|
|
|
public function chooseParent(TaxonInterface $taxon) |
56
|
|
|
{ |
57
|
|
|
$this->getElement('parent')->selectOption($taxon->getName(), false); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
*/ |
63
|
|
|
public function deleteTaxonOnPageByName($name) |
64
|
|
|
{ |
65
|
|
|
$leafs = $this->getLeafs(); |
66
|
|
|
foreach ($leafs as $leaf) { |
67
|
|
|
if ($leaf->getText() === $name) { |
68
|
|
|
$leaf->pressButton('Delete'); |
69
|
|
|
|
70
|
|
|
break; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
throw new ElementNotFoundException($this->getDriver(), 'Delete button'); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* {@inheritdoc} |
79
|
|
|
*/ |
80
|
|
|
public function describeItAs($description, $languageCode) |
81
|
|
|
{ |
82
|
|
|
$this->getDocument()->fillField(sprintf('sylius_taxon_translations_%s_description', $languageCode), $description); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* {@inheritdoc} |
87
|
|
|
*/ |
88
|
|
|
public function hasTaxonWithName($name) |
89
|
|
|
{ |
90
|
|
|
return 0 !== $this->countTaxonsByName($name); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* {@inheritdoc} |
95
|
|
|
*/ |
96
|
|
|
public function nameIt($name, $languageCode) |
97
|
|
|
{ |
98
|
|
|
$this->getDocument()->fillField(sprintf('sylius_taxon_translations_%s_name', $languageCode), $name); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* {@inheritdoc} |
103
|
|
|
*/ |
104
|
|
|
public function specifyPermalink($permalink, $languageCode) |
105
|
|
|
{ |
106
|
|
|
$this->getDocument()->fillField(sprintf('sylius_taxon_translations_%s_permalink', $languageCode), $permalink); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* {@inheritdoc} |
111
|
|
|
*/ |
112
|
|
|
protected function getDefinedElements() |
113
|
|
|
{ |
114
|
|
|
return array_merge(parent::getDefinedElements(), [ |
115
|
|
|
'code' => '#sylius_taxon_code', |
116
|
|
|
'name' => '#sylius_taxon_translations_en_US_name', |
117
|
|
|
'parent' => '#sylius_taxon_parent', |
118
|
|
|
'permalink' => '#sylius_taxon_translations_en_US_permalink', |
119
|
|
|
'description' => '#sylius_taxon_translations_en_US_description', |
120
|
|
|
'tree' => '.ui.list', |
121
|
|
|
]); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @return NodeElement[] |
126
|
|
|
* |
127
|
|
|
* @throws ElementNotFoundException |
128
|
|
|
*/ |
129
|
|
|
private function getLeafs() |
130
|
|
|
{ |
131
|
|
|
$tree = $this->getElement('tree'); |
132
|
|
|
Assert::notNull($tree); |
133
|
|
|
|
134
|
|
|
return $tree->findAll('css', '.item > .content > .header'); |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|