From d092c0531145a49a638d623b18a84976db09cbff Mon Sep 17 00:00:00 2001 From: Jan-Niclas Loosen Date: Mon, 19 Oct 2026 14:40:13 +0200 Subject: [PATCH] fix: VariableArea::verify vergleicht auch den Namen; Docstring beschreibt, was verify und differences wirklich fangen Co-Authored-By: Claude Sonnet 5.5 --- src/Integrations/Divi/Design/VariableArea.php | 20 ++++++++++++++----- .../Divi/Design/VariableAreaTest.php | 9 +++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/Integrations/Divi/Design/VariableArea.php b/src/Integrations/Divi/Design/VariableArea.php index 14307d1..dc58dcc 100644 --- a/src/Integrations/Divi/Design/VariableArea.php +++ b/src/Integrations/Divi/Design/VariableArea.php @@ -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 $raw - * @return array "type/id" => [status, has a value], sorted + * @return array "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'] ?? ''), ]; } } diff --git a/tests/Unit/Integrations/Divi/Design/VariableAreaTest.php b/tests/Unit/Integrations/Divi/Design/VariableAreaTest.php index c57dba8..ec423ce 100644 --- a/tests/Unit/Integrations/Divi/Design/VariableAreaTest.php +++ b/tests/Unit/Integrations/Divi/Design/VariableAreaTest.php @@ -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) + ); } }