fix
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Tests\TestCase;
|
||||
|
||||
class VMangosSiteCredentialsMigrationTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
config([
|
||||
'database.default' => 'migration_test',
|
||||
'database.connections.migration_test' => ['driver' => 'sqlite', 'database' => ':memory:', 'prefix' => ''],
|
||||
]);
|
||||
DB::purge('migration_test');
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
DB::purge('migration_test');
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function test_fresh_install_and_repeated_migrations_preserve_web_mappings(): void
|
||||
{
|
||||
$create = require database_path('migrations/2026_10_03_000002_create_vmangos_site_credentials.php');
|
||||
$link = require database_path('migrations/2026_10_04_000001_add_web_user_id_to_vmangos_site_credentials.php');
|
||||
$create->up();
|
||||
$link->up();
|
||||
DB::table('site_credentials')->insert(['account_id' => 1, 'web_user_id' => 42]);
|
||||
|
||||
$create->up();
|
||||
$link->up();
|
||||
$this->assertDatabaseHas('site_credentials', [
|
||||
'account_id' => 1, 'web_user_id' => 42, 'salt_hex' => null, 'verifier_hex' => null,
|
||||
]);
|
||||
$this->assertSame(1, DB::table('site_credentials')->count());
|
||||
|
||||
$link->down();
|
||||
$create->down();
|
||||
$this->assertDatabaseHas('site_credentials', ['account_id' => 1, 'web_user_id' => 42]);
|
||||
}
|
||||
|
||||
public function test_existing_legacy_table_is_upgraded_without_losing_credentials(): void
|
||||
{
|
||||
Schema::create('site_credentials', function (Blueprint $table): void {
|
||||
$table->unsignedInteger('account_id')->primary();
|
||||
$table->unsignedInteger('legacy_account_id')->nullable()->unique();
|
||||
$table->char('salt_hex', 64);
|
||||
$table->char('verifier_hex', 64);
|
||||
$table->timestamps();
|
||||
});
|
||||
DB::table('site_credentials')->insert([
|
||||
'account_id' => 7, 'legacy_account_id' => 17,
|
||||
'salt_hex' => str_repeat('A', 64), 'verifier_hex' => str_repeat('B', 64),
|
||||
]);
|
||||
|
||||
$create = require database_path('migrations/2026_10_03_000002_create_vmangos_site_credentials.php');
|
||||
$link = require database_path('migrations/2026_10_04_000001_add_web_user_id_to_vmangos_site_credentials.php');
|
||||
$create->up();
|
||||
$link->up();
|
||||
$this->assertDatabaseHas('site_credentials', [
|
||||
'account_id' => 7, 'legacy_account_id' => 17, 'web_user_id' => null,
|
||||
'salt_hex' => str_repeat('A', 64), 'verifier_hex' => str_repeat('B', 64),
|
||||
]);
|
||||
DB::table('site_credentials')->insert(['account_id' => 8, 'web_user_id' => 28]);
|
||||
$this->assertDatabaseHas('site_credentials', ['account_id' => 8, 'salt_hex' => null, 'verifier_hex' => null]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user