fix: VariableArea::verify vergleicht auch den Namen; Docstring beschreibt, was verify und differences wirklich fangen

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Jan-Niclas Loosen
2026-10-19 14:40:13 +02:00
co-authored by Claude Sonnet 5.5
parent 25252c92f2
commit d092c05311
2 changed files with 24 additions and 5 deletions
+15 -5
View File
@@ -13,8 +13,11 @@ defined('ABSPATH') || exit;
* as a whole through GlobalVariablesAdapter::save() together with the inventory read right before, which Divi checks
* for changes in between (global_variables_stale). Divi refuses an inventory that lacks a stored ID, so a restore keeps
* the variables created after the snapshot, archived (VariableBook::restoredFrom()) – also when the pipeline rolls back
* a write that went through. Without the variables_manager right Divi silently saves nothing: verify() compares the
* read-back (same variables, status and non-empty values), differences() names the values Divi sanitized.
* a write that went through. verify() compares the read-back by variable: present or not, status, label and whether
* the value is empty – so missing, added, archived or activated variables, a changed label and an emptied value fail
* it. A missing variables_manager right is refused before writing (DesignRights::variables), not found here. Divi
* dropping or sanitizing a label or value to something else still passes verify(); differences() names those as
* warnings.
*/
final class VariableArea implements DesignArea
{
@@ -74,9 +77,15 @@ final class VariableArea implements DesignArea
public function differences(array $expected, array $actual): array
{
$warnings = [];
$names = ['label' => 'den Namen', 'value' => 'den Wert'];
foreach (VariableDiff::between(VariableBook::fromDivi($expected), VariableBook::fromDivi($actual)) as $row) {
if ($row['action'] === 'changed') {
$warnings[] = sprintf('Divi hat den Wert der Variablen „%s“ beim Speichern bereinigt.', $row['name']);
$what = array_intersect_key($names, array_flip($row['fields'] ?? []));
if ($row['action'] === 'changed' && $what !== []) {
$warnings[] = sprintf(
'Divi hat %s der Variablen „%s“ beim Speichern bereinigt.',
implode(' und ', $what),
$row['name']
);
}
}
@@ -85,7 +94,7 @@ final class VariableArea implements DesignArea
/**
* @param array<array-key, mixed> $raw
* @return array<string, array{0: string, 1: bool}> "type/id" => [status, has a value], sorted
* @return array<string, array{0: string, 1: bool, 2: string}> "type/id" => [status, has a value, label], sorted
*/
private static function shape(array $raw): array
{
@@ -96,6 +105,7 @@ final class VariableArea implements DesignArea
$shape[$type . '/' . $id] = [
(string) ($entry['status'] ?? ''),
is_scalar($value) && (string) $value !== '',
(string) ($entry['label'] ?? ''),
];
}
}
@@ -135,7 +135,11 @@ final class VariableAreaTest extends TestCase
$emptied = $expected;
$emptied['numbers']['gvid-radius0001']['value'] = '';
$relabeled = $expected;
$relabeled['numbers']['gvid-radius0001']['label'] = 'Anders';
self::assertTrue($area->verify($expected, $sanitized));
self::assertFalse($area->verify($expected, $relabeled));
self::assertFalse($area->verify($expected, $missing));
self::assertFalse($area->verify($expected, $archived));
self::assertFalse($area->verify($expected, $emptied));
@@ -155,5 +159,10 @@ final class VariableAreaTest extends TestCase
['Divi hat den Wert der Variablen „Slogan“ beim Speichern bereinigt.'],
$area->differences($expected, $sanitized)
);
$sanitized['strings']['gvid-slogan0001']['label'] = 'Slogan neu';
self::assertSame(
['Divi hat den Namen und den Wert der Variablen „Slogan neu“ beim Speichern bereinigt.'],
$area->differences($expected, $sanitized)
);
}
}