Welcome to mirror list, hosted at ThFree Co, Russian Federation.

CNullElement.php « elements « web « include « tests « php « frontends - github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5155205abe434926aad5317d97992ffd2ec64699 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<?php
/*
** Zabbix
** Copyright (C) 2001-2020 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
**/

require_once 'vendor/autoload.php';

/**
 * NullObject implementation for non-existing web page element.
 */
class CNullElement {

	/**
	 * Element can be used as castable object to cast element to specific type.
	 */
	use CastableTrait;

	/**
	 * Element locator.
	 *
	 * @var string
	 */
	protected $locator;

	/**
	 * Element selector.
	 *
	 * @var WebDriverBy
	 */
	protected $by;

	/**
	 * Get object selector (if any) as text.
	 *
	 * @return string
	 */
	public function getSelectorAsText() {
		return $this->locator;
	}

	/**
	 * Initialize element.
	 *
	 * @param type $options
	 */
	public function __construct($options = []) {
		foreach ($options as $key => $value) {
			if (property_exists($this, $key)) {
				$this->$key = $value;
			}
		}

		if ($this->locator === null && array_key_exists('by', $options)) {
			$this->locator = '"'.$this->by->getValue().'" ('.$this->by->getMechanism().')';
		}
	}

	/**
	 * Simplified selector for elements that can be located directly on page.
	 * @throws Exception
	 */
	public static function find() {
		throw new Exception('Element cannot be located without selector.');
	}

	/**
	 * Null element is never casted to any element type.
	 *
	 * @param string $class      class to be casted to
	 * @param array  $options    additional options passed to object
	 *
	 * @return $this
	 */
	public function cast($class, $options = []) {
		return $this;
	}

	/**
	 * Get condition that will always return false.
	 *
	 * @return callable
	 */
	protected static function getFailCondition() {
		return function () {
			return false;
		};
	}

	/**
	 * @inheritdoc
	 */
	public function getClickableCondition() {
		return self::getFailCondition();
	}

	/**
	 * @inheritdoc
	 */
	public function getPresentCondition() {
		return self::getFailCondition();
	}

	/**
	 * @inheritdoc
	 */
	public function getVisibleCondition() {
		return self::getFailCondition();
	}

	/**
	 * @inheritdoc
	 */
	public function getTextPresentCondition($text) {
		return self::getFailCondition();
	}

	/**
	 * @inheritdoc
	 */
	public function getAttributesPresentCondition($attributes) {
		return self::getFailCondition();
	}

	/**
	 * @inheritdoc
	 */
	public function getReadyCondition() {
		return self::getFailCondition();
	}

	/**
	 * Wait until element changes it's state from stalled to normal.
	 *
	 * @throws Exception
	 */
	public function waitUntilReloaded() {
		throw new Exception('Cannot wait for null element reload.');
	}

	/**
	 * Wait until element is selected.
	 *
	 * @throws Exception
	 */
	public function waitUntilSelected() {
		throw new Exception('Cannot wait for null element to be selected.');
	}

	/**
	 * Null element cannot be used to detect element type.
	 *
	 * @param type $options
	 */
	public function detect($options = []) {
		return $this;
	}

	/**
	 * Check element value.
	 *
	 * @param mixed $expected    expected value of the element
	 *
	 * @return boolean
	 *
	 * @throws Exception
	 */
	public function checkValue($expected, $raise_exception = true) {
		if ($raise_exception) {
			throw new Exception('Cannot check value of null element.');
		}

		return false;
	}

	/**
	 * Call methods specific for custom element types.
	 *
	 * @param string $name         method name
	 * @param array  $arguments    method arguments
	 *
	 * @return mixed
	 *
	 * @throws Exception
	 */
	public function __call($name, $arguments) {
		// Null object returns false for all isXXX methods (isReady, isVisible, isEnabled...).
		if (substr($name, 0, 2) === 'is') {
			// Some methods (like isEnabled) allow passing boolean argument to get reversed result.
			$expected = (count($arguments) === 1 && is_bool($arguments[0])) ? $arguments[0] : true;

			return $expected === false;
		}

		$selector = $this->getSelectorAsText();
		if ($selector !== null) {
			$selector = ' located by '.$selector;
		}

		throw new Exception('Failed to find element'.$selector.' and execute "'.$name.'".');
	}
}