Skip to content

Commit 18c2cf6

Browse files
Button: Update gradient e2e expectations for background.gradient storage
With background.gradient support, the Background panel stores both preset and custom gradients in style.background.gradient instead of the legacy gradient attribute or style.color.gradient. Background support renders on the server, so the saved markup no longer carries the gradient class or inline style. Check the gradient in the editor canvas instead, and cover preset gradients in the server render test.
1 parent 1a5fca6 commit 18c2cf6

2 files changed

Lines changed: 29 additions & 4 deletions

File tree

‎phpunit/blocks/render-block-button-test.php‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,24 @@ public function test_background_gradient_appends_to_existing_link_style() {
179179
$result
180180
);
181181
}
182+
183+
/**
184+
* @covers ::gutenberg_render_block_core_button
185+
*/
186+
public function test_background_gradient_preset_applies_to_link() {
187+
$attributes = array(
188+
'style' => array(
189+
'background' => array(
190+
'gradient' => 'var:preset|gradient|purple-to-yellow',
191+
),
192+
),
193+
);
194+
195+
$result = gutenberg_render_block_core_button( $attributes, self::$button_content );
196+
$processor = new WP_HTML_Tag_Processor( $result );
197+
$processor->next_tag( 'a' );
198+
199+
$this->assertSame( 'background-image:var(--wp--preset--gradient--purple-to-yellow);', $processor->get_attribute( 'style' ) );
200+
$this->assertTrue( $processor->has_class( 'has-background' ) );
201+
}
182202
}

‎test/e2e/specs/editor/blocks/buttons.spec.js‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,12 +392,17 @@ test.describe( 'Buttons', () => {
392392
.getByRole( 'option', { name: 'Gradient: Purple to yellow' } )
393393
.click();
394394

395+
// Background support renders on the server, so the gradient is absent from the saved markup.
396+
await expect(
397+
editor.canvas.locator( '.wp-block-button__link' )
398+
).toHaveCSS( 'background-image', /gradient/ );
399+
395400
// Check the content.
396401
const content = await editor.getEditedPostContent();
397402
expect( content ).toBe(
398403
`<!-- wp:buttons -->
399-
<div class=\"wp-block-buttons\"><!-- wp:button {\"gradient\":\"purple-to-yellow\"} -->
400-
<div class=\"wp-block-button\"><a class=\"wp-block-button__link has-purple-to-yellow-gradient-background has-background wp-element-button\">Content</a></div>
404+
<div class=\"wp-block-buttons\"><!-- wp:button {\"style\":{\"background\":{\"gradient\":\"var:preset|gradient|purple-to-yellow\"}}} -->
405+
<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\">Content</a></div>
401406
<!-- /wp:button --></div>
402407
<!-- /wp:buttons -->`
403408
);
@@ -437,8 +442,8 @@ test.describe( 'Buttons', () => {
437442
const content = await editor.getEditedPostContent();
438443
expect( content ).toBe(
439444
`<!-- wp:buttons -->
440-
<div class=\"wp-block-buttons\"><!-- wp:button {\"style\":{\"color\":{\"gradient\":\"linear-gradient(135deg,rgb(255,0,0) 0%,rgb(0,255,0) 100%)\"}}} -->
441-
<div class=\"wp-block-button\"><a class=\"wp-block-button__link has-background wp-element-button\" style=\"background:linear-gradient(135deg,rgb(255,0,0) 0%,rgb(0,255,0) 100%)\">Content</a></div>
445+
<div class=\"wp-block-buttons\"><!-- wp:button {\"style\":{\"background\":{\"gradient\":\"linear-gradient(135deg,rgb(255,0,0) 0%,rgb(0,255,0) 100%)\"}}} -->
446+
<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\">Content</a></div>
442447
<!-- /wp:button --></div>
443448
<!-- /wp:buttons -->`
444449
);

0 commit comments

Comments
 (0)