Completed
Pull Request — 3.1 (#348)
by Piotr
29:38 queued 15:17
created

AdminPanel::getNavbarBrandText()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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
declare(strict_types=1);
11
12
namespace FSi\Bundle\AdminBundle\Behat\Page;
13
14
use Behat\Mink\Element\NodeElement;
15
16
class AdminPanel extends Page
17
{
18
    protected $path = '/admin/';
19
20
    public function hasMenuElement(string $name, ?string $group = null): bool
21
    {
22
        if (null === $group) {
23
            return $this->getMenu()->has('css', sprintf('li > a:contains("%s")', $name));
24
        }
25
26
        $groupExpandButton = $this->getMenu()->find('css', sprintf('li.dropdown > a:contains("%s")', $group));
27
28
        if (null !== $groupExpandButton) {
29
            return $groupExpandButton->getParent()->has('css', sprintf('ul > li > a:contains("%s")', $name));
30
        }
31
32
        return false;
33
    }
34
35
    public function getMenuElementsCount(): int
36
    {
37
        return count($this->getMenu()->findAll('css', 'li.admin-element'));
38
    }
39
40
    public function getMenu(): ?NodeElement
41
    {
42
        return $this->find('css', '#top-menu');
43
    }
44
45
    public function getNavbarBrandText(): string
46
    {
47
        return $this->find('css', 'a.navbar-brand')->getText();
48
    }
49
50
    public function getLanguageDropdownOptions(): array
51
    {
52
        $link = $this->getLanguageDropdown();
53
        if (null === $link) {
54
            return [];
55
        }
56
57
        $linkNodes = $this->findAll('css', 'li#language > ul > li');
58
59
        return array_filter(array_map(function(NodeElement $element) {
60
            return $element->getText();
61
        }, $linkNodes));
62
    }
63
64
    public function getLanguageDropdown(): ?NodeElement
65
    {
66
        return $this->find('css', 'li#language');
67
    }
68
}
69