Make WordPress Core

Ticket #16560: 16560-unit-test.2.patch

File 16560-unit-test.2.patch, 4.9 KB (added by kurtpayne, 13 years ago)

Asserting bad protocols (e.g. FTP) get prepended with current site's URL

  • wp-testcase/test_includes_wp-scripts.php

     
    3535                // No scripts left to print
    3636                $this->assertEquals("", get_echo('wp_print_scripts'));
    3737        }
     38       
     39        /**
     40         * Test the different protocol references in wp_enqueue_script
     41         * @global WP_Scripts $wp_scripts
     42         */
     43        public function test_protocols() {
     44                $this->knownWPBug( 16560 );
     45
     46                // Init
     47                global $wp_scripts;
     48                $base_url_backup = $wp_scripts->base_url;
     49                $wp_scripts->base_url = 'http://localhost/wordpress';
     50                $expected = '';
     51                $ver = get_bloginfo( 'version' );
     52
     53                // Try with an HTTP reference
     54                wp_enqueue_script( 'jquery-http', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js' );
     55                $expected  .= "<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js?ver=$ver'></script>\n";
     56
     57                // Try with an HTTPS reference
     58                wp_enqueue_script( 'jquery-https', 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js' );
     59                $expected  .= "<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js?ver=$ver'></script>\n";
     60               
     61                // Try with an automatic protocol reference (//)
     62                wp_enqueue_script( 'jquery-doubleslash', '//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js' );
     63                $expected  .= "<script type='text/javascript' src='//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js?ver=$ver'></script>\n";
     64
     65                // Try with a local resource and an automatic protocol reference (//)
     66                $url = '/' . plugins_url( '/my_plugin/script.js');
     67                wp_enqueue_script( 'plugin-script', $url  );
     68                $expected  .= "<script type='text/javascript' src='$url?ver=$ver'></script>\n";
     69
     70                // Try with a bad protocol
     71                wp_enqueue_script( 'jquery-ftp', 'ftp://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js' );
     72                $expected  .= "<script type='text/javascript' src='{$wp_scripts->base_url}ftp://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js?ver=$ver'></script>\n";
     73               
     74                // Go!
     75                $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
     76
     77                // No scripts left to print
     78                $this->assertEquals( '', get_echo( 'wp_print_scripts' ) );
     79
     80                // Cleanup
     81                $wp_scripts->base_url = $base_url_backup;
     82        }
    3883}
    3984?>
     85 No newline at end of file
  • wp-testcase/test_includes_wp-styles.php

     
    3333                // No styles left to print
    3434                $this->assertEquals("", get_echo('wp_print_styles'));
    3535        }
     36       
     37        /**
     38         * Test the different protocol references in wp_enqueue_style
     39         * @global WP_Styles $wp_styles
     40         */
     41        public function test_protocols() {
     42                $this->knownWPBug( 16560 );
     43
     44                // Init
     45                global $wp_styles;
     46                $base_url_backup = $wp_styles->base_url;
     47                $wp_styles->base_url = 'http://localhost/wordpress';
     48                $expected = '';
     49                $ver = get_bloginfo( 'version' );
     50
     51                // Try with an HTTP reference
     52                wp_enqueue_style( 'reset-css-http', 'http://yui.yahooapis.com/2.8.1/build/reset/reset-min.css' );
     53                $expected  .= "<link rel='stylesheet' id='reset-css-http-css'  href='http://yui.yahooapis.com/2.8.1/build/reset/reset-min.css?ver=$ver' type='text/css' media='all' />\n";
     54
     55                // Try with an HTTPS reference
     56                wp_enqueue_style( 'reset-css-https', 'http://yui.yahooapis.com/2.8.1/build/reset/reset-min.css' );
     57                $expected  .= "<link rel='stylesheet' id='reset-css-https-css'  href='http://yui.yahooapis.com/2.8.1/build/reset/reset-min.css?ver=$ver' type='text/css' media='all' />\n";
     58               
     59                // Try with an automatic protocol reference (//)
     60                wp_enqueue_style( 'reset-css-doubleslash', '//yui.yahooapis.com/2.8.1/build/reset/reset-min.css' );
     61                $expected  .= "<link rel='stylesheet' id='reset-css-doubleslash-css'  href='//yui.yahooapis.com/2.8.1/build/reset/reset-min.css?ver=$ver' type='text/css' media='all' />\n";
     62               
     63                // Try with a local resource and an automatic protocol reference (//)
     64                $url = '/' . plugins_url( '/my_plugin/style.css');
     65                wp_enqueue_style( 'plugin-style', $url  );
     66                $expected  .= "<link rel='stylesheet' id='plugin-style-css'  href='$url?ver=$ver' type='text/css' media='all' />\n";
     67
     68                // Try with a bad protocol
     69                wp_enqueue_style( 'reset-css-ftp', 'ftp://yui.yahooapis.com/2.8.1/build/reset/reset-min.css' );
     70                $expected  .= "<link rel='stylesheet' id='reset-css-ftp-css'  href='{$wp_styles->base_url}ftp://yui.yahooapis.com/2.8.1/build/reset/reset-min.css?ver=$ver' type='text/css' media='all' />\n";
     71
     72                // Go!
     73                $this->assertEquals( $expected, get_echo( 'wp_print_styles' ) );
     74
     75                // No styles left to print
     76                $this->assertEquals( '', get_echo( 'wp_print_styles' ) );
     77
     78                // Cleanup
     79                $wp_styles->base_url = $base_url_backup;
     80        }
    3681}
    3782?>