1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Geocoder package. |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* @license MIT License |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Geocoder\Tests\Dumper; |
14
|
|
|
|
15
|
|
|
use Geocoder\Dumper\Kml; |
16
|
|
|
use Geocoder\Model\Address; |
17
|
|
|
use PHPUnit\Framework\TestCase; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Jan Sorgalla <[email protected]> |
21
|
|
|
* @author William Durand <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class KmlTest extends TestCase |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var Kml |
27
|
|
|
*/ |
28
|
|
|
private $dumper; |
29
|
|
|
|
30
|
|
|
public function setUp() |
31
|
|
|
{ |
32
|
|
|
$this->dumper = new Kml(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testDump() |
36
|
|
|
{ |
37
|
|
|
$address = Address::createFromArray([]); |
38
|
|
|
$expected = <<<'KML' |
39
|
|
|
<?xml version="1.0" encoding="UTF-8"?> |
40
|
|
|
<kml xmlns="http://www.opengis.net/kml/2.2"> |
41
|
|
|
<Document> |
42
|
|
|
<Placemark> |
43
|
|
|
<name><![CDATA[]]></name> |
44
|
|
|
<description><![CDATA[]]></description> |
45
|
|
|
<Point> |
46
|
|
|
<coordinates>0.0000000,0.0000000,0</coordinates> |
47
|
|
|
</Point> |
48
|
|
|
</Placemark> |
49
|
|
|
</Document> |
50
|
|
|
</kml> |
51
|
|
|
KML; |
52
|
|
|
|
53
|
|
|
$result = $this->dumper->dump($address); |
54
|
|
|
|
55
|
|
|
$this->assertTrue(is_string($result)); |
56
|
|
|
$this->assertEquals($expected, $result); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testDumpWithData() |
60
|
|
|
{ |
61
|
|
|
$address = Address::createFromArray([ |
62
|
|
|
'latitude' => 48.8631507, |
63
|
|
|
'longitude' => 2.3889114, |
64
|
|
|
'locality' => 'Paris', |
65
|
|
|
]); |
66
|
|
|
$expected = <<<'KML' |
67
|
|
|
<?xml version="1.0" encoding="UTF-8"?> |
68
|
|
|
<kml xmlns="http://www.opengis.net/kml/2.2"> |
69
|
|
|
<Document> |
70
|
|
|
<Placemark> |
71
|
|
|
<name><![CDATA[Paris]]></name> |
72
|
|
|
<description><![CDATA[Paris]]></description> |
73
|
|
|
<Point> |
74
|
|
|
<coordinates>2.3889114,48.8631507,0</coordinates> |
75
|
|
|
</Point> |
76
|
|
|
</Placemark> |
77
|
|
|
</Document> |
78
|
|
|
</kml> |
79
|
|
|
KML; |
80
|
|
|
|
81
|
|
|
$result = $this->dumper->dump($address); |
82
|
|
|
|
83
|
|
|
$this->assertTrue(is_string($result)); |
84
|
|
|
$this->assertEquals($expected, $result); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|