Test Failed
Branch develop (db5506)
by Felipe
03:46
created

TestBuilder::writeTests()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
	function connection_failed($dbms, $fn, $errno, $errmsg, $p1=false, $p2=false) {
0 ignored issues
show
Unused Code introduced by
The parameter $p1 is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

2
	function connection_failed($dbms, $fn, $errno, $errmsg, /** @scrutinizer ignore-unused */ $p1=false, $p2=false) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $p2 is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

2
	function connection_failed($dbms, $fn, $errno, $errmsg, $p1=false, /** @scrutinizer ignore-unused */ $p2=false) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $dbms is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

2
	function connection_failed(/** @scrutinizer ignore-unused */ $dbms, $fn, $errno, $errmsg, $p1=false, $p2=false) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $fn is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

2
	function connection_failed($dbms, /** @scrutinizer ignore-unused */ $fn, $errno, $errmsg, $p1=false, $p2=false) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $errno is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

2
	function connection_failed($dbms, $fn, /** @scrutinizer ignore-unused */ $errno, $errmsg, $p1=false, $p2=false) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
3
		echo "<div>{$errmsg}</div>\n";
4
		exit;
5
	}
6
7
	$_no_db_connection = true; /* load lib.inc.php without trying to connect */
8
	$_REQUEST['language'] = 'english';
9
	define('ADODB_ERROR_HANDLER','connection_failed');
10
	chdir(dirname(__FILE__). '/../..');
11
	require_once('./libraries/lib.inc.php');
12
13
	/*
14
	 * This class help building a selenium HTML test file for PPA.
15
	**/
16
	class TestBuilder {
17
		/**
18
		 * Constructor
19
		 * @param $serverDesc The server['desc'] conf param to which we are writing this test file for.
20
		 * @param $title The title of the HTML test page
21
		 * @param $desc The top description on the HTML test page
22
		 */
23
		public function __construct($title, $desc) {
24
			global $misc;
25
			$this->title = $title;
1 ignored issue
show
Bug Best Practice introduced by
The property title does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
26
27
			$serverid = $_GET['server'];
28
29
			require('./tests/selenium/config.test.php');
30
			require_once('./classes/database/Connection.php');
31
32
			$this->webUrl = $webUrl;
1 ignored issue
show
Bug Best Practice introduced by
The property webUrl does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
Comprehensibility Best Practice introduced by
The variable $webUrl seems to be never defined.
Loading history...
33
			$_REQUEST['server'] = $serverid;
34
35
			$server = $misc->getServerInfo($serverid);
36
			$server['username'] = $super_user[$server['desc']];
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $super_user seems to be never defined.
Loading history...
37
			$server['password'] = $super_pass[$server['desc']];
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $super_pass seems to be never defined.
Loading history...
38
39
			$misc->setServerInfo(null, $server, $serverid);
40
41
			$this->server = $server;
1 ignored issue
show
Bug Best Practice introduced by
The property server does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
42
43
			$this->data = $misc->getDatabaseAccessor($server['defaultdb']);
1 ignored issue
show
Bug Best Practice introduced by
The property data does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
44
45
			echo "<html>\n<head>
46
				<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
47
				<title>$title</title>
48
				</head>
49
				<body>
50
				<table cellpadding=\"1\" cellspacing=\"1\" border=\"1\">
51
				<thead>
52
				<tr><td rowspan=\"1\" colspan=\"3\">$desc</td></tr>
53
				</thead><tbody>";
54
		}
55
		
56
		/**
57
		 * Write the test file, close it,
58
		 * append the test file to the TestSuite.html file and destroy itself
59
		 * @param $testfile The path to the test file to create
60
		 * @param $testsuite_file The path to the TestSuite.html file
61
		 */
62
		public function writeTests() { //$testfile, $testsuite_file) {
63
			//echo $this->code;
64
			return;
65
		}
66
		
67
		/**
68
		 * Add a selenium test to the file
69
		 * @param $action the selenium action (first column)
70
		 * @param $selector the selector to select the object to work on (second column)
71
		 * @param $value (optional) the expected (or not) value (third column)
0 ignored issues
show
Bug introduced by
The type optional 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...
72
		 */
73
		public function test($action, $selector, $value='') {
74
			echo "<tr>\n<td>$action</td>\n<td>$selector</td>\n<td>$value</td>\n</tr>\n";
75
		}
76
77
		public function addComment($c) {
78
			echo "<tr>\n<th colspan=\"3\">{$c}</th>\n</tr>\n";
79
		}
80
81
		/**
82
		 * Add steps to login on PPA using the given credentials
83
		 * @param $u The username to use
84
		 * @param $p The password to use
85
		 */
86
		public function login($u, $p) {
87
			$this->addComment("Login as {$this->server['username']}");
88
			$this->test('open', "{$this->webUrl}/intro.php");
89
			$this->select('language', 'English');
90
			$this->test('open', "{$this->webUrl}/login.php?server={$this->data->conn->host}&subject=server");
91
			$this->test('type', "//input[@name='loginUsername']", $u);
92
			$this->test('type', "//input[@id='loginPassword']", $p);
93
			$this->test('clickAndWait', 'loginSubmit');
94
			$this->test('assertText', "//div[@class='topbar']/descendant::span[@class='username']", $u);
95
		}
96
97
		/**
98
		 * Add steps to logout from the server
99
		 */
100
		public function logout() {
101
			global $lang;
102
103
			$this->addComment("Logout");
104
			$this->test('clickAndWait', "//div[@class='trail']/descendant::tr/td[1]/a/span[@class='label' and text()='phpPgAdmin']");
105
			$this->test('clickAndWait', "link={$lang['strservers']}");
106
			$this->test('clickAndWait', "//tr/td/a[text()='{$this->server['desc']}']/../../td/a[text()='{$lang['strlogout']}']");
107
108
			$this->test('assertText', "//p[@class='message']",
109
				sprintf($lang['strlogoutmsg'], $this->server['desc'])
110
			);
111
		}
112
113
		/**
114
		 * Add a selenium type test to the file
115
		 * @param $selector the selector to select the object to work on (second column)
116
		 * @param $value (optional) the expected (or not) value (third column)
117
		 */
118
		public function type($selector, $value) {
119
			$this->test('type', $selector, $value);
120
		}
121
122
		/**
123
		 * Add a selenium select test to the file
124
		 * @param $selector the selector to select the object to work on (second column)
125
		 * @param $value (optional) the expected (or not) value (third column)
126
		 */
127
		public function select($selector, $value) {
128
			$this->test('select', $selector, $value);
129
		}
130
		
131
		/**
132
		 * Add a selenium addSelection test to the file
133
		 * @param $selector the selector to select the object to work on (second column)
134
		 * @param $value (optional) the expected (or not) value (third column)
135
		 */
136
		public function addSelection($selector, $value) {
137
			$this->test('addSelection', $selector, $value);
138
		}
139
140
		/**
141
		 * Add a selenium click test to the file
142
		 * @param $selector the selector to select the object to work on (second column)
143
		 */
144
		public function click($selector) {
145
			$this->test('click', $selector);
146
		}
147
		
148
		/**
149
		 * Add a selenium check test to the file
150
		 * @param $selector the selector to select the object to work on (second column)
151
		 */
152
		public function check($selector) {
153
			$this->test('check', $selector);
154
		}
155
		
156
		/**
157
		 * Add a selenium uncheck test to the file
158
		 * @param $selector the selector to select the object to work on (second column)
159
		 */
160
		public function uncheck($selector) {
161
			$this->test('uncheck', $selector);
162
		}
163
164
		/**
165
		 * Add a selenium clickAndWait est to the file
166
		 * @param $selector the selector to select the object to work on (second column)
167
		 */
168
		public function clickAndWait($selector) {
169
			$this->test('clickAndWait', $selector);
170
		}
171
172
		/**
173
		 * Add a selenium assertText test to the file
174
		 * @param $selector the selector to select the object to work on (second column)
175
		 * @param $value (optional) the expected (or not) value (third column)
176
		 */
177
		public function assertText($selector, $value) {
178
			$this->test('assertText', $selector, $value);
179
		}
180
		
181
		/**
182
		 * Add a selenium assertErrorOnNext test to the file
183
		 * @param $msg the selenium error message expected
184
		 */
185
		public function assertErrorOnNext($msg) {
186
			$this->test('assertErrorOnNext', $msg);
187
		}
188
		
189
	}
190
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
191