Skip to content

Commit

Permalink
Revert test changes moved to #924
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Jan 9, 2024
1 parent 3da1363 commit 2181d88
Show file tree
Hide file tree
Showing 21 changed files with 57 additions and 124 deletions.
36 changes: 3 additions & 33 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
<config name="testVersion" value="7.0-"/>

<rule ref="WordPress-Docs"/>
<rule ref="WordPress-Extra" />
<rule ref="WordPress-Extra">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="WordPress.WP.I18n"/>
<config name="text_domain" value="performance-lab,default"/>

Expand Down Expand Up @@ -71,37 +73,5 @@
<exclude-pattern>tests/utils/*</exclude-pattern>
</rule>

<!-- Ignore inapplicable WordPress-Extra sniffs in tests. -->
<rule ref="WordPress.WP.EnqueuedResourceParameters">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="WordPress.Security.EscapeOutput.OutputNotEscaped">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="WordPress.WP.AlternativeFunctions.unlink_unlink">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="WordPress.WP.GlobalVariablesOverride.Prohibited">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="WordPress.PHP.DevelopmentFunctions.error_log_var_export">
<exclude-pattern>tests/*</exclude-pattern>
</rule>

<!-- Exceptions for variable name casing. -->
<rule ref="WordPress.NamingConventions.ValidVariableName">
<properties>
<property name="allowed_custom_properties" type="array">
<element value="nodeValue"/>
<element value="parentNode"/>
<element value="createTextNode"/>
<element value="textContent"/>
</property>
</properties>
</rule>

<rule ref="SlevomatCodingStandard.Functions.StaticClosure" />
</ruleset>
2 changes: 1 addition & 1 deletion tests/admin/load-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function test_perflab_add_modules_page() {
remove_all_filters( 'plugin_action_links_' . plugin_basename( PERFLAB_MAIN_FILE ) );

// Does not register the page if the perflab_active_modules filter is used.
add_filter( 'perflab_active_modules', '__return_empty_array' );
add_filter( 'perflab_active_modules', '__return_null' );

Check failure on line 87 in tests/admin/load-tests.php

View workflow job for this annotation

GitHub Actions / PHP

Filter callback return statement is missing.
$hook_suffix = perflab_add_modules_page();
$this->assertFalse( $hook_suffix );
$this->assertFalse( isset( $_wp_submenu_nopriv['options-general.php'][ PERFLAB_MODULES_SCREEN ] ) );
Expand Down
2 changes: 1 addition & 1 deletion tests/admin/server-timing-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function test_perflab_load_server_timing_page() {
perflab_load_server_timing_page();
$this->assertArrayHasKey( PERFLAB_SERVER_TIMING_SCREEN, $wp_settings_sections );
$expected_sections = array( 'benchmarking' );
if ( ! has_filter( 'template_include', 'ilo_buffer_output' ) ) {
if ( ! has_filter( 'template_include', 'image_loading_optimization_buffer_output' ) ) {
$expected_sections[] = 'output-buffering';
}
$this->assertEqualSets(
Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
require_once $_test_root . '/includes/functions.php';
tests_add_filter(
'plugins_loaded',
static function () {
static function() {
require_once TESTS_PLUGIN_DIR . '/admin/load.php';
require_once TESTS_PLUGIN_DIR . '/admin/server-timing.php';
$module_files = glob( TESTS_PLUGIN_DIR . '/modules/*/*/load.php' );
Expand Down
14 changes: 7 additions & 7 deletions tests/load-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ public function test_perflab_get_module_settings() {
$has_passed_default = false;
add_filter(
'default_option_' . PERFLAB_MODULES_SETTING,
static function ( $current_default, $option, $passed_default ) use ( &$has_passed_default ) {
static function( $default, $option, $passed_default ) use ( &$has_passed_default ) {
// This callback just records whether there is a default value being passed.
$has_passed_default = $passed_default;
return $current_default;
return $default;
},
10,
3
Expand Down Expand Up @@ -134,7 +134,7 @@ public function test_perflab_get_active_modules() {
$expected_active_modules = array_keys(
array_filter(
perflab_get_modules_setting_default(),
static function ( $module_settings ) {
static function( $module_settings ) {
return $module_settings['enabled'];
}
)
Expand All @@ -158,7 +158,7 @@ public function test_perflab_get_generator_content() {
array_pop( $active_modules );
add_filter(
'perflab_active_modules',
static function () use ( $active_modules ) {
static function() use ( $active_modules ) {
return $active_modules;
}
);
Expand Down Expand Up @@ -229,7 +229,7 @@ private function get_expected_default_option() {
$default_enabled_modules = require PERFLAB_PLUGIN_DIR_PATH . 'default-enabled-modules.php';
return array_reduce(
$default_enabled_modules,
static function ( $module_settings, $module_dir ) {
static function( $module_settings, $module_dir ) {
$module_settings[ $module_dir ] = array( 'enabled' => true );
return $module_settings;
},
Expand Down Expand Up @@ -312,13 +312,13 @@ private function set_up_mock_filesystem() {

add_filter(
'filesystem_method_file',
static function () {
static function() {
return __DIR__ . '/utils/Filesystem/WP_Filesystem_MockFilesystem.php';
}
);
add_filter(
'filesystem_method',
static function () {
static function() {
return 'MockFilesystem';
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,4 @@ public static function delete_autoloaded_option() {
delete_option( self::AUTOLOADED_OPTION_KEY );
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function test_tag_add_adjust_to_image_attributes( $image_path, $expected_

$filtered_image_tags_added = dominant_color_img_tag_add_dominant_color( $filtered_image_mock_lazy_load, 'the_content', $attachment_id );

$this->assertStringContainsString( 'data-has-transparency="' . wp_json_encode( $expected_transparency ) . '"', $filtered_image_tags_added );
$this->assertStringContainsString( 'data-has-transparency="' . json_encode( $expected_transparency ) . '"', $filtered_image_tags_added );

foreach ( $expected_color as $color ) {
if ( false !== strpos( $color, $filtered_image_tags_added ) ) {
Expand Down Expand Up @@ -210,7 +210,7 @@ public function data_provider_dominant_color_check_inline_style() {
public function test_dominant_color_update_attachment_image_attributes( $style_attr, $expected ) {
$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/dominant-color-images/red.jpg' );

$attachment_image = wp_get_attachment_image( $attachment_id, 'full', '', array( 'style' => $style_attr ) );
$attachment_image = wp_get_attachment_image( $attachment_id, 'full', '', array( "style" => $style_attr ) );
$this->assertStringContainsString( $expected, $attachment_image );
}

Expand Down
3 changes: 1 addition & 2 deletions tests/modules/images/webp-uploads/helper-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ public function it_should_return_empty_array_when_filter_returns_empty_array() {
* @test
*/
public function it_should_return_default_transforms_when_filter_returns_non_array_type() {
/** @phpstan-ignore-next-line */
add_filter( 'webp_uploads_upload_image_mime_transforms', '__return_null' );

Check failure on line 367 in tests/modules/images/webp-uploads/helper-tests.php

View workflow job for this annotation

GitHub Actions / PHP

Filter callback return statement is missing.

$default_transforms = array(
Expand Down Expand Up @@ -521,7 +520,7 @@ public function test_webp_uploads_in_frontend_body_within_wp_head() {
$result = null;
add_action(
'wp_head',
static function () use ( &$result ) {
static function() use ( &$result ) {
$result = webp_uploads_in_frontend_body();
}
);
Expand Down
6 changes: 3 additions & 3 deletions tests/modules/images/webp-uploads/load-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ public function it_should_not_replace_the_references_to_a_jpg_image_when_disable

add_filter(
'webp_uploads_content_image_mimes',
static function ( $mime_types ) {
static function( $mime_types ) {
unset( $mime_types[ array_search( 'image/webp', $mime_types, true ) ] );
return $mime_types;
}
Expand Down Expand Up @@ -733,7 +733,7 @@ public function it_should_prevent_replacing_an_image_uploaded_via_external_sourc

add_filter(
'webp_uploads_pre_replace_additional_image_source',
static function () {
static function() {
return '<img src="https://ia600200.us.archive.org/16/items/SPD-SLRSY-1867/hubblesite_2001_06.jpg">';
}
);
Expand Down Expand Up @@ -899,7 +899,7 @@ public function it_should_not_add_fallback_script_if_content_has_no_updated_imag
public function it_should_create_mime_types_for_allowed_sizes_only_via_filter() {
add_filter(
'webp_uploads_image_sizes_with_additional_mime_type_support',
static function ( $sizes ) {
static function( $sizes ) {
$sizes['allowed_size_400x300'] = true;
return $sizes;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/modules/images/webp-uploads/rest-api-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function it_should_add_sources_to_rest_response() {

add_filter(
'webp_uploads_upload_image_mime_transforms',
static function ( $transforms ) {
static function( $transforms ) {
$transforms['image/jpeg'] = array( 'image/jpeg', 'image/webp' );
return $transforms;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,12 @@ public function test_perflab_aea_get_path_from_resource_url_outside_wp_setup() {
$expected_path = WP_CONTENT_DIR . '/themes/test-theme/style.css';
add_filter(
'content_url',
static function () {
static function( $url ) {
return site_url() . '/content';
}
);
$this->assertSame( $expected_path, perflab_aea_get_path_from_resource_url( $test_url ) );
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public function test_perflab_aea_audit_enqueued_scripts() {
),
$transient
);

}

/**
Expand All @@ -92,10 +93,8 @@ public function test_perflab_aea_audit_enqueued_styles_transient_already_set() {

Audit_Assets_Transients_Set::set_style_transient_with_data( 3 );

// Avoid deprecation warning due to related change in WordPress 6.4.
remove_action( 'wp_print_styles', 'print_emoji_styles' );
// Avoids echoing styles.
get_echo( 'wp_print_styles' );

perflab_aea_audit_enqueued_styles();
$transient = get_transient( 'aea_enqueued_front_page_styles' );
$this->assertIsArray( $transient );
Expand Down Expand Up @@ -140,9 +139,6 @@ public function test_perflab_aea_audit_enqueued_styles() {
$style .= "\tbackground: red;\n";
$style .= '}';
wp_add_inline_style( 'style1', $style );

// Avoid deprecation warning due to related change in WordPress 6.4.
remove_action( 'wp_print_styles', 'print_emoji_styles' );
get_echo( 'wp_print_styles' );

perflab_aea_audit_enqueued_styles();
Expand Down Expand Up @@ -241,23 +237,7 @@ public function test_perflab_aea_clean_aea_audit_action() {
$_REQUEST['_wpnonce'] = wp_create_nonce( 'clean_aea_audit' );
$_GET['action'] = 'clean_aea_audit';
$this->current_user_can_view_site_health_checks_cap();
$redirected_url = null;
add_filter(
'wp_redirect',
static function ( $url ) use ( &$redirected_url ) {
$redirected_url = $url;
return false;
}
);
$_REQUEST['_wp_http_referer'] = add_query_arg(
array(
'_wpnonce' => 'foo',
'action' => 'bar',
),
home_url( '/' )
);
perflab_aea_clean_aea_audit_action();
$this->assertSame( home_url( '/' ), $redirected_url );
$this->assertFalse( get_transient( 'aea_enqueued_front_page_scripts' ) );
$this->assertFalse( get_transient( 'aea_enqueued_front_page_styles' ) );
}
Expand Down Expand Up @@ -302,3 +282,4 @@ public function mock_data_perflab_aea_enqueued_css_assets_test_callback( $number
return Site_Health_Mock_Responses::return_aea_enqueued_css_assets_test_callback_more_than_threshold( $number_of_assets );
}
}

48 changes: 12 additions & 36 deletions tests/server-timing/load-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function test_perflab_server_timing_register_metric() {
perflab_server_timing_register_metric(
'test-metric',
array(
'measure_callback' => static function ( $metric ) {
'measure_callback' => static function( $metric ) {
$metric->set_value( 100 );
},
'access_cap' => 'exist',
Expand All @@ -42,7 +42,7 @@ public function test_perflab_server_timing_use_output_buffer() {
}

public function test_perflab_wrap_server_timing() {
$cb = static function () {
$cb = static function() {
return 123;
};

Expand All @@ -64,7 +64,7 @@ public function test_perflab_register_server_timing_setting() {

// Reset relevant globals.
$wp_registered_settings = array();
$new_allowed_options = array();
$new_allowed_options = array();

perflab_register_server_timing_setting();

Expand Down Expand Up @@ -103,61 +103,37 @@ public function data_perflab_sanitize_server_timing_setting() {
),
'empty list, array' => array(
array( 'benchmarking_actions' => array() ),
array(
'benchmarking_actions' => array(),
'output_buffering' => false,
),
array( 'benchmarking_actions' => array(), 'output_buffering' => false ),
),
'empty list, string' => array(
array( 'benchmarking_actions' => '' ),
array(
'benchmarking_actions' => array(),
'output_buffering' => false,
),
array( 'benchmarking_actions' => array(), 'output_buffering' => false ),
),
'empty list, string with whitespace' => array(
array( 'benchmarking_actions' => ' ' ),
array(
'benchmarking_actions' => array(),
'output_buffering' => false,
),
array( 'benchmarking_actions' => array(), 'output_buffering' => false ),
),
'regular list, array' => array(
array( 'benchmarking_actions' => array( 'after_setup_theme', 'init', 'wp_loaded' ) ),
array(
'benchmarking_actions' => array( 'after_setup_theme', 'init', 'wp_loaded' ),
'output_buffering' => false,
),
array( 'benchmarking_actions' => array( 'after_setup_theme', 'init', 'wp_loaded' ), 'output_buffering' => false ),
),
'regular list, string' => array(
array( 'benchmarking_actions' => "after_setup_theme\ninit\nwp_loaded" ),
array(
'benchmarking_actions' => array( 'after_setup_theme', 'init', 'wp_loaded' ),
'output_buffering' => false,
),
array( 'benchmarking_actions' => array( 'after_setup_theme', 'init', 'wp_loaded' ), 'output_buffering' => false ),
),
'regular list, string with whitespace' => array(
array( 'benchmarking_actions' => "after_setup_ theme \ninit \n\nwp_loaded\n" ),
array(
'benchmarking_actions' => array( 'after_setup_theme', 'init', 'wp_loaded' ),
'output_buffering' => false,
),
array( 'benchmarking_actions' => array( 'after_setup_theme', 'init', 'wp_loaded' ), 'output_buffering' => false ),
),
'regular list, array with duplicates' => array(
array( 'benchmarking_actions' => array( 'after_setup_theme', 'init', 'wp_loaded', 'init' ) ),
array(
'benchmarking_actions' => array( 'after_setup_theme', 'init', 'wp_loaded' ),
'output_buffering' => false,
),
array( 'benchmarking_actions' => array( 'after_setup_theme', 'init', 'wp_loaded' ), 'output_buffering' => false ),
),
'regular list, array with special hook chars' => array(
array( 'benchmarking_actions' => array( 'namespace/hookname', 'namespace.hookname' ) ),
array(
'benchmarking_actions' => array( 'namespace/hookname', 'namespace.hookname' ),
'output_buffering' => false,
),
array( 'benchmarking_actions' => array( 'namespace/hookname', 'namespace.hookname' ), 'output_buffering' => false ),
),
'output buffering enabled' => array(
'output buffering enabled' => array(
array( 'output_buffering' => 'on' ),
array( 'output_buffering' => true ),
),
Expand Down
Loading

0 comments on commit 2181d88

Please sign in to comment.