|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* (c) FSi sp. z o.o. <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace FSi\Bundle\AdminBundle\Behat\Context\Page; |
|
11
|
|
|
|
|
12
|
|
|
use Behat\Mink\Element\NodeElement; |
|
13
|
|
|
use SensioLabs\Behat\PageObjectExtension\PageObject\Exception\UnexpectedPageException; |
|
14
|
|
|
|
|
15
|
|
|
class NewsList extends Page |
|
16
|
|
|
{ |
|
17
|
|
|
protected $path = '/admin/list/news'; |
|
18
|
|
|
|
|
19
|
|
|
public function getHeader() |
|
20
|
|
|
{ |
|
21
|
|
|
return $this->find('css', '#page-header')->getText(); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function hasBatchActionsDropdown() |
|
25
|
|
|
{ |
|
26
|
|
|
return $this->has('css', 'select[data-datagrid-name]'); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function hasBatchAction($value) |
|
30
|
|
|
{ |
|
31
|
|
|
$select = $this->find('css', 'select[data-datagrid-name]'); |
|
32
|
|
|
return $select->has('css', sprintf('option:contains("%s")', $value)); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function pressBatchCheckboxInRow($rowIndex) |
|
36
|
|
|
{ |
|
37
|
|
|
$tr = $this->find('xpath', sprintf("descendant-or-self::table/tbody/tr[position() = %d]", $rowIndex)); |
|
38
|
|
|
$tr->find('css', 'input[type="checkbox"]')->check(); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function pressBatchActionConfirmationButton() |
|
42
|
|
|
{ |
|
43
|
|
|
$this->find('css', 'button[data-datagrid-name]')->click(); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function selectBatchAction($action) |
|
47
|
|
|
{ |
|
48
|
|
|
$this->find('css', 'select[data-datagrid-name]')->selectOption($action); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function selectAllElements() |
|
52
|
|
|
{ |
|
53
|
|
|
$th = $this->find('xpath', "descendant-or-self::table/thead/tr/th[position() = 1]"); |
|
54
|
|
|
$th->find('css', 'input[type="checkbox"]')->click(); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function isColumnEditable($columnHeader) |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->getCell($columnHeader, 1)->has('css', 'a.editable'); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function getColumnPosition($columnHeader) |
|
63
|
|
|
{ |
|
64
|
|
|
$headers = $this->findAll('css', 'th'); |
|
65
|
|
|
foreach ($headers as $index => $header) { |
|
66
|
|
|
/** @var NodeElement $header */ |
|
67
|
|
|
if ($header->has('css', 'span')) { |
|
68
|
|
|
if ($header->find('css', 'span')->getText() == $columnHeader) { |
|
69
|
|
|
return $index + 1; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
throw new UnexpectedPageException(sprintf("Cant find column %s", $columnHeader)); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function getCell($columnHeader, $rowNumber) |
|
78
|
|
|
{ |
|
79
|
|
|
$columnPos = $this->getColumnPosition($columnHeader); |
|
80
|
|
|
return $this->find('xpath', sprintf("descendant-or-self::table/tbody/tr[%d]/td[%d]", $rowNumber, $columnPos)); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function getPopover() |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->find('css', '.popover'); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
protected function verifyPage() |
|
89
|
|
|
{ |
|
90
|
|
|
if (!$this->has('css', '#page-header:contains("List of elements")')) { |
|
91
|
|
|
throw new UnexpectedPageException(sprintf("%s page is missing \"List of elements\" header", $this->path)); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|