Completed
Push — master ( 7af247...90e87c )
by Dmitry
04:11
created

Hub::needPageByName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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
    /**
15
     * @param Example $data
16
     * @return Hub
17
     * @throws \Exception
18
     */
19
    public function fillForm(Example $data)
20
    {
21
        $I = $this->tester;
22
        foreach ($data as $field => $value) {
23
            if (is_null($value)) {
24
                continue;
25
            }
26
            switch (true) {
27
                case in_array($field, ['type_id', 'nic_media', 'digit_capacity_id']):
28
                    (new Dropdown($I, "select[name$=\"[{$field}]\"]"))->setValue($value);
29
                    break;
30
                case in_array($field, ['note']):
31
                    (new Textarea($I, "textarea[name$=\"[{$field}]\"]"))->setValue($value);
32
                    break;
33
                case in_array($field, ['net_id', 'kvm_id', 'pdu_id', 'rack_id', 'pdu2_id', 'nic2_id', 'ipmi_id', 'location_id']):
34
                    (new Select2($I, "select[name$=\"[{$field}]\"]"))->setValue($value);
35
                    break;
36
                default:
37
                    (new Input($I, "input[name$=\"[{$field}]\"]"))->setValue($value);
38
            }
39
        }
40
41
        return $this;
42
    }
43
44
    /**
45
     * @return Hub
46
     * @throws \Codeception\Exception\ModuleException
47
     */
48
    public function submitForm(): self
49
    {
50
        $this->tester->pressButton('Save');
51
        $this->tester->waitForPageUpdate();
52
53
        return $this;
54
    }
55
56
    /**
57
     * @return Hub
58
     * @throws \Codeception\Exception\ModuleException
59
     */
60
    public function hasNotErrors(): self
61
    {
62
        $this->tester->waitForPageUpdate();
63
        $this->tester->dontSeeElement("//*[contains(@class, 'has-error')]");
64
65
        return $this;
66
    }
67
68
    /**
69
     * @return Hub
70
     */
71
    public function hasErrors(): self
72
    {
73
        $this->tester->seeElement("//*[contains(@class, 'has-error')]");
74
75
        return $this;
76
    }
77
}
78