mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
Adds a `public` visibility to test fixtures, tests, data providers, and callbacks methods. Adds a `private` visibility to helper methods within test classes. Renames callbacks and helpers that previously started with a `_` prefix. Why? For consistency and to leverage using the method visibility. Further naming standardizations is beyond the scope of this commit. Props costdev, jrf, hellofromTonya. Fixes #54177. git-svn-id: https://develop.svn.wordpress.org/trunk@52010 602fd350-edb4-49c9-b593-d223f7449a82
133 lines
2.8 KiB
PHP
133 lines
2.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Test wp_sanitize_script_attributes().
|
|
*
|
|
* @group dependencies
|
|
* @group scripts
|
|
* @covers ::wp_sanitize_script_attributes
|
|
*/
|
|
class Tests_Functions_wpSanitizeScriptAttributes extends WP_UnitTestCase {
|
|
|
|
public function test_sanitize_script_attributes_type_set() {
|
|
add_theme_support( 'html5', array( 'script' ) );
|
|
|
|
$this->assertSame(
|
|
' type="application/javascript" src="https://DOMAIN.TLD/PATH/FILE.js" nomodule',
|
|
wp_sanitize_script_attributes(
|
|
array(
|
|
'type' => 'application/javascript',
|
|
'src' => 'https://DOMAIN.TLD/PATH/FILE.js',
|
|
'async' => false,
|
|
'nomodule' => true,
|
|
)
|
|
)
|
|
);
|
|
|
|
remove_theme_support( 'html5' );
|
|
|
|
$this->assertSame(
|
|
' src="https://DOMAIN.TLD/PATH/FILE.js" type="application/javascript" nomodule="nomodule"',
|
|
wp_sanitize_script_attributes(
|
|
array(
|
|
'src' => 'https://DOMAIN.TLD/PATH/FILE.js',
|
|
'type' => 'application/javascript',
|
|
'async' => false,
|
|
'nomodule' => true,
|
|
)
|
|
)
|
|
);
|
|
}
|
|
|
|
public function test_sanitize_script_attributes_type_not_set() {
|
|
add_theme_support( 'html5', array( 'script' ) );
|
|
|
|
$this->assertSame(
|
|
' src="https://DOMAIN.TLD/PATH/FILE.js" nomodule',
|
|
wp_sanitize_script_attributes(
|
|
array(
|
|
'src' => 'https://DOMAIN.TLD/PATH/FILE.js',
|
|
'async' => false,
|
|
'nomodule' => true,
|
|
)
|
|
)
|
|
);
|
|
|
|
remove_theme_support( 'html5' );
|
|
|
|
$this->assertSame(
|
|
' src="https://DOMAIN.TLD/PATH/FILE.js" nomodule="nomodule"',
|
|
wp_sanitize_script_attributes(
|
|
array(
|
|
'src' => 'https://DOMAIN.TLD/PATH/FILE.js',
|
|
'async' => false,
|
|
'nomodule' => true,
|
|
)
|
|
)
|
|
);
|
|
}
|
|
|
|
|
|
public function test_sanitize_script_attributes_no_attributes() {
|
|
add_theme_support( 'html5', array( 'script' ) );
|
|
|
|
$this->assertSame(
|
|
'',
|
|
wp_sanitize_script_attributes( array() )
|
|
);
|
|
|
|
remove_theme_support( 'html5' );
|
|
}
|
|
|
|
public function test_sanitize_script_attributes_relative_src() {
|
|
add_theme_support( 'html5', array( 'script' ) );
|
|
|
|
$this->assertSame(
|
|
' src="PATH/FILE.js" nomodule',
|
|
wp_sanitize_script_attributes(
|
|
array(
|
|
'src' => 'PATH/FILE.js',
|
|
'async' => false,
|
|
'nomodule' => true,
|
|
)
|
|
)
|
|
);
|
|
|
|
remove_theme_support( 'html5' );
|
|
}
|
|
|
|
|
|
public function test_sanitize_script_attributes_only_false_boolean_attributes() {
|
|
add_theme_support( 'html5', array( 'script' ) );
|
|
|
|
$this->assertSame(
|
|
'',
|
|
wp_sanitize_script_attributes(
|
|
array(
|
|
'async' => false,
|
|
'nomodule' => false,
|
|
)
|
|
)
|
|
);
|
|
|
|
remove_theme_support( 'html5' );
|
|
}
|
|
|
|
public function test_sanitize_script_attributes_only_true_boolean_attributes() {
|
|
add_theme_support( 'html5', array( 'script' ) );
|
|
|
|
$this->assertSame(
|
|
' async nomodule',
|
|
wp_sanitize_script_attributes(
|
|
array(
|
|
'async' => true,
|
|
'nomodule' => true,
|
|
)
|
|
)
|
|
);
|
|
|
|
remove_theme_support( 'html5' );
|
|
}
|
|
|
|
}
|