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

Fonts Library: Test improvements #53702

Merged
merged 7 commits into from
Aug 16, 2023

Conversation

hellofromtonya
Copy link
Contributor

@hellofromtonya hellofromtonya commented Aug 15, 2023

Part of #52698 tracking issue.

What?

For Core readiness and parity, this PR improves the tests by:

  • Splitting a class' tests into 1 test class per public method.
  • Adding tests where needed for improved coverage.
  • Splitting happy and unhappy paths into separate test methods and data providers.

Why?

To prepare the tests for merging into Core.

How?

Each Fonts Library PHP class is split into separate test classes, one per public method.

  • Split WP_Font_Family
  • Split WP_Font_Family_Utils
  • Split WP_Fonts_Library

WP_REST_Fonts_Library_Controller is not included in this PR as it needs different considerations to align with the other REST API tests in Core. A follow-up PR will handle it.

Testing Instructions

PHPUnit tests and all CI jobs should still pass ✅

Splits the tests into 1 test file per public method.
@hellofromtonya hellofromtonya added the [Feature] Typography Font and typography-related issues and PRs label Aug 15, 2023
@WordPress WordPress deleted a comment from github-actions bot Aug 15, 2023
@hellofromtonya hellofromtonya added the [Type] Code Quality Issues or PRs that relate to code quality label Aug 15, 2023
@WordPress WordPress deleted a comment from github-actions bot Aug 15, 2023
@hellofromtonya hellofromtonya added [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. and removed [Type] Code Quality Issues or PRs that relate to code quality labels Aug 15, 2023
@hellofromtonya hellofromtonya self-assigned this Aug 15, 2023
@WordPress WordPress deleted a comment from github-actions bot Aug 15, 2023
@hellofromtonya hellofromtonya force-pushed the fix/fonts-library-phpunit-tests-for-core-parity branch from 17bdf16 to b7ad62f Compare August 16, 2023 16:04
@hellofromtonya hellofromtonya added Backport from WordPress Core Pull request that needs to be backported to a Gutenberg release from WordPress Core Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta and removed Backport from WordPress Core Pull request that needs to be backported to a Gutenberg release from WordPress Core labels Aug 16, 2023
@WordPress WordPress deleted a comment from github-actions bot Aug 16, 2023
@hellofromtonya
Copy link
Contributor Author

For tracking purposes, marking this PR as part of the fonts management feature that will be merged into Core for WP 6.4.

@WordPress WordPress deleted a comment from github-actions bot Aug 16, 2023
@hellofromtonya hellofromtonya force-pushed the fix/fonts-library-phpunit-tests-for-core-parity branch from b7ad62f to bd91b81 Compare August 16, 2023 16:19
@hellofromtonya hellofromtonya marked this pull request as ready for review August 16, 2023 16:20
@hellofromtonya
Copy link
Contributor Author

Hey @costdev, as a follow-up to our discussion of the Font Library PR, this PR splits and improves its tests, i.e. 1 test file per public method. It's following the work you and I have been doing in Core.

What do you think? Have time for a review?

Copy link
Contributor

@costdev costdev left a comment

Choose a reason for hiding this comment

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

Thanks for the ping! 🙂 Just a few of suggestions and a question about possible additional tests in future.

'txt' => array( '/temp/test.txt' ),
'zip' => array( '/temp/lato.zip' ),
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should there be additional tests (not necessarily in this PR) to ensure if an extender filters the supported MIME types, that ::has_font_mime_type() takes this into consideration? I imagine this is already handled in the implementation, but might it be worth protecting this functionality with a test or two for when something is added/removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, the list of valid mime types is not filterable. ::has_font_mime_type() checks the mime via wp_check_filetype() by passing the allowed types via a hardcoded list in WP_Fonts_Library::ALLOWED_FONT_MIME_TYPES. There are no filters in the process.

phpunit/fonts-library/wpFontFamily/__construct-test.php Outdated Show resolved Hide resolved
phpunit/fonts-library/wpFontFamily/getFontPost-test.php Outdated Show resolved Hide resolved
phpunit/fonts-library/wpFontFamily/hasFontFaces-test.php Outdated Show resolved Hide resolved
phpunit/fonts-library/wpFontFamily/install-test.php Outdated Show resolved Hide resolved
phpunit/fonts-library/wpFontFamily/uninstall-test.php Outdated Show resolved Hide resolved
hellofromtonya and others added 3 commits August 16, 2023 12:13
Props @costdev

Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com>
@WordPress WordPress deleted a comment from github-actions bot Aug 16, 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/fonts-library/wpFontFamily/__construct-test.php
❔ phpunit/fonts-library/wpFontFamily/base.php
❔ phpunit/fonts-library/wpFontFamily/getData-test.php
❔ phpunit/fonts-library/wpFontFamily/getDataAsJson-test.php
❔ phpunit/fonts-library/wpFontFamily/getFontPost-test.php
❔ phpunit/fonts-library/wpFontFamily/hasFontFaces-test.php
❔ phpunit/fonts-library/wpFontFamily/install-test.php
❔ phpunit/fonts-library/wpFontFamily/uninstall-test.php
❔ phpunit/fonts-library/wpFontFamilyUtils/getFilenameFromFontFace-test.php
❔ phpunit/fonts-library/wpFontFamilyUtils/hasFontMimeType-test.php
❔ phpunit/fonts-library/wpFontsLibrary/getFontsDir-test.php
❔ phpunit/fonts-library/wpFontsLibrary/setUploadDir-test.php
❔ phpunit/fonts-library/wpFontFamilyUtils/mergeFontsData-test.php

Copy link
Contributor

@costdev costdev left a comment

Choose a reason for hiding this comment

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

Thanks for the updates @hellofromtonya! This looks good to me now 🙂

Copy link
Contributor

@anton-vlasenko anton-vlasenko left a comment

Choose a reason for hiding this comment

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

I've reviewed the tests and couldn't find any issues.
Since this PR aims to refactor existing test classes, I'm not expecting any potential issues.
✅ LGTM.

@hellofromtonya
Copy link
Contributor Author

Thank you @costdev and @anton-vlasenko! Merging it now.

@hellofromtonya hellofromtonya merged commit 67454a0 into trunk Aug 16, 2023
50 checks passed
@hellofromtonya hellofromtonya deleted the fix/fonts-library-phpunit-tests-for-core-parity branch August 16, 2023 18:17
@github-actions github-actions bot added this to the Gutenberg 16.6 milestone Aug 16, 2023
@hellofromtonya hellofromtonya added Needs PHP backport Needs PHP backport to Core and removed Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta labels Sep 6, 2023
@youknowriad youknowriad added Backported to WP Core Pull request that has been successfully merged into WP Core and removed Needs PHP backport Needs PHP backport to Core labels Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backported to WP Core Pull request that has been successfully merged into WP Core [Feature] Typography Font and typography-related issues and PRs [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants