++ Prima versione del designer piantine + Skill grafica
This commit is contained in:
117
tests/Unit/PiantineAreaTest.php
Normal file
117
tests/Unit/PiantineAreaTest.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\Services\Piantine\PiantineArea;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use RuntimeException;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Il KML dell'area citta': dal file caricato alla FeatureCollection su disco.
|
||||
*
|
||||
* I KML reali arrivano da sorgenti diverse (Google My Maps, Google Earth,
|
||||
* export storici) e dichiarano il namespace in modi diversi: il parsing deve
|
||||
* digerirli tutti, perche' l'amministratore non puo' "sistemare" un KML.
|
||||
*/
|
||||
class PiantineAreaTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private const KML_POLIGONO = <<<'XML'
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<kml xmlns="http://www.opengis.net/kml/2.2">
|
||||
<Document>
|
||||
<Placemark>
|
||||
<name>Area centro</name>
|
||||
<Polygon><outerBoundaryIs><LinearRing>
|
||||
<coordinates>
|
||||
13.35,38.11,0 13.37,38.11,0 13.37,38.13,0 13.35,38.11,0
|
||||
</coordinates>
|
||||
</LinearRing></outerBoundaryIs></Polygon>
|
||||
</Placemark>
|
||||
</Document>
|
||||
</kml>
|
||||
XML;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Storage::fake('local');
|
||||
}
|
||||
|
||||
public function test_un_poligono_con_namespace_ogc_viene_riconosciuto(): void
|
||||
{
|
||||
$geojson = (new PiantineArea())->kmlInGeoJson(self::KML_POLIGONO);
|
||||
|
||||
$this->assertSame('FeatureCollection', $geojson['type']);
|
||||
$this->assertCount(1, $geojson['features']);
|
||||
|
||||
$feature = $geojson['features'][0];
|
||||
$this->assertSame('Area centro', $feature['properties']['name']);
|
||||
$this->assertSame('Polygon', $feature['geometry']['type']);
|
||||
$this->assertSame([13.35, 38.11], $feature['geometry']['coordinates'][0][0]);
|
||||
$this->assertCount(4, $feature['geometry']['coordinates'][0]);
|
||||
}
|
||||
|
||||
public function test_una_linestring_senza_namespace_viene_riconosciuta(): void
|
||||
{
|
||||
$kml = <<<'XML'
|
||||
<?xml version="1.0"?>
|
||||
<kml><Document><Folder><Placemark>
|
||||
<name>Perimetro</name>
|
||||
<LineString><coordinates>13.1,38.1 13.2,38.2 13.3,38.1</coordinates></LineString>
|
||||
</Placemark></Folder></Document></kml>
|
||||
XML;
|
||||
|
||||
$geojson = (new PiantineArea())->kmlInGeoJson($kml);
|
||||
|
||||
$this->assertCount(1, $geojson['features']);
|
||||
$this->assertSame('LineString', $geojson['features'][0]['geometry']['type']);
|
||||
$this->assertCount(3, $geojson['features'][0]['geometry']['coordinates']);
|
||||
}
|
||||
|
||||
public function test_un_kml_senza_geometrie_viene_rifiutato(): void
|
||||
{
|
||||
$this->expectException(RuntimeException::class);
|
||||
|
||||
(new PiantineArea())->salvaKml('<kml><Document></Document></kml>', 'vuoto.kml');
|
||||
}
|
||||
|
||||
public function test_un_file_non_xml_viene_rifiutato(): void
|
||||
{
|
||||
$this->expectException(RuntimeException::class);
|
||||
|
||||
(new PiantineArea())->salvaKml('questo non è xml', 'rotto.kml');
|
||||
}
|
||||
|
||||
public function test_salva_kml_scrive_area_e_configurazione(): void
|
||||
{
|
||||
$area = new PiantineArea();
|
||||
|
||||
$quante = $area->salvaKml(self::KML_POLIGONO, 'citta.kml');
|
||||
|
||||
$this->assertSame(1, $quante);
|
||||
Storage::disk('local')->assertExists('piantine/area.kml');
|
||||
Storage::disk('local')->assertExists('piantine/area.geojson');
|
||||
|
||||
$this->assertSame('citta.kml', $area->config()['kml_nome']);
|
||||
$this->assertSame('Polygon', $area->area()['features'][0]['geometry']['type']);
|
||||
}
|
||||
|
||||
public function test_la_localita_esplicita_vince_sul_nome_congregazione(): void
|
||||
{
|
||||
\App\Models\Setting::firstOrCreate([], ['congregazione_nome' => 'Congregazione di prova']);
|
||||
|
||||
$area = new PiantineArea();
|
||||
$this->assertSame('Congregazione di prova', $area->localita());
|
||||
|
||||
$area->impostaLocalita('Palermo Nord');
|
||||
$this->assertSame('Palermo Nord', $area->localita());
|
||||
|
||||
// Svuotarla riporta al nome della congregazione.
|
||||
$area->impostaLocalita(' ');
|
||||
$this->assertSame('Congregazione di prova', $area->localita());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user