|
1
|
|
|
<?php |
|
2
|
|
|
function connection_failed($dbms, $fn, $errno, $errmsg, $p1=false, $p2=false) { |
|
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; |
|
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; |
|
33
|
|
|
$_REQUEST['server'] = $serverid; |
|
34
|
|
|
|
|
35
|
|
|
$server = $misc->getServerInfo($serverid); |
|
36
|
|
|
$server['username'] = $super_user[$server['desc']]; |
|
37
|
|
|
$server['password'] = $super_pass[$server['desc']]; |
|
38
|
|
|
|
|
39
|
|
|
$misc->setServerInfo(null, $server, $serverid); |
|
40
|
|
|
|
|
41
|
|
|
$this->server = $server; |
|
42
|
|
|
|
|
43
|
|
|
$this->data = $misc->getDatabaseAccessor($server['defaultdb']); |
|
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) |
|
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
|
|
|
?> |
|
191
|
|
|
|