Make WordPress Core


Ignore:
Timestamp:
11/10/2017 10:29:45 PM (7 years ago)
Author:
westonruter
Message:

Settings: Replace count() call with empty() in get_settings_errors() to prevent PHP 7.2 warnings when $wp_settings_errors is null.

Props pross, dd32, westonruter.
See #40109.
Fixes #42498 for trunk.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/option/sanitize-option.php

    r37747 r42146  
    158158        );
    159159    }
     160
     161    /**
     162     * Test calling get_settings_errors() with variations on where it gets errors from.
     163     *
     164     * @ticket 42498
     165     * @covers get_settings_errors()
     166     * @global array $wp_settings_errors
     167     */
     168    public function test_get_settings_errors_sources() {
     169        global $wp_settings_errors;
     170
     171        $blogname_error = array(
     172            'setting' => 'blogname',
     173            'code'    => 'blogname',
     174            'message' => 'Capital P dangit!',
     175            'type'    => 'error',
     176        );
     177        $blogdescription_error = array(
     178            'setting' => 'blogdescription',
     179            'code'    => 'blogdescription',
     180            'message' => 'Too short',
     181            'type'    => 'error',
     182        );
     183
     184        $wp_settings_errors = null;
     185        $this->assertSame( array(), get_settings_errors( 'blogname' ) );
     186
     187        // Test getting errors from transient.
     188        $_GET['settings-updated'] = '1';
     189        set_transient( 'settings_errors', array( $blogname_error ) );
     190        $wp_settings_errors = null;
     191        $this->assertSame( array( $blogname_error ), get_settings_errors( 'blogname' ) );
     192
     193        // Test getting errors from transient and from global.
     194        $_GET['settings-updated'] = '1';
     195        set_transient( 'settings_errors', array( $blogname_error ) );
     196        $wp_settings_errors = null;
     197        add_settings_error( $blogdescription_error['setting'], $blogdescription_error['code'], $blogdescription_error['message'], $blogdescription_error['type'] );
     198        $this->assertEqualSets( array( $blogname_error, $blogdescription_error ), get_settings_errors() );
     199
     200        $wp_settings_errors = null;
     201    }
    160202}
Note: See TracChangeset for help on using the changeset viewer.