Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Background image block support: Add tests, adjust injection logic slightly #54489

Merged

Conversation

andrewserong
Copy link
Contributor

@andrewserong andrewserong commented Sep 15, 2023

What?

Part of: #54336

Add PHP tests for the background image block support.

Also, adjust the style injection slightly, so that if the existing style attribute ends in a semi-colon, we still inject the newly created styles.

Why?

While working on the backport for the background image block support over in WordPress/wordpress-develop#5209, I added some tests, and noticed the logic for injecting the style tag needed adjusting slightly. While in Gutenberg, inline styles don't include a trailing semi-colon, I thought it'd be good to factor it in, just in case, for the future reliability of the support and interacting with other styles.

Also, it's good to add tests for features!

How?

  • Ensure that we append to the style attribute irrespective of whether or not a semi-colon already exists at the end of the current value.
  • Add PHP tests for the background image support to cover injecting when no style tag exists, when a style tag exists with a single rule in it, and when there are multiple rules with a trailing semi-colon. Also check that the background image will not be output if the block does not have support for it.

Testing Instructions

  1. Smoke test that the background image support still works as expected in the block editor (Add a Group block, add a background image to it, save the post, and view on the site frontend — then add some styles to the Group block, like text color, and repeat).
  2. Check that tests pass, or to run npm run test:unit:php:base -- --filter WP_Block_Supports_Background_Test locally to confirm.

@andrewserong andrewserong added [Type] Code Quality Issues or PRs that relate to code quality [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi labels Sep 15, 2023
@andrewserong andrewserong self-assigned this Sep 15, 2023
@github-actions
Copy link

This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress.

If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged.

If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack.

Thank you! ❤️

View changed files
❔ phpunit/block-supports/background-test.php
❔ lib/block-supports/background.php

@github-actions
Copy link

Flaky tests detected in 5899a63.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6194420786
📝 Reported issues:

@ramonjd ramonjd added the Backport from WordPress Core Pull request that needs to be backported to a Gutenberg release from WordPress Core label Sep 25, 2023
@andrewserong andrewserong removed the [Type] Code Quality Issues or PRs that relate to code quality label Sep 25, 2023
Copy link
Member

@ramonjd ramonjd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests and changes to block-supports/background.php match Core

Tests pass 👍🏻

Tested background image using a Group block with border and some other styles. Editor and frontend match.

🚀

@andrewserong
Copy link
Contributor Author

Thanks for the review! 🙇

@andrewserong andrewserong merged commit da8f1aa into trunk Sep 25, 2023
@andrewserong andrewserong deleted the update/background-image-block-support-to-add-tests branch September 25, 2023 23:55
@github-actions github-actions bot added this to the Gutenberg 16.8 milestone Sep 25, 2023
@getdave
Copy link
Contributor

getdave commented Jan 22, 2024

✅ I updated the PHP Sync Tracking Issue for WP 6.5 to note this PR does not require a backport for WP 6.5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backport from WordPress Core Pull request that needs to be backported to a Gutenberg release from WordPress Core [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants