From d6fabac1a9de1daf3f232d2d330ea99d88ba00e5 Mon Sep 17 00:00:00 2001 From: Chris Huber Date: Sat, 27 Jun 2026 19:26:02 -0400 Subject: [PATCH] Translate source CSS button styling onto native core/button attributes Imported CTA buttons converted to core/button but carried zero native style attributes (backgroundColor/textColor/style.color/style.border were all empty); the resolved source CSS was only carried as a non-canonical inline style string, so WordPress rendered the buttons with default grey styling after block recovery. This reuses the transformer's existing CSS-rule resolution (mergedPresentationStyle -> matchesCssSelector over
Buy now
" + }, + "expected_blocks": [ + { "path": "blocks.0", "name": "core/buttons" }, + { "path": "blocks.0.innerBlocks.0", "name": "core/button", "attrs": { "text": "Buy now", "url": "/buy", "className": "btn btn-primary", "style": { "color": { "background": "#13314f", "text": "#ffffff" }, "border": { "radius": "6px" }, "spacing": { "padding": { "top": "12px", "right": "24px", "bottom": "12px", "left": "24px" } } } } } + ], + "expected_fallbacks": [], + "expect": [ + { "path": "status", "assert": "equals", "value": "success" }, + { "path": "serialized_blocks", "assert": "contains", "value": "class=\"wp-block-button__link has-text-color has-background wp-element-button btn btn-primary\"" }, + { "path": "serialized_blocks", "assert": "contains", "value": "style=\"color:#ffffff;background-color:#13314f;border-radius:6px;padding-top:12px;padding-right:24px;padding-bottom:12px;padding-left:24px\"" }, + { "path": "serialized_blocks", "assert": "not_contains", "value": "is-style-outline" } + ] +} diff --git a/php-transformer/tests/fixtures/parity/html-button-style-fidelity-outline-from-css.json b/php-transformer/tests/fixtures/parity/html-button-style-fidelity-outline-from-css.json new file mode 100644 index 00000000..0e2b44b3 --- /dev/null +++ b/php-transformer/tests/fixtures/parity/html-button-style-fidelity-outline-from-css.json @@ -0,0 +1,31 @@ +{ + "schema": "blocks-engine/php-transformer/parity-fixture/v1", + "name": "html-button-style-fidelity-outline-from-css", + "description": "Outline/ghost CTA button whose styling lives only in page
Learn more
" + }, + "expected_blocks": [ + { "path": "blocks.0", "name": "core/buttons" }, + { "path": "blocks.0.innerBlocks.0", "name": "core/button", "attrs": { "text": "Learn more", "url": "/learn", "className": "btn btn-ghost is-style-outline", "style": { "color": { "text": "#135e96" }, "border": { "width": "2px", "style": "solid", "color": "#135e96", "radius": "8px" }, "spacing": { "padding": { "top": "12px", "right": "24px", "bottom": "12px", "left": "24px" } } } } } + ], + "expected_fallbacks": [], + "expect": [ + { "path": "status", "assert": "equals", "value": "success" }, + { "path": "serialized_blocks", "assert": "contains", "value": "
" }, + { "path": "serialized_blocks", "assert": "contains", "value": "class=\"wp-block-button__link has-text-color has-border-color wp-element-button btn btn-ghost is-style-outline\"" }, + { "path": "serialized_blocks", "assert": "contains", "value": "style=\"color:#135e96;border-color:#135e96;border-width:2px;border-style:solid;border-radius:8px;padding-top:12px;padding-right:24px;padding-bottom:12px;padding-left:24px\"" }, + { "path": "serialized_blocks", "assert": "not_contains", "value": "background-color" }, + { "path": "serialized_blocks", "assert": "not_contains", "value": "has-background" } + ] +} diff --git a/php-transformer/tests/fixtures/parity/html-button-style-fidelity-unstyled-default.json b/php-transformer/tests/fixtures/parity/html-button-style-fidelity-unstyled-default.json new file mode 100644 index 00000000..b6fb40cb --- /dev/null +++ b/php-transformer/tests/fixtures/parity/html-button-style-fidelity-unstyled-default.json @@ -0,0 +1,30 @@ +{ + "schema": "blocks-engine/php-transformer/parity-fixture/v1", + "name": "html-button-style-fidelity-unstyled-default", + "description": "Negative case: a button-class anchor with no resolvable source color/border CSS is not fabricated with colors. It converts to a default core/button with no style attribute, has-background, or inline color styling.", + "source_reference": { + "repo": "php-transformer", + "path": "tests/fixtures/parity/html-button-style-fidelity-unstyled-default.json", + "notes": "Generic style-fidelity negative fixture: unstyled buttons stay default (issue #233)." + }, + "legacy_comparison": { + "skip": true, + "reason": "New native button style-fidelity behavior has no legacy equivalent." + }, + "operation": "html_transformer.transform", + "input": { + "content": "
Go now
" + }, + "expected_blocks": [ + { "path": "blocks.0", "name": "core/buttons" }, + { "path": "blocks.0.innerBlocks.0", "name": "core/button", "attrs": { "text": "Go now", "url": "/go", "className": "btn cta-link" } } + ], + "expected_fallbacks": [], + "expect": [ + { "path": "status", "assert": "equals", "value": "success" }, + { "path": "serialized_blocks", "assert": "contains", "value": "" }, + { "path": "serialized_blocks", "assert": "not_contains", "value": "has-background" }, + { "path": "serialized_blocks", "assert": "not_contains", "value": "has-text-color" }, + { "path": "serialized_blocks", "assert": "not_contains", "value": "style=" } + ] +} diff --git a/php-transformer/tests/fixtures/parity/html-cta-container-static-css-button-style-signals.json b/php-transformer/tests/fixtures/parity/html-cta-container-static-css-button-style-signals.json index e0a5220b..0829135a 100644 --- a/php-transformer/tests/fixtures/parity/html-cta-container-static-css-button-style-signals.json +++ b/php-transformer/tests/fixtures/parity/html-cta-container-static-css-button-style-signals.json @@ -17,16 +17,16 @@ }, "expected_blocks": [ { "path": "blocks.0", "name": "core/buttons" }, - { "path": "blocks.0.innerBlocks.0", "name": "core/button", "attrs": { "text": "Book now", "url": "/book", "className": "primary", "style": "background-color:#2563eb;color:#fff;border:2px solid #2563eb;border-radius:999px;padding:14px 28px;font-weight:700" } }, - { "path": "blocks.0.innerBlocks.1", "name": "core/button", "attrs": { "text": "Learn more", "url": "/learn", "className": "secondary is-style-outline", "style": "background-color:transparent;color:#2563eb;border:2px solid currentColor;border-radius:999px;padding:14px 28px;font-weight:700" } } + { "path": "blocks.0.innerBlocks.0", "name": "core/button", "attrs": { "text": "Book now", "url": "/book", "className": "primary", "style": { "color": { "background": "#2563eb", "text": "#fff" }, "border": { "width": "2px", "style": "solid", "color": "#2563eb", "radius": "999px" }, "spacing": { "padding": { "top": "14px", "right": "28px", "bottom": "14px", "left": "28px" } }, "typography": { "fontWeight": "700" } } } }, + { "path": "blocks.0.innerBlocks.1", "name": "core/button", "attrs": { "text": "Learn more", "url": "/learn", "className": "secondary is-style-outline", "style": { "color": { "text": "#2563eb" }, "border": { "width": "2px", "style": "solid", "color": "currentColor", "radius": "999px" }, "spacing": { "padding": { "top": "14px", "right": "28px", "bottom": "14px", "left": "28px" } }, "typography": { "fontWeight": "700" } } } } ], "expected_fallbacks": [], "expect": [ { "path": "status", "assert": "equals", "value": "success" }, - { "path": "serialized_blocks", "assert": "contains", "value": "class=\"wp-block-button__link wp-element-button primary\"" }, - { "path": "serialized_blocks", "assert": "contains", "value": "background-color:#2563eb;color:#fff;border:2px solid #2563eb;border-radius:999px;padding:14px 28px;font-weight:700" }, + { "path": "serialized_blocks", "assert": "contains", "value": "class=\"wp-block-button__link has-text-color has-background has-border-color wp-element-button primary\"" }, + { "path": "serialized_blocks", "assert": "contains", "value": "style=\"color:#fff;background-color:#2563eb;border-color:#2563eb;border-width:2px;border-style:solid;border-radius:999px;padding-top:14px;padding-right:28px;padding-bottom:14px;padding-left:28px;font-weight:700\"" }, { "path": "serialized_blocks", "assert": "contains", "value": "class=\"wp-block-button is-style-outline\"" }, - { "path": "serialized_blocks", "assert": "contains", "value": "class=\"wp-block-button__link wp-element-button secondary is-style-outline\"" }, - { "path": "serialized_blocks", "assert": "contains", "value": "background-color:transparent;color:#2563eb;border:2px solid currentColor;border-radius:999px;padding:14px 28px;font-weight:700" } + { "path": "serialized_blocks", "assert": "contains", "value": "class=\"wp-block-button__link has-text-color has-border-color wp-element-button secondary is-style-outline\"" }, + { "path": "serialized_blocks", "assert": "contains", "value": "style=\"color:#2563eb;border-color:currentColor;border-width:2px;border-style:solid;border-radius:999px;padding-top:14px;padding-right:28px;padding-bottom:14px;padding-left:28px;font-weight:700\"" } ] } diff --git a/php-transformer/tests/fixtures/parity/html-source-styled-button-preserves-style.json b/php-transformer/tests/fixtures/parity/html-source-styled-button-preserves-style.json index 7e1634f4..b20ab17e 100644 --- a/php-transformer/tests/fixtures/parity/html-source-styled-button-preserves-style.json +++ b/php-transformer/tests/fixtures/parity/html-source-styled-button-preserves-style.json @@ -17,13 +17,14 @@ }, "expected_blocks": [ { "path": "blocks.0", "name": "core/buttons" }, - { "path": "blocks.0.innerBlocks.0", "name": "core/button", "attrs": { "text": "Buy now", "className": "checkout-button", "style": "background-color:#111827;color:#f9fafb;border:0;border-radius:6px;padding:10px 20px;font-weight:800;text-transform:uppercase" } } + { "path": "blocks.0.innerBlocks.0", "name": "core/button", "attrs": { "text": "Buy now", "className": "checkout-button", "style": { "color": { "background": "#111827", "text": "#f9fafb" }, "border": { "radius": "6px" }, "spacing": { "padding": { "top": "10px", "right": "20px", "bottom": "10px", "left": "20px" } }, "typography": { "fontWeight": "800", "textTransform": "uppercase" } } } } ], "expected_fallbacks": [], "expect": [ { "path": "status", "assert": "equals", "value": "success" }, - { "path": "serialized_blocks", "assert": "contains", "value": "class=\"wp-block-button__link wp-element-button checkout-button\"" }, - { "path": "serialized_blocks", "assert": "contains", "value": "style=\"background-color:#111827;color:#f9fafb;border:0;border-radius:6px;padding:10px 20px;font-weight:800;text-transform:uppercase\"" }, - { "path": "serialized_blocks", "assert": "not_contains", "value": "background-color:#f7f7f7" } + { "path": "serialized_blocks", "assert": "contains", "value": "class=\"wp-block-button__link has-text-color has-background wp-element-button checkout-button\"" }, + { "path": "serialized_blocks", "assert": "contains", "value": "style=\"color:#f9fafb;background-color:#111827;border-radius:6px;padding-top:10px;padding-right:20px;padding-bottom:10px;padding-left:20px;font-weight:800;text-transform:uppercase\"" }, + { "path": "serialized_blocks", "assert": "not_contains", "value": "background-color:#f7f7f7" }, + { "path": "serialized_blocks", "assert": "not_contains", "value": "border-width" } ] }