diff --git a/src/Bundle/ChillMainBundle/Tests/Doctrine/Model/PointTest.php b/src/Bundle/ChillMainBundle/Tests/Doctrine/Model/PointTest.php new file mode 100644 index 000000000..5632bf96a --- /dev/null +++ b/src/Bundle/ChillMainBundle/Tests/Doctrine/Model/PointTest.php @@ -0,0 +1,119 @@ + + */ +class ExportControllerTest extends KernelTestCase +{ + + public function testToWKT() + { + $lon = 4.8634; + $lat = 50.47382; + $point = $this->preparePoint($lon, $lat); + + $this->assertEquals($point->toWKT(),'SRID=4326;POINT(4.8634 50.47382)'); + } + + public function testToGeojson() + { + $lon = 4.8634; + $lat = 50.47382; + $point = $this->preparePoint($lon, $lat); + + $this->assertEquals($point->toGeoJson(),'{"type":"Point","coordinates":[4.8634,50.47382]}'); + } + + public function testToArrayGeoJson() + { + $lon = 4.8634; + $lat = 50.47382; + $point = $this->preparePoint($lon, $lat); + + $this->assertEquals( + $point->toArrayGeoJson(), + [ + 'type' => 'Point', + 'coordinates' => [4.8634, 50.47382] + ] + ); + } + + public function testJsonSerialize() + { + $lon = 4.8634; + $lat = 50.47382; + $point = $this->preparePoint($lon, $lat); + + $this->assertEquals( + $point->jsonSerialize(), + [ + 'type' => 'Point', + 'coordinates' => [4.8634, 50.47382] + ] + ); + } + + public function testFromGeoJson() + { + $geojson = '{"type":"Point","coordinates":[4.8634,50.47382]}'; + $lon = 4.8634; + $lat = 50.47382; + $point = $this->preparePoint($lon, $lat);; + + $this->assertEquals($point, Point::fromGeoJson($geojson)); + } + + public function testFromLonLat() + { + $lon = 4.8634; + $lat = 50.47382; + $point = $this->preparePoint($lon, $lat);; + + $this->assertEquals($point, Point::fromLonLat($lon, $lat)); + } + + public function testFromArrayGeoJson() + { + $array = [ + 'type' => 'Point', + 'coordinates' => [4.8634, 50.47382] + ]; + $lon = 4.8634; + $lat = 50.47382; + $point = $this->preparePoint($lon, $lat);; + + $this->assertEquals($point, Point::fromArrayGeoJson($array)); + } + + public function testGetLat() + { + $lon = 4.8634; + $lat = 50.47382; + $point = $this->preparePoint($lon, $lat);; + + $this->assertEquals($lat, $point->getLat()); + } + + public function testGetLon() + { + $lon = 4.8634; + $lat = 50.47382; + $point = $this->preparePoint($lon, $lat);; + + $this->assertEquals($lon, $point->getLon()); + } + + private function preparePoint($lon, $lat) + { + return Point::fromLonLat($lon, $lat); + } + +}