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
|
<?php
class WebTestHelper extends WebTestCase {
/* Compute protocol and hostname prefix, no trailing slash. */
function hostPrefix() {
$http = (!empty($_SERVER["HTTP_MOZ_REQ_METHOD"]) && $_SERVER["HTTP_MOZ_REQ_METHOD"] == 'HTTPS') ? 'https://' : 'http://';
$uriBase = $http . $_SERVER['HTTP_HOST'];
return $uriBase;
}
/* Compute the URI for the given action, accounting for us possibly not
* being at the root of the web space.
*/
function actionURI($action) {
/**
If HTTP_MOZ_REQ_METHOD indicates this was requested via https://,
use that, otherwise default to http://
*/
return $this->hostPrefix() . $this->actionPath($action);
}
/* As above, but just the local path and not a complete URI. */
function actionPath($action) {
return preg_replace('/\/tests.*/', $action, setUri());
}
/* Return a URI computed from the installation base, without locale or app. */
function rawURI($path) {
return $this->hostPrefix() . $this->rawPath($path);
}
/* As above, but just the local path and not a complete URI. */
function rawPath($path) {
return preg_replace('/\/' . LANG . '\/' . APP_SHORTNAME . '\/tests.*/', $path, setUri());
}
/* Make a GET for the given action, accounting for us possibly not being at
* the root of the web space.
*/
function getAction($action) {
$this->get($this->actionURI($action));
}
/* GET a fully-specified local URI path (needs to include site prefix if any). */
function getPath($path) {
$this->get($this->hostPrefix() . $path);
}
/**
* Logs in with test account info.
*/
function login() {
$username = 'nobody@sugarlabs.org';
$password = 'test';
$path = $this->actionURI('/users/login');
$data = array(
'data[Login][email]' => $username,
'data[Login][password]' => $password
);
$this->post($path, $data);
$this->assertNoUnwantedText(_('error_username_or_pw_wrong'), 'Logged in with test account');
}
/**
* Check if the retrieved XML document is well-formed/trivially parsable
* (no DTD validity for now)
*/
function checkXML() {
$browser = $this->getBrowser();
$data = $browser->getContent();
$xmlparser = xml_parser_create();
return (xml_parse($xmlparser, $data, true) == 1);;
}
/**
* Check that there is a link like <a href=$href>$title</a>.
*/
function assertLinkLocation($href, $title) {
$pattern = '#<a [^>]*href="[^"]*'.$href.'"[^>]*>'.$title.'</a>#';
$this->assertWantedPattern($pattern, htmlentities($pattern));
}
}
?>
|