Skip to content

Commit

Permalink
[Webfonts] Use Core's _deprecated_argument() for deprecating data s…
Browse files Browse the repository at this point in the history
…tructures (#47125)

* WP_Webfonts::migrate_deprecated_structure()

* WP_Webfonts::extract_font_family_from_deprecated_webfonts_structure()

* Remove unused test method
  • Loading branch information
Tonya Mork authored Jan 23, 2023
1 parent ce8bb74 commit 70ba921
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 21 deletions.
4 changes: 2 additions & 2 deletions lib/experimental/fonts-api/deprecations/class-wp-webfonts.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public function enqueue_webfont( $font_family_name ) {
public function migrate_deprecated_structure( array $webfonts ) {
$message = 'A deprecated fonts array structure passed to wp_register_fonts(). ' .
'Variations must be grouped and keyed by their font family.';
trigger_error( $message, E_USER_DEPRECATED );
_deprecated_argument( __METHOD__, '14.9.1', $message );

$new_webfonts = array();
foreach ( $webfonts as $webfont ) {
Expand Down Expand Up @@ -197,7 +197,7 @@ public function is_deprecated_structure( array $webfonts ) {
* @return string|null The font family slug if successfully registered. Else null.
*/
protected function extract_font_family_from_deprecated_webfonts_structure( array $webfont, $message ) {
trigger_error( $message, E_USER_DEPRECATED );
_deprecated_argument( __METHOD__, '14.9.1', $message );

$font_family = WP_Fonts_Utils::get_font_family_from_variation( $webfont );
if ( ! $font_family ) {
Expand Down
9 changes: 0 additions & 9 deletions phpunit/fonts-api/wp-fonts-testcase.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,4 @@ protected function get_handles_for_provider( array $fonts, $provider_id ) {

return $handles;
}

/**
* Suppresses deprecation notices allowing a test to skip deprecations
* to test notices or other specifics.
*/
protected function suppress_deprecations() {
$this->error_reporting_level = error_reporting();
error_reporting( $this->error_reporting_level & ~E_USER_DEPRECATED );
}
}
16 changes: 6 additions & 10 deletions phpunit/fonts-api/wpRegisterFonts-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,27 +105,23 @@ public function data_fonts() {
/**
* @dataProvider data_deprecated_structure
*
* @expectedDeprecated WP_Webfonts::migrate_deprecated_structure
*
* @param array $fonts Fonts to test.
*/
public function test_should_throw_deprecation_with_deprecated_structure( array $fonts ) {
$this->expectDeprecation();
$this->expectDeprecationMessage(
'A deprecated fonts array structure passed to wp_register_fonts(). ' .
'Variations must be grouped and keyed by their font family.'
);

wp_register_fonts( $fonts );
}

/**
* @dataProvider data_deprecated_structure
*
* @expectedDeprecated WP_Webfonts::migrate_deprecated_structure
*
* @param array $fonts Fonts to test.
* @param array $expected Expected results.
*/
public function test_should_register_with_deprecated_structure( array $fonts, array $expected ) {
$this->suppress_deprecations();

$actual = wp_register_fonts( $fonts );
$this->assertSame( $expected['wp_register_fonts'], $actual, 'Font family handle(s) should be returned' );
$this->assertSame( $expected['get_registered'], $this->get_registered_handles(), 'Fonts should match registered queue' );
Expand Down Expand Up @@ -236,12 +232,12 @@ public function data_deprecated_structure() {
/**
* @dataProvider data_invalid_font_family
*
* @expectedDeprecated WP_Webfonts::migrate_deprecated_structure
*
* @param array $fonts Fonts to test.
* @param string $expected_message Expected notice message.
*/
public function test_should_not_register_with_undefined_font_family( array $fonts, $expected_message ) {
$this->suppress_deprecations();

$this->expectNotice();
$this->expectNoticeMessage( $expected_message );

Expand Down

1 comment on commit 70ba921

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in 70ba921.
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/3989562178
📝 Reported issues:

Please sign in to comment.