Skip to content

Commit cbddb78

Browse files
Tests: Use console.log() instead of document.write() in sanitization tests
Updates the example script tags in get_post() and sanitize_term() tests to use console.log(), which is a more appropriate example for modern testing. Co-authored-by: gemini-cli <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 5fbfeed commit cbddb78

2 files changed

Lines changed: 7 additions & 8 deletions

File tree

tests/phpunit/tests/post/getPost.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static function set_up_before_class(): void {
1919
global $wpdb;
2020
$wpdb->update(
2121
$wpdb->posts,
22-
array( 'post_title' => 'Test <script>document.write("Hello, World!")</script> Title' ),
22+
array( 'post_title' => 'Test <script>console.log("Hello, World!")</script> Title' ),
2323
array( 'ID' => self::$post_id )
2424
);
2525
clean_post_cache( self::$post_id );
@@ -111,7 +111,6 @@ public function test_get_post_sanitization( string $filter, string $expected ):
111111
$this->assertSame( $filter, $post->filter );
112112
}
113113

114-
115114
/**
116115
* Data provider for test_get_post_sanitization.
117116
*
@@ -124,23 +123,23 @@ public function data_provider_to_test_get_post_sanitization(): array {
124123
return array(
125124
'Raw filter' => array(
126125
'filter' => 'raw',
127-
'expected' => 'Test <script>document.write("Hello, World!")</script> Title',
126+
'expected' => 'Test <script>console.log("Hello, World!")</script> Title',
128127
),
129128
'Edit filter' => array(
130129
'filter' => 'edit',
131-
'expected' => 'Test &lt;script&gt;document.write(&quot;Hello, World!&quot;)&lt;/script&gt; Title',
130+
'expected' => 'Test &lt;script&gt;console.log(&quot;Hello, World!&quot;)&lt;/script&gt; Title',
132131
),
133132
'Display filter' => array(
134133
'filter' => 'display',
135-
'expected' => 'Test <script>document.write("Hello, World!")</script> Title',
134+
'expected' => 'Test <script>console.log("Hello, World!")</script> Title',
136135
),
137136
'Attribute filter' => array(
138137
'filter' => 'attribute',
139-
'expected' => 'Test &lt;script&gt;document.write(&quot;Hello, World!&quot;)&lt;/script&gt; Title',
138+
'expected' => 'Test &lt;script&gt;console.log(&quot;Hello, World!&quot;)&lt;/script&gt; Title',
140139
),
141140
'JS filter' => array(
142141
'filter' => 'js',
143-
'expected' => 'Test &lt;script&gt;document.write(&quot;Hello, World!&quot;)&lt;/script&gt; Title',
142+
'expected' => 'Test &lt;script&gt;console.log(&quot;Hello, World!&quot;)&lt;/script&gt; Title',
144143
),
145144
);
146145
}

tests/phpunit/tests/term/sanitizeTerm.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function test_sanitize_term( Closure $input_callback, string $context, st
4848
* }>
4949
*/
5050
public function data_sanitize_term(): array {
51-
$description = 'Test <script>document.write("Hello")</script> Description';
51+
$description = 'Test <script>console.log("Hello")</script> Description';
5252

5353
return array(
5454
'Object with term_id, edit context' => array(

0 commit comments

Comments
 (0)