mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-14 09:34:41 +00:00
Coding Standards: Add visibility to methods in tests/phpunit/tests/.
Adds a `public` visibility to test fixtures, tests, data providers, and callbacks methods. Adds a `private` visibility to helper methods within test classes. Renames callbacks and helpers that previously started with a `_` prefix. Why? For consistency and to leverage using the method visibility. Further naming standardizations is beyond the scope of this commit. Props costdev, jrf, hellofromTonya. Fixes #54177. git-svn-id: https://develop.svn.wordpress.org/trunk@52010 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -10,7 +10,7 @@ class Tests_General_wpResourceHints extends WP_UnitTestCase {
|
||||
private $old_wp_scripts;
|
||||
private $old_wp_styles;
|
||||
|
||||
function set_up() {
|
||||
public function set_up() {
|
||||
parent::set_up();
|
||||
$this->old_wp_scripts = isset( $GLOBALS['wp_scripts'] ) ? $GLOBALS['wp_scripts'] : null;
|
||||
$this->old_wp_styles = isset( $GLOBALS['wp_styles'] ) ? $GLOBALS['wp_styles'] : null;
|
||||
@@ -24,13 +24,13 @@ class Tests_General_wpResourceHints extends WP_UnitTestCase {
|
||||
$GLOBALS['wp_styles']->default_version = get_bloginfo( 'version' );
|
||||
}
|
||||
|
||||
function tear_down() {
|
||||
public function tear_down() {
|
||||
$GLOBALS['wp_scripts'] = $this->old_wp_scripts;
|
||||
$GLOBALS['wp_styles'] = $this->old_wp_styles;
|
||||
parent::tear_down();
|
||||
}
|
||||
|
||||
function test_should_have_defaults_on_frontend() {
|
||||
public function test_should_have_defaults_on_frontend() {
|
||||
$expected = "<link rel='dns-prefetch' href='//s.w.org' />\n";
|
||||
|
||||
$this->expectOutputString( $expected );
|
||||
@@ -38,22 +38,22 @@ class Tests_General_wpResourceHints extends WP_UnitTestCase {
|
||||
wp_resource_hints();
|
||||
}
|
||||
|
||||
function test_dns_prefetching() {
|
||||
public function test_dns_prefetching() {
|
||||
$expected = "<link rel='dns-prefetch' href='//s.w.org' />\n" .
|
||||
"<link rel='dns-prefetch' href='//wordpress.org' />\n" .
|
||||
"<link rel='dns-prefetch' href='//google.com' />\n" .
|
||||
"<link rel='dns-prefetch' href='//make.wordpress.org' />\n";
|
||||
|
||||
add_filter( 'wp_resource_hints', array( $this, '_add_dns_prefetch_domains' ), 10, 2 );
|
||||
add_filter( 'wp_resource_hints', array( $this, 'add_dns_prefetch_domains' ), 10, 2 );
|
||||
|
||||
$actual = get_echo( 'wp_resource_hints' );
|
||||
|
||||
remove_filter( 'wp_resource_hints', array( $this, '_add_dns_prefetch_domains' ) );
|
||||
remove_filter( 'wp_resource_hints', array( $this, 'add_dns_prefetch_domains' ) );
|
||||
|
||||
$this->assertSame( $expected, $actual );
|
||||
}
|
||||
|
||||
function _add_dns_prefetch_domains( $hints, $method ) {
|
||||
public function add_dns_prefetch_domains( $hints, $method ) {
|
||||
if ( 'dns-prefetch' === $method ) {
|
||||
$hints[] = 'http://wordpress.org';
|
||||
$hints[] = 'https://wordpress.org';
|
||||
@@ -69,23 +69,23 @@ class Tests_General_wpResourceHints extends WP_UnitTestCase {
|
||||
/**
|
||||
* @ticket 37652
|
||||
*/
|
||||
function test_preconnect() {
|
||||
public function test_preconnect() {
|
||||
$expected = "<link rel='dns-prefetch' href='//s.w.org' />\n" .
|
||||
"<link rel='preconnect' href='//wordpress.org' />\n" .
|
||||
"<link rel='preconnect' href='https://make.wordpress.org' />\n" .
|
||||
"<link rel='preconnect' href='http://google.com' />\n" .
|
||||
"<link rel='preconnect' href='http://w.org' />\n";
|
||||
|
||||
add_filter( 'wp_resource_hints', array( $this, '_add_preconnect_domains' ), 10, 2 );
|
||||
add_filter( 'wp_resource_hints', array( $this, 'add_preconnect_domains' ), 10, 2 );
|
||||
|
||||
$actual = get_echo( 'wp_resource_hints' );
|
||||
|
||||
remove_filter( 'wp_resource_hints', array( $this, '_add_preconnect_domains' ) );
|
||||
remove_filter( 'wp_resource_hints', array( $this, 'add_preconnect_domains' ) );
|
||||
|
||||
$this->assertSame( $expected, $actual );
|
||||
}
|
||||
|
||||
function _add_preconnect_domains( $hints, $method ) {
|
||||
public function add_preconnect_domains( $hints, $method ) {
|
||||
if ( 'preconnect' === $method ) {
|
||||
$hints[] = '//wordpress.org';
|
||||
$hints[] = 'https://make.wordpress.org';
|
||||
@@ -97,22 +97,22 @@ class Tests_General_wpResourceHints extends WP_UnitTestCase {
|
||||
return $hints;
|
||||
}
|
||||
|
||||
function test_prerender() {
|
||||
public function test_prerender() {
|
||||
$expected = "<link rel='dns-prefetch' href='//s.w.org' />\n" .
|
||||
"<link rel='prerender' href='https://make.wordpress.org/great-again' />\n" .
|
||||
"<link rel='prerender' href='http://jobs.wordpress.net' />\n" .
|
||||
"<link rel='prerender' href='//core.trac.wordpress.org' />\n";
|
||||
|
||||
add_filter( 'wp_resource_hints', array( $this, '_add_prerender_urls' ), 10, 2 );
|
||||
add_filter( 'wp_resource_hints', array( $this, 'add_prerender_urls' ), 10, 2 );
|
||||
|
||||
$actual = get_echo( 'wp_resource_hints' );
|
||||
|
||||
remove_filter( 'wp_resource_hints', array( $this, '_add_prerender_urls' ) );
|
||||
remove_filter( 'wp_resource_hints', array( $this, 'add_prerender_urls' ) );
|
||||
|
||||
$this->assertSame( $expected, $actual );
|
||||
}
|
||||
|
||||
function _add_prerender_urls( $hints, $method ) {
|
||||
public function add_prerender_urls( $hints, $method ) {
|
||||
if ( 'prerender' === $method ) {
|
||||
$hints[] = 'https://make.wordpress.org/great-again';
|
||||
$hints[] = 'http://jobs.wordpress.net';
|
||||
@@ -123,20 +123,20 @@ class Tests_General_wpResourceHints extends WP_UnitTestCase {
|
||||
return $hints;
|
||||
}
|
||||
|
||||
function test_parse_url_dns_prefetch() {
|
||||
public function test_parse_url_dns_prefetch() {
|
||||
$expected = "<link rel='dns-prefetch' href='//s.w.org' />\n" .
|
||||
"<link rel='dns-prefetch' href='//make.wordpress.org' />\n";
|
||||
|
||||
add_filter( 'wp_resource_hints', array( $this, '_add_dns_prefetch_long_urls' ), 10, 2 );
|
||||
add_filter( 'wp_resource_hints', array( $this, 'add_dns_prefetch_long_urls' ), 10, 2 );
|
||||
|
||||
$actual = get_echo( 'wp_resource_hints' );
|
||||
|
||||
remove_filter( 'wp_resource_hints', array( $this, '_add_dns_prefetch_long_urls' ) );
|
||||
remove_filter( 'wp_resource_hints', array( $this, 'add_dns_prefetch_long_urls' ) );
|
||||
|
||||
$this->assertSame( $expected, $actual );
|
||||
}
|
||||
|
||||
function _add_dns_prefetch_long_urls( $hints, $method ) {
|
||||
public function add_dns_prefetch_long_urls( $hints, $method ) {
|
||||
if ( 'dns-prefetch' === $method ) {
|
||||
$hints[] = 'http://make.wordpress.org/wp-includes/css/editor.css';
|
||||
}
|
||||
@@ -144,7 +144,7 @@ class Tests_General_wpResourceHints extends WP_UnitTestCase {
|
||||
return $hints;
|
||||
}
|
||||
|
||||
function test_dns_prefetch_styles() {
|
||||
public function test_dns_prefetch_styles() {
|
||||
$expected = "<link rel='dns-prefetch' href='//fonts.googleapis.com' />\n" .
|
||||
"<link rel='dns-prefetch' href='//s.w.org' />\n";
|
||||
|
||||
@@ -163,7 +163,7 @@ class Tests_General_wpResourceHints extends WP_UnitTestCase {
|
||||
|
||||
}
|
||||
|
||||
function test_dns_prefetch_scripts() {
|
||||
public function test_dns_prefetch_scripts() {
|
||||
$expected = "<link rel='dns-prefetch' href='//fonts.googleapis.com' />\n" .
|
||||
"<link rel='dns-prefetch' href='//s.w.org' />\n";
|
||||
|
||||
@@ -184,7 +184,7 @@ class Tests_General_wpResourceHints extends WP_UnitTestCase {
|
||||
/**
|
||||
* @ticket 37385
|
||||
*/
|
||||
function test_dns_prefetch_scripts_does_not_include_registered_only() {
|
||||
public function test_dns_prefetch_scripts_does_not_include_registered_only() {
|
||||
$expected = "<link rel='dns-prefetch' href='//s.w.org' />\n";
|
||||
$unexpected = "<link rel='dns-prefetch' href='//wordpress.org' />\n";
|
||||
|
||||
@@ -201,7 +201,7 @@ class Tests_General_wpResourceHints extends WP_UnitTestCase {
|
||||
/**
|
||||
* @ticket 37502
|
||||
*/
|
||||
function test_deregistered_scripts_are_ignored() {
|
||||
public function test_deregistered_scripts_are_ignored() {
|
||||
$expected = "<link rel='dns-prefetch' href='//s.w.org' />\n";
|
||||
|
||||
wp_enqueue_script( 'test-script', 'http://example.org/script.js' );
|
||||
@@ -214,23 +214,23 @@ class Tests_General_wpResourceHints extends WP_UnitTestCase {
|
||||
/**
|
||||
* @ticket 37652
|
||||
*/
|
||||
function test_malformed_urls() {
|
||||
public function test_malformed_urls() {
|
||||
$expected = "<link rel='dns-prefetch' href='//s.w.org' />\n";
|
||||
|
||||
// Errant colon.
|
||||
add_filter( 'wp_resource_hints', array( $this, '_add_malformed_url_errant_colon' ), 10, 2 );
|
||||
add_filter( 'wp_resource_hints', array( $this, 'add_malformed_url_errant_colon' ), 10, 2 );
|
||||
$actual = get_echo( 'wp_resource_hints' );
|
||||
remove_filter( 'wp_resource_hints', array( $this, '_add_malformed_url_errant_colon' ) );
|
||||
remove_filter( 'wp_resource_hints', array( $this, 'add_malformed_url_errant_colon' ) );
|
||||
$this->assertSame( $expected, $actual );
|
||||
|
||||
// Unsupported Scheme.
|
||||
add_filter( 'wp_resource_hints', array( $this, '_add_malformed_url_unsupported_scheme' ), 10, 2 );
|
||||
add_filter( 'wp_resource_hints', array( $this, 'add_malformed_url_unsupported_scheme' ), 10, 2 );
|
||||
$actual = get_echo( 'wp_resource_hints' );
|
||||
remove_filter( 'wp_resource_hints', array( $this, '_add_malformed_url_unsupported_scheme' ) );
|
||||
remove_filter( 'wp_resource_hints', array( $this, 'add_malformed_url_unsupported_scheme' ) );
|
||||
$this->assertSame( $expected, $actual );
|
||||
}
|
||||
|
||||
function _add_malformed_url_errant_colon( $hints, $method ) {
|
||||
public function add_malformed_url_errant_colon( $hints, $method ) {
|
||||
if ( 'preconnect' === $method ) {
|
||||
$hints[] = '://core.trac.wordpress.org/ticket/37652';
|
||||
}
|
||||
@@ -238,7 +238,7 @@ class Tests_General_wpResourceHints extends WP_UnitTestCase {
|
||||
return $hints;
|
||||
}
|
||||
|
||||
function _add_malformed_url_unsupported_scheme( $hints, $method ) {
|
||||
public function add_malformed_url_unsupported_scheme( $hints, $method ) {
|
||||
if ( 'preconnect' === $method ) {
|
||||
$hints[] = 'git://develop.git.wordpress.org/';
|
||||
}
|
||||
@@ -249,23 +249,23 @@ class Tests_General_wpResourceHints extends WP_UnitTestCase {
|
||||
/**
|
||||
* @ticket 38121
|
||||
*/
|
||||
function test_custom_attributes() {
|
||||
public function test_custom_attributes() {
|
||||
$expected = "<link rel='dns-prefetch' href='//s.w.org' />\n" .
|
||||
"<link rel='preconnect' href='https://make.wordpress.org' />\n" .
|
||||
"<link crossorigin as='image' pr='0.5' href='https://example.com/foo.jpeg' rel='prefetch' />\n" .
|
||||
"<link crossorigin='use-credentials' as='style' href='https://example.com/foo.css' rel='prefetch' />\n" .
|
||||
"<link href='http://wordpress.org' rel='prerender' />\n";
|
||||
|
||||
add_filter( 'wp_resource_hints', array( $this, '_add_url_with_attributes' ), 10, 2 );
|
||||
add_filter( 'wp_resource_hints', array( $this, 'add_url_with_attributes' ), 10, 2 );
|
||||
|
||||
$actual = get_echo( 'wp_resource_hints' );
|
||||
|
||||
remove_filter( 'wp_resource_hints', array( $this, '_add_url_with_attributes' ) );
|
||||
remove_filter( 'wp_resource_hints', array( $this, 'add_url_with_attributes' ) );
|
||||
|
||||
$this->assertSame( $expected, $actual );
|
||||
}
|
||||
|
||||
function _add_url_with_attributes( $hints, $method ) {
|
||||
public function add_url_with_attributes( $hints, $method ) {
|
||||
// Ignore hints with missing href attributes.
|
||||
$hints[] = array(
|
||||
'rel' => 'foo',
|
||||
|
||||
Reference in New Issue
Block a user