|
| 1 | +<?php |
| 2 | + |
| 3 | +use Phaza\LaravelPostgis\Geometries\Point; |
| 4 | +use Phaza\LaravelPostgis\Geometries\MultiPoint; |
| 5 | +use Phaza\LaravelPostgis\Geometries\LineString; |
| 6 | +use Phaza\LaravelPostgis\Geometries\MultiLineString; |
| 7 | +use Phaza\LaravelPostgis\Geometries\Polygon; |
| 8 | +use Phaza\LaravelPostgis\Geometries\MultiPolygon; |
| 9 | +use Phaza\LaravelPostgis\Geometries\GeometryCollection; |
| 10 | + |
| 11 | +class UnderLocaleTest extends BaseTestCase |
| 12 | +{ |
| 13 | + |
| 14 | + public static function setUpBeforeClass() |
| 15 | + { |
| 16 | + setlocale(LC_NUMERIC, 'fr_FR.utf-8'); |
| 17 | + } |
| 18 | + |
| 19 | + public static function tearDownAfterClass() |
| 20 | + { |
| 21 | + setlocale(LC_NUMERIC, null); |
| 22 | + } |
| 23 | + |
| 24 | + public function setUp() |
| 25 | + { |
| 26 | + if(localeconv()['decimal_point'] == '.') { |
| 27 | + $this->markTestSkipped('The locale is not available for testing float output formatting'); |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + public function testPointToWKT() |
| 32 | + { |
| 33 | + $point = new Point(1.5, 2.5); |
| 34 | + $this->assertEquals('POINT(2.5 1.5)', $point->toWKT()); |
| 35 | + } |
| 36 | + |
| 37 | + public function testMultiPointToWKT() |
| 38 | + { |
| 39 | + $multipoint = new MultiPoint([new Point(1.5, 1.5), new Point(1.5, 2.5), new Point(2.5, 2.5)]); |
| 40 | + |
| 41 | + $this->assertEquals('MULTIPOINT((1.5 1.5),(2.5 1.5),(2.5 2.5))', $multipoint->toWKT()); |
| 42 | + } |
| 43 | + |
| 44 | + public function testLineStringToWKT() |
| 45 | + { |
| 46 | + $linestring = new LineString([new Point(1.5, 1.5), new Point(2.5, 2.5), new Point(3.5, 3.5)]); |
| 47 | + |
| 48 | + $this->assertEquals('LINESTRING(1.5 1.5,2.5 2.5,3.5 3.5)', $linestring->toWKT()); |
| 49 | + } |
| 50 | + |
| 51 | + public function testMultiLineStringToWKT() |
| 52 | + { |
| 53 | + $collection = new LineString( |
| 54 | + [ |
| 55 | + new Point(1.5, 1.5), |
| 56 | + new Point(1.5, 2.5), |
| 57 | + new Point(2.5, 2.5), |
| 58 | + new Point(2.5, 1.5), |
| 59 | + new Point(1.5, 1.5) |
| 60 | + ] |
| 61 | + ); |
| 62 | + |
| 63 | + $multilinestring = new MultiLineString([$collection]); |
| 64 | + |
| 65 | + $this->assertSame('MULTILINESTRING((1.5 1.5,2.5 1.5,2.5 2.5,1.5 2.5,1.5 1.5))', $multilinestring->toWKT()); |
| 66 | + } |
| 67 | + |
| 68 | + public function testPolygonToWKT() |
| 69 | + { |
| 70 | + $collection = new LineString( |
| 71 | + [ |
| 72 | + new Point(1.5, 1.5), |
| 73 | + new Point(1.5, 2.5), |
| 74 | + new Point(2.5, 2.5), |
| 75 | + new Point(2.5, 1.5), |
| 76 | + new Point(1.5, 1.5) |
| 77 | + ] |
| 78 | + ); |
| 79 | + |
| 80 | + $polygon = new Polygon([$collection]); |
| 81 | + |
| 82 | + $this->assertEquals('POLYGON((1.5 1.5,2.5 1.5,2.5 2.5,1.5 2.5,1.5 1.5))', $polygon->toWKT()); |
| 83 | + } |
| 84 | + |
| 85 | + public function testMultiPolygonToWKT() |
| 86 | + { |
| 87 | + $collection1 = new LineString( |
| 88 | + [ |
| 89 | + new Point(1.5, 1.5), |
| 90 | + new Point(1.5, 2.5), |
| 91 | + new Point(2.5, 2.5), |
| 92 | + new Point(2.5, 1.5), |
| 93 | + new Point(1.5, 1.5) |
| 94 | + ] |
| 95 | + ); |
| 96 | + |
| 97 | + $collection2 = new LineString( |
| 98 | + [ |
| 99 | + new Point(10.5, 10.5), |
| 100 | + new Point(10.5, 20.5), |
| 101 | + new Point(20.5, 20.5), |
| 102 | + new Point(20.5, 10.5), |
| 103 | + new Point(10.5, 10.5) |
| 104 | + ] |
| 105 | + ); |
| 106 | + |
| 107 | + $polygon1 = new Polygon([$collection1, $collection2]); |
| 108 | + |
| 109 | + $collection3 = new LineString( |
| 110 | + [ |
| 111 | + new Point(100.5, 100.5), |
| 112 | + new Point(100.5, 200.5), |
| 113 | + new Point(200.5, 200.5), |
| 114 | + new Point(200.5, 100.5), |
| 115 | + new Point(100.5, 100.5) |
| 116 | + ] |
| 117 | + ); |
| 118 | + |
| 119 | + $polygon2 = new Polygon([$collection3]); |
| 120 | + |
| 121 | + $multiPolygon = new MultiPolygon([$polygon1, $polygon2]); |
| 122 | + |
| 123 | + $this->assertEquals( |
| 124 | + 'MULTIPOLYGON(((1.5 1.5,2.5 1.5,2.5 2.5,1.5 2.5,1.5 1.5),(10.5 10.5,20.5 10.5,20.5 20.5,10.5 20.5,10.5 10.5)),((100.5 100.5,200.5 100.5,200.5 200.5,100.5 200.5,100.5 100.5)))', |
| 125 | + $multiPolygon->toWKT() |
| 126 | + ); |
| 127 | + } |
| 128 | + |
| 129 | + public function testGeometryCollectionToWKT() |
| 130 | + { |
| 131 | + $collection = new LineString( |
| 132 | + [ |
| 133 | + new Point(1.5, 1.5), |
| 134 | + new Point(1.5, 2.5), |
| 135 | + new Point(2.5, 2.5), |
| 136 | + new Point(2.5, 1.5), |
| 137 | + new Point(1.5, 1.5) |
| 138 | + ] |
| 139 | + ); |
| 140 | + |
| 141 | + $point = new Point(100.5, 200.5); |
| 142 | + |
| 143 | + $geo_collection = new GeometryCollection([$collection, $point]); |
| 144 | + |
| 145 | + $this->assertEquals( |
| 146 | + 'GEOMETRYCOLLECTION(LINESTRING(1.5 1.5,2.5 1.5,2.5 2.5,1.5 2.5,1.5 1.5),POINT(200.5 100.5))', |
| 147 | + $geo_collection->toWKT() |
| 148 | + ); |
| 149 | + } |
| 150 | + |
| 151 | +} |
0 commit comments