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\Crud; |
13
|
|
|
|
14
|
|
|
use Behat\Mink\Exception\ElementNotFoundException; |
15
|
|
|
use Behat\Mink\Session; |
16
|
|
|
use Sylius\Behat\Page\SymfonyPage; |
17
|
|
|
use Symfony\Component\Routing\RouterInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Arkadiusz Krakowiak <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class CreatePage extends SymfonyPage implements CreatePageInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
private $resourceName; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param Session $session |
31
|
|
|
* @param array $parameters |
32
|
|
|
* @param RouterInterface $router |
33
|
|
|
* @param string $resourceName |
34
|
|
|
*/ |
35
|
|
|
public function __construct(Session $session, array $parameters, RouterInterface $router, $resourceName) |
36
|
|
|
{ |
37
|
|
|
parent::__construct($session, $parameters, $router); |
38
|
|
|
|
39
|
|
|
$this->resourceName = strtolower($resourceName); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* {@inheritdoc} |
44
|
|
|
*/ |
45
|
|
|
public function create() |
46
|
|
|
{ |
47
|
|
|
$this->getDocument()->pressButton('Create'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* {@inheritdoc} |
52
|
|
|
*/ |
53
|
|
|
public function getValidationMessage($element) |
54
|
|
|
{ |
55
|
|
|
$foundElement = $this->getFieldElement($element); |
56
|
|
|
if (null === $foundElement) { |
57
|
|
|
throw new ElementNotFoundException($this->getSession(), 'Field element'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$validationMessage = $foundElement->find('css', '.sylius-validation-error'); |
61
|
|
|
if (null === $validationMessage) { |
62
|
|
|
throw new ElementNotFoundException($this->getSession(), 'Validation message', 'css', '.sylius-validation-error'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return $validationMessage->getText(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* {@inheritdoc} |
70
|
|
|
*/ |
71
|
|
|
public function getRouteName() |
72
|
|
|
{ |
73
|
|
|
return sprintf('sylius_admin_%s_create', $this->resourceName); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param string $element |
78
|
|
|
* |
79
|
|
|
* @return \Behat\Mink\Element\NodeElement|null |
80
|
|
|
* |
81
|
|
|
* @throws ElementNotFoundException |
82
|
|
|
*/ |
83
|
|
|
private function getFieldElement($element) |
84
|
|
|
{ |
85
|
|
|
$element = $this->getElement($element); |
86
|
|
|
while (null !== $element && !($element->hasClass('field'))) { |
87
|
|
|
$element = $element->getParent(); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
return $element; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|