test: Smoke für Farben und Variablen gegen Divi 5.15.1; docs: Formate-Nachtrag 4c, Variablen nur archivieren (Spec §7.2)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
0893b7e184
commit
bb2377991d
+150
@@ -0,0 +1,150 @@
|
||||
#!/usr/bin/env bash
|
||||
# End-to-end checks of Etappe 4c (global colors and variables: create, relative color, cycle, main color, archive,
|
||||
# detach on a page, snapshots, restore) through the OAuth-protected endpoint against the real Divi. Runs INSIDE the
|
||||
# DDEV web container:
|
||||
# cd /home/janniclas/Projekte/WordPress && timeout 900 ddev exec bash wp-content/plugins/WP-LIT-MCP/tests/Integration/divi-colors-variables-smoke.sh
|
||||
# Creates colors/variables named "LIT Smoke <run> …" and one draft page. The EXIT trap puts the options et_divi (colors,
|
||||
# customizer colors) and et_divi_global_variables back to what they were and deletes the page by exact ID.
|
||||
set -euo pipefail
|
||||
cd /var/www/html
|
||||
# shellcheck source=lib.sh
|
||||
source wp-content/plugins/WP-LIT-MCP/tests/Integration/lib.sh
|
||||
|
||||
ADMIN_LOGIN=$(wp user list --role=administrator --field=user_login | head -1)
|
||||
RUN="$(date +%s)-$$"
|
||||
PREFIX="LIT Smoke $RUN"
|
||||
ORIGINAL_THEME=$(wp option get et_divi --format=json 2>/dev/null || echo '{}')
|
||||
ORIGINAL_VARIABLES=$(wp option get et_divi_global_variables --format=json 2>/dev/null || echo '{}')
|
||||
PAGE_ID=""
|
||||
|
||||
cleanup() {
|
||||
printf '%s' "$LIT_THEME" | wp option update et_divi --format=json >/dev/null 2>&1 \
|
||||
|| echo "WARN: et_divi not restored"
|
||||
printf '%s' "$LIT_VARIABLES" | wp option update et_divi_global_variables --format=json >/dev/null 2>&1 \
|
||||
|| echo "WARN: global variables not restored"
|
||||
wp eval 'ET_Core_PageResource::remove_static_resources("all", "all", true);' >/dev/null 2>&1 || true
|
||||
if [ -n "$PAGE_ID" ]; then wp post delete "$PAGE_ID" --force >/dev/null 2>&1 || true; fi
|
||||
cleanup_app_passwords_for "$ADMIN_LOGIN"
|
||||
}
|
||||
export LIT_THEME="$ORIGINAL_THEME" LIT_VARIABLES="$ORIGINAL_VARIABLES"
|
||||
trap 'rc=$?; cleanup; guard_exit "$rc" || exit $?' EXIT
|
||||
|
||||
connect "$ADMIN_LOGIN"
|
||||
|
||||
# confirm <tool> <input JSON>: dry run must answer confirm_required; then the confirmed call; prints the result.
|
||||
confirm() {
|
||||
local dry rev
|
||||
dry=$(ability "$1" "$2")
|
||||
[ "$(error_code "$dry")" = "confirm_required" ] || fail "$1 dry run: $dry"
|
||||
rev=$(echo "$dry" | jq -r '.__error | fromjson | .design_rev')
|
||||
ability "$1" "$(echo "$2" | jq -c --arg r "$rev" '. + {confirm: true, design_rev: $r}')"
|
||||
}
|
||||
stored_color() { # $1 = label -> the stored color value
|
||||
wp eval "foreach (ET\Builder\Packages\GlobalData\GlobalData::get_global_colors() as \$c) { if ((\$c['label'] ?? '') === '$1') { echo \$c['color']; } }"
|
||||
}
|
||||
color_id() { # $1 = label
|
||||
wp eval "foreach (ET\Builder\Packages\GlobalData\GlobalData::get_global_colors() as \$id => \$c) { if ((\$c['label'] ?? '') === '$1') { echo \$id; } }"
|
||||
}
|
||||
variable_field() { # $1 = label, $2 = field
|
||||
wp eval "foreach (ET\Builder\Packages\GlobalData\GlobalData::get_global_variables() as \$items) { foreach ((array) \$items as \$v) { \$v = (array) \$v; if ((\$v['label'] ?? '') === '$1') { echo \$v['$2'] ?? ''; } } }"
|
||||
}
|
||||
|
||||
# 1. Create a color: dry run, confirm, stale design_rev, stored in Divi.
|
||||
NEW=$(jq -cn --arg l "$PREFIX Holz" '{items: [{label: $l, color: "#5b3a29"}]}')
|
||||
DONE=$(confirm lit/divi-colors-set "$NEW")
|
||||
[ "$(echo "$DONE" | jq -r '.ok')" = "true" ] || fail "colors create: $DONE"
|
||||
COLORS_SNAPSHOT=$(echo "$DONE" | jq -r '.snapshot_id')
|
||||
[ "$(stored_color "$PREFIX Holz")" = "#5b3a29" ] || fail "color not stored"
|
||||
STALE=$(ability lit/divi-colors-set "$(echo "$NEW" | jq -c '.items[0].label += " 2" | . + {confirm: true, design_rev: "veraltet"}')")
|
||||
[ "$(error_code "$STALE")" = "rev_mismatch" ] || fail "stale design_rev: $STALE"
|
||||
pass "color created ($COLORS_SNAPSHOT), stale design_rev refused"
|
||||
|
||||
# 2. A relative color from a placeholder; a cycle is refused.
|
||||
REL=$(jq -cn --arg l "$PREFIX Holz hell" --arg b "{{color:$PREFIX Holz}}" \
|
||||
'{items: [{label: $l, color: $b, relative: {lightness: 20}}]}')
|
||||
DONE=$(confirm lit/divi-colors-set "$REL")
|
||||
[ "$(echo "$DONE" | jq -r '.ok')" = "true" ] || fail "relative color: $DONE"
|
||||
BASE_ID=$(color_id "$PREFIX Holz")
|
||||
stored_color "$PREFIX Holz hell" | grep -q "$BASE_ID" || fail "relative color does not reference $BASE_ID"
|
||||
CYCLE=$(jq -cn --arg l "$PREFIX Holz" --arg b "{{color:$PREFIX Holz hell}}" \
|
||||
'{items: [{id: $l, color: $b, relative: {lightness: 5}}]}')
|
||||
[ "$(error_code "$(ability lit/divi-colors-set "$CYCLE")")" = "validation_failed" ] || fail "cycle not refused"
|
||||
pass "relative color stored, cycle refused"
|
||||
|
||||
# 3. A main color changes the customizer option and reads back at once.
|
||||
OLD_PRIMARY=$(wp eval 'echo et_get_option("accent_color", "#2ea3f2");')
|
||||
NEW_PRIMARY="#123456"; [ "$OLD_PRIMARY" = "$NEW_PRIMARY" ] && NEW_PRIMARY="#654321"
|
||||
DONE=$(confirm lit/divi-colors-set "$(jq -cn --arg c "$NEW_PRIMARY" '{items: [{id: "primary", color: $c}]}')")
|
||||
[ "$(echo "$DONE" | jq -r '.ok')" = "true" ] || fail "main color: $DONE"
|
||||
[ "$(wp eval 'echo et_get_option("accent_color");')" = "$NEW_PRIMARY" ] || fail "accent_color not written"
|
||||
pass "main color written to the customizer option"
|
||||
|
||||
# 4. Deactivating a color is a status change, not a removal.
|
||||
DONE=$(confirm lit/divi-colors-set "$(jq -cn --arg l "$PREFIX Holz hell" '{items: [{id: $l, status: "inactive"}]}')")
|
||||
[ "$(echo "$DONE" | jq -r '.ok')" = "true" ] || fail "deactivate: $DONE"
|
||||
wp eval "foreach (ET\Builder\Packages\GlobalData\GlobalData::get_global_colors() as \$c) { if ((\$c['label'] ?? '') === '$PREFIX Holz hell') { exit(\$c['status'] === 'inactive' ? 0 : 1); } } exit(1);" \
|
||||
|| fail "color not inactive"
|
||||
pass "color deactivated"
|
||||
|
||||
# 5. Variables: create a number variable, archive it (never deleted, V1).
|
||||
VAR=$(jq -cn --arg l "$PREFIX Radius" '{items: [{type: "numbers", label: $l, value: "12px"}]}')
|
||||
DONE=$(confirm lit/divi-variables-set "$VAR")
|
||||
[ "$(echo "$DONE" | jq -r '.ok')" = "true" ] || fail "variable create: $DONE"
|
||||
VARIABLES_SNAPSHOT=$(echo "$DONE" | jq -r '.snapshot_id')
|
||||
[ "$(variable_field "$PREFIX Radius" value)" = "12px" ] || fail "variable not stored"
|
||||
VAR_ID=$(variable_field "$PREFIX Radius" id)
|
||||
case "$VAR_ID" in gvid-??????????) ;; *) fail "variable id format: $VAR_ID" ;; esac
|
||||
pass "variable created ($VARIABLES_SNAPSHOT, $VAR_ID)"
|
||||
|
||||
# 6. A page uses the variable; detach replaces the reference by its value.
|
||||
PAGE_ID=$(wp post create --post_type=page --post_status=draft --post_title="$PREFIX Seite" --post_content="$(wp eval "
|
||||
\$ref = '\$variable(' . wp_json_encode(['type' => 'content', 'value' => ['name' => '$VAR_ID', 'settings' => new stdClass()]]) . ')\$';
|
||||
\$text = ['content' => ['innerContent' => ['desktop' => ['value' => 'Hallo']]],
|
||||
'module' => ['decoration' => ['spacing' => ['desktop' => ['value' => ['padding' => ['top' => \$ref]]]]]]];
|
||||
echo serialize_block(['blockName' => 'divi/placeholder', 'attrs' => [], 'innerBlocks' => [
|
||||
['blockName' => 'divi/section', 'attrs' => [], 'innerBlocks' => [
|
||||
['blockName' => 'divi/row', 'attrs' => [], 'innerBlocks' => [
|
||||
['blockName' => 'divi/column', 'attrs' => ['module' => ['decoration' => ['sizing' => ['desktop' => ['value' => ['flexType' => '24_24']]]]]], 'innerBlocks' => [
|
||||
['blockName' => 'divi/text', 'attrs' => \$text, 'innerBlocks' => [], 'innerHTML' => '', 'innerContent' => []],
|
||||
], 'innerHTML' => '', 'innerContent' => [null]],
|
||||
], 'innerHTML' => '', 'innerContent' => [null]],
|
||||
], 'innerHTML' => '', 'innerContent' => [null]],
|
||||
], 'innerHTML' => '', 'innerContent' => [null]]);
|
||||
")" --porcelain)
|
||||
wp post get "$PAGE_ID" --field=post_content | grep -q "$VAR_ID" || fail "page does not reference the variable"
|
||||
DETACH=$(jq -cn --arg v "$VAR_ID" --argjson p "$PAGE_ID" '{variable: $v, post_ids: [$p]}')
|
||||
DRY=$(ability lit/divi-design-detach "$DETACH")
|
||||
[ "$(error_code "$DRY")" = "confirm_required" ] || fail "detach dry run: $DRY"
|
||||
DONE=$(ability lit/divi-design-detach "$(echo "$DETACH" | jq -c '. + {confirm: true}')")
|
||||
[ "$(echo "$DONE" | jq -r '.ok')" = "true" ] || fail "detach: $DONE"
|
||||
CONTENT=$(wp post get "$PAGE_ID" --field=post_content)
|
||||
echo "$CONTENT" | grep -q "$VAR_ID" && fail "reference still in the page"
|
||||
echo "$CONTENT" | grep -q '12px' || fail "value not written into the page"
|
||||
pass "variable detached from the page (reference replaced by 12px)"
|
||||
|
||||
# 7. Archive the variable; it stays in the option with status archived.
|
||||
DONE=$(confirm lit/divi-variables-set "$(jq -cn --arg l "$PREFIX Radius" '{items: [{id: $l, status: "archived"}]}')")
|
||||
[ "$(echo "$DONE" | jq -r '.ok')" = "true" ] || fail "archive: $DONE"
|
||||
[ "$(variable_field "$PREFIX Radius" status)" = "archived" ] || fail "variable not archived"
|
||||
pass "variable archived, not removed"
|
||||
|
||||
# 8. Restore the variables snapshot taken before step 5: the variable created later stays, archived (V1).
|
||||
LIST=$(ability lit/divi-design-snapshots '{"area": "variables"}')
|
||||
echo "$LIST" | jq -e --arg s "$VARIABLES_SNAPSHOT" 'any(.snapshots[]; .id == $s)' >/dev/null || fail "snapshot not listed: $LIST"
|
||||
# Activate it again first: restoring while it is already archived would be a no-op without confirm_required.
|
||||
DONE=$(confirm lit/divi-variables-set "$(jq -cn --arg l "$PREFIX Radius" '{items: [{id: $l, status: "active"}]}')")
|
||||
[ "$(echo "$DONE" | jq -r '.ok')" = "true" ] || fail "reactivate: $DONE"
|
||||
[ "$(variable_field "$PREFIX Radius" status)" = "active" ] || fail "variable not active again"
|
||||
DONE=$(confirm lit/divi-design-restore "$(jq -cn --arg s "$VARIABLES_SNAPSHOT" '{snapshot_id: $s}')")
|
||||
[ "$(echo "$DONE" | jq -r '.ok')" = "true" ] || fail "variables restore: $DONE"
|
||||
[ "$(variable_field "$PREFIX Radius" status)" = "archived" ] || fail "variable lost by the restore"
|
||||
pass "variables restored, the later variable stays archived"
|
||||
|
||||
# 9. Restore the colors snapshot taken before step 1: the colors of this run are gone, the main color is back.
|
||||
DONE=$(confirm lit/divi-design-restore "$(jq -cn --arg s "$COLORS_SNAPSHOT" '{snapshot_id: $s}')")
|
||||
[ "$(echo "$DONE" | jq -r '.ok')" = "true" ] || fail "colors restore: $DONE"
|
||||
[ -z "$(color_id "$PREFIX Holz")" ] || fail "restored colors still hold the new color"
|
||||
[ "$(wp eval 'echo et_get_option("accent_color", "#2ea3f2");')" = "$OLD_PRIMARY" ] || fail "main color not restored"
|
||||
pass "colors restored (new colors gone, main color back)"
|
||||
|
||||
finish
|
||||
Reference in New Issue
Block a user