|
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; |
|
13
|
|
|
|
|
14
|
|
|
use Behat\Mink\Element\NodeElement; |
|
15
|
|
|
use Behat\Mink\Session; |
|
16
|
|
|
use Symfony\Component\Routing\RouterInterface; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @author Arkadiusz Krakowiak <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
abstract class SymfonyPage extends Page implements SymfonyPageInterface |
|
|
|
|
|
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @var RouterInterface |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $router; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var array |
|
30
|
|
|
*/ |
|
31
|
|
|
protected static $additionalParameters = ['_locale' => 'en_US']; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param Session $session |
|
35
|
|
|
* @param array $parameters |
|
36
|
|
|
* @param RouterInterface $router |
|
37
|
|
|
*/ |
|
38
|
|
|
public function __construct(Session $session, array $parameters, RouterInterface $router) |
|
39
|
|
|
{ |
|
40
|
|
|
parent::__construct($session, $parameters); |
|
41
|
|
|
|
|
42
|
|
|
$this->router = $router; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* {@inheritdoc} |
|
47
|
|
|
*/ |
|
48
|
|
|
abstract public function getRouteName(); |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* {@inheritdoc} |
|
52
|
|
|
*/ |
|
53
|
|
|
protected function getUrl(array $urlParameters = []) |
|
54
|
|
|
{ |
|
55
|
|
|
$path = $this->router->generate($this->getRouteName(), $urlParameters + static::$additionalParameters); |
|
56
|
|
|
|
|
57
|
|
|
$replace = []; |
|
58
|
|
|
foreach (static::$additionalParameters as $key => $value) { |
|
59
|
|
|
$replace[sprintf('&%s=%s', $key, $value)] = ''; |
|
60
|
|
|
$replace[sprintf('?%s=%s&', $key, $value)] = '?'; |
|
61
|
|
|
$replace[sprintf('?%s=%s', $key, $value)] = ''; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
$path = str_replace(array_keys($replace), array_values($replace), $path); |
|
65
|
|
|
|
|
66
|
|
|
return $this->makePathAbsolute($path); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* {@inheritdoc} |
|
71
|
|
|
*/ |
|
72
|
|
|
protected function verifyUrl(array $urlParameters = []) |
|
73
|
|
|
{ |
|
74
|
|
|
$matchedRoute = $this->router->match('/' . str_replace($this->makePathAbsolute(''), '', $this->getDriver()->getCurrentUrl())); |
|
75
|
|
|
|
|
76
|
|
|
if (isset($matchedRoute['_locale'])) { |
|
77
|
|
|
$urlParameters += ['_locale' => $matchedRoute['_locale']]; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
parent::verifyUrl($urlParameters); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @param NodeElement $modalContainer |
|
85
|
|
|
* @param string $appearClass |
|
86
|
|
|
* |
|
87
|
|
|
* @todo it really shouldn't be here :) |
|
|
|
|
|
|
88
|
|
|
*/ |
|
89
|
|
|
protected function waitForModalToAppear(NodeElement $modalContainer, $appearClass = 'in') |
|
90
|
|
|
{ |
|
91
|
|
|
$this->getDocument()->waitFor(1, function () use ($modalContainer, $appearClass) { |
|
92
|
|
|
return false !== strpos($modalContainer->getAttribute('class'), $appearClass); |
|
93
|
|
|
}); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @param string $path |
|
98
|
|
|
* |
|
99
|
|
|
* @return string |
|
100
|
|
|
*/ |
|
101
|
|
|
final protected function makePathAbsolute($path) |
|
102
|
|
|
{ |
|
103
|
|
|
$baseUrl = rtrim($this->getParameter('base_url'), '/').'/'; |
|
104
|
|
|
|
|
105
|
|
|
return 0 !== strpos($path, 'http') ? $baseUrl.ltrim($path, '/') : $path; |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.