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
|
<html>
<head>
<script src="../../OLLoader.js"></script>
<script type="text/javascript">
var snippet = '<foo version="2.0.0"></foo>';
var snippet2 = '<foo></foo>';
function test_Format_Versioned_constructor(t) {
t.plan(5);
var format = new OpenLayers.Format.XML.VersionedOGC({version: "1.0.0"});
t.ok(format instanceof OpenLayers.Format.XML.VersionedOGC,
"new OpenLayers.Format.XML.VersionedOGC returns object" );
t.eq(format.version, "1.0.0", "constructor sets version correctly");
t.eq(format.defaultVersion, null, "defaultVersion should be null if not specified");
t.eq(typeof format.read, "function", "format has a read function");
t.eq(typeof format.write, "function", "format has a read function");
}
function test_getVersion(t) {
t.plan(6);
var format = new OpenLayers.Format.XML.VersionedOGC();
// read
var data = new OpenLayers.Format.XML().read(snippet);
var root = data.documentElement;
var version = format.getVersion(root);
t.eq(version, "2.0.0", "Version taken from document");
format = new OpenLayers.Format.XML.VersionedOGC({version: "1.0.0"});
version = format.getVersion(root);
t.eq(version, "1.0.0", "Version taken from parser takes preference");
format = new OpenLayers.Format.XML.VersionedOGC({defaultVersion: "3.0.0"});
data = new OpenLayers.Format.XML().read(snippet2);
root = data.documentElement;
version = format.getVersion(root);
t.eq(version, "3.0.0", "If nothing else is set, defaultVersion should be returned");
// write
version = format.getVersion(null, {version: "1.3.0"});
t.eq(version, "1.3.0", "Version from options returned");
version = format.getVersion(null);
t.eq(version, "3.0.0", "defaultVersion returned if no version specified in options and no version on the format");
format.version = "2.1.3";
version = format.getVersion(null);
t.eq(version, "2.1.3", "version returned of the Format if no version specified in options");
}
</script>
</head>
<body>
</body>
</html>
|