Skip to content

Commit 5957f4e

Browse files
committed
Tests: Simplify formatting and KSES coverage.
Remove overlapping wrapper and private-helper checks while retaining public KSES coverage. Consolidate the `pre_kses` argument contract and use literal expected values for `wp_kses_post_deep()`. Developed in: #15013 Props dmsnell. See #65819. git-svn-id: https://develop.svn.wordpress.org/trunk@65040 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 0e6d670 commit 5957f4e

8 files changed

Lines changed: 35 additions & 142 deletions

File tree

‎tests/phpunit/tests/formatting/sanitizeTitleForQuery.php‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,6 @@
99
*/
1010
class Tests_Formatting_SanitizeTitleForQuery extends WP_UnitTestCase {
1111

12-
/**
13-
* @ticket 65819
14-
*/
15-
public function test_matches_sanitize_title_with_query_context() {
16-
$title = 'Hello World!';
17-
18-
$this->assertSame(
19-
sanitize_title( $title, '', 'query' ),
20-
sanitize_title_for_query( $title )
21-
);
22-
}
23-
2412
/**
2513
* @ticket 65819
2614
*/

‎tests/phpunit/tests/formatting/tagEscape.php‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,13 @@ public function test_tag_escape( $tag_name, $expected ) {
2828
*/
2929
public static function data_tag_escape() {
3030
return array(
31-
'empty string' => array( '', '' ),
3231
'lowercase tag' => array( 'div', 'div' ),
3332
'uppercase lowercased' => array( 'DIV', 'div' ),
3433
'mixed case' => array( 'SpAn', 'span' ),
3534
'allows hyphen underscore' => array( 'my-custom_tag', 'my-custom_tag' ),
3635
'allows colon for namespaced' => array( 'svg:path', 'svg:path' ),
37-
'strips invalid characters' => array( 'div<script>', 'divscript' ),
38-
'strips spaces' => array( 'hello world', 'helloworld' ),
36+
'invalid characters removed' => array( 'div<script>', 'divscript' ),
37+
'invalid spaces not allowed' => array( 'hello world', 'helloworld' ),
3938
);
4039
}
4140

‎tests/phpunit/tests/formatting/wpSprintf.php‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ public static function data_wp_sprintf_l() {
102102
'one item' => array( 'Tags: %l.', array( 'one' ), 'Tags: one.' ),
103103
'two items' => array( 'Tags: %l.', array( 'one', 'two' ), 'Tags: one and two.' ),
104104
'three items' => array( 'Tags: %l.', array( 'one', 'two', 'three' ), 'Tags: one, two, and three.' ),
105-
'four items' => array( 'Tags: %l.', array( 'one', 'two', 'three', 'four' ), 'Tags: one, two, three, and four.' ),
106105
'string instead of a list' => array( 'Tags: %l.', 'one', 'Tags: one.' ),
107106
'zero string item' => array( 'Tags: %l.', array( '0', '1' ), 'Tags: 0 and 1.' ),
108107
);

‎tests/phpunit/tests/kses.php‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2995,4 +2995,31 @@ public static function data_allowed_attributes_in_descriptions() {
29952995
),
29962996
);
29972997
}
2998+
2999+
/**
3000+
* Tests that the pre_kses filter receives its documented context arguments.
3001+
*
3002+
* @ticket 65819
3003+
* @covers ::wp_kses_hook
3004+
*/
3005+
public function test_pre_kses_filter_receives_context_arguments() {
3006+
$received = null;
3007+
$filter = static function ( $content, $allowed_html, $allowed_protocols ) use ( &$received ) {
3008+
$received = array( $content, $allowed_html, $allowed_protocols );
3009+
return $content;
3010+
};
3011+
3012+
// Run before the default priority-10 filters so the probe sees these exact inputs.
3013+
add_filter( 'pre_kses', $filter, 9, 3 );
3014+
try {
3015+
wp_kses_hook( 'content', 'data', array( 'http', 'https' ) );
3016+
} finally {
3017+
remove_filter( 'pre_kses', $filter, 9 );
3018+
}
3019+
3020+
$this->assertSame(
3021+
array( 'content', 'data', array( 'http', 'https' ) ),
3022+
$received
3023+
);
3024+
}
29983025
}

‎tests/phpunit/tests/kses/wpKsesAllowPdfObjects.php‎

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,47 +9,10 @@
99
*/
1010
class Tests_Kses_wpKsesAllowPdfObjects extends WP_UnitTestCase {
1111

12-
/**
13-
* @ticket 65819
14-
*/
15-
public function test_rejects_urls_with_query_string() {
16-
$uploads = wp_upload_dir( null, false );
17-
18-
$this->assertFalse( _wp_kses_allow_pdf_objects( $uploads['url'] . '/file.pdf?download=.pdf' ) );
19-
}
20-
21-
/**
22-
* @ticket 65819
23-
*/
24-
public function test_rejects_urls_with_fragment() {
25-
$uploads = wp_upload_dir( null, false );
26-
27-
$this->assertFalse( _wp_kses_allow_pdf_objects( $uploads['url'] . '/file.pdf#page=.pdf' ) );
28-
}
29-
30-
/**
31-
* @ticket 65819
32-
*/
33-
public function test_rejects_non_pdf_extension() {
34-
$uploads = wp_upload_dir( null, false );
35-
36-
$this->assertFalse( _wp_kses_allow_pdf_objects( $uploads['url'] . '/file.txt' ) );
37-
}
38-
3912
/**
4013
* @ticket 65819
4114
*/
4215
public function test_rejects_pdf_from_other_host() {
4316
$this->assertFalse( _wp_kses_allow_pdf_objects( 'https://evil.example/file.pdf' ) );
4417
}
45-
46-
/**
47-
* @ticket 65819
48-
*/
49-
public function test_allows_pdf_from_uploads_host() {
50-
$uploads = wp_upload_dir( null, false );
51-
$url = trailingslashit( $uploads['url'] ) . 'document.pdf';
52-
53-
$this->assertTrue( _wp_kses_allow_pdf_objects( $url ) );
54-
}
5518
}

‎tests/phpunit/tests/kses/wpKsesHook.php‎

Lines changed: 0 additions & 64 deletions
This file was deleted.

‎tests/phpunit/tests/kses/wpKsesPostDeep.php‎

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ public function test_sanitizes_string_values() {
1616
$input = '<p>Safe</p><script>alert(1)</script>';
1717
$result = wp_kses_post_deep( $input );
1818

19-
$this->assertSame( wp_kses_post( $input ), $result );
20-
$this->assertStringContainsString( '<p>Safe</p>', $result );
21-
$this->assertStringNotContainsString( '<script', $result );
19+
$this->assertSame( '<p>Safe</p>', $result );
2220
}
2321

2422
/**
@@ -34,21 +32,16 @@ public function test_sanitizes_nested_array_values() {
3432
);
3533

3634
$expected = array(
37-
'title' => wp_kses_post( $input['title'] ),
35+
'title' => '<strong>Ok</strong>',
3836
'nested' => array(
39-
'body' => wp_kses_post( $input['nested']['body'] ),
37+
'body' => '<p>Hello</p>',
4038
),
41-
'allowed' => wp_kses_post( $input['allowed'] ),
39+
'allowed' => '<em>emphasis</em>',
4240
);
4341

4442
$result = wp_kses_post_deep( $input );
4543

4644
$this->assertSame( $expected, $result );
47-
$this->assertStringContainsString( '<strong>Ok</strong>', $result['title'] );
48-
$this->assertStringNotContainsString( '<script', $result['title'] );
49-
$this->assertStringContainsString( '<p>Hello</p>', $result['nested']['body'] );
50-
$this->assertStringNotContainsString( '<iframe', $result['nested']['body'] );
51-
$this->assertSame( '<em>emphasis</em>', $result['allowed'] );
5245
}
5346

5447
/**
@@ -58,11 +51,8 @@ public function test_sanitizes_object_string_properties() {
5851
$input = new stdClass();
5952
$input->html = '<p>Ok</p><script>bad</script>';
6053

61-
$expected = wp_kses_post( $input->html );
62-
$result = wp_kses_post_deep( $input );
54+
$result = wp_kses_post_deep( $input );
6355

64-
$this->assertSame( $expected, $result->html );
65-
$this->assertStringContainsString( '<p>Ok</p>', $result->html );
66-
$this->assertStringNotContainsString( '<script', $result->html );
56+
$this->assertSame( '<p>Ok</p>', $result->html );
6757
}
6858
}

‎tests/phpunit/tests/kses/wpKsesUriAttributes.php‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,6 @@ public function test_returns_expected_default_uri_attributes() {
2222
$this->assertNotContains( 'class', $attributes );
2323
}
2424

25-
/**
26-
* @ticket 65819
27-
*/
28-
public function test_returns_list_of_strings() {
29-
foreach ( wp_kses_uri_attributes() as $attribute ) {
30-
$this->assertIsString( $attribute );
31-
}
32-
}
33-
3425
/**
3526
* @ticket 65819
3627
*/

0 commit comments

Comments
 (0)