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\PageObjectExtension\Page; |
13
|
|
|
|
14
|
|
|
use Behat\Mink\Session; |
15
|
|
|
use SensioLabs\Behat\PageObjectExtension\PageObject\Exception\ElementNotFoundException; |
16
|
|
|
use SensioLabs\Behat\PageObjectExtension\PageObject\Factory; |
17
|
|
|
use SensioLabs\Behat\PageObjectExtension\PageObject\Page; |
18
|
|
|
use Symfony\Component\Routing\RouterInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author Arkadiusz Krakowiak <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
abstract class SymfonyPage extends Page |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var RouterInterface |
27
|
|
|
*/ |
28
|
|
|
protected $router; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param Session $session |
32
|
|
|
* @param Factory $factory |
33
|
|
|
* @param array $parameters |
34
|
|
|
* @param RouterInterface $router |
35
|
|
|
*/ |
36
|
|
|
public function __construct(Session $session, Factory $factory, array $parameters = [], RouterInterface $router) |
37
|
|
|
{ |
38
|
|
|
parent::__construct($session, $factory, $parameters); |
39
|
|
|
|
40
|
|
|
$this->router = $router; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param string $locator |
45
|
|
|
* |
46
|
|
|
* @throws ElementNotFoundException |
47
|
|
|
*/ |
48
|
|
|
public function pressRadio($locator) |
49
|
|
|
{ |
50
|
|
|
$radio = $this->findField($locator); |
51
|
|
|
|
52
|
|
|
if (null === $radio) { |
53
|
|
|
throw new ElementNotFoundException(sprintf('"%s" element is not present on the page', $locator)); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$this->fillField($radio->getAttribute('name'), $radio->getAttribute('value')); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param array $urlParameters |
61
|
|
|
*/ |
62
|
|
|
public function assertRoute(array $urlParameters = array()) |
63
|
|
|
{ |
64
|
|
|
$this->verify($urlParameters); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param array $urlParameters |
69
|
|
|
* |
70
|
|
|
* @return string |
71
|
|
|
*/ |
72
|
|
|
protected function getUrl(array $urlParameters = array()) |
73
|
|
|
{ |
74
|
|
|
if (null === $this->getRouteName()) { |
75
|
|
|
throw new \RuntimeException('You need to provide route name, null given'); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return $this->router->generate($this->getRouteName(), $urlParameters, true); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
abstract public function getRouteName(); |
82
|
|
|
} |
83
|
|
|
|