Tests: Add a unit test for PHP 8.1 deprecation notice in wp_user_settings().

This ensures that PHP 8.1 "passing null to non-nullable" deprecation notice is not thrown for the `$domain` parameter of `setcookie()` calls in the function.

Follow-up to [53490].

See #54914.

git-svn-id: https://develop.svn.wordpress.org/trunk@53493 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2022-06-13 15:20:02 +00:00
parent 26d3ef0bf0
commit cde9366b3a

View File

@ -0,0 +1,36 @@
<?php
/**
* Test wp_user_settings().
*
* @group option
* @group user
* @covers ::wp_user_settings
*/
class Tests_Option_wpUserSettings extends WP_UnitTestCase {
/**
* Tests that PHP 8.1 "passing null to non-nullable" deprecation notice
* is not thrown for the `$domain` parameter of setcookie() calls in the function.
*
* The notice that we should not see:
* `Deprecated: setcookie(): Passing null to parameter #5 ($domain) of type string is deprecated`.
*
* Note: This does not test the actual functioning of wp_user_settings().
* It just and only tests for/against the deprecation notice.
*
* @ticket 54914
*/
public function test_wp_user_settings_does_not_throw_deprecation_notice_for_setcookie() {
set_current_screen( 'edit.php' );
wp_set_current_user( self::factory()->user->create() );
// Verify that the function's starting conditions are satisfied.
$this->assertTrue( is_admin() );
$this->assertGreaterThan( 0, get_current_user_id() );
// `Cannot modify header information - headers already sent by...` from setcookie().
$this->expectWarning();
wp_user_settings();
}
}