Completed
Push — master ( 9fec5b...0ee870 )
by Andrii
06:47 queued 10s
created

Hub   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 14
eloc 33
dl 0
loc 71
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A hasErrors() 0 5 1
A check() 0 9 3
A waitPjax() 0 5 1
A needPageByName() 0 6 1
A hasNotErrors() 0 5 1
A submitForm() 0 7 1
A fillForm() 0 17 6
1
<?php
2
3
namespace hipanel\modules\server\tests\_support\Page\Hub;
4
5
use Codeception\Example;
0 ignored issues
show
Bug introduced by
The type Codeception\Example was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use hipanel\tests\_support\Page\Authenticated;
7
use hipanel\tests\_support\Page\Widget\Input\Dropdown;
8
use hipanel\tests\_support\Page\Widget\Input\Input;
9
use hipanel\tests\_support\Page\Widget\Input\Select2;
10
use hipanel\tests\_support\Page\Widget\Input\Textarea;
11
12
abstract class Hub extends Authenticated
13
{
14
    public function fillForm(Example $data)
15
    {
16
        $I = $this->tester;
17
        foreach ($data as $field => $value) {
18
            if ($value) {
19
                switch (true) {
20
                    case in_array($field, ['type_id']):
21
                        (new Dropdown($I, "select[name$=\"[{$field}]\"]"))->setValue($value);
22
                        break;
23
                    case in_array($field, ['note']):
24
                        (new Textarea($I, "textarea[name$=\"[{$field}]\"]"))->setValue($value);
25
                        break;
26
                    case in_array($field, ['net_id', 'kvm_id', 'pdu_id', 'rack_id', 'pdu2_id', 'nic2_id', 'ipmi_id', 'location_id']):
27
                        (new Select2($I, "select[name$=\"[{$field}]\"]"))->setValue($value);
28
                        break;
29
                    default:
30
                        (new Input($I, "input[name$=\"[{$field}]\"]"))->setValue($value);
31
                }
32
            }
33
        }
34
    }
35
36
    public function needPageByName(string $name): self
37
    {
38
        $this->tester->click("//td/a[contains(text(), '{$name}')]");
39
        $this->waitPjax();
40
41
        return $this;
42
    }
43
44
    public function submitForm(): self
45
    {
46
        $this->tester->pressButton('Save');
47
        $this->waitPjax();
48
        $this->hasNotErrors();
49
50
        return $this;
51
    }
52
53
    public function hasNotErrors(): self
54
    {
55
        $this->tester->dontSeeElement("//*[contains(@class, 'has-error')]");
56
57
        return $this;
58
    }
59
60
    public function hasErrors(): self
61
    {
62
        $this->tester->seeElement("//*[contains(@class, 'has-error')]");
63
64
        return $this;
65
    }
66
67
    public function check($data): self
68
    {
69
        foreach ($data as $field => $value) {
70
            if ($value) {
71
                $this->tester->see($value);
72
            }
73
        }
74
75
        return $this;
76
    }
77
78
    public function waitPjax(): self
79
    {
80
        $this->tester->waitForJS("return $.active == 0;", 30);
81
82
        return $this;
83
    }
84
}
85