WordPress.org

Make WordPress Core

Ticket #42498: 42498.3.diff

File 42498.3.diff, 2.3 KB (added by westonruter, 4 years ago)
  • src/wp-admin/includes/template.php

    diff --git src/wp-admin/includes/template.php src/wp-admin/includes/template.php
    index ec0fb52591..0c8c863ec7 100644
    function get_settings_errors( $setting = '', $sanitize = false ) { 
    14571457        }
    14581458
    14591459        // Check global in case errors have been added on this pageload.
    1460         if ( ! count( $wp_settings_errors ) )
     1460        if ( empty( $wp_settings_errors ) ) {
    14611461                return array();
     1462        }
    14621463
    14631464        // Filter the results to those of a specific setting if one was set.
    14641465        if ( $setting ) {
  • tests/phpunit/tests/option/sanitize-option.php

    diff --git tests/phpunit/tests/option/sanitize-option.php tests/phpunit/tests/option/sanitize-option.php
    index bb4a814c54..632b70cbc2 100644
    class Tests_Sanitize_Option extends WP_UnitTestCase { 
    157157                        array( '/%year/%postname%/', '/%year/%postname%/', true ),
    158158                );
    159159        }
     160
     161        /**
     162         * Test calling get_settings_errors() with variations on where it gets errors from.
     163         *
     164         * @ticket 42498
     165         * @global array $wp_settings_errors
     166         */
     167        public function test_get_settings_errors_sources() {
     168                global $wp_settings_errors;
     169
     170                $blogname_error = array(
     171                        'setting' => 'blogname',
     172                        'code'    => 'blogname',
     173                        'message' => 'Capital P dangit!',
     174                        'type'    => 'error',
     175                );
     176                $blogdescription_error = array(
     177                        'setting' => 'blogdescription',
     178                        'code'    => 'blogdescription',
     179                        'message' => 'Too short',
     180                        'type'    => 'error',
     181                );
     182
     183                $wp_settings_errors = null;
     184                $this->assertSame( array(), get_settings_errors( 'blogname' ) );
     185
     186                // Test getting errors from transient.
     187                $_GET['settings-updated'] = '1';
     188                set_transient( 'settings_errors', array( $blogname_error ) );
     189                $wp_settings_errors = null;
     190                $this->assertSame( array( $blogname_error ), get_settings_errors( 'blogname' ) );
     191
     192                // Test getting errors from transient and from global.
     193                $_GET['settings-updated'] = '1';
     194                set_transient( 'settings_errors', array( $blogname_error ) );
     195                $wp_settings_errors = null;
     196                add_settings_error( $blogdescription_error['setting'], $blogdescription_error['code'], $blogdescription_error['message'], $blogdescription_error['type'] );
     197                $this->assertEqualSets( array( $blogname_error, $blogdescription_error ), get_settings_errors() );
     198
     199                $wp_settings_errors = null;
     200        }
    160201}