Make WordPress Core

Ticket #39125: 39125.2.diff

File 39125.2.diff, 2.2 KB (added by tyxla, 8 years ago)

Update patch to include a unit test.

  • src/wp-includes/class-wp-customize-manager.php

     
    38893889                $this->add_setting( 'external_header_video', array(
    38903890                        'theme_supports'    => array( 'custom-header', 'video' ),
    38913891                        'transport'         => 'postMessage',
    3892                         'sanitize_callback' => 'esc_url_raw',
     3892                        'sanitize_callback' => array( $this, '_sanitize_external_header_video' ),
    38933893                        'validate_callback' => array( $this, '_validate_external_header_video' ),
    38943894                ) );
    38953895
     
    43124312        }
    43134313
    43144314        /**
     4315         * Callback for sanitizing the external_header_video value.
     4316         *
     4317         * @since 4.7.1
     4318         *
     4319         * @param string $value
     4320         * @return string
     4321         */
     4322        public function _sanitize_external_header_video( $value ) {
     4323                return esc_url_raw( trim( $value ) );
     4324        }
     4325
     4326        /**
    43154327         * Callback for rendering the custom logo, used in the custom_logo partial.
    43164328         *
    43174329         * This method exists because the partial object and context data are passed
  • tests/phpunit/tests/customize/manager.php

     
    25802580                $result = $this->manager->panels();
    25812581                $this->assertEquals( $panels_sorted, array_keys( $result ) );
    25822582        }
     2583
     2584        /**
     2585         * Verify sanitization of external header video URL will trim the whitespaces in the beginning and end of the URL.
     2586         *
     2587         * @ticket 39125
     2588         */
     2589        function test_sanitize_external_header_video_trim() {
     2590                $this->manager->register_controls();
     2591                $setting = $this->manager->get_setting( 'external_header_video' );
     2592                $video_url = 'https://www.youtube.com/watch?v=KiS8rZBeIO0';
     2593
     2594                $whitespaces = array(
     2595                        ' ',  // space
     2596                        "\t", // horizontal tab
     2597                        "\n", // line feed
     2598                        "\r", // carriage return,
     2599                        "\f", // form feed,
     2600                        "\v"  // vertical tab
     2601                );
     2602
     2603                foreach ( $whitespaces as $whitespace  ) {
     2604                        $sanitized = $setting->sanitize( $whitespace . $video_url . $whitespace );
     2605                        $this->assertEquals( $video_url, $sanitized );
     2606                }
     2607        }
    25832608}
    25842609
    25852610require_once ABSPATH . WPINC . '/class-wp-customize-setting.php';