Coding Standards: Give the $id variable in slashed data tests a more descriptive name.

See #50767, #51344.

git-svn-id: https://develop.svn.wordpress.org/trunk@49004 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2020-09-19 10:53:15 +00:00
parent ffc129395c
commit 4018e92c39
6 changed files with 148 additions and 145 deletions

View File

@ -32,7 +32,7 @@ class Tests_Attachment_Slashes extends WP_UnitTestCase {
* Tests the model function that expects slashed data.
*/
function test_wp_insert_attachment() {
$id = wp_insert_attachment(
$post_id = wp_insert_attachment(
array(
'post_status' => 'publish',
'post_title' => $this->slash_1,
@ -41,13 +41,13 @@ class Tests_Attachment_Slashes extends WP_UnitTestCase {
'post_type' => 'post',
)
);
$post = get_post( $id );
$post = get_post( $post_id );
$this->assertSame( wp_unslash( $this->slash_1 ), $post->post_title );
$this->assertSame( wp_unslash( $this->slash_3 ), $post->post_content_filtered );
$this->assertSame( wp_unslash( $this->slash_5 ), $post->post_excerpt );
$id = wp_insert_attachment(
$post_id = wp_insert_attachment(
array(
'post_status' => 'publish',
'post_title' => $this->slash_2,
@ -56,7 +56,7 @@ class Tests_Attachment_Slashes extends WP_UnitTestCase {
'post_type' => 'post',
)
);
$post = get_post( $id );
$post = get_post( $post_id );
$this->assertSame( wp_unslash( $this->slash_2 ), $post->post_title );
$this->assertSame( wp_unslash( $this->slash_4 ), $post->post_content_filtered );

View File

@ -37,7 +37,7 @@ class Tests_Comment_Slashes extends WP_UnitTestCase {
// Not testing comment_author_email or comment_author_url
// as slashes are not permitted in that data.
$data = array(
$data = array(
'comment_post_ID' => $post_id,
'comment_author' => $this->slash_1,
'comment_author_url' => '',
@ -45,14 +45,14 @@ class Tests_Comment_Slashes extends WP_UnitTestCase {
'comment_type' => '',
'comment_content' => $this->slash_7,
);
$id = wp_new_comment( $data );
$comment_id = wp_new_comment( $data );
$comment = get_comment( $id );
$comment = get_comment( $comment_id );
$this->assertSame( wp_unslash( $this->slash_1 ), $comment->comment_author );
$this->assertSame( wp_unslash( $this->slash_7 ), $comment->comment_content );
$data = array(
$data = array(
'comment_post_ID' => $post_id,
'comment_author' => $this->slash_2,
'comment_author_url' => '',
@ -60,9 +60,9 @@ class Tests_Comment_Slashes extends WP_UnitTestCase {
'comment_type' => '',
'comment_content' => $this->slash_4,
);
$id = wp_new_comment( $data );
$comment_id = wp_new_comment( $data );
$comment = get_comment( $id );
$comment = get_comment( $comment_id );
$this->assertSame( wp_unslash( $this->slash_2 ), $comment->comment_author );
$this->assertSame( wp_unslash( $this->slash_4 ), $comment->comment_content );

View File

@ -34,20 +34,21 @@ class Tests_Meta_Slashes extends WP_UnitTestCase {
* Tests the controller function that expects slashed data.
*/
function test_edit_post() {
$id = self::factory()->post->create();
$post_id = self::factory()->post->create();
if ( function_exists( 'wp_add_post_meta' ) ) {
$meta_1 = wp_add_post_meta( $id, 'slash_test_1', 'foo' );
$meta_2 = wp_add_post_meta( $id, 'slash_test_2', 'foo' );
$meta_3 = wp_add_post_meta( $id, 'slash_test_3', 'foo' );
$meta_1 = wp_add_post_meta( $post_id, 'slash_test_1', 'foo' );
$meta_2 = wp_add_post_meta( $post_id, 'slash_test_2', 'foo' );
$meta_3 = wp_add_post_meta( $post_id, 'slash_test_3', 'foo' );
} else {
// Expects slashed data.
$meta_1 = add_post_meta( $id, 'slash_test_1', addslashes( 'foo' ) );
$meta_2 = add_post_meta( $id, 'slash_test_2', addslashes( 'foo' ) );
$meta_3 = add_post_meta( $id, 'slash_test_3', addslashes( 'foo' ) );
$meta_1 = add_post_meta( $post_id, 'slash_test_1', addslashes( 'foo' ) );
$meta_2 = add_post_meta( $post_id, 'slash_test_2', addslashes( 'foo' ) );
$meta_3 = add_post_meta( $post_id, 'slash_test_3', addslashes( 'foo' ) );
}
$_POST = array();
$_POST['post_ID'] = $id;
$_POST['post_ID'] = $post_id;
$_POST['metakeyselect'] = '#NONE#';
$_POST['metakeyinput'] = 'slash_test_0';
$_POST['metavalue'] = $this->slash_6;
@ -69,15 +70,15 @@ class Tests_Meta_Slashes extends WP_UnitTestCase {
$_POST = add_magic_quotes( $_POST ); // The edit_post() function will strip slashes.
edit_post();
$post = get_post( $id );
$post = get_post( $post_id );
$this->assertSame( $this->slash_6, get_post_meta( $id, 'slash_test_0', true ) );
$this->assertSame( $this->slash_1, get_post_meta( $id, 'slash_test_1', true ) );
$this->assertSame( $this->slash_3, get_post_meta( $id, 'slash_test_2', true ) );
$this->assertSame( $this->slash_4, get_post_meta( $id, 'slash_test_3', true ) );
$this->assertSame( $this->slash_6, get_post_meta( $post_id, 'slash_test_0', true ) );
$this->assertSame( $this->slash_1, get_post_meta( $post_id, 'slash_test_1', true ) );
$this->assertSame( $this->slash_3, get_post_meta( $post_id, 'slash_test_2', true ) );
$this->assertSame( $this->slash_4, get_post_meta( $post_id, 'slash_test_3', true ) );
$_POST = array();
$_POST['post_ID'] = $id;
$_POST['post_ID'] = $post_id;
$_POST['metakeyselect'] = '#NONE#';
$_POST['metakeyinput'] = 'slash_test_0';
$_POST['metavalue'] = $this->slash_7;
@ -99,138 +100,140 @@ class Tests_Meta_Slashes extends WP_UnitTestCase {
$_POST = add_magic_quotes( $_POST ); // The edit_post() function will strip slashes.
edit_post();
$post = get_post( $id );
$post = get_post( $post_id );
$this->assertSame( $this->slash_2, get_post_meta( $id, 'slash_test_1', true ) );
$this->assertSame( $this->slash_4, get_post_meta( $id, 'slash_test_2', true ) );
$this->assertSame( $this->slash_5, get_post_meta( $id, 'slash_test_3', true ) );
$this->assertSame( $this->slash_2, get_post_meta( $post_id, 'slash_test_1', true ) );
$this->assertSame( $this->slash_4, get_post_meta( $post_id, 'slash_test_2', true ) );
$this->assertSame( $this->slash_5, get_post_meta( $post_id, 'slash_test_3', true ) );
}
/**
* Tests the legacy model function that expects slashed data.
*/
function test_add_post_meta() {
$id = self::factory()->post->create();
add_post_meta( $id, 'slash_test_1', addslashes( $this->slash_1 ) );
add_post_meta( $id, 'slash_test_2', addslashes( $this->slash_3 ) );
add_post_meta( $id, 'slash_test_3', addslashes( $this->slash_4 ) );
$post_id = self::factory()->post->create();
$this->assertSame( $this->slash_1, get_post_meta( $id, 'slash_test_1', true ) );
$this->assertSame( $this->slash_3, get_post_meta( $id, 'slash_test_2', true ) );
$this->assertSame( $this->slash_4, get_post_meta( $id, 'slash_test_3', true ) );
add_post_meta( $post_id, 'slash_test_1', addslashes( $this->slash_1 ) );
add_post_meta( $post_id, 'slash_test_2', addslashes( $this->slash_3 ) );
add_post_meta( $post_id, 'slash_test_3', addslashes( $this->slash_4 ) );
$this->assertSame( $this->slash_1, get_post_meta( $post_id, 'slash_test_1', true ) );
$this->assertSame( $this->slash_3, get_post_meta( $post_id, 'slash_test_2', true ) );
$this->assertSame( $this->slash_4, get_post_meta( $post_id, 'slash_test_3', true ) );
}
/**
* Tests the legacy model function that expects slashed data.
*/
function test_update_post_meta() {
$id = self::factory()->post->create();
update_post_meta( $id, 'slash_test_1', addslashes( $this->slash_1 ) );
update_post_meta( $id, 'slash_test_2', addslashes( $this->slash_3 ) );
update_post_meta( $id, 'slash_test_3', addslashes( $this->slash_4 ) );
$post_id = self::factory()->post->create();
$this->assertSame( $this->slash_1, get_post_meta( $id, 'slash_test_1', true ) );
$this->assertSame( $this->slash_3, get_post_meta( $id, 'slash_test_2', true ) );
$this->assertSame( $this->slash_4, get_post_meta( $id, 'slash_test_3', true ) );
update_post_meta( $post_id, 'slash_test_1', addslashes( $this->slash_1 ) );
update_post_meta( $post_id, 'slash_test_2', addslashes( $this->slash_3 ) );
update_post_meta( $post_id, 'slash_test_3', addslashes( $this->slash_4 ) );
$this->assertSame( $this->slash_1, get_post_meta( $post_id, 'slash_test_1', true ) );
$this->assertSame( $this->slash_3, get_post_meta( $post_id, 'slash_test_2', true ) );
$this->assertSame( $this->slash_4, get_post_meta( $post_id, 'slash_test_3', true ) );
}
/**
* Tests the model function that expects slashed data.
*/
function test_add_comment_meta() {
$id = self::$comment_id;
$comment_id = self::$comment_id;
add_comment_meta( $id, 'slash_test_1', $this->slash_1 );
add_comment_meta( $id, 'slash_test_2', $this->slash_3 );
add_comment_meta( $id, 'slash_test_3', $this->slash_5 );
add_comment_meta( $comment_id, 'slash_test_1', $this->slash_1 );
add_comment_meta( $comment_id, 'slash_test_2', $this->slash_3 );
add_comment_meta( $comment_id, 'slash_test_3', $this->slash_5 );
$this->assertSame( wp_unslash( $this->slash_1 ), get_comment_meta( $id, 'slash_test_1', true ) );
$this->assertSame( wp_unslash( $this->slash_3 ), get_comment_meta( $id, 'slash_test_2', true ) );
$this->assertSame( wp_unslash( $this->slash_5 ), get_comment_meta( $id, 'slash_test_3', true ) );
$this->assertSame( wp_unslash( $this->slash_1 ), get_comment_meta( $comment_id, 'slash_test_1', true ) );
$this->assertSame( wp_unslash( $this->slash_3 ), get_comment_meta( $comment_id, 'slash_test_2', true ) );
$this->assertSame( wp_unslash( $this->slash_5 ), get_comment_meta( $comment_id, 'slash_test_3', true ) );
add_comment_meta( $id, 'slash_test_4', $this->slash_2 );
add_comment_meta( $id, 'slash_test_5', $this->slash_4 );
add_comment_meta( $id, 'slash_test_6', $this->slash_6 );
add_comment_meta( $comment_id, 'slash_test_4', $this->slash_2 );
add_comment_meta( $comment_id, 'slash_test_5', $this->slash_4 );
add_comment_meta( $comment_id, 'slash_test_6', $this->slash_6 );
$this->assertSame( wp_unslash( $this->slash_2 ), get_comment_meta( $id, 'slash_test_4', true ) );
$this->assertSame( wp_unslash( $this->slash_4 ), get_comment_meta( $id, 'slash_test_5', true ) );
$this->assertSame( wp_unslash( $this->slash_6 ), get_comment_meta( $id, 'slash_test_6', true ) );
$this->assertSame( wp_unslash( $this->slash_2 ), get_comment_meta( $comment_id, 'slash_test_4', true ) );
$this->assertSame( wp_unslash( $this->slash_4 ), get_comment_meta( $comment_id, 'slash_test_5', true ) );
$this->assertSame( wp_unslash( $this->slash_6 ), get_comment_meta( $comment_id, 'slash_test_6', true ) );
}
/**
* Tests the model function that expects slashed data.
*/
function test_update_comment_meta() {
$id = self::$comment_id;
$comment_id = self::$comment_id;
add_comment_meta( $id, 'slash_test_1', 'foo' );
add_comment_meta( $id, 'slash_test_2', 'foo' );
add_comment_meta( $id, 'slash_test_3', 'foo' );
add_comment_meta( $comment_id, 'slash_test_1', 'foo' );
add_comment_meta( $comment_id, 'slash_test_2', 'foo' );
add_comment_meta( $comment_id, 'slash_test_3', 'foo' );
update_comment_meta( $id, 'slash_test_1', $this->slash_1 );
update_comment_meta( $id, 'slash_test_2', $this->slash_3 );
update_comment_meta( $id, 'slash_test_3', $this->slash_5 );
update_comment_meta( $comment_id, 'slash_test_1', $this->slash_1 );
update_comment_meta( $comment_id, 'slash_test_2', $this->slash_3 );
update_comment_meta( $comment_id, 'slash_test_3', $this->slash_5 );
$this->assertSame( wp_unslash( $this->slash_1 ), get_comment_meta( $id, 'slash_test_1', true ) );
$this->assertSame( wp_unslash( $this->slash_3 ), get_comment_meta( $id, 'slash_test_2', true ) );
$this->assertSame( wp_unslash( $this->slash_5 ), get_comment_meta( $id, 'slash_test_3', true ) );
$this->assertSame( wp_unslash( $this->slash_1 ), get_comment_meta( $comment_id, 'slash_test_1', true ) );
$this->assertSame( wp_unslash( $this->slash_3 ), get_comment_meta( $comment_id, 'slash_test_2', true ) );
$this->assertSame( wp_unslash( $this->slash_5 ), get_comment_meta( $comment_id, 'slash_test_3', true ) );
update_comment_meta( $id, 'slash_test_1', $this->slash_2 );
update_comment_meta( $id, 'slash_test_2', $this->slash_4 );
update_comment_meta( $id, 'slash_test_3', $this->slash_6 );
update_comment_meta( $comment_id, 'slash_test_1', $this->slash_2 );
update_comment_meta( $comment_id, 'slash_test_2', $this->slash_4 );
update_comment_meta( $comment_id, 'slash_test_3', $this->slash_6 );
$this->assertSame( wp_unslash( $this->slash_2 ), get_comment_meta( $id, 'slash_test_1', true ) );
$this->assertSame( wp_unslash( $this->slash_4 ), get_comment_meta( $id, 'slash_test_2', true ) );
$this->assertSame( wp_unslash( $this->slash_6 ), get_comment_meta( $id, 'slash_test_3', true ) );
$this->assertSame( wp_unslash( $this->slash_2 ), get_comment_meta( $comment_id, 'slash_test_1', true ) );
$this->assertSame( wp_unslash( $this->slash_4 ), get_comment_meta( $comment_id, 'slash_test_2', true ) );
$this->assertSame( wp_unslash( $this->slash_6 ), get_comment_meta( $comment_id, 'slash_test_3', true ) );
}
/**
* Tests the model function that expects slashed data.
*/
function test_add_user_meta() {
$id = self::factory()->user->create();
$user_id = self::factory()->user->create();
add_user_meta( $id, 'slash_test_1', $this->slash_1 );
add_user_meta( $id, 'slash_test_2', $this->slash_3 );
add_user_meta( $id, 'slash_test_3', $this->slash_5 );
add_user_meta( $user_id, 'slash_test_1', $this->slash_1 );
add_user_meta( $user_id, 'slash_test_2', $this->slash_3 );
add_user_meta( $user_id, 'slash_test_3', $this->slash_5 );
$this->assertSame( wp_unslash( $this->slash_1 ), get_user_meta( $id, 'slash_test_1', true ) );
$this->assertSame( wp_unslash( $this->slash_3 ), get_user_meta( $id, 'slash_test_2', true ) );
$this->assertSame( wp_unslash( $this->slash_5 ), get_user_meta( $id, 'slash_test_3', true ) );
$this->assertSame( wp_unslash( $this->slash_1 ), get_user_meta( $user_id, 'slash_test_1', true ) );
$this->assertSame( wp_unslash( $this->slash_3 ), get_user_meta( $user_id, 'slash_test_2', true ) );
$this->assertSame( wp_unslash( $this->slash_5 ), get_user_meta( $user_id, 'slash_test_3', true ) );
add_user_meta( $id, 'slash_test_4', $this->slash_2 );
add_user_meta( $id, 'slash_test_5', $this->slash_4 );
add_user_meta( $id, 'slash_test_6', $this->slash_6 );
add_user_meta( $user_id, 'slash_test_4', $this->slash_2 );
add_user_meta( $user_id, 'slash_test_5', $this->slash_4 );
add_user_meta( $user_id, 'slash_test_6', $this->slash_6 );
$this->assertSame( wp_unslash( $this->slash_2 ), get_user_meta( $id, 'slash_test_4', true ) );
$this->assertSame( wp_unslash( $this->slash_4 ), get_user_meta( $id, 'slash_test_5', true ) );
$this->assertSame( wp_unslash( $this->slash_6 ), get_user_meta( $id, 'slash_test_6', true ) );
$this->assertSame( wp_unslash( $this->slash_2 ), get_user_meta( $user_id, 'slash_test_4', true ) );
$this->assertSame( wp_unslash( $this->slash_4 ), get_user_meta( $user_id, 'slash_test_5', true ) );
$this->assertSame( wp_unslash( $this->slash_6 ), get_user_meta( $user_id, 'slash_test_6', true ) );
}
/**
* Tests the model function that expects slashed data.
*/
function test_update_user_meta() {
$id = self::factory()->user->create();
$user_id = self::factory()->user->create();
add_user_meta( $id, 'slash_test_1', 'foo' );
add_user_meta( $id, 'slash_test_2', 'foo' );
add_user_meta( $id, 'slash_test_3', 'foo' );
add_user_meta( $user_id, 'slash_test_1', 'foo' );
add_user_meta( $user_id, 'slash_test_2', 'foo' );
add_user_meta( $user_id, 'slash_test_3', 'foo' );
update_user_meta( $id, 'slash_test_1', $this->slash_1 );
update_user_meta( $id, 'slash_test_2', $this->slash_3 );
update_user_meta( $id, 'slash_test_3', $this->slash_5 );
update_user_meta( $user_id, 'slash_test_1', $this->slash_1 );
update_user_meta( $user_id, 'slash_test_2', $this->slash_3 );
update_user_meta( $user_id, 'slash_test_3', $this->slash_5 );
$this->assertSame( wp_unslash( $this->slash_1 ), get_user_meta( $id, 'slash_test_1', true ) );
$this->assertSame( wp_unslash( $this->slash_3 ), get_user_meta( $id, 'slash_test_2', true ) );
$this->assertSame( wp_unslash( $this->slash_5 ), get_user_meta( $id, 'slash_test_3', true ) );
$this->assertSame( wp_unslash( $this->slash_1 ), get_user_meta( $user_id, 'slash_test_1', true ) );
$this->assertSame( wp_unslash( $this->slash_3 ), get_user_meta( $user_id, 'slash_test_2', true ) );
$this->assertSame( wp_unslash( $this->slash_5 ), get_user_meta( $user_id, 'slash_test_3', true ) );
update_user_meta( $id, 'slash_test_1', $this->slash_2 );
update_user_meta( $id, 'slash_test_2', $this->slash_4 );
update_user_meta( $id, 'slash_test_3', $this->slash_6 );
update_user_meta( $user_id, 'slash_test_1', $this->slash_2 );
update_user_meta( $user_id, 'slash_test_2', $this->slash_4 );
update_user_meta( $user_id, 'slash_test_3', $this->slash_6 );
$this->assertSame( wp_unslash( $this->slash_2 ), get_user_meta( $id, 'slash_test_1', true ) );
$this->assertSame( wp_unslash( $this->slash_4 ), get_user_meta( $id, 'slash_test_2', true ) );
$this->assertSame( wp_unslash( $this->slash_6 ), get_user_meta( $id, 'slash_test_3', true ) );
$this->assertSame( wp_unslash( $this->slash_2 ), get_user_meta( $user_id, 'slash_test_1', true ) );
$this->assertSame( wp_unslash( $this->slash_4 ), get_user_meta( $user_id, 'slash_test_2', true ) );
$this->assertSame( wp_unslash( $this->slash_6 ), get_user_meta( $user_id, 'slash_test_3', true ) );
}
}

View File

@ -32,10 +32,10 @@ class Tests_Post_Slashes extends WP_UnitTestCase {
* Tests the controller function that expects slashed data.
*/
function test_edit_post() {
$id = self::factory()->post->create();
$post_id = self::factory()->post->create();
$_POST = array();
$_POST['post_ID'] = $id;
$_POST['post_ID'] = $post_id;
$_POST['post_title'] = $this->slash_1;
$_POST['content'] = $this->slash_5;
$_POST['excerpt'] = $this->slash_7;
@ -50,7 +50,7 @@ class Tests_Post_Slashes extends WP_UnitTestCase {
$this->assertSame( $this->slash_7, $post->post_excerpt );
$_POST = array();
$_POST['post_ID'] = $id;
$_POST['post_ID'] = $post_id;
$_POST['post_title'] = $this->slash_2;
$_POST['content'] = $this->slash_4;
$_POST['excerpt'] = $this->slash_6;
@ -69,7 +69,7 @@ class Tests_Post_Slashes extends WP_UnitTestCase {
* Tests the model function that expects slashed data.
*/
function test_wp_insert_post() {
$id = wp_insert_post(
$post_id = wp_insert_post(
array(
'post_status' => 'publish',
'post_title' => $this->slash_1,
@ -79,13 +79,13 @@ class Tests_Post_Slashes extends WP_UnitTestCase {
'slashed' => false,
)
);
$post = get_post( $id );
$post = get_post( $post_id );
$this->assertSame( wp_unslash( $this->slash_1 ), $post->post_title );
$this->assertSame( wp_unslash( $this->slash_3 ), $post->post_content );
$this->assertSame( wp_unslash( $this->slash_5 ), $post->post_excerpt );
$id = wp_insert_post(
$post_id = wp_insert_post(
array(
'post_status' => 'publish',
'post_title' => $this->slash_2,
@ -94,7 +94,7 @@ class Tests_Post_Slashes extends WP_UnitTestCase {
'post_type' => 'post',
)
);
$post = get_post( $id );
$post = get_post( $post_id );
$this->assertSame( wp_unslash( $this->slash_2 ), $post->post_title );
$this->assertSame( wp_unslash( $this->slash_4 ), $post->post_content );
@ -105,17 +105,17 @@ class Tests_Post_Slashes extends WP_UnitTestCase {
* Tests the model function that expects slashed data.
*/
function test_wp_update_post() {
$id = self::factory()->post->create();
$post_id = self::factory()->post->create();
wp_update_post(
array(
'ID' => $id,
'ID' => $post_id,
'post_title' => $this->slash_1,
'post_content' => $this->slash_3,
'post_excerpt' => $this->slash_5,
)
);
$post = get_post( $id );
$post = get_post( $post_id );
$this->assertSame( wp_unslash( $this->slash_1 ), $post->post_title );
$this->assertSame( wp_unslash( $this->slash_3 ), $post->post_content );
@ -123,13 +123,13 @@ class Tests_Post_Slashes extends WP_UnitTestCase {
wp_update_post(
array(
'ID' => $id,
'ID' => $post_id,
'post_title' => $this->slash_2,
'post_content' => $this->slash_4,
'post_excerpt' => $this->slash_6,
)
);
$post = get_post( $id );
$post = get_post( $post_id );
$this->assertSame( wp_unslash( $this->slash_2 ), $post->post_title );
$this->assertSame( wp_unslash( $this->slash_4 ), $post->post_content );
@ -140,26 +140,26 @@ class Tests_Post_Slashes extends WP_UnitTestCase {
* @ticket 27550
*/
function test_wp_trash_untrash() {
$post = array(
$post = array(
'post_title' => $this->slash_1,
'post_content' => $this->slash_3,
'post_excerpt' => $this->slash_5,
);
$id = wp_insert_post( wp_slash( $post ) );
$post_id = wp_insert_post( wp_slash( $post ) );
$trashed = wp_trash_post( $id );
$trashed = wp_trash_post( $post_id );
$this->assertNotEmpty( $trashed );
$post = get_post( $id );
$post = get_post( $post_id );
$this->assertSame( $this->slash_1, $post->post_title );
$this->assertSame( $this->slash_3, $post->post_content );
$this->assertSame( $this->slash_5, $post->post_excerpt );
$untrashed = wp_untrash_post( $id );
$untrashed = wp_untrash_post( $post_id );
$this->assertNotEmpty( $untrashed );
$post = get_post( $id );
$post = get_post( $post_id );
$this->assertSame( $this->slash_1, $post->post_title );
$this->assertSame( $this->slash_3, $post->post_content );

View File

@ -82,14 +82,14 @@ class Tests_Term_Slashes extends WP_Ajax_UnitTestCase {
'post_tag',
);
foreach ( $taxonomies as $taxonomy ) {
$id = self::factory()->term->create(
$term_id = self::factory()->term->create(
array(
'taxonomy' => $taxonomy,
)
);
$update = wp_update_term(
$id,
$term_id,
$taxonomy,
array(
'name' => $this->slash_1,
@ -97,31 +97,31 @@ class Tests_Term_Slashes extends WP_Ajax_UnitTestCase {
)
);
$term = get_term( $id, $taxonomy );
$term = get_term( $term_id, $taxonomy );
$this->assertSame( wp_unslash( $this->slash_1 ), $term->name );
$this->assertSame( wp_unslash( $this->slash_3 ), $term->description );
$update = wp_update_term(
$id,
$term_id,
$taxonomy,
array(
'name' => $this->slash_3,
'description' => $this->slash_5,
)
);
$term = get_term( $id, $taxonomy );
$term = get_term( $term_id, $taxonomy );
$this->assertSame( wp_unslash( $this->slash_3 ), $term->name );
$this->assertSame( wp_unslash( $this->slash_5 ), $term->description );
$update = wp_update_term(
$id,
$term_id,
$taxonomy,
array(
'name' => $this->slash_2,
'description' => $this->slash_4,
)
);
$term = get_term( $id, $taxonomy );
$term = get_term( $term_id, $taxonomy );
$this->assertSame( wp_unslash( $this->slash_2 ), $term->name );
$this->assertSame( wp_unslash( $this->slash_4 ), $term->description );
}

View File

@ -48,8 +48,8 @@ class Tests_User_Slashes extends WP_UnitTestCase {
$_POST = add_magic_quotes( $_POST ); // The add_user() function will strip slashes.
$id = add_user();
$user = get_user_to_edit( $id );
$user_id = add_user();
$user = get_user_to_edit( $user_id );
$this->assertSame( $this->slash_1, $user->first_name );
$this->assertSame( $this->slash_3, $user->last_name );
@ -73,8 +73,8 @@ class Tests_User_Slashes extends WP_UnitTestCase {
$_POST = add_magic_quotes( $_POST ); // The add_user() function will strip slashes.
$id = add_user();
$user = get_user_to_edit( $id );
$user_id = add_user();
$user = get_user_to_edit( $user_id );
$this->assertSame( $this->slash_2, $user->first_name );
$this->assertSame( $this->slash_4, $user->last_name );
@ -87,7 +87,7 @@ class Tests_User_Slashes extends WP_UnitTestCase {
* Tests the controller function that expects slashed data.
*/
function test_edit_user() {
$id = self::factory()->user->create();
$user_id = self::factory()->user->create();
$_POST = array();
$_GET = array();
@ -102,8 +102,8 @@ class Tests_User_Slashes extends WP_UnitTestCase {
$_POST = add_magic_quotes( $_POST ); // The edit_user() function will strip slashes.
$id = edit_user( $id );
$user = get_user_to_edit( $id );
$user_id = edit_user( $user_id );
$user = get_user_to_edit( $user_id );
$this->assertSame( $this->slash_1, $user->first_name );
$this->assertSame( $this->slash_3, $user->last_name );
@ -124,8 +124,8 @@ class Tests_User_Slashes extends WP_UnitTestCase {
$_POST = add_magic_quotes( $_POST ); // The edit_user() function will strip slashes.
$id = edit_user( $id );
$user = get_user_to_edit( $id );
$user_id = edit_user( $user_id );
$user = get_user_to_edit( $user_id );
$this->assertSame( $this->slash_2, $user->first_name );
$this->assertSame( $this->slash_4, $user->last_name );
@ -138,7 +138,7 @@ class Tests_User_Slashes extends WP_UnitTestCase {
* Tests the model function that expects slashed data.
*/
function test_wp_insert_user() {
$id = wp_insert_user(
$user_id = wp_insert_user(
array(
'user_login' => 'slash_example_user_3',
'role' => 'subscriber',
@ -151,7 +151,7 @@ class Tests_User_Slashes extends WP_UnitTestCase {
'user_pass' => '',
)
);
$user = get_user_to_edit( $id );
$user = get_user_to_edit( $user_id );
$this->assertSame( wp_unslash( $this->slash_1 ), $user->first_name );
$this->assertSame( wp_unslash( $this->slash_3 ), $user->last_name );
@ -159,7 +159,7 @@ class Tests_User_Slashes extends WP_UnitTestCase {
$this->assertSame( wp_unslash( $this->slash_7 ), $user->display_name );
$this->assertSame( wp_unslash( $this->slash_3 ), $user->description );
$id = wp_insert_user(
$user_id = wp_insert_user(
array(
'user_login' => 'slash_example_user_4',
'role' => 'subscriber',
@ -172,7 +172,7 @@ class Tests_User_Slashes extends WP_UnitTestCase {
'user_pass' => '',
)
);
$user = get_user_to_edit( $id );
$user = get_user_to_edit( $user_id );
$this->assertSame( wp_unslash( $this->slash_2 ), $user->first_name );
$this->assertSame( wp_unslash( $this->slash_4 ), $user->last_name );
@ -185,10 +185,10 @@ class Tests_User_Slashes extends WP_UnitTestCase {
* Tests the model function that expects slashed data.
*/
function test_wp_update_user() {
$id = self::factory()->user->create();
$id = wp_update_user(
$user_id = self::factory()->user->create();
$user_id = wp_update_user(
array(
'ID' => $id,
'ID' => $user_id,
'role' => 'subscriber',
'first_name' => $this->slash_1,
'last_name' => $this->slash_3,
@ -197,7 +197,7 @@ class Tests_User_Slashes extends WP_UnitTestCase {
'description' => $this->slash_3,
)
);
$user = get_user_to_edit( $id );
$user = get_user_to_edit( $user_id );
$this->assertSame( wp_unslash( $this->slash_1 ), $user->first_name );
$this->assertSame( wp_unslash( $this->slash_3 ), $user->last_name );
@ -205,9 +205,9 @@ class Tests_User_Slashes extends WP_UnitTestCase {
$this->assertSame( wp_unslash( $this->slash_7 ), $user->display_name );
$this->assertSame( wp_unslash( $this->slash_3 ), $user->description );
$id = wp_update_user(
$user_id = wp_update_user(
array(
'ID' => $id,
'ID' => $user_id,
'role' => 'subscriber',
'first_name' => $this->slash_2,
'last_name' => $this->slash_4,
@ -216,7 +216,7 @@ class Tests_User_Slashes extends WP_UnitTestCase {
'description' => $this->slash_4,
)
);
$user = get_user_to_edit( $id );
$user = get_user_to_edit( $user_id );
$this->assertSame( wp_unslash( $this->slash_2 ), $user->first_name );
$this->assertSame( wp_unslash( $this->slash_4 ), $user->last_name );