wordpress-develop/tests/phpunit/tests/formatting/escJs.php
Sergey Biryukov 4d2762ed93 Tests: Rename classes in phpunit/tests/formatting/ per the naming conventions.
https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#naming-and-organization

Follow-up to [47780], [48911], [49327], [50291], [50292], [50342], [50452], [50453], [50456], [50967], [50968], [50969], [51491], [51492], [51493].

See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51623 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-16 21:33:54 +00:00

47 lines
1.2 KiB
PHP

<?php
/**
* @group formatting
*/
class Tests_Formatting_EscJs extends WP_UnitTestCase {
function test_js_escape_simple() {
$out = esc_js( 'foo bar baz();' );
$this->assertSame( 'foo bar baz();', $out );
}
function test_js_escape_quotes() {
$out = esc_js( 'foo "bar" \'baz\'' );
// Does it make any sense to change " into &quot;? Why not \"?
$this->assertSame( "foo &quot;bar&quot; \'baz\'", $out );
}
function test_js_escape_backslash() {
$bs = '\\';
$out = esc_js( 'foo ' . $bs . 't bar ' . $bs . $bs . ' baz' );
// \t becomes t - bug?
$this->assertSame( 'foo t bar ' . $bs . $bs . ' baz', $out );
}
function test_js_escape_amp() {
$out = esc_js( 'foo & bar &baz; &nbsp;' );
$this->assertSame( 'foo &amp; bar &amp;baz; &nbsp;', $out );
}
function test_js_escape_quote_entity() {
$out = esc_js( 'foo &#x27; bar &#39; baz &#x26;' );
$this->assertSame( "foo \\' bar \\' baz &#x26;", $out );
}
function test_js_no_carriage_return() {
$out = esc_js( "foo\rbar\nbaz\r" );
// \r is stripped.
$this->assertSame( "foobar\\nbaz", $out );
}
function test_js_escape_rn() {
$out = esc_js( "foo\r\nbar\nbaz\r\n" );
// \r is stripped.
$this->assertSame( "foo\\nbar\\nbaz\\n", $out );
}
}