Completed
Push — master ( 090eb4...72fae7 )
by Dmitry
17:23 queued 02:35
created

CheckBox::getCheckBoxState()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace hipanel\tests\_support\Page\Widget\Input;
4
5
/**
6
 * Class CheckBox.
7
 *
8
 * Represents checkbox element
9
 */
10
class CheckBox extends TestableInput
11
{
12
    /**
13
     * @return string
14
     */
15
    protected function getSearchSelector(): string
16
    {
17
        // TODO: Implement getSearchSelector() method.
18
    }
19
20
    /**
21
     * @return string
22
     */
23
    protected function getFilterSelector(): string
24
    {
25
        // TODO: Implement getFilterSelector() method.
26
    }
27
28
    /**
29
     * @param string $value
30
     */
31
    public function setValue(string $value): void
32
    {
33
        $checkBoxState = $this->getCheckBoxState();
34
        if ($checkBoxState === (bool)$value) {
35
            return;
36
        }
37
        $this->clickCheckBox();
38
    }
39
40
    private function clickCheckBox(): void
41
    {
42
        $this->tester->executeJS(<<<JS
43
document.querySelector(arguments[0]).click();
44
JS
45
            , [$this->selector]);
46
    }
47
48
    /**
49
     * @return bool
50
     */
51
    private function getCheckBoxState(): bool
52
    {
53
        $state = $this->tester->executeJS(<<<JS
54
return document.querySelector(arguments[0]).checked;
55
JS
56
            , [$this->selector]);
57
58
        return $state;
59
    }
60
}
61