license: built full stack, test and documentation
Some checks failed
docs / build (push) Has been cancelled
docs / deploy (push) Has been cancelled

This commit is contained in:
Giuseppe Naponiello
2026-07-03 12:47:47 +02:00
parent f8206b5840
commit 271acacb1d
39 changed files with 4078 additions and 57 deletions

View File

@@ -0,0 +1,107 @@
<?php
namespace Tests\Feature;
use App\Enums\LicenseKind;
use App\Models\Lists\License;
use Database\Seeders\DatabaseSeeder;
use Database\Seeders\LicenseSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class LicenseSeederTest extends TestCase
{
use RefreshDatabase;
public function test_it_seeds_the_initial_license_set(): void
{
$this->seed(LicenseSeeder::class);
$this->assertSame(11, License::count());
}
public function test_legacy_ids_are_fixed_for_the_etl(): void
{
$this->seed(LicenseSeeder::class);
// v1: 1=Public Domain, 2=CC0, 3=CC BY — l'ETL mappa le FK 1:1.
$this->assertSame('PDM 1.0', License::find(1)?->acronym);
$this->assertSame('CC0 1.0', License::find(2)?->acronym);
$this->assertSame('CC BY 4.0', License::find(3)?->acronym);
}
public function test_only_open_licenses_are_allowed_for_records(): void
{
$this->seed(LicenseSeeder::class);
$this->assertEqualsCanonicalizing(
['CC0-1.0', 'CC-BY-4.0'],
License::forRecord()->pluck('spdx_id')->all()
);
}
public function test_every_license_is_available_for_media(): void
{
$this->seed(LicenseSeeder::class);
$this->assertSame(11, License::forMedia()->count());
$this->assertSame(11, License::active()->count());
}
public function test_marks_and_rights_statements_have_no_spdx_id_and_no_file(): void
{
$this->seed(LicenseSeeder::class);
License::where('kind', '!=', LicenseKind::License)->get()->each(function (License $license): void {
$this->assertNull($license->spdx_id, "{$license->acronym} must have no SPDX id");
$this->assertNull($license->file, "{$license->acronym} must have no legal text file");
});
}
public function test_proper_licenses_have_spdx_id_file_and_uri(): void
{
$this->seed(LicenseSeeder::class);
$proper = License::where('kind', LicenseKind::License)->get();
$this->assertCount(7, $proper);
$proper->each(function (License $license): void {
$this->assertNotNull($license->spdx_id);
$this->assertSame("{$license->spdx_id}.txt", $license->file);
$this->assertNotNull($license->uri);
});
}
public function test_legal_text_files_ship_with_the_application(): void
{
$this->seed(LicenseSeeder::class);
License::whereNotNull('file')->get()->each(function (License $license): void {
$this->assertFileExists(storage_path("app/public/licenses/{$license->file}"));
});
}
public function test_every_entry_has_an_admin_facing_description(): void
{
$this->seed(LicenseSeeder::class);
License::all()->each(function (License $license): void {
$this->assertNotEmpty($license->description, "{$license->acronym} must have a description");
});
}
public function test_it_is_idempotent(): void
{
$this->seed(LicenseSeeder::class);
$this->seed(LicenseSeeder::class);
$this->assertSame(11, License::count());
}
public function test_database_seeder_includes_the_licenses(): void
{
$this->seed(DatabaseSeeder::class);
$this->assertSame(11, License::count());
}
}