1 | <?php |
||
23 | class GpxTest extends TestCase |
||
24 | { |
||
25 | /** |
||
26 | * @var Gpx |
||
27 | */ |
||
28 | private $dumper; |
||
29 | |||
30 | public function setUp() |
||
31 | { |
||
32 | $this->dumper = new Gpx(); |
||
33 | } |
||
34 | |||
35 | public function testDump() |
||
36 | { |
||
37 | $address = Address::createFromArray([]); |
||
38 | $expected = sprintf(<<<'GPX' |
||
39 | <?xml version="1.0" encoding="UTF-8" standalone="no" ?> |
||
40 | <gpx |
||
41 | version="1.0" |
||
42 | creator="Geocoder" version="%s" |
||
43 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||
44 | xmlns="http://www.topografix.com/GPX/1/0" |
||
45 | xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd"> |
||
46 | <wpt lat="%01.7f" lon="%01.7f"> |
||
47 | <name><![CDATA[]]></name> |
||
48 | <type><![CDATA[Address]]></type> |
||
49 | </wpt> |
||
50 | </gpx> |
||
51 | GPX |
||
52 | , Geocoder::VERSION, '0', '0'); |
||
53 | |||
54 | $result = $this->dumper->dump($address); |
||
55 | |||
56 | $this->assertTrue(is_string($result)); |
||
57 | $this->assertEquals($expected, $result); |
||
58 | } |
||
59 | |||
60 | public function testDumpWithData() |
||
61 | { |
||
62 | $address = Address::createFromArray([ |
||
63 | 'latitude' => 48.8631507, |
||
64 | 'longitude' => 2.3889114, |
||
65 | ]); |
||
66 | |||
67 | $expected = sprintf(<<<'GPX' |
||
68 | <?xml version="1.0" encoding="UTF-8" standalone="no" ?> |
||
69 | <gpx |
||
70 | version="1.0" |
||
71 | creator="Geocoder" version="%s" |
||
72 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||
73 | xmlns="http://www.topografix.com/GPX/1/0" |
||
74 | xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd"> |
||
75 | <wpt lat="%01.7f" lon="%01.7f"> |
||
76 | <name><![CDATA[]]></name> |
||
77 | <type><![CDATA[Address]]></type> |
||
78 | </wpt> |
||
79 | </gpx> |
||
80 | GPX |
||
81 | , Geocoder::VERSION, $address->getCoordinates()->getLatitude(), $address->getCoordinates()->getLongitude()); |
||
82 | |||
83 | $result = $this->dumper->dump($address); |
||
84 | |||
85 | $this->assertTrue(is_string($result)); |
||
86 | $this->assertEquals($expected, $result); |
||
87 | } |
||
88 | |||
89 | public function testDumpWithBounds() |
||
90 | { |
||
91 | $address = Address::createFromArray([ |
||
92 | 'latitude' => 48.8631507, |
||
93 | 'longitude' => 2.3889114, |
||
94 | 'bounds' => [ |
||
95 | 'south' => 48.8631507, |
||
96 | 'west' => 2.3889114, |
||
97 | 'north' => 48.8631507, |
||
98 | 'east' => 2.388911, |
||
99 | ], |
||
100 | ]); |
||
101 | $bounds = $address->getBounds()->toArray(); |
||
102 | |||
103 | $expected = sprintf(<<<'GPX' |
||
104 | <?xml version="1.0" encoding="UTF-8" standalone="no" ?> |
||
105 | <gpx |
||
106 | version="1.0" |
||
107 | creator="Geocoder" version="%s" |
||
108 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||
109 | xmlns="http://www.topografix.com/GPX/1/0" |
||
110 | xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd"> |
||
111 | <bounds minlat="%01.6f" minlon="%01.6f" maxlat="%01.6f" maxlon="%01.6f"/> |
||
112 | <wpt lat="%01.7f" lon="%01.7f"> |
||
113 | <name><![CDATA[]]></name> |
||
114 | <type><![CDATA[Address]]></type> |
||
115 | </wpt> |
||
116 | </gpx> |
||
117 | GPX |
||
118 | , Geocoder::VERSION, $bounds['east'], '48.863151', $bounds['east'], '48.863151', $bounds['north'], $bounds['west']); |
||
119 | |||
120 | $this->assertNotNull($address->getBounds()); |
||
121 | |||
122 | $result = $this->dumper->dump($address); |
||
123 | |||
124 | $this->assertTrue(is_string($result)); |
||
125 | $this->assertEquals($expected, $result); |
||
126 | } |
||
127 | |||
128 | public function testDumpWithName() |
||
129 | { |
||
130 | $bounds = [ |
||
131 | 'south' => 48.8631507, |
||
132 | 'west' => 2.3889114, |
||
133 | 'north' => 48.8631507, |
||
134 | 'east' => 2.388911, ]; |
||
135 | |||
136 | $address = Address::createFromArray([ |
||
137 | 'latitude' => 48.8631507, |
||
138 | 'longitude' => 2.3889114, |
||
139 | 'bounds' => $bounds, |
||
140 | 'locality' => 'Paris', |
||
141 | 'streetName' => 'Avenue Gambetta', |
||
142 | 'streetNumber' => '10', |
||
143 | 'subLocality' => '20e Arrondissement', |
||
144 | 'adminLevels' => [['level' => 1, 'name' => 'Ile-de-France']], |
||
145 | 'country' => 'France', |
||
146 | ]); |
||
147 | |||
148 | $expected = sprintf(<<<'GPX' |
||
149 | <?xml version="1.0" encoding="UTF-8" standalone="no" ?> |
||
150 | <gpx |
||
151 | version="1.0" |
||
152 | creator="Geocoder" version="%s" |
||
153 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||
154 | xmlns="http://www.topografix.com/GPX/1/0" |
||
155 | xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd"> |
||
156 | <bounds minlat="%01.6f" minlon="%01.6f" maxlat="%01.6f" maxlon="%01.6f"/> |
||
157 | <wpt lat="%01.7f" lon="%01.7f"> |
||
158 | <name><![CDATA[10, Avenue Gambetta, Paris, Ile-de-France, France]]></name> |
||
159 | <type><![CDATA[Address]]></type> |
||
160 | </wpt> |
||
161 | </gpx> |
||
162 | GPX |
||
163 | , Geocoder::VERSION, $bounds['east'], '48.863151', $bounds['east'], '48.863151', $bounds['north'], $bounds['west']); |
||
164 | |||
165 | $this->assertNotNull($address->getBounds()); |
||
166 | |||
167 | $result = $this->dumper->dump($address); |
||
168 | |||
169 | $this->assertTrue(is_string($result)); |
||
170 | $this->assertEquals($expected, $result); |
||
171 | } |
||
172 | } |
||
173 |