++ Prima versione del designer piantine + Skill grafica

This commit is contained in:
2026-08-28 15:32:14 +02:00
parent 8aa29cc467
commit 7e4c8aa9b8
62 changed files with 16340 additions and 4 deletions

View File

@@ -0,0 +1,86 @@
<?php
namespace Tests\Unit;
use App\Models\Territorio;
use App\Models\TerritorioMappa;
use App\Services\Piantine\PiantinaRenderer;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Storage;
use RuntimeException;
use Tests\TestCase;
/**
* Il client del container map-renderer: cosa succede quando risponde bene,
* quando risponde con un errore e quando risponde con qualcosa che non e' un
* PNG (un proxy che restituisce una pagina HTML, per esempio).
*/
class PiantinaRendererTest extends TestCase
{
use RefreshDatabase;
private const GEOMETRIA = '{"type":"Polygon","coordinates":[[[13.35,38.11],[13.37,38.11],[13.37,38.13],[13.35,38.11]]]}';
protected function setUp(): void
{
parent::setUp();
Storage::fake('public');
}
private function mappa(): TerritorioMappa
{
$territorio = Territorio::create(['numero' => '42', 'attivo' => true]);
return TerritorioMappa::create([
'territorio_id' => $territorio->id,
'geojson' => self::GEOMETRIA,
]);
}
public function test_un_rendering_riuscito_salva_il_png_e_aggiorna_la_mappa(): void
{
Http::fake(['*/render' => Http::response("\x89PNG\r\n\x1a\ncontenuto-finto")]);
$mappa = $this->mappa();
$path = (new PiantinaRenderer())->render($mappa);
Storage::disk('public')->assertExists($path);
$mappa->refresh();
$this->assertSame($path, $mappa->image_path);
$this->assertNotNull($mappa->rendered_at);
}
public function test_un_errore_del_renderer_diventa_un_messaggio_leggibile(): void
{
Http::fake(['*/render' => Http::response(['error' => 'area troppo estesa'], 413)]);
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('area troppo estesa');
(new PiantinaRenderer())->render($this->mappa());
}
public function test_una_risposta_che_non_e_un_png_viene_rifiutata(): void
{
Http::fake(['*/render' => Http::response('<html>proxy error</html>')]);
$this->expectException(RuntimeException::class);
(new PiantinaRenderer())->render($this->mappa());
}
public function test_una_geometria_corrotta_blocca_prima_di_chiamare_il_renderer(): void
{
Http::fake();
$mappa = $this->mappa();
$mappa->update(['geojson' => 'non-json']);
$this->expectException(RuntimeException::class);
(new PiantinaRenderer())->render($mappa->refresh());
Http::assertNothingSent();
}
}