mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
This ensures that not only the return values match the expected results, but also that their type is the same. Going forward, stricter type checking by using `assertSame()` should generally be preferred to `assertEquals()` where appropriate, to make the tests more reliable. Props johnbillion, jrf, SergeyBiryukov. See #38266. git-svn-id: https://develop.svn.wordpress.org/trunk@48937 602fd350-edb4-49c9-b593-d223f7449a82
41 lines
1.7 KiB
PHP
41 lines
1.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group formatting
|
|
*/
|
|
class Tests_Formatting_EscHtml extends WP_UnitTestCase {
|
|
function test_esc_html_basics() {
|
|
// Simple string.
|
|
$html = 'The quick brown fox.';
|
|
$this->assertSame( $html, esc_html( $html ) );
|
|
|
|
// URL with &.
|
|
$html = 'http://localhost/trunk/wp-login.php?action=logout&_wpnonce=cd57d75985';
|
|
$escaped = 'http://localhost/trunk/wp-login.php?action=logout&_wpnonce=cd57d75985';
|
|
$this->assertSame( $escaped, esc_html( $html ) );
|
|
|
|
// SQL query.
|
|
$html = "SELECT meta_key, meta_value FROM wp_trunk_sitemeta WHERE meta_key IN ('site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'can_compress_scripts', 'global_terms_enabled') AND site_id = 1";
|
|
$escaped = 'SELECT meta_key, meta_value FROM wp_trunk_sitemeta WHERE meta_key IN ('site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'can_compress_scripts', 'global_terms_enabled') AND site_id = 1';
|
|
$this->assertSame( $escaped, esc_html( $html ) );
|
|
}
|
|
|
|
function test_escapes_ampersands() {
|
|
$source = 'penn & teller & at&t';
|
|
$res = 'penn & teller & at&t';
|
|
$this->assertSame( $res, esc_html( $source ) );
|
|
}
|
|
|
|
function test_escapes_greater_and_less_than() {
|
|
$source = 'this > that < that <randomhtml />';
|
|
$res = 'this > that < that <randomhtml />';
|
|
$this->assertSame( $res, esc_html( $source ) );
|
|
}
|
|
|
|
function test_ignores_existing_entities() {
|
|
$source = '& £ " &';
|
|
$res = '& £ " &';
|
|
$this->assertSame( $res, esc_html( $source ) );
|
|
}
|
|
}
|