forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathescHtml.php
More file actions
42 lines (36 loc) · 1.79 KB
/
escHtml.php
File metadata and controls
42 lines (36 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
/**
* @group formatting
*
* @covers ::esc_html
*/
class Tests_Formatting_EscHtml extends WP_UnitTestCase {
public 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 ) );
}
public function test_escapes_ampersands() {
$source = 'penn & teller & at&t';
$res = 'penn & teller & at&t';
$this->assertSame( $res, esc_html( $source ) );
}
public function test_escapes_greater_and_less_than() {
$source = 'this > that < that <randomhtml />';
$res = 'this > that < that <randomhtml />';
$this->assertSame( $res, esc_html( $source ) );
}
public function test_ignores_existing_entities() {
$source = '& £ " &';
$res = '& £ " &';
$this->assertSame( $res, esc_html( $source ) );
}
}