Completed
Push — master ( 81c6e7...6c71bd )
by Piotr
02:30
created

SubscribersList   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
lcom 2
cbo 3
dl 0
loc 46
rs 10
c 1
b 0
f 0
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 SensioLabs\Behat\PageObjectExtension\PageObject\Exception\UnexpectedPageException;
13
14
class SubscribersList extends Page
15
{
16
    protected $path = '/admin/list/subscriber';
17
18
    public function getHeader()
19
    {
20
        return $this->find('css', '#page-header')->getText();
21
    }
22
23
    public function isColumnEditable($columnHeader)
24
    {
25
        return $this->getCell($columnHeader, 1)->has('css', 'a.editable');
26
    }
27
28
    public function getColumnPosition($columnHeader)
29
    {
30
        $headers = $this->findAll('css', 'th');
31
        foreach ($headers as $index => $header) {
32
            if ($header->has('css', 'span')) {
33
                if ($header->find('css', 'span')->getText() == $columnHeader) {
34
                    return $index + 1;
35
                }
36
            }
37
        }
38
39
        throw new UnexpectedPageException(sprintf("Cant find column %s", $columnHeader));
40
    }
41
42
    public function getCell($columnHeader, $rowNumber)
43
    {
44
        $columnPos = $this->getColumnPosition($columnHeader);
45
        return $this->find('xpath', sprintf("descendant-or-self::table/tbody/tr[%d]/td[%d]", $rowNumber, $columnPos));
46
    }
47
48
    public function getPopover()
49
    {
50
        return $this->find('css', 'div.popover-content');
51
    }
52
53
    protected function verifyPage()
54
    {
55
        if (!$this->has('css', '#page-header:contains("List of elements")')) {
56
            throw new UnexpectedPageException(sprintf("%s page is missing \"List of elements\" header", $this->path));
57
        }
58
    }
59
}
60