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\Session; |
15
|
|
|
use Sylius\Behat\Page\ElementNotFoundException; |
16
|
|
|
use Sylius\Behat\Page\SymfonyPage; |
17
|
|
|
use Sylius\Behat\TableManipulatorInterface; |
18
|
|
|
use Symfony\Component\Routing\RouterInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author Arkadiusz Krakowiak <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class IndexPage extends SymfonyPage implements IndexPageInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var array |
27
|
|
|
*/ |
28
|
|
|
protected $elements = [ |
29
|
|
|
'message' => '.message', |
30
|
|
|
'messageContent' => '.message > .content', |
31
|
|
|
'table' => '.table', |
32
|
|
|
]; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var TableManipulatorInterface |
36
|
|
|
*/ |
37
|
|
|
private $tableManipulator; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
private $resourceName; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param Session $session |
46
|
|
|
* @param array $parameters |
47
|
|
|
* @param RouterInterface $router |
48
|
|
|
* @param TableManipulatorInterface $tableManipulator |
49
|
|
|
* @param string $resourceName |
50
|
|
|
*/ |
51
|
|
|
public function __construct( |
52
|
|
|
Session $session, |
53
|
|
|
array $parameters, |
54
|
|
|
RouterInterface $router, |
55
|
|
|
TableManipulatorInterface $tableManipulator, |
56
|
|
|
$resourceName |
57
|
|
|
) { |
58
|
|
|
parent::__construct($session, $parameters, $router); |
59
|
|
|
|
60
|
|
|
$this->tableManipulator = $tableManipulator; |
61
|
|
|
$this->resourceName = strtolower($resourceName); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* {@inheritdoc} |
66
|
|
|
*/ |
67
|
|
|
public function hasSuccessMessage() |
68
|
|
|
{ |
69
|
|
|
try { |
70
|
|
|
return $this->getElement('message')->hasClass('positive'); |
71
|
|
|
} catch (ElementNotFoundException $exception) { |
72
|
|
|
return false; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* {@inheritdoc} |
78
|
|
|
*/ |
79
|
|
|
public function isSuccessfullyCreated() |
80
|
|
|
{ |
81
|
|
|
return $this->hasMessage(sprintf('Success %s has been successfully created.', ucfirst($this->resourceName))); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* {@inheritdoc} |
86
|
|
|
*/ |
87
|
|
|
public function isSuccessfullyUpdated() |
88
|
|
|
{ |
89
|
|
|
return $this->hasMessage(sprintf('Success %s has been successfully updated.', ucfirst($this->resourceName))); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* {@inheritdoc} |
94
|
|
|
*/ |
95
|
|
|
public function isSuccessfullyDeleted() |
96
|
|
|
{ |
97
|
|
|
return $this->hasMessage(sprintf('Success %s has been successfully deleted.', ucfirst($this->resourceName))); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* {@inheritdoc} |
102
|
|
|
*/ |
103
|
|
|
public function isResourceOnPage(array $parameters) |
104
|
|
|
{ |
105
|
|
|
try { |
106
|
|
|
$rows = $this->tableManipulator->getRowsWithFields($this->getElement('table'), $parameters); |
107
|
|
|
|
108
|
|
|
return 1 === count($rows); |
109
|
|
|
} catch (\InvalidArgumentException $exception) { |
110
|
|
|
return false; |
111
|
|
|
} catch (ElementNotFoundException $exception) { |
112
|
|
|
return false; |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* {@inheritdoc} |
118
|
|
|
*/ |
119
|
|
|
public function hasMessage($message) |
120
|
|
|
{ |
121
|
|
|
try { |
122
|
|
|
return $message === $this->getElement('messageContent')->getText(); |
123
|
|
|
} catch (ElementNotFoundException $exception) { |
124
|
|
|
return false; |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* {@inheritdoc} |
130
|
|
|
*/ |
131
|
|
|
protected function getRouteName() |
132
|
|
|
{ |
133
|
|
|
return sprintf('sylius_admin_%s_index', $this->resourceName); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @return string |
138
|
|
|
*/ |
139
|
|
|
protected function getResourceName() |
140
|
|
|
{ |
141
|
|
|
return $this->resourceName; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @return TableManipulatorInterface |
146
|
|
|
*/ |
147
|
|
|
protected function getTableManipulator() |
148
|
|
|
{ |
149
|
|
|
return $this->tableManipulator; |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
|