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\Session; |
15
|
|
|
use Symfony\Component\Routing\RouterInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @author Arkadiusz Krakowiak <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
abstract class SymfonyPage extends Page |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var RouterInterface |
24
|
|
|
*/ |
25
|
|
|
protected $router; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param Session $session |
29
|
|
|
* @param array $parameters |
30
|
|
|
* @param RouterInterface $router |
31
|
|
|
*/ |
32
|
|
|
public function __construct(Session $session, array $parameters, RouterInterface $router) |
33
|
|
|
{ |
34
|
|
|
parent::__construct($session, $parameters); |
35
|
|
|
|
36
|
|
|
$this->router = $router; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* {@inheritdoc} |
41
|
|
|
*/ |
42
|
|
|
protected function getUrl(array $urlParameters = []) |
43
|
|
|
{ |
44
|
|
|
if (null === $this->getRouteName()) { |
45
|
|
|
throw new \RuntimeException('You need to provide route name, null given'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
$url = $this->router->generate($this->getRouteName(), $urlParameters); |
49
|
|
|
$url = $this->makePathAbsoluteWithBehatParameter($url); |
50
|
|
|
|
51
|
|
|
return $url; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param string $path |
56
|
|
|
* |
57
|
|
|
* @return string |
58
|
|
|
*/ |
59
|
|
|
protected function makePathAbsoluteWithBehatParameter($path) |
60
|
|
|
{ |
61
|
|
|
$baseUrl = rtrim($this->getParameter('base_url'), '/').'/'; |
62
|
|
|
|
63
|
|
|
return 0 !== strpos($path, 'http') ? $baseUrl.ltrim($path, '/') : $path; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* {@inheritdoc} |
68
|
|
|
* |
69
|
|
|
* Not used by Symfony page. |
70
|
|
|
*/ |
71
|
|
|
protected function getPath() |
72
|
|
|
{ |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
abstract protected function getRouteName(); |
76
|
|
|
} |
77
|
|
|
|