/
TranslateXMLCommandTest.php
451 lines (396 loc) · 16.9 KB
/
TranslateXMLCommandTest.php
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
<?php
/**
* @package geocatalog
* @subpackage tests
*/
class TranslateXMLCommandTest extends SapphireTest
{
/**
* Also uses SimpleNzctFixture in setUp()
*/
public static $fixture_file = 'geocatalogue/tests/GetRecordsCommandTest.yml';
public static $ISO19139response='<?xml version="1.0" encoding="UTF-8"?>
<csw:GetRecordsResponse xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/cat/csw/2.0.2 http://schemas.opengis.net/csw/2.0.2/CSW-discovery.xsd">
<csw:SearchStatus timestamp="2009-08-27T08:37:38" />
<csw:SearchResults numberOfRecordsMatched="1" numberOfRecordsReturned="1" elementSet="summary" nextRecord="0">
<gmd:MD_Metadata xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:gml="http://www.opengis.net/gml" xmlns:gts="http://www.isotc211.org/2005/gts" xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:geonet="http://www.fao.org/geonetwork">
<gmd:fileIdentifier>
<gco:CharacterString xmlns:srv="http://www.isotc211.org/2005/srv" xmlns:gmx="http://www.isotc211.org/2005/gmx">0587e442-eaee-470d-a0d1-3e3a54cc983b</gco:CharacterString>
</gmd:fileIdentifier>
<gmd:language>
<gco:CharacterString>eng</gco:CharacterString>
</gmd:language>
<gmd:characterSet>
<gmd:MD_CharacterSetCode codeListValue="utf8" codeList="http://www.isotc211.org/2005/resources/codeList.xml#MD_CharacterSetCode" />
</gmd:characterSet>
<gmd:dateStamp>
<gco:DateTime xmlns:srv="http://www.isotc211.org/2005/srv" xmlns:gmx="http://www.isotc211.org/2005/gmx">2007-07-19T14:45:07</gco:DateTime>
</gmd:dateStamp>
<gmd:metadataStandardName>
<gco:CharacterString xmlns:srv="http://www.isotc211.org/2005/srv" xmlns:gmx="http://www.isotc211.org/2005/gmx">ISO 19115:2003/19139</gco:CharacterString>
</gmd:metadataStandardName>
<gmd:metadataStandardVersion>
<gco:CharacterString xmlns:srv="http://www.isotc211.org/2005/srv" xmlns:gmx="http://www.isotc211.org/2005/gmx">1.0</gco:CharacterString>
</gmd:metadataStandardVersion>
<gmd:referenceSystemInfo>
<gmd:MD_ReferenceSystem>
<gmd:referenceSystemIdentifier>
<gmd:RS_Identifier>
<gmd:code>
<gco:CharacterString>WGS 1984</gco:CharacterString>
</gmd:code>
</gmd:RS_Identifier>
</gmd:referenceSystemIdentifier>
</gmd:MD_ReferenceSystem>
</gmd:referenceSystemInfo>
<gmd:identificationInfo>
<gmd:MD_DataIdentification>
<gmd:citation>
<gmd:CI_Citation>
<gmd:title>
<gco:CharacterString>Hydrological Basins in Africa (Sample record, please remove!)</gco:CharacterString>
</gmd:title>
</gmd:CI_Citation>
</gmd:citation>
<gmd:abstract>
<gco:CharacterString>Major hydrological basins and their sub-basins. This dataset divides the African continent according to its hydrological characteristics.
The dataset consists of the following information:- numerical code and name of the major basin (MAJ_BAS and MAJ_NAME); - area of the major basin in square km (MAJ_AREA); - numerical code and name of the sub-basin (SUB_BAS and SUB_NAME); - area of the sub-basin in square km (SUB_AREA); - numerical code of the sub-basin towards which the sub-basin flows (TO_SUBBAS) (the codes -888 and -999 have been assigned respectively to internal sub-basins and to sub-basins draining into the sea)</gco:CharacterString>
</gmd:abstract>
<gmd:graphicOverview>
<gmd:MD_BrowseGraphic>
<gmd:fileName>
<gco:CharacterString>thumbnail_s.gif</gco:CharacterString>
</gmd:fileName>
</gmd:MD_BrowseGraphic>
</gmd:graphicOverview>
<gmd:graphicOverview>
<gmd:MD_BrowseGraphic>
<gmd:fileName>
<gco:CharacterString>thumbnail.gif</gco:CharacterString>
</gmd:fileName>
</gmd:MD_BrowseGraphic>
</gmd:graphicOverview>
<gmd:resourceConstraints>
<gmd:MD_Constraints>
<gmd:useLimitation gco:nilReason="missing">
<gco:CharacterString />
</gmd:useLimitation>
</gmd:MD_Constraints>
</gmd:resourceConstraints>
<gmd:spatialRepresentationType>
<gmd:MD_SpatialRepresentationTypeCode codeList="http://www.isotc211.org/2005/resources/codeList.xml#MD_SpatialRepresentationTypeCode" codeListValue="vector" />
</gmd:spatialRepresentationType>
<gmd:spatialResolution>
<gmd:MD_Resolution>
<gmd:equivalentScale>
<gmd:MD_RepresentativeFraction>
<gmd:denominator>
<gco:Integer>5000000</gco:Integer>
</gmd:denominator>
</gmd:MD_RepresentativeFraction>
</gmd:equivalentScale>
</gmd:MD_Resolution>
</gmd:spatialResolution>
<gmd:language>
<gco:CharacterString>eng</gco:CharacterString>
</gmd:language>
<gmd:characterSet>
<gmd:MD_CharacterSetCode codeList="http://www.isotc211.org/2005/resources/codeList.xml#MD_CharacterSetCode" codeListValue="utf8" />
</gmd:characterSet>
<gmd:topicCategory>
<gmd:MD_TopicCategoryCode>inlandWaters</gmd:MD_TopicCategoryCode>
</gmd:topicCategory>
<gmd:extent>
<gmd:EX_Extent>
<gmd:geographicElement>
<gmd:EX_GeographicBoundingBox>
<gmd:westBoundLongitude>
<gco:Decimal>-17.3</gco:Decimal>
</gmd:westBoundLongitude>
<gmd:southBoundLatitude>
<gco:Decimal>-34.6</gco:Decimal>
</gmd:southBoundLatitude>
<gmd:eastBoundLongitude>
<gco:Decimal>51.1</gco:Decimal>
</gmd:eastBoundLongitude>
<gmd:northBoundLatitude>
<gco:Decimal>38.2</gco:Decimal>
</gmd:northBoundLatitude>
</gmd:EX_GeographicBoundingBox>
</gmd:geographicElement>
</gmd:EX_Extent>
</gmd:extent>
</gmd:MD_DataIdentification>
</gmd:identificationInfo>
<gmd:distributionInfo>
<gmd:MD_Distribution>
<gmd:distributionFormat>
<gmd:MD_Format>
<gmd:name>
<gco:CharacterString>ShapeFile</gco:CharacterString>
</gmd:name>
<gmd:version>
<gco:CharacterString>Grass Version 6.1</gco:CharacterString>
</gmd:version>
</gmd:MD_Format>
</gmd:distributionFormat>
<gmd:transferOptions>
<gmd:MD_DigitalTransferOptions>
<gmd:onLine>
<gmd:CI_OnlineResource>
<gmd:linkage>
<gmd:URL>http://www.fao.org/ag/AGL/aglw/aquastat/watresafrica/index.stm</gmd:URL>
</gmd:linkage>
</gmd:CI_OnlineResource>
</gmd:onLine>
<gmd:onLine>
<gmd:CI_OnlineResource>
<gmd:linkage xmlns:srv="http://www.isotc211.org/2005/srv" xmlns:gmx="http://www.isotc211.org/2005/gmx">
<gmd:URL>http://localhost:8080/geonetwork/srv/en/resources.get?id=11&fname=basins.zip&access=private</gmd:URL>
</gmd:linkage>
</gmd:CI_OnlineResource>
</gmd:onLine>
<gmd:onLine>
<gmd:CI_OnlineResource>
<gmd:linkage>
<gmd:URL>http://geonetwork3.fao.org/ows/296</gmd:URL>
</gmd:linkage>
</gmd:CI_OnlineResource>
</gmd:onLine>
</gmd:MD_DigitalTransferOptions>
</gmd:transferOptions>
</gmd:MD_Distribution>
</gmd:distributionInfo>
<gmd:dataQualityInfo>
<gmd:DQ_DataQuality>
<gmd:lineage>
<gmd:LI_Lineage>
<gmd:statement>
<gco:CharacterString>The linework of the map is obtained by delineating drainage basin boundaries from an hydrologically corrected digital elevation model with a resolution of 1 * 1 km.</gco:CharacterString>
</gmd:statement>
</gmd:LI_Lineage>
</gmd:lineage>
</gmd:DQ_DataQuality>
</gmd:dataQualityInfo>
</gmd:MD_Metadata>
</csw:SearchResults>
</csw:GetRecordsResponse>
';
public static $HTMLResponseNoDocType='<html>
<head>
<base href="http://www.silverstripe.com/" >
<title>SilverStripe.com - Open Source CMS / Framework</title>
</head>
<body>
<h1>SilverStripe</h1>
</body>
</html>';
public static $EmptyXMLResponse='<?xml version="1.0" encoding="UTF-8"?><nothing></nothing>';
protected $controller = null;
/**
* Initiate the controller and page classes and configure GeoNetwork service
* to use the mockup-controller for testing.
*/
public function setUp()
{
parent::setUp();
$url = Director::absoluteBaseURL() . 'GetRecordsCommandTest_Controller';
$page = $this->objFromFixture('CataloguePage', 'catalogue');
$page->GeonetworkBaseURL = $url;
$this->controller = new CataloguePage_Controller($page);
$this->controller->pushCurrent();
GetRecordsCommand::set_catalogue_url("/getrecords?usetestmanifest=1&flush=1");
}
/**
* Remove test controller from global controller-stack.
*/
public function tearDown()
{
$this->controller->popCurrent();
parent::tearDown();
}
/**
* testTranslateXMLCommand
*
* Using the standard Response translating it into PHP-Code to set up the
* the structure for MDMetadataObject
*
*/
public function testTranslateXMLCommand()
{
$baseURL = Director::baseFolder();
//seting up the environment
$data = array(
'xml' => self::$ISO19139response,
'xsl' => $baseURL.'/geocatalogue/xslt/ISO19139/iso19139_to_silverstripe.xsl',
);
$cmd = $this->controller->getCommand("TranslateXML", $data);
$result = $cmd->execute();
$position = strpos($result, '0587e442-eaee-470d-a0d1-3e3a54cc983b');
if ($position === false) {
$this->assertEquals(1, 0, 'UUID not found in translation.>>>'. $result . '<<<');
}
}
/**
* testTranslateXMLCommandWithHTMLResponseNoDoctype
*
* Using a valid HTML-Response without a DocType is the way of the geonetwork server to
* indicate that an error has occured
*
*/
public function testTranslateXMLCommandWithHTMLResponseNoDoctype()
{
$baseURL = Director::baseFolder();
//seting up the environment
$data = array(
'xml' => self::$HTMLResponseNoDocType ,
'xsl' => $baseURL.'/geocatalogue/xslt/iso19139_to_silverstripe.xsl',
);
$cmd = $this->controller->getCommand("TranslateXML", $data);
//execute has to throw an error
try {
$result = $cmd->execute();
} catch (TranslateXMLCommand_Exception $e) {
return;
}
$this->assertTrue(false, 'TranslateXML should throw an error on html-content starting with <html>');
}
/**
* testTranslateXMLCommandWithEmptyXMLResponse
*
* Using a valid XML-Response with just an empty
* should result in an empty string
*
*/
public function testTranslateXMLCommandWithEmptyXMLResponse()
{
//seting up the environment
$baseURL = Director::baseFolder();
$data = array(
'xml' => self::$EmptyXMLResponse ,
'xsl' => $baseURL.'/geocatalogue/xslt/ISO19139/iso19139_to_silverstripe.xsl',
);
$cmd = $this->controller->getCommand("TranslateXML", $data);
//execute has not to throw an error
try {
$result = $cmd->execute();
} catch (TranslateXMLCommand_Exception $e) {
$this->assertTrue(false, 'TranslateXML should NOT throw an error on valid xml-content');
}
$this->assertTrue(isset($result), 'results has not been set');
$this->assertTrue($result == '', 'results must be an empty string');
}
/**
* testTranslateXMLCommandWithEmptyResponse
*
* Using an empty Response should result in an empty string
*
*/
public function testTranslateXMLCommandWithEmptyResponse()
{
//seting up the environment
$baseURL = Director::baseFolder();
$data = array(
'xml' => '' ,
'xsl' => $baseURL.'/geocatalogue/xslt/ISO19139/iso19139_to_silverstripe.xsl',
);
$cmd = $this->controller->getCommand("TranslateXML", $data);
//execute has not to throw an error
try {
$result = $cmd->execute();
} catch (TranslateXMLCommand_Exception $e) {
$this->assertTrue(false, 'TranslateXML should NOT throw an error on empty Request');
}
$this->assertTrue(isset($result), 'results has been set');
$this->assertTrue($result == '', 'results must be an empty string');
}
/**
* testTranslateXMLCommandWithNullResponse
*
* Using a null Response should result in an empty string
*
*/
public function testTranslateXMLCommandWithNullResponse()
{
//seting up the environment
$baseURL = Director::baseFolder();
$data = array(
'xml' => null,
'xsl' => $baseURL.'/geocatalogue/xslt/ISO19139/iso19139_to_silverstripe.xsl',
);
$cmd = $this->controller->getCommand("TranslateXML", $data);
//execute has not to throw an error
try {
$result = $cmd->execute();
} catch (TranslateXMLCommand_Exception $e) {
return;// ok, we got an exception
}
$this->assertTrue(false, 'TranslateXML should throw an error on null Request');
}
/**
* testTranslateXMLCommandWithEmptyStylesheet
*
* Using an empty stylesheet should result in an exception
*
*/
public function testTranslateXMLCommandWithEmptyStylesheet()
{
//seting up the environment
$data = array(
'xml' => self::$EmptyXMLResponse ,
'xsl' => '',
);
$cmd = $this->controller->getCommand("TranslateXML", $data);
//execute has not to throw an error
try {
$result = $cmd->execute();
} catch (TranslateXMLCommand_Exception $e) {
return; //ok we got an excetion
}
$this->assertTrue(false, 'TranslateXML should throw an exception on an empty stylesheet');
}
/**
* testTranslateXMLCommandWithNullStylesheet
*
* Using NO stylesheet should result in an exception
*
*/
public function testTranslateXMLCommandWithNullStylesheet()
{
//seting up the environment
$data = array(
'xml' => self::$EmptyXMLResponse ,
'xsl' => null,
);
$cmd = $this->controller->getCommand("TranslateXML", $data);
//execute has not to throw an error
try {
$result = $cmd->execute();
} catch (TranslateXMLCommand_Exception $e) {
return; //ok we got an excetion
}
$this->assertTrue(false, 'TranslateXML should throw an exception if there is NO stylesheet');
}
/**
* testTranslateXMLCommandWithInvalidStylesheet
*
* Using an invalid stylesheet should result in an exception
*
*/
public function testTranslateXMLCommandWithInvalidStylesheet()
{
//seting up the environment
$data = array(
'xml' => self::$EmptyXMLResponse ,
'xsl' => '../NoStylesheetFound',
);
$cmd = $this->controller->getCommand("TranslateXML", $data);
//execute has not to throw an error
try {
$result = $cmd->execute();
} catch (TranslateXMLCommand_Exception $e) {
return; //ok we got an excetion
}
$this->assertTrue(false, 'TranslateXML should throw an exception if the stylesheet could not be found');
}
}