mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-09-13 04:20:18 +00:00
Adds an expectation for PHP 8.1 "passing null to non-nullable" deprecation notice to select tests where the deprecation is generated by one of the functions in the `wp-includes/formatting.php` file, either via a filter hook callback or by a direct call. Instead of haphazardly fixing these issues exposed by the tests, a more structural and all-encompassing solution for input validation should be architected and implemented as otherwise, we'll keep running into similar issues time and again with each new PHP version. To discourage people from "fixing" these issues now anyway, this commit "hides" nearly all of these issues from the test runs. Once a more structural solution is designed, these tests and the underlying functions causing the deprecation notices should be revisited and the structural solution put in place. Includes a few minor other tweaks to select tests: * Removing a stray `return` (twice) from assertion statements. * Removing calls to `ob_*()` functions in favour of letting PHPUnit manage the output catching. This prevents warnings along the lines of `Test code or tested code did not (only) close its own output buffers`. Props jrf, hellofromTonya. See #53635. git-svn-id: https://develop.svn.wordpress.org/trunk@51968 602fd350-edb4-49c9-b593-d223f7449a82
125 lines
4.7 KiB
PHP
125 lines
4.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group formatting
|
|
*/
|
|
class Tests_Formatting_wpRelUgc extends WP_UnitTestCase {
|
|
|
|
/**
|
|
* @ticket 48022
|
|
*/
|
|
public function test_add_ugc() {
|
|
if ( PHP_VERSION_ID >= 80100 ) {
|
|
/*
|
|
* For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
|
|
* via hooked in filter functions until a more structural solution to the
|
|
* "missing input validation" conundrum has been architected and implemented.
|
|
*/
|
|
$this->expectDeprecation();
|
|
$this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
|
|
}
|
|
|
|
$content = '<p>This is some cool <a href="/">Code</a></p>';
|
|
$expected = '<p>This is some cool <a href=\"/\" rel=\"nofollow ugc\">Code</a></p>';
|
|
$this->assertSame( $expected, wp_rel_ugc( $content ) );
|
|
}
|
|
|
|
/**
|
|
* @ticket 48022
|
|
*/
|
|
public function test_convert_ugc() {
|
|
if ( PHP_VERSION_ID >= 80100 ) {
|
|
/*
|
|
* For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
|
|
* via hooked in filter functions until a more structural solution to the
|
|
* "missing input validation" conundrum has been architected and implemented.
|
|
*/
|
|
$this->expectDeprecation();
|
|
$this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
|
|
}
|
|
|
|
$content = '<p>This is some cool <a href="/" rel="weird">Code</a></p>';
|
|
$expected = '<p>This is some cool <a href=\"/\" rel=\"weird nofollow ugc\">Code</a></p>';
|
|
$this->assertSame( $expected, wp_rel_ugc( $content ) );
|
|
}
|
|
|
|
/**
|
|
* @ticket 48022
|
|
* @dataProvider data_wp_rel_ugc
|
|
*/
|
|
public function test_wp_rel_ugc( $input, $output, $expect_deprecation = false ) {
|
|
if ( true === $expect_deprecation && PHP_VERSION_ID >= 80100 ) {
|
|
/*
|
|
* For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
|
|
* via hooked in filter functions until a more structural solution to the
|
|
* "missing input validation" conundrum has been architected and implemented.
|
|
*/
|
|
$this->expectDeprecation();
|
|
$this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
|
|
}
|
|
|
|
$this->assertSame( wp_slash( $output ), wp_rel_ugc( $input ) );
|
|
}
|
|
|
|
public function data_wp_rel_ugc() {
|
|
$home_url_http = set_url_scheme( home_url(), 'http' );
|
|
$home_url_https = set_url_scheme( home_url(), 'https' );
|
|
|
|
return array(
|
|
array(
|
|
'<a href="">Double Quotes</a>',
|
|
'<a href="" rel="nofollow ugc">Double Quotes</a>',
|
|
true,
|
|
),
|
|
array(
|
|
'<a href="https://wordpress.org">Double Quotes</a>',
|
|
'<a href="https://wordpress.org" rel="nofollow ugc">Double Quotes</a>',
|
|
),
|
|
array(
|
|
"<a href='https://wordpress.org'>Single Quotes</a>",
|
|
"<a href='https://wordpress.org' rel=\"nofollow ugc\">Single Quotes</a>",
|
|
),
|
|
array(
|
|
'<a href="https://wordpress.org" title="Title">Multiple attributes</a>',
|
|
'<a href="https://wordpress.org" title="Title" rel="nofollow ugc">Multiple attributes</a>',
|
|
),
|
|
array(
|
|
'<a title="Title" href="https://wordpress.org">Multiple attributes</a>',
|
|
'<a title="Title" href="https://wordpress.org" rel="nofollow ugc">Multiple attributes</a>',
|
|
),
|
|
array(
|
|
'<a data-someflag href="https://wordpress.org">Multiple attributes</a>',
|
|
'<a data-someflag href="https://wordpress.org" rel="nofollow ugc">Multiple attributes</a>',
|
|
),
|
|
array(
|
|
'<a data-someflag title="Title" href="https://wordpress.org" onclick="" >Everything at once</a>',
|
|
'<a data-someflag title="Title" href="https://wordpress.org" onclick="" rel="nofollow ugc">Everything at once</a>',
|
|
),
|
|
array(
|
|
'<a href="' . $home_url_http . '/some-url">Home URL (http)</a>',
|
|
'<a href="' . $home_url_http . '/some-url">Home URL (http)</a>',
|
|
),
|
|
array(
|
|
'<a href="' . $home_url_https . '/some-url">Home URL (https)</a>',
|
|
'<a href="' . $home_url_https . '/some-url">Home URL (https)</a>',
|
|
),
|
|
);
|
|
}
|
|
|
|
public function test_append_ugc_with_valueless_attribute() {
|
|
if ( PHP_VERSION_ID >= 80100 ) {
|
|
/*
|
|
* For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
|
|
* via hooked in filter functions until a more structural solution to the
|
|
* "missing input validation" conundrum has been architected and implemented.
|
|
*/
|
|
$this->expectDeprecation();
|
|
$this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
|
|
}
|
|
|
|
$content = '<p>This is some cool <a href="demo.com" download rel="hola">Code</a></p>';
|
|
$expected = '<p>This is some cool <a href=\"demo.com\" download rel=\"hola nofollow ugc\">Code</a></p>';
|
|
$this->assertSame( $expected, wp_rel_ugc( $content ) );
|
|
}
|
|
}
|