From 1a400a063032c90ac07b8f6916a18cc5f3f9a547 Mon Sep 17 00:00:00 2001
From: jrfnl <jrfnl@users.noreply.github.com>
Date: Sat, 27 Jul 2019 01:32:47 +0200
Subject: [PATCH] [tests] Remove work-arounds for PHP < 5.6
---
tests/phpunit/includes/utils.php | 8 ++------
tests/phpunit/tests/admin/wpPrivacyRequestsTable.php | 4 ----
tests/phpunit/tests/compat.php | 5 -----
tests/phpunit/tests/customize/nav-menus.php | 4 +---
tests/phpunit/tests/db/charset.php | 4 ----
tests/phpunit/tests/functions.php | 4 ----
tests/phpunit/tests/post/query.php | 5 -----
tests/phpunit/tests/rest-api/rest-request.php | 8 --------
tests/phpunit/tests/theme/customHeader.php | 9 ---------
tests/phpunit/tests/widgets/media-widget.php | 5 -----
10 files changed, 3 insertions(+), 53 deletions(-)
diff --git a/tests/phpunit/includes/utils.php b/tests/phpunit/includes/utils.php
index a213bce0d0..9a03250f6a 100644
|
a
|
b
|
class WpdbExposedMethodsForTesting extends wpdb { |
| 465 | 465 | function benchmark_pcre_backtracking( $pattern, $subject, $strategy ) { |
| 466 | 466 | $saved_config = ini_get( 'pcre.backtrack_limit' ); |
| 467 | 467 | |
| 468 | | // Attempt to prevent PHP crashes. Adjust these lower when needed. |
| 469 | | if ( version_compare( phpversion(), '5.4.8', '>' ) ) { |
| 470 | | $limit = 1000000; |
| 471 | | } else { |
| 472 | | $limit = 20000; // 20,000 is a reasonable upper limit, but see also https://core.trac.wordpress.org/ticket/29557#comment:10 |
| 473 | | } |
| | 468 | // Attempt to prevent PHP crashes. Adjust these lower when needed. |
| | 469 | $limit = 1000000; |
| 474 | 470 | |
| 475 | 471 | // Start with small numbers, so if a crash is encountered at higher numbers we can still debug the problem. |
| 476 | 472 | for ( $i = 4; $i <= $limit; $i *= 2 ) { |
diff --git a/tests/phpunit/tests/admin/wpPrivacyRequestsTable.php b/tests/phpunit/tests/admin/wpPrivacyRequestsTable.php
index 9c9be20f92..debe163862 100644
|
a
|
b
|
class Tests_Admin_WpPrivacyRequestsTable extends WP_UnitTestCase { |
| 24 | 24 | * @return PHPUnit_Framework_MockObject_MockObject|WP_Privacy_Requests_Table $instance Mocked class instance. |
| 25 | 25 | */ |
| 26 | 26 | public function get_mocked_class_instance() { |
| 27 | | if ( version_compare( PHP_VERSION, '5.3', '<' ) ) { |
| 28 | | $this->markTestSkipped( 'ReflectionMethod::setAccessible is only available in PHP 5.3+' ); |
| 29 | | } |
| 30 | | |
| 31 | 27 | $args = array( |
| 32 | 28 | 'plural' => 'privacy_requests', |
| 33 | 29 | 'singular' => 'privacy_request', |
diff --git a/tests/phpunit/tests/compat.php b/tests/phpunit/tests/compat.php
index d70d0271b1..a0797317cc 100644
|
a
|
b
|
EOT; |
| 246 | 246 | $this->markTestSkipped( 'The intl extension is not loaded. ResourceBundle not tested for is_countable().' ); |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | | if ( version_compare( PHP_VERSION, '5.4', '<' ) ) { |
| 250 | | $this->markTestSkipped( 'ResourceBundle is only countable in PHP 5.4+' ); |
| 251 | | return; |
| 252 | | } |
| 253 | | |
| 254 | 249 | $this->assertTrue( is_countable( new ResourceBundle( 'en', null ) ) ); |
| 255 | 250 | } |
| 256 | 251 | |
diff --git a/tests/phpunit/tests/customize/nav-menus.php b/tests/phpunit/tests/customize/nav-menus.php
index e7387773ac..1de6047097 100644
|
a
|
b
|
class Test_WP_Customize_Nav_Menus extends WP_UnitTestCase { |
| 1083 | 1083 | ); |
| 1084 | 1084 | |
| 1085 | 1085 | // Add global namespace prefix to check #41488. |
| 1086 | | if ( version_compare( PHP_VERSION, '5.3', '>=' ) ) { |
| 1087 | | $original_args['fallback_cb'] = '\\' . $original_args['fallback_cb']; |
| 1088 | | } |
| | 1086 | $original_args['fallback_cb'] = '\\' . $original_args['fallback_cb']; |
| 1089 | 1087 | |
| 1090 | 1088 | $args = $menus->filter_wp_nav_menu_args( $original_args ); |
| 1091 | 1089 | |
diff --git a/tests/phpunit/tests/db/charset.php b/tests/phpunit/tests/db/charset.php
index 3089ec9a74..dc7f7c3b8f 100644
|
a
|
b
|
class Tests_DB_Charset extends WP_UnitTestCase { |
| 482 | 482 | * @ticket 21212 |
| 483 | 483 | */ |
| 484 | 484 | function test_strip_invalid_text( $data, $expected, $message ) { |
| 485 | | if ( version_compare( PHP_VERSION, '5.3', '<' ) && stristr( php_uname( 's' ), 'win' ) ) { |
| 486 | | $this->markTestSkipped( 'This test fails in PHP 5.2 on Windows. See https://core.trac.wordpress.org/ticket/31262' ); |
| 487 | | } |
| 488 | | |
| 489 | 485 | $charset = self::$_wpdb->charset; |
| 490 | 486 | if ( isset( $data[0]['connection_charset'] ) ) { |
| 491 | 487 | $new_charset = $data[0]['connection_charset']; |
diff --git a/tests/phpunit/tests/functions.php b/tests/phpunit/tests/functions.php
index 2191af7ddb..dd29c779e5 100644
|
a
|
b
|
class Tests_Functions extends WP_UnitTestCase { |
| 918 | 918 | * @ticket 28786 |
| 919 | 919 | */ |
| 920 | 920 | function test_wp_json_encode_depth() { |
| 921 | | if ( version_compare( PHP_VERSION, '5.5', '<' ) ) { |
| 922 | | $this->markTestSkipped( 'json_encode() supports the $depth parameter in PHP 5.5+' ); |
| 923 | | }; |
| 924 | | |
| 925 | 921 | $data = array( array( array( 1, 2, 3 ) ) ); |
| 926 | 922 | $json = wp_json_encode( $data, 0, 1 ); |
| 927 | 923 | $this->assertFalse( $json ); |
diff --git a/tests/phpunit/tests/post/query.php b/tests/phpunit/tests/post/query.php
index 7388dc24b7..4bac94c1bc 100644
|
a
|
b
|
class Tests_Post_Query extends WP_UnitTestCase { |
| 705 | 705 | * @dataProvider set_found_posts_provider |
| 706 | 706 | */ |
| 707 | 707 | public function test_set_found_posts_not_posts_as_an_array( $posts, $expected ) { |
| 708 | | if ( version_compare( PHP_VERSION, '5.3', '<' ) ) { |
| 709 | | $this->markTestSkipped( 'ReflectionMethod::setAccessible is only available in PHP 5.3+' ); |
| 710 | | return; |
| 711 | | } |
| 712 | | |
| 713 | 708 | $q = new WP_Query( |
| 714 | 709 | array( |
| 715 | 710 | 'post_type' => 'wptests_pt', |
diff --git a/tests/phpunit/tests/rest-api/rest-request.php b/tests/phpunit/tests/rest-api/rest-request.php
index cf3d79142c..2dd539a509 100644
|
a
|
b
|
class Tests_REST_Request extends WP_UnitTestCase { |
| 491 | 491 | } |
| 492 | 492 | |
| 493 | 493 | public function test_has_valid_params_json_error() { |
| 494 | | if ( version_compare( PHP_VERSION, '5.3', '<' ) ) { |
| 495 | | return $this->markTestSkipped( 'JSON validation is only available for PHP 5.3+' ); |
| 496 | | } |
| 497 | | |
| 498 | 494 | $this->request->set_header( 'Content-Type', 'application/json' ); |
| 499 | 495 | $this->request->set_body( '{"invalid": JSON}' ); |
| 500 | 496 | |
| … |
… |
class Tests_REST_Request extends WP_UnitTestCase { |
| 507 | 503 | |
| 508 | 504 | |
| 509 | 505 | public function test_has_valid_params_empty_json_no_error() { |
| 510 | | if ( version_compare( PHP_VERSION, '5.3', '<' ) ) { |
| 511 | | return $this->markTestSkipped( 'JSON validation is only available for PHP 5.3+' ); |
| 512 | | } |
| 513 | | |
| 514 | 506 | $this->request->set_header( 'Content-Type', 'application/json' ); |
| 515 | 507 | $this->request->set_body( '' ); |
| 516 | 508 | |
diff --git a/tests/phpunit/tests/theme/customHeader.php b/tests/phpunit/tests/theme/customHeader.php
index eeb240fc91..65b037042a 100644
|
a
|
b
|
class Tests_Theme_Custom_Header extends WP_UnitTestCase { |
| 126 | 126 | $this->assertFalse( has_custom_header() ); |
| 127 | 127 | $this->assertEmpty( $html ); |
| 128 | 128 | |
| 129 | | // ReflectionMethod::setAccessible is only available in PHP 5.3+ |
| 130 | | if ( version_compare( PHP_VERSION, '5.3', '<' ) ) { |
| 131 | | return; |
| 132 | | } |
| 133 | 129 | // The container should always be returned in the Customizer preview. |
| 134 | 130 | $this->_set_customize_previewing( true ); |
| 135 | 131 | $html = get_custom_header_markup(); |
| … |
… |
class Tests_Theme_Custom_Header extends WP_UnitTestCase { |
| 226 | 222 | } |
| 227 | 223 | |
| 228 | 224 | function test_header_script_is_enqueued_by_the_custom_header_markup_without_video_when_previewing_in_customizer() { |
| 229 | | if ( version_compare( PHP_VERSION, '5.3', '<' ) ) { |
| 230 | | $this->markTestSkipped( 'ReflectionMethod::setAccessible is only available in PHP 5.3+' ); |
| 231 | | return; |
| 232 | | } |
| 233 | | |
| 234 | 225 | $this->_add_theme_support( |
| 235 | 226 | array( |
| 236 | 227 | 'video' => true, |
diff --git a/tests/phpunit/tests/widgets/media-widget.php b/tests/phpunit/tests/widgets/media-widget.php
index 86a06eccc6..6b9dc926ce 100644
|
a
|
b
|
class Test_WP_Widget_Media extends WP_UnitTestCase { |
| 479 | 479 | * @covers WP_Widget_Media::has_content() |
| 480 | 480 | */ |
| 481 | 481 | function test_has_content() { |
| 482 | | if ( version_compare( PHP_VERSION, '5.3', '<' ) ) { |
| 483 | | $this->markTestSkipped( 'ReflectionMethod::setAccessible is only available for PHP 5.3+' ); |
| 484 | | return; |
| 485 | | } |
| 486 | | |
| 487 | 482 | $attachment_id = self::factory()->attachment->create_object( |
| 488 | 483 | array( |
| 489 | 484 | 'file' => DIR_TESTDATA . '/images/canola.jpg', |