wordpress-develop/tests/phpunit/tests/formatting/escJs.php
Tonya Mork 40ac5de838 Coding Standards: Add visibility to methods in tests/phpunit/tests/.
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
2021-11-04 15:22:47 +00:00

47 lines
1.3 KiB
PHP

<?php
/**
* @group formatting
*/
class Tests_Formatting_EscJs extends WP_UnitTestCase {
public function test_js_escape_simple() {
$out = esc_js( 'foo bar baz();' );
$this->assertSame( 'foo bar baz();', $out );
}
public 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 );
}
public 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 );
}
public function test_js_escape_amp() {
$out = esc_js( 'foo & bar &baz; &nbsp;' );
$this->assertSame( 'foo &amp; bar &amp;baz; &nbsp;', $out );
}
public function test_js_escape_quote_entity() {
$out = esc_js( 'foo &#x27; bar &#39; baz &#x26;' );
$this->assertSame( "foo \\' bar \\' baz &#x26;", $out );
}
public function test_js_no_carriage_return() {
$out = esc_js( "foo\rbar\nbaz\r" );
// \r is stripped.
$this->assertSame( "foobar\\nbaz", $out );
}
public function test_js_escape_rn() {
$out = esc_js( "foo\r\nbar\nbaz\r\n" );
// \r is stripped.
$this->assertSame( "foo\\nbar\\nbaz\\n", $out );
}
}