Skip to content

Commit

Permalink
Add KmlFormatterTest
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenDeDauw committed Nov 20, 2018
1 parent d4d96aa commit 1e6ec73
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Elements/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ class Location extends BaseElement {
*/
private $visitedIcon = '';

public function __construct( LatLongValue $coordinates ) {
public function __construct( LatLongValue $coordinates, string $title = '', string $text = '' ) {
$this->coordinates = $coordinates;
$this->setTitle( $title );
$this->setText( $text );
}

public static function newFromLatLon( float $lat, float $lon ): self {
Expand Down
3 changes: 1 addition & 2 deletions src/Presentation/KmlFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function formatLocationsAsKml( Location ...$locations ): string {
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
$elements
$elements
</Document>
</kml>
EOT;
Expand Down Expand Up @@ -59,7 +59,6 @@ private function locationToKmlPlacemark( Location $location ): string {
$coordinates
</Point>
</Placemark>
EOT;
}

Expand Down
66 changes: 66 additions & 0 deletions tests/Unit/Presentation/KmlFormatterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace Maps\Tests\Presentation;

use DataValues\Geo\Values\LatLongValue;
use Maps\Elements\Location;
use Maps\Presentation\KmlFormatter;
use PHPUnit\Framework\TestCase;

/**
* @covers \Maps\Presentation\KmlFormatter
*
* @licence GNU GPL v2+
* @author Jeroen De Dauw < [email protected] >
*/
class KmlFormatterTest extends TestCase {

public function testEmptyList() {
$this->assertSame(
'<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
</Document>
</kml>',
( new KmlFormatter() )->formatLocationsAsKml()
);
}

public function testSeveralLocations() {
$this->assertSame(
'<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Placemark>
<name><![CDATA[ first title]]></name>
<description><![CDATA[ first text]]></description>
<Point>
<coordinates>23,42.42,0</coordinates>
</Point>
</Placemark>
<Placemark>
<name><![CDATA[ second title]]></name>
<description><![CDATA[ second text]]></description>
<Point>
<coordinates>0,-1,0</coordinates>
</Point>
</Placemark>
</Document>
</kml>',
( new KmlFormatter() )->formatLocationsAsKml(
new Location(
new LatLongValue( 42.42,23 ),
'first title',
'first text'
),
new Location(
new LatLongValue( -1,0 ),
'second title',
'second text'
)
)
);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace Maps\Tests\Presentation;

use Maps\Presentation\ParameterExtractor;
use PHPUnit\Framework\TestCase;

Expand Down

0 comments on commit 1e6ec73

Please sign in to comment.