Completed
Push — master ( edb2b9...da334f )
by Dmitry
13:12
created

tests/_support/Page/Widget/Input/TestableInput.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * HiPanel core package
4
 *
5
 * @link      https://hipanel.com/
6
 * @package   hipanel-core
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2014-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\tests\_support\Page\Widget\Input;
12
13
use hipanel\tests\_support\AcceptanceTester;
14
15
/**
16
 * Class TestableInput.
17
 *
18
 * Basic class for input elements.
19
 * The elements can be created in three different ways:
20
 * 1. Free input element
21
 *  In this case, instance should be created using a common constructor.
22
 *  The selector of the element should be put to the constructor.
23
 *      new Class(tester, selector)
24
 *
25
 * 2. As Advanced search element
26
 *      Class::asAdvancedSearch($tester, $title)
27
 *
28
 * 3. As Table filter element of indexes page
29
 *      Class::asTableFilter($tester, $columnName)
30
 *
31
 *  In last two cases, the element should be created with related named
32
 *  constructors.
33
 *  The second argument is title of element in Advanced search or
34
 *  column name in Table filter respectively.
35
 */
36
abstract class TestableInput
37
{
38
    protected $tester;
39
40
    /**
41
     * @var string $title
42
     */
43
    protected $title;
44
45
    /**
46
     * @var string $auxName
47
     */
48
    protected $auxName;
49
50
    /**
51
     * @var string $selector
52
     */
53
    protected $selector;
54
55
    const AS_BASE = 'div.advanced-search ';
56
57
    const TF_BASE = 'tr.filters ';
58
59
    /**
60
     * TestableInput constructor.
61
     * @param AcceptanceTester $tester
62
     * @param string $selector
63
     */
64
    public function __construct(AcceptanceTester $tester, string $selector)
65
    {
66
        $this->tester = $tester;
67
        $this->selector = $selector;
68
    }
69
70
    /**
71
     * @param AcceptanceTester $tester
72
     * @param string $title
73
     * @return TestableInput
74
     */
75 View Code Duplication
    public static function asAdvancedSearch(AcceptanceTester $tester, string $title): TestableInput
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
76
    {
77
        $instance           = new static($tester, '');
78
        $instance->title    = $title;
79
        $instance->auxName  = $instance->computeAuxName($title);
80
        $instance->selector = $instance->getSearchSelector();
81
82
        return $instance;
83
    }
84
85
    /**
86
     * @param AcceptanceTester $tester
87
     * @param $columnName
88
     * @return TestableInput
89
     */
90 View Code Duplication
    public static function asTableFilter(AcceptanceTester $tester, string $columnName): TestableInput
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
91
    {
92
        $instance           = new static($tester, '');
93
        $instance->auxName  = $instance->computeAuxName($columnName);
94
        $instance->selector = $instance->getFilterSelector();
95
96
        return $instance;
97
    }
98
99
    /**
100
     * @return string
101
     */
102
    abstract protected function getSearchSelector(): string;
103
104
    /**
105
     * @return string
106
     */
107
    abstract protected function getFilterSelector(): string;
108
109
    /**
110
     * @param string $value
111
     */
112
    abstract public function setValue(string $value): void;
113
114
    /**
115
     * @return string
116
     */
117
    public function getSelector(): string
118
    {
119
        return $this->selector;
120
    }
121
122
    /**
123
     * @param string $name
124
     * @return string
125
     */
126
    private function computeAuxName(string $name): string
127
    {
128
        return substr(strtolower($name), 0, 5);
129
    }
130
131
    /**
132
     * Checks whether input is visible.
133
     */
134
    public function isVisible(): void
135
    {
136
        $this->tester->seeElement($this->selector);
137
    }
138
}
139