Completed
Push — master ( 7ec96a...9f5631 )
by Dmitry
15:28 queued 13:03
created

Create   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 139
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 16
lcom 1
cbo 2
dl 0
loc 139
rs 10
c 0
b 0
f 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
A loadPage() 0 6 1
A savePlan() 0 9 1
A createPlan() 0 13 1
A fillName() 0 6 1
A chooseType() 0 7 1
A setGrouping() 0 6 1
A findClient() 0 9 1
A chooseCurrency() 0 8 1
A fillNote() 0 6 1
A seeFields() 0 7 1
A seeLabels() 0 9 2
A seeTypeDropdownList() 0 20 2
A seeCurrencyDropdownList() 0 18 2
1
<?php
2
3
namespace hipanel\modules\finance\tests\_support\Page\plan;
4
5
use hipanel\helpers\Url;
6
7
class Create extends Plan
8
{
9
    protected function loadPage()
10
    {
11
        $I = $this->tester;
12
13
        $I->needPage(Url::to("@plan/create"));
14
    }
15
16
    protected function savePlan()
17
    {
18
        $I = $this->tester;
19
20
        $I->click('Save');
21
        $I->closeNotification("Plan was successfully created");
22
23
        $this->id = $I->grabFromCurrentUrl('/id=(\d+)/');
24
    }
25
26
    public function createPlan(): int
27
    {
28
        $this->loadPage();
29
        $this->fillName();
30
        $this->chooseType();
31
        $this->setGrouping();
32
        $this->findClient();
33
        $this->chooseCurrency();
34
        $this->fillNote();
35
        $this->savePlan();
36
37
        return $this->id;
38
    }
39
40
    private function fillName()
41
    {
42
        $I = $this->tester;
43
44
        $I->fillField(['name' => 'Plan[name]'], $this->name);
45
    }
46
47
    private function chooseType()
48
    {
49
        $I = $this->tester;
50
51
        $I->click(['name' => 'Plan[type]']);
52
        $I->click("//select/option[.='{$this->type}']");
53
    }
54
55
    protected function setGrouping()
56
    {
57
        $I = $this->tester;
58
59
        $I->uncheckOption("//input[@name='Plan[is_grouping]'][@type='checkbox']");
60
    }
61
62
    private function findClient()
63
    {
64
        $I = $this->tester;
65
66
        $I->click("//select[@name='Plan[client]']/../span");
67
        $I->fillField('//input[@class="select2-search__field"]', $this->client);
68
        $I->waitForElementNotVisible('.loading-results', 120);
69
        $I->click('.select2-results__option--highlighted');
70
    }
71
72
    private function chooseCurrency()
73
    {
74
        $I = $this->tester;
75
76
        $I->click("//select[@name='Plan[currency]']/../span");
77
        $I->click("//select/option[.='{$this->currency}']");
78
        $I->click("//select[@name='Plan[currency]']/../span");
79
    }
80
81
    private function fillNote()
82
    {
83
        $I = $this->tester;
84
85
        $I->fillField(['name' => 'Plan[note]'], $this->note);
86
    }
87
88
    public function seeFields()
89
    {
90
        $this->loadPage();
91
        $this->seeLabels();
92
        $this->seeTypeDropdownList();
93
        $this->seeCurrencyDropdownList();
94
    }
95
96
    private function seeLabels()
97
    {
98
        $I = $this->tester;
99
100
        $list = ['Name', 'Type', 'Client', 'Currency', 'Note', ];
101
        foreach ($list as $label) {
102
            $I->see($label, "//label[@class='control-label']");
103
        }
104
    }
105
106
    private function seeTypeDropdownList()
107
    {
108
        $I = $this->tester;
109
110
        $list = [
111
            'server' => 'Server',
112
            'vcdn' => 'vCDN',
113
            'pcdn' => 'pCDN',
114
            'ip' => 'IP',
115
            'account' => 'Account',
116
            'domain' => 'Domain',
117
            'client' => 'Client',
118
            'template' => 'Template',
119
        ];
120
        $I->click(['name' => 'Plan[type]']);
121
        foreach ($list as $key => $text) {
122
            $I->see($text, "//select/option[@value='{$key}']");
123
        }
124
        $I->clickWithLeftButton('h1');
125
    }
126
127
    private function seeCurrencyDropdownList()
128
    {
129
        $I = $this->tester;
130
131
        $I->click("//select[@name='Plan[currency]']/../span");
132
        $list = [
133
            'usd' => 'USD',
134
            'eur' => 'EUR',
135
            'uah' => 'UAH',
136
            'rub' => 'RUB',
137
            'pln' => 'PLN',
138
            'btc' => 'BTC',
139
        ];
140
        foreach ($list as $key => $text) {
141
            $I->see($text, "//select/option[@value='{$key}']");
142
        }
143
        $I->clickWithLeftButton('h1');
144
    }
145
}
146