|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Monofony package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Monofony |
|
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 Monofony\Bridge\Behat\Crud; |
|
13
|
|
|
|
|
14
|
|
|
use Behat\Mink\Exception\ElementNotFoundException; |
|
15
|
|
|
use Behat\Mink\Session; |
|
16
|
|
|
use FriendsOfBehat\PageObjectExtension\Page\SymfonyPage; |
|
17
|
|
|
use Symfony\Component\Routing\RouterInterface; |
|
18
|
|
|
|
|
19
|
|
|
abstract class AbstractCreatePage extends SymfonyPage implements CreatePageInterface |
|
20
|
|
|
{ |
|
21
|
|
|
public function __construct(Session $session, \ArrayAccess $minkParameters, RouterInterface $router) |
|
22
|
|
|
{ |
|
23
|
|
|
parent::__construct($session, $minkParameters, $router); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* {@inheritdoc} |
|
28
|
|
|
*/ |
|
29
|
|
|
public function create(): void |
|
30
|
|
|
{ |
|
31
|
|
|
$this->getDocument()->pressButton('Create'); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* {@inheritdoc} |
|
36
|
|
|
*/ |
|
37
|
|
|
public function getValidationMessage(string $element): string |
|
38
|
|
|
{ |
|
39
|
|
|
$foundElement = $this->getFieldElement($element); |
|
40
|
|
|
if (null === $foundElement) { |
|
41
|
|
|
throw new ElementNotFoundException($this->getSession(), 'Field element'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
$validationMessage = $foundElement->find('css', '.sylius-validation-error'); |
|
45
|
|
|
if (null === $validationMessage) { |
|
46
|
|
|
throw new ElementNotFoundException($this->getSession(), 'Validation message', 'css', '.sylius-validation-error'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
return $validationMessage->getText(); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param string $element |
|
54
|
|
|
* |
|
55
|
|
|
* @return \Behat\Mink\Element\NodeElement|null |
|
56
|
|
|
* |
|
57
|
|
|
* @throws ElementNotFoundException |
|
58
|
|
|
*/ |
|
59
|
|
|
private function getFieldElement($element) |
|
60
|
|
|
{ |
|
61
|
|
|
$element = $this->getElement($element); |
|
62
|
|
|
while (null !== $element && !$element->hasClass('field')) { |
|
63
|
|
|
$element = $element->getParent(); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return $element; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|