Completed
Push — master ( 30cb53...645fea )
by Paweł
36:15 queued 26:35
created

CreatePage::selectScope()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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\Zone;
13
14
use Behat\Mink\Exception\ElementNotFoundException;
15
use Sylius\Behat\Behaviour\NamesIt;
16
use Sylius\Behat\Behaviour\SpecifiesItsCode;
17
use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage;
18
use Webmozart\Assert\Assert;
19
20
/**
21
 * @author Arkadiusz Krakowiak <[email protected]>
22
 */
23
class CreatePage extends BaseCreatePage implements CreatePageInterface
24
{
25
    use NamesIt;
26
    use SpecifiesItsCode;
27
28
    public function addMember()
29
    {
30
        $this->getDocument()->clickLink('Add member');
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function checkValidationMessageForMembers($message)
37
    {
38
        $membersValidationElement = $this->getElement('ui_segment')->find('css', '.sylius-validation-error');
39
        if (null === $membersValidationElement) {
40
            throw new ElementNotFoundException($this->getDriver(), 'members validation box', 'css', '.sylius-validation-error');
41
        }
42
43
        return $membersValidationElement->getText() === $message;
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function chooseMember($name)
50
    {
51
        $selectItems = $this->getDocument()->waitFor(2, function () {
52
            return $this->getDocument()->findAll('css', 'div[data-form-type="collection"] select');
53
        });
54
        $lastSelectItem = end($selectItems);
55
56
        if (false === $lastSelectItem) {
57
            throw new ElementNotFoundException($this->getSession(), 'select', 'css', 'div[data-form-type="collection"] select');
58
        }
59
60
        $lastSelectItem->selectOption($name);
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function selectScope($scope)
67
    {
68
        $this->getDocument()->selectFieldOption('Scope', $scope);
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public function hasType($type)
75
    {
76
        $typeField = $this->getElement('type');
77
        $selectedOption = $typeField->find('css', 'option[selected]');
78
79
        return lcfirst($selectedOption->getText()) === $type;
80
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85
    public function isTypeFieldDisabled()
86
    {
87
        return $this->getElement('type')->hasAttribute('disabled');
88
    }
89
90
    /**
91
     * {@inheritdoc}
92
     */
93
    protected function getDefinedElements()
94
    {
95
        return array_merge(parent::getDefinedElements(), [
96
            'code' => '#sylius_zone_code',
97
            'name' => '#sylius_zone_name',
98
            'type' => '#sylius_zone_type',
99
            'ui_segment' => '.ui.segment',
100
        ]);
101
    }
102
}
103