diff --git a/src/Elements/Location.php b/src/Elements/Location.php index c2b789c15..6ea8c4be0 100644 --- a/src/Elements/Location.php +++ b/src/Elements/Location.php @@ -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 { diff --git a/src/Presentation/KmlFormatter.php b/src/Presentation/KmlFormatter.php index 9446be260..7773e6c30 100644 --- a/src/Presentation/KmlFormatter.php +++ b/src/Presentation/KmlFormatter.php @@ -21,7 +21,7 @@ public function formatLocationsAsKml( Location ...$locations ): string { - $elements +$elements EOT; @@ -59,7 +59,6 @@ private function locationToKmlPlacemark( Location $location ): string { $coordinates - EOT; } diff --git a/tests/Unit/Presentation/KmlFormatterTest.php b/tests/Unit/Presentation/KmlFormatterTest.php new file mode 100644 index 000000000..f503269e5 --- /dev/null +++ b/tests/Unit/Presentation/KmlFormatterTest.php @@ -0,0 +1,66 @@ + + */ +class KmlFormatterTest extends TestCase { + + public function testEmptyList() { + $this->assertSame( + ' + + + + +', + ( new KmlFormatter() )->formatLocationsAsKml() + ); + } + + public function testSeveralLocations() { + $this->assertSame( + ' + + + + + + + 23,42.42,0 + + + + + + + 0,-1,0 + + + +', + ( new KmlFormatter() )->formatLocationsAsKml( + new Location( + new LatLongValue( 42.42,23 ), + 'first title', + 'first text' + ), + new Location( + new LatLongValue( -1,0 ), + 'second title', + 'second text' + ) + ) + ); + } + +} diff --git a/tests/Unit/ParameterExtractorTest.php b/tests/Unit/Presentation/ParameterExtractorTest.php similarity index 97% rename from tests/Unit/ParameterExtractorTest.php rename to tests/Unit/Presentation/ParameterExtractorTest.php index 29c48a275..d96157986 100644 --- a/tests/Unit/ParameterExtractorTest.php +++ b/tests/Unit/Presentation/ParameterExtractorTest.php @@ -1,5 +1,7 @@