MySQL: JSON-Schlüsselreihenfolge darf keine Rolle spielen
All checks were successful
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m40s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m23s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m53s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m47s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 3m2s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 3m5s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 2m50s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 2m41s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m6s

MySQL speichert Schlüssel in JSON-Spalten sortiert, MariaDB unverändert.
- Seiten: „Stand unverändert → kein Entwurf“ vergleicht jetzt unabhängig von der
  Schlüsselreihenfolge (auf MySQL entstand sonst bei jedem Speichern ein Entwurf)
- Formulare: Antworten in Ergebnisansicht und E-Mail in der Reihenfolge des Formulars
- Tests vergleichen assoziative Arrays ohne Reihenfolge; neue Tests dafür

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-26 11:22:46 +00:00
parent 21c706e5f5
commit 2b5fe55f8e
9 changed files with 92 additions and 6 deletions

View file

@ -0,0 +1,46 @@
<?php
namespace Tests\Unit;
use App\Pagebuilder\Content;
use Inhaus\Plugins\Forms\Models\Form;
use Inhaus\Plugins\Forms\Models\FormSubmission;
use Tests\TestCase;
/**
* MySQL speichert Schlüssel in JSON-Spalten sortiert (MariaDB nicht). Nichts
* Fachliches darf von dieser Reihenfolge abhängen.
*/
class JsonKeyOrderTest extends TestCase
{
public function test_content_comparison_ignores_key_order(): void
{
$a = ['blocks' => [['id' => 'abcd1234', 'type' => 'heading', 'data' => ['text' => 'Hallo', 'level' => '2', 'align' => 'left']]]];
$b = ['blocks' => [['data' => ['align' => 'left', 'level' => '2', 'text' => 'Hallo'], 'type' => 'heading', 'id' => 'abcd1234']]];
$c = ['blocks' => [['id' => 'abcd1234', 'type' => 'heading', 'data' => ['text' => 'Anders', 'level' => '2', 'align' => 'left']]]];
$swapped = ['blocks' => array_reverse([...$a['blocks'], ...$c['blocks']])];
$this->assertTrue(Content::same($a, $b));
$this->assertFalse(Content::same($a, $c));
$this->assertFalse(Content::same(['blocks' => [...$a['blocks'], ...$c['blocks']]], $swapped), 'Die Reihenfolge von Blöcken zählt.');
}
public function test_form_answers_follow_the_form_order(): void
{
$form = new Form(['fields' => [
['type' => 'text', 'data' => ['label' => 'Name', 'key' => 'name']],
['type' => 'text', 'data' => ['label' => 'Abteilung', 'key' => 'abteilung']],
['type' => 'textarea', 'data' => ['label' => 'Begründung', 'key' => 'begruendung']],
]]);
$submission = new FormSubmission(['data' => [
'altfeld' => ['label' => 'Altes Feld', 'type' => 'text', 'value' => 'x'],
'begruendung' => ['label' => 'Begründung', 'type' => 'textarea', 'value' => 'weil'],
'name' => ['label' => 'Name', 'type' => 'text', 'value' => 'Anna'],
'abteilung' => ['label' => 'Abteilung', 'type' => 'text', 'value' => 'Pflege'],
]]);
$submission->setRelation('form', $form);
$this->assertSame(['name', 'abteilung', 'begruendung', 'altfeld'], array_keys($submission->orderedAnswers()));
}
}