|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* HiPanel core package |
|
4
|
|
|
* |
|
5
|
|
|
* @link https://hipanel.com/ |
|
6
|
|
|
* @package hipanel-core |
|
7
|
|
|
* @license BSD-3-Clause |
|
8
|
|
|
* @copyright Copyright (c) 2014-2019, HiQDev (http://hiqdev.com/) |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace hipanel\tests\_support\Page; |
|
12
|
|
|
|
|
13
|
|
|
use hipanel\tests\_support\AcceptanceTester; |
|
14
|
|
|
use hipanel\tests\_support\Page\Widget\Grid; |
|
15
|
|
|
use hipanel\tests\_support\Page\Widget\Input\Dropdown; |
|
16
|
|
|
use hipanel\tests\_support\Page\Widget\Input\TestableInput; |
|
17
|
|
|
|
|
18
|
|
|
class IndexPage extends Authenticated |
|
19
|
|
|
{ |
|
20
|
|
|
/** @var string */ |
|
21
|
|
|
protected $gridSelector = "//form[contains(@id, 'bulk') and contains(@id, 'search')]"; |
|
22
|
|
|
|
|
23
|
|
|
/** @var Grid */ |
|
24
|
|
|
public $gridView; |
|
25
|
|
|
|
|
26
|
|
|
public function __construct(AcceptanceTester $I, string $gridSelector = null) |
|
27
|
|
|
{ |
|
28
|
|
|
parent::__construct($I); |
|
29
|
|
|
|
|
30
|
|
|
$this->gridView = new Grid($I, $gridSelector ?? $this->gridSelector); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param TestableInput[] $inputs example: |
|
35
|
|
|
* ```php |
|
36
|
|
|
* [ |
|
37
|
|
|
* Input::asAdvancedSearch(Tester, 'Name'), |
|
38
|
|
|
* Select2::asAdvancedSearch(Tester, 'Status') |
|
39
|
|
|
* ] |
|
40
|
|
|
*``` |
|
41
|
|
|
*/ |
|
42
|
|
|
public function containsFilters(array $inputs): void |
|
43
|
|
|
{ |
|
44
|
|
|
$I = $this->tester; |
|
45
|
|
|
|
|
46
|
|
|
$I->see('Advanced search', 'h3'); |
|
47
|
|
|
|
|
48
|
|
|
foreach ($inputs as $input) { |
|
49
|
|
|
$input->isVisible(); |
|
50
|
|
|
} |
|
51
|
|
|
$I->see('Search', TestableInput::AS_BASE . "button[type='submit']"); |
|
52
|
|
|
$I->see('Clear', TestableInput::AS_BASE . 'a'); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param string[] $list array of legend list |
|
57
|
|
|
*/ |
|
58
|
|
|
public function containsLegend(array $list): void |
|
59
|
|
|
{ |
|
60
|
|
|
$I = $this->tester; |
|
61
|
|
|
|
|
62
|
|
|
$I->see('Legend', 'h3'); |
|
63
|
|
|
|
|
64
|
|
|
foreach ($list as $text) { |
|
65
|
|
|
$I->see($text, "//h3[text()='Legend']/../../div/ul/li"); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @param string[] $buttons array of buttons |
|
71
|
|
|
*/ |
|
72
|
|
|
public function containsBulkButtons(array $buttons): void |
|
73
|
|
|
{ |
|
74
|
|
|
$I = $this->tester; |
|
75
|
|
|
|
|
76
|
|
|
foreach ($buttons as $text) { |
|
77
|
|
|
$I->see($text, "//button[@type='submit' or @type='button']"); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @param string[] $columnNames array of column names |
|
83
|
|
|
* @param string|null $representation the representation name |
|
84
|
|
|
* @throws \Codeception\Exception\ModuleException |
|
85
|
|
|
*/ |
|
86
|
|
|
public function containsColumns(array $columnNames, $representation = null): void |
|
87
|
|
|
{ |
|
88
|
|
|
$this->gridView->containsColumns($columnNames, $representation); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @see Grid::containsAmountOfRows() |
|
93
|
|
|
* |
|
94
|
|
|
* @param int $amount |
|
95
|
|
|
*/ |
|
96
|
|
|
public function containsAmountOfRows(int $amount): void |
|
97
|
|
|
{ |
|
98
|
|
|
$this->gridView->containsAmountOfRows($amount); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @see Grid::getRowDataKeyByNumber() |
|
103
|
|
|
* |
|
104
|
|
|
* @param int $rowNumber |
|
105
|
|
|
* @return string |
|
106
|
|
|
*/ |
|
107
|
|
|
public function getRowDataKeyByNumber(int $rowNumber): string |
|
108
|
|
|
{ |
|
109
|
|
|
return $this->gridView->getRowDataKeyByNumber($rowNumber); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @see Grid::filterBy() |
|
114
|
|
|
* |
|
115
|
|
|
* @param TestableInput $inputElement |
|
116
|
|
|
* @param string $value |
|
117
|
|
|
* @throws \Codeception\Exception\ModuleException |
|
118
|
|
|
*/ |
|
119
|
|
|
public function filterBy(TestableInput $inputElement, string $value): void |
|
120
|
|
|
{ |
|
121
|
|
|
$this->gridView->filterBy($inputElement, $value); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @see Grid::selectRowByNumber() |
|
126
|
|
|
* |
|
127
|
|
|
* @param int $n - number of the row that should be selected |
|
128
|
|
|
*/ |
|
129
|
|
|
public function selectTableRowByNumber(int $n): void |
|
130
|
|
|
{ |
|
131
|
|
|
$this->gridView->selectRowByNumber($n); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* @see Grid::openRowMenuByNumber() |
|
136
|
|
|
* |
|
137
|
|
|
* @param int $n - number of the row which menu should be opened |
|
138
|
|
|
*/ |
|
139
|
|
|
public function openRowMenuByNumber(int $n): void |
|
140
|
|
|
{ |
|
141
|
|
|
$this->gridView->openRowMenuByNumber($n); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* @see Grid::openRowMenuById() |
|
146
|
|
|
* |
|
147
|
|
|
* @param string $id - id of item which menu should be opened |
|
148
|
|
|
*/ |
|
149
|
|
|
public function openRowMenuById(string $id): void |
|
150
|
|
|
{ |
|
151
|
|
|
$this->gridView->openRowMenuById($id); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* @see Grid::openRowMenuByColumnValue() |
|
156
|
|
|
* |
|
157
|
|
|
* @param string $column |
|
158
|
|
|
* @param string $value |
|
159
|
|
|
* @throws \Codeception\Exception\ModuleException |
|
160
|
|
|
*/ |
|
161
|
|
|
public function openRowMenuByColumnValue(string $column, string $value): void |
|
162
|
|
|
{ |
|
163
|
|
|
$this->gridView->openRowMenuByColumnValue($column, $value); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* @see Grid::chooseRowMenuOption() |
|
168
|
|
|
* |
|
169
|
|
|
* @param $option - the name of option that should be clicked |
|
170
|
|
|
* @throws \Codeception\Exception\ModuleException |
|
171
|
|
|
*/ |
|
172
|
|
|
public function chooseRowMenuOption(string $option): void |
|
173
|
|
|
{ |
|
174
|
|
|
$this->gridView->chooseRowMenuOption($option); |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* @see Grid::countRowsInTableBody() |
|
179
|
|
|
* |
|
180
|
|
|
* @return int |
|
181
|
|
|
*/ |
|
182
|
|
|
public function countRowsInTableBody(): int |
|
183
|
|
|
{ |
|
184
|
|
|
return $this->gridView->countRowsInTableBody(); |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* Checks whether filtering works properly. |
|
189
|
|
|
* |
|
190
|
|
|
* @param string $filterBy |
|
191
|
|
|
* @param string $name |
|
192
|
|
|
* @throws \Codeception\Exception\ModuleException |
|
193
|
|
|
*/ |
|
194
|
|
|
public function checkFilterBy(string $filterBy, string $name): void |
|
195
|
|
|
{ |
|
196
|
|
|
$this->filterBy(new Dropdown($this->tester, "tr.filters select[name*=$filterBy]"), $name); |
|
197
|
|
|
$count = $this->countRowsInTableBody(); |
|
198
|
|
|
for ($i = 1; $i <= $count; ++$i) { |
|
199
|
|
|
$this->tester->see($name, "//tbody/tr[$i]"); |
|
200
|
|
|
} |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
/** |
|
204
|
|
|
* @see Grid::sortBy() |
|
205
|
|
|
* |
|
206
|
|
|
* @param string $columnName |
|
207
|
|
|
* @throws \Codeception\Exception\ModuleException |
|
208
|
|
|
*/ |
|
209
|
|
|
public function sortBy(string $columnName): void |
|
210
|
|
|
{ |
|
211
|
|
|
$this->gridView->sortBy($columnName); |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
/** |
|
215
|
|
|
* @see Grid::checkSortingBy() |
|
216
|
|
|
* |
|
217
|
|
|
* @param string $sortBy |
|
218
|
|
|
* @throws \Codeception\Exception\ModuleException |
|
219
|
|
|
*/ |
|
220
|
|
|
public function checkSortingBy(string $sortBy): void |
|
221
|
|
|
{ |
|
222
|
|
|
$this->gridView->checkSortingBy($sortBy); |
|
223
|
|
|
} |
|
224
|
|
|
} |
|
225
|
|
|
|