wordpress-develop/tests/phpunit/tests/formatting/sanitizeTextField.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

144 lines
3.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* @group formatting
*/
class Tests_Formatting_SanitizeTextField extends WP_UnitTestCase {
public function data_sanitize_text_field() {
return array(
array(
'оРангутанг', // Ensure UTF-8 text is safe. The Р is D0 A0 and A0 is the non-breaking space.
'оРангутанг',
),
array(
'САПР', // Ensure UTF-8 text is safe. the Р is D0 A0 and A0 is the non-breaking space.
'САПР',
),
array(
'one is < two',
'one is &lt; two',
),
array(
"one is <\n two",
array(
'oneline' => 'one is &lt; two',
'multiline' => "one is &lt;\n two",
),
),
array(
"foo <div\n> bar",
array(
'oneline' => 'foo bar',
'multiline' => 'foo bar',
),
),
array(
"foo <\ndiv\n> bar",
array(
'oneline' => 'foo &lt; div > bar',
'multiline' => "foo &lt;\ndiv\n> bar",
),
),
array(
'tags <span>are</span> <em>not allowed</em> here',
'tags are not allowed here',
),
array(
' we should trim leading and trailing whitespace ',
'we should trim leading and trailing whitespace',
),
array(
'we trim extra internal whitespace only in single line texts',
array(
'oneline' => 'we trim extra internal whitespace only in single line texts',
'multiline' => 'we trim extra internal whitespace only in single line texts',
),
),
array(
"tabs \tget removed in single line texts",
array(
'oneline' => 'tabs get removed in single line texts',
'multiline' => "tabs \tget removed in single line texts",
),
),
array(
"newlines are allowed only\n in multiline texts",
array(
'oneline' => 'newlines are allowed only in multiline texts',
'multiline' => "newlines are allowed only\n in multiline texts",
),
),
array(
'We also %AB remove %ab octets',
'We also remove octets',
),
array(
'We don\'t need to wory about %A
B removing %a
b octets even when %a B they are obscured by whitespace',
array(
'oneline' => 'We don\'t need to wory about %A B removing %a b octets even when %a B they are obscured by whitespace',
'multiline' => "We don't need to wory about %A\n B removing %a\n b octets even when %a B they are obscured by whitespace",
),
),
array(
'%AB%BC%DE', // Just octets.
'', // Emtpy as we strip all the octets out.
),
array(
'Invalid octects remain %II',
'Invalid octects remain %II',
),
array(
'Nested octects %%%ABABAB %A%A%ABBB',
'Nested octects',
),
array(
array(),
'',
),
array(
array( 1, 2, 'foo' ),
'',
),
array(
new WP_Query,
'',
),
array(
2,
'2',
),
array(
false,
'',
),
array(
true,
'1',
),
array(
10.1,
'10.1',
),
);
}
/**
* @ticket 32257
* @dataProvider data_sanitize_text_field
*/
public function test_sanitize_text_field( $string, $expected ) {
if ( is_array( $expected ) ) {
$expected_oneline = $expected['oneline'];
$expected_multiline = $expected['multiline'];
} else {
$expected_oneline = $expected;
$expected_multiline = $expected;
}
$this->assertSame( $expected_oneline, sanitize_text_field( $string ) );
$this->assertSameIgnoreEOL( $expected_multiline, sanitize_textarea_field( $string ) );
}
}