Changeset 53557
- Timestamp:
- 06/23/2022 02:24:08 PM (2 years ago)
- Location:
- trunk/tests/phpunit/tests
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/attachment/slashes.php
r52010 r53557 7 7 */ 8 8 class Tests_Attachment_Slashes extends WP_UnitTestCase { 9 10 /* 11 * It is important to test with both even and odd numbered slashes, 12 * as KSES does a strip-then-add slashes in some of its function calls. 13 */ 14 15 const SLASH_1 = 'String with 1 slash \\'; 16 const SLASH_2 = 'String with 2 slashes \\\\'; 17 const SLASH_3 = 'String with 3 slashes \\\\\\'; 18 const SLASH_4 = 'String with 4 slashes \\\\\\\\'; 19 const SLASH_5 = 'String with 5 slashes \\\\\\\\\\'; 20 const SLASH_6 = 'String with 6 slashes \\\\\\\\\\\\'; 21 const SLASH_7 = 'String with 7 slashes \\\\\\\\\\\\\\'; 22 9 23 protected static $author_id; 10 24 … … 17 31 18 32 wp_set_current_user( self::$author_id ); 19 20 // It is important to test with both even and odd numbered slashes,21 // as KSES does a strip-then-add slashes in some of its function calls.22 $this->slash_1 = 'String with 1 slash \\';23 $this->slash_2 = 'String with 2 slashes \\\\';24 $this->slash_3 = 'String with 3 slashes \\\\\\';25 $this->slash_4 = 'String with 4 slashes \\\\\\\\';26 $this->slash_5 = 'String with 5 slashes \\\\\\\\\\';27 $this->slash_6 = 'String with 6 slashes \\\\\\\\\\\\';28 $this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\';29 33 } 30 34 … … 36 40 array( 37 41 'post_status' => 'publish', 38 'post_title' => $this->slash_1,39 'post_content_filtered' => $this->slash_3,40 'post_excerpt' => $this->slash_5,42 'post_title' => self::SLASH_1, 43 'post_content_filtered' => self::SLASH_3, 44 'post_excerpt' => self::SLASH_5, 41 45 'post_type' => 'post', 42 46 ) … … 44 48 $post = get_post( $post_id ); 45 49 46 $this->assertSame( wp_unslash( $this->slash_1 ), $post->post_title );47 $this->assertSame( wp_unslash( $this->slash_3 ), $post->post_content_filtered );48 $this->assertSame( wp_unslash( $this->slash_5 ), $post->post_excerpt );50 $this->assertSame( wp_unslash( self::SLASH_1 ), $post->post_title ); 51 $this->assertSame( wp_unslash( self::SLASH_3 ), $post->post_content_filtered ); 52 $this->assertSame( wp_unslash( self::SLASH_5 ), $post->post_excerpt ); 49 53 50 54 $post_id = wp_insert_attachment( 51 55 array( 52 56 'post_status' => 'publish', 53 'post_title' => $this->slash_2,54 'post_content_filtered' => $this->slash_4,55 'post_excerpt' => $this->slash_6,57 'post_title' => self::SLASH_2, 58 'post_content_filtered' => self::SLASH_4, 59 'post_excerpt' => self::SLASH_6, 56 60 'post_type' => 'post', 57 61 ) … … 59 63 $post = get_post( $post_id ); 60 64 61 $this->assertSame( wp_unslash( $this->slash_2 ), $post->post_title );62 $this->assertSame( wp_unslash( $this->slash_4 ), $post->post_content_filtered );63 $this->assertSame( wp_unslash( $this->slash_6 ), $post->post_excerpt );65 $this->assertSame( wp_unslash( self::SLASH_2 ), $post->post_title ); 66 $this->assertSame( wp_unslash( self::SLASH_4 ), $post->post_content_filtered ); 67 $this->assertSame( wp_unslash( self::SLASH_6 ), $post->post_excerpt ); 64 68 } 65 69 -
trunk/tests/phpunit/tests/comment/slashes.php
r52010 r53557 7 7 */ 8 8 class Tests_Comment_Slashes extends WP_UnitTestCase { 9 10 /* 11 * It is important to test with both even and odd numbered slashes, 12 * as KSES does a strip-then-add slashes in some of its function calls. 13 */ 14 15 const SLASH_1 = 'String with 1 slash \\'; 16 const SLASH_2 = 'String with 2 slashes \\\\'; 17 const SLASH_3 = 'String with 3 slashes \\\\\\'; 18 const SLASH_4 = 'String with 4 slashes \\\\\\\\'; 19 const SLASH_5 = 'String with 5 slashes \\\\\\\\\\'; 20 const SLASH_6 = 'String with 6 slashes \\\\\\\\\\\\'; 21 const SLASH_7 = 'String with 7 slashes \\\\\\\\\\\\\\'; 22 9 23 protected static $author_id; 10 24 protected static $post_id; … … 20 34 21 35 wp_set_current_user( self::$author_id ); 22 23 // It is important to test with both even and odd numbered slashes,24 // as KSES does a strip-then-add slashes in some of its function calls.25 $this->slash_1 = 'String with 1 slash \\';26 $this->slash_2 = 'String with 2 slashes \\\\';27 $this->slash_3 = 'String with 3 slashes \\\\\\';28 $this->slash_4 = 'String with 4 slashes \\\\\\\\';29 $this->slash_5 = 'String with 5 slashes \\\\\\\\\\';30 $this->slash_6 = 'String with 6 slashes \\\\\\\\\\\\';31 $this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\';32 36 } 33 37 … … 42 46 $data = array( 43 47 'comment_post_ID' => $post_id, 44 'comment_author' => $this->slash_1,48 'comment_author' => self::SLASH_1, 45 49 'comment_author_url' => '', 46 50 'comment_author_email' => '', 47 51 'comment_type' => '', 48 'comment_content' => $this->slash_7,52 'comment_content' => self::SLASH_7, 49 53 ); 50 54 $comment_id = wp_new_comment( $data ); … … 52 56 $comment = get_comment( $comment_id ); 53 57 54 $this->assertSame( wp_unslash( $this->slash_1 ), $comment->comment_author );55 $this->assertSame( wp_unslash( $this->slash_7 ), $comment->comment_content );58 $this->assertSame( wp_unslash( self::SLASH_1 ), $comment->comment_author ); 59 $this->assertSame( wp_unslash( self::SLASH_7 ), $comment->comment_content ); 56 60 57 61 $data = array( 58 62 'comment_post_ID' => $post_id, 59 'comment_author' => $this->slash_2,63 'comment_author' => self::SLASH_2, 60 64 'comment_author_url' => '', 61 65 'comment_author_email' => '', 62 66 'comment_type' => '', 63 'comment_content' => $this->slash_4,67 'comment_content' => self::SLASH_4, 64 68 ); 65 69 $comment_id = wp_new_comment( $data ); … … 67 71 $comment = get_comment( $comment_id ); 68 72 69 $this->assertSame( wp_unslash( $this->slash_2 ), $comment->comment_author );70 $this->assertSame( wp_unslash( $this->slash_4 ), $comment->comment_content );73 $this->assertSame( wp_unslash( self::SLASH_2 ), $comment->comment_author ); 74 $this->assertSame( wp_unslash( self::SLASH_4 ), $comment->comment_content ); 71 75 } 72 76 … … 87 91 $_POST['comment_ID'] = $comment_id; 88 92 $_POST['comment_status'] = ''; 89 $_POST['newcomment_author'] = $this->slash_1;93 $_POST['newcomment_author'] = self::SLASH_1; 90 94 $_POST['newcomment_author_url'] = ''; 91 95 $_POST['newcomment_author_email'] = ''; 92 $_POST['content'] = $this->slash_7;96 $_POST['content'] = self::SLASH_7; 93 97 94 98 $_POST = add_magic_quotes( $_POST ); // The edit_comment() function will strip slashes. … … 97 101 $comment = get_comment( $comment_id ); 98 102 99 $this->assertSame( $this->slash_1, $comment->comment_author );100 $this->assertSame( $this->slash_7, $comment->comment_content );103 $this->assertSame( self::SLASH_1, $comment->comment_author ); 104 $this->assertSame( self::SLASH_7, $comment->comment_content ); 101 105 102 106 $_POST = array(); 103 107 $_POST['comment_ID'] = $comment_id; 104 108 $_POST['comment_status'] = ''; 105 $_POST['newcomment_author'] = $this->slash_2;109 $_POST['newcomment_author'] = self::SLASH_2; 106 110 $_POST['newcomment_author_url'] = ''; 107 111 $_POST['newcomment_author_email'] = ''; 108 $_POST['content'] = $this->slash_4;112 $_POST['content'] = self::SLASH_4; 109 113 110 114 $_POST = add_magic_quotes( $_POST ); // The edit_comment() function will strip slashes. … … 113 117 $comment = get_comment( $comment_id ); 114 118 115 $this->assertSame( $this->slash_2, $comment->comment_author );116 $this->assertSame( $this->slash_4, $comment->comment_content );119 $this->assertSame( self::SLASH_2, $comment->comment_author ); 120 $this->assertSame( self::SLASH_4, $comment->comment_content ); 117 121 } 118 122 … … 126 130 array( 127 131 'comment_post_ID' => $post_id, 128 'comment_author' => $this->slash_1,129 'comment_content' => $this->slash_7,132 'comment_author' => self::SLASH_1, 133 'comment_content' => self::SLASH_7, 130 134 ) 131 135 ); 132 136 $comment = get_comment( $comment_id ); 133 137 134 $this->assertSame( wp_unslash( $this->slash_1 ), $comment->comment_author );135 $this->assertSame( wp_unslash( $this->slash_7 ), $comment->comment_content );138 $this->assertSame( wp_unslash( self::SLASH_1 ), $comment->comment_author ); 139 $this->assertSame( wp_unslash( self::SLASH_7 ), $comment->comment_content ); 136 140 137 141 $comment_id = wp_insert_comment( 138 142 array( 139 143 'comment_post_ID' => $post_id, 140 'comment_author' => $this->slash_2,141 'comment_content' => $this->slash_4,144 'comment_author' => self::SLASH_2, 145 'comment_content' => self::SLASH_4, 142 146 ) 143 147 ); 144 148 $comment = get_comment( $comment_id ); 145 149 146 $this->assertSame( wp_unslash( $this->slash_2 ), $comment->comment_author );147 $this->assertSame( wp_unslash( $this->slash_4 ), $comment->comment_content );150 $this->assertSame( wp_unslash( self::SLASH_2 ), $comment->comment_author ); 151 $this->assertSame( wp_unslash( self::SLASH_4 ), $comment->comment_content ); 148 152 } 149 153 … … 162 166 array( 163 167 'comment_ID' => $comment_id, 164 'comment_author' => $this->slash_1,165 'comment_content' => $this->slash_7,168 'comment_author' => self::SLASH_1, 169 'comment_content' => self::SLASH_7, 166 170 ) 167 171 ); 168 172 $comment = get_comment( $comment_id ); 169 173 170 $this->assertSame( wp_unslash( $this->slash_1 ), $comment->comment_author );171 $this->assertSame( wp_unslash( $this->slash_7 ), $comment->comment_content );174 $this->assertSame( wp_unslash( self::SLASH_1 ), $comment->comment_author ); 175 $this->assertSame( wp_unslash( self::SLASH_7 ), $comment->comment_content ); 172 176 173 177 wp_update_comment( 174 178 array( 175 179 'comment_ID' => $comment_id, 176 'comment_author' => $this->slash_2,177 'comment_content' => $this->slash_4,180 'comment_author' => self::SLASH_2, 181 'comment_content' => self::SLASH_4, 178 182 ) 179 183 ); 180 184 $comment = get_comment( $comment_id ); 181 185 182 $this->assertSame( wp_unslash( $this->slash_2 ), $comment->comment_author );183 $this->assertSame( wp_unslash( $this->slash_4 ), $comment->comment_content );186 $this->assertSame( wp_unslash( self::SLASH_2 ), $comment->comment_author ); 187 $this->assertSame( wp_unslash( self::SLASH_4 ), $comment->comment_content ); 184 188 } 185 189 -
trunk/tests/phpunit/tests/meta/slashes.php
r52010 r53557 7 7 */ 8 8 class Tests_Meta_Slashes extends WP_UnitTestCase { 9 10 /* 11 * It is important to test with both even and odd numbered slashes, 12 * as KSES does a strip-then-add slashes in some of its function calls. 13 */ 14 15 const SLASH_1 = 'String with 1 slash \\'; 16 const SLASH_2 = 'String with 2 slashes \\\\'; 17 const SLASH_3 = 'String with 3 slashes \\\\\\'; 18 const SLASH_4 = 'String with 4 slashes \\\\\\\\'; 19 const SLASH_5 = 'String with 5 slashes \\\\\\\\\\'; 20 const SLASH_6 = 'String with 6 slashes \\\\\\\\\\\\'; 21 const SLASH_7 = 'String with 7 slashes \\\\\\\\\\\\\\'; 22 9 23 protected static $editor_id; 10 24 protected static $post_id; … … 23 37 24 38 wp_set_current_user( self::$editor_id ); 25 26 $this->slash_1 = 'String with 1 slash \\';27 $this->slash_2 = 'String with 2 slashes \\\\';28 $this->slash_3 = 'String with 3 slashes \\\\\\';29 $this->slash_4 = 'String with 4 slashes \\\\\\\\';30 $this->slash_5 = 'String with 5 slashes \\\\\\\\\\';31 $this->slash_6 = 'String with 6 slashes \\\\\\\\\\\\';32 $this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\';33 39 } 34 40 … … 54 60 $_POST['metakeyselect'] = '#NONE#'; 55 61 $_POST['metakeyinput'] = 'slash_test_0'; 56 $_POST['metavalue'] = $this->slash_6;62 $_POST['metavalue'] = self::SLASH_6; 57 63 $_POST['meta'] = array( 58 64 $meta_1 => array( 59 65 'key' => 'slash_test_1', 60 'value' => $this->slash_1,66 'value' => self::SLASH_1, 61 67 ), 62 68 $meta_2 => array( 63 69 'key' => 'slash_test_2', 64 'value' => $this->slash_3,70 'value' => self::SLASH_3, 65 71 ), 66 72 $meta_3 => array( 67 73 'key' => 'slash_test_3', 68 'value' => $this->slash_4,74 'value' => self::SLASH_4, 69 75 ), 70 76 ); … … 75 81 $post = get_post( $post_id ); 76 82 77 $this->assertSame( $this->slash_6, get_post_meta( $post_id, 'slash_test_0', true ) );78 $this->assertSame( $this->slash_1, get_post_meta( $post_id, 'slash_test_1', true ) );79 $this->assertSame( $this->slash_3, get_post_meta( $post_id, 'slash_test_2', true ) );80 $this->assertSame( $this->slash_4, get_post_meta( $post_id, 'slash_test_3', true ) );83 $this->assertSame( self::SLASH_6, get_post_meta( $post_id, 'slash_test_0', true ) ); 84 $this->assertSame( self::SLASH_1, get_post_meta( $post_id, 'slash_test_1', true ) ); 85 $this->assertSame( self::SLASH_3, get_post_meta( $post_id, 'slash_test_2', true ) ); 86 $this->assertSame( self::SLASH_4, get_post_meta( $post_id, 'slash_test_3', true ) ); 81 87 82 88 $_POST = array(); … … 84 90 $_POST['metakeyselect'] = '#NONE#'; 85 91 $_POST['metakeyinput'] = 'slash_test_0'; 86 $_POST['metavalue'] = $this->slash_7;92 $_POST['metavalue'] = self::SLASH_7; 87 93 $_POST['meta'] = array( 88 94 $meta_1 => array( 89 95 'key' => 'slash_test_1', 90 'value' => $this->slash_2,96 'value' => self::SLASH_2, 91 97 ), 92 98 $meta_2 => array( 93 99 'key' => 'slash_test_2', 94 'value' => $this->slash_4,100 'value' => self::SLASH_4, 95 101 ), 96 102 $meta_3 => array( 97 103 'key' => 'slash_test_3', 98 'value' => $this->slash_5,104 'value' => self::SLASH_5, 99 105 ), 100 106 ); … … 105 111 $post = get_post( $post_id ); 106 112 107 $this->assertSame( $this->slash_2, get_post_meta( $post_id, 'slash_test_1', true ) );108 $this->assertSame( $this->slash_4, get_post_meta( $post_id, 'slash_test_2', true ) );109 $this->assertSame( $this->slash_5, get_post_meta( $post_id, 'slash_test_3', true ) );113 $this->assertSame( self::SLASH_2, get_post_meta( $post_id, 'slash_test_1', true ) ); 114 $this->assertSame( self::SLASH_4, get_post_meta( $post_id, 'slash_test_2', true ) ); 115 $this->assertSame( self::SLASH_5, get_post_meta( $post_id, 'slash_test_3', true ) ); 110 116 } 111 117 … … 116 122 $post_id = self::$post_id; 117 123 118 add_post_meta( $post_id, 'slash_test_1', addslashes( $this->slash_1 ) );119 add_post_meta( $post_id, 'slash_test_2', addslashes( $this->slash_3 ) );120 add_post_meta( $post_id, 'slash_test_3', addslashes( $this->slash_4 ) );121 122 $this->assertSame( $this->slash_1, get_post_meta( $post_id, 'slash_test_1', true ) );123 $this->assertSame( $this->slash_3, get_post_meta( $post_id, 'slash_test_2', true ) );124 $this->assertSame( $this->slash_4, get_post_meta( $post_id, 'slash_test_3', true ) );124 add_post_meta( $post_id, 'slash_test_1', addslashes( self::SLASH_1 ) ); 125 add_post_meta( $post_id, 'slash_test_2', addslashes( self::SLASH_3 ) ); 126 add_post_meta( $post_id, 'slash_test_3', addslashes( self::SLASH_4 ) ); 127 128 $this->assertSame( self::SLASH_1, get_post_meta( $post_id, 'slash_test_1', true ) ); 129 $this->assertSame( self::SLASH_3, get_post_meta( $post_id, 'slash_test_2', true ) ); 130 $this->assertSame( self::SLASH_4, get_post_meta( $post_id, 'slash_test_3', true ) ); 125 131 } 126 132 … … 131 137 $post_id = self::$post_id; 132 138 133 update_post_meta( $post_id, 'slash_test_1', addslashes( $this->slash_1 ) );134 update_post_meta( $post_id, 'slash_test_2', addslashes( $this->slash_3 ) );135 update_post_meta( $post_id, 'slash_test_3', addslashes( $this->slash_4 ) );136 137 $this->assertSame( $this->slash_1, get_post_meta( $post_id, 'slash_test_1', true ) );138 $this->assertSame( $this->slash_3, get_post_meta( $post_id, 'slash_test_2', true ) );139 $this->assertSame( $this->slash_4, get_post_meta( $post_id, 'slash_test_3', true ) );139 update_post_meta( $post_id, 'slash_test_1', addslashes( self::SLASH_1 ) ); 140 update_post_meta( $post_id, 'slash_test_2', addslashes( self::SLASH_3 ) ); 141 update_post_meta( $post_id, 'slash_test_3', addslashes( self::SLASH_4 ) ); 142 143 $this->assertSame( self::SLASH_1, get_post_meta( $post_id, 'slash_test_1', true ) ); 144 $this->assertSame( self::SLASH_3, get_post_meta( $post_id, 'slash_test_2', true ) ); 145 $this->assertSame( self::SLASH_4, get_post_meta( $post_id, 'slash_test_3', true ) ); 140 146 } 141 147 … … 146 152 $comment_id = self::$comment_id; 147 153 148 add_comment_meta( $comment_id, 'slash_test_1', $this->slash_1 );149 add_comment_meta( $comment_id, 'slash_test_2', $this->slash_3 );150 add_comment_meta( $comment_id, 'slash_test_3', $this->slash_5 );151 152 $this->assertSame( wp_unslash( $this->slash_1 ), get_comment_meta( $comment_id, 'slash_test_1', true ) );153 $this->assertSame( wp_unslash( $this->slash_3 ), get_comment_meta( $comment_id, 'slash_test_2', true ) );154 $this->assertSame( wp_unslash( $this->slash_5 ), get_comment_meta( $comment_id, 'slash_test_3', true ) );155 156 add_comment_meta( $comment_id, 'slash_test_4', $this->slash_2 );157 add_comment_meta( $comment_id, 'slash_test_5', $this->slash_4 );158 add_comment_meta( $comment_id, 'slash_test_6', $this->slash_6 );159 160 $this->assertSame( wp_unslash( $this->slash_2 ), get_comment_meta( $comment_id, 'slash_test_4', true ) );161 $this->assertSame( wp_unslash( $this->slash_4 ), get_comment_meta( $comment_id, 'slash_test_5', true ) );162 $this->assertSame( wp_unslash( $this->slash_6 ), get_comment_meta( $comment_id, 'slash_test_6', true ) );154 add_comment_meta( $comment_id, 'slash_test_1', self::SLASH_1 ); 155 add_comment_meta( $comment_id, 'slash_test_2', self::SLASH_3 ); 156 add_comment_meta( $comment_id, 'slash_test_3', self::SLASH_5 ); 157 158 $this->assertSame( wp_unslash( self::SLASH_1 ), get_comment_meta( $comment_id, 'slash_test_1', true ) ); 159 $this->assertSame( wp_unslash( self::SLASH_3 ), get_comment_meta( $comment_id, 'slash_test_2', true ) ); 160 $this->assertSame( wp_unslash( self::SLASH_5 ), get_comment_meta( $comment_id, 'slash_test_3', true ) ); 161 162 add_comment_meta( $comment_id, 'slash_test_4', self::SLASH_2 ); 163 add_comment_meta( $comment_id, 'slash_test_5', self::SLASH_4 ); 164 add_comment_meta( $comment_id, 'slash_test_6', self::SLASH_6 ); 165 166 $this->assertSame( wp_unslash( self::SLASH_2 ), get_comment_meta( $comment_id, 'slash_test_4', true ) ); 167 $this->assertSame( wp_unslash( self::SLASH_4 ), get_comment_meta( $comment_id, 'slash_test_5', true ) ); 168 $this->assertSame( wp_unslash( self::SLASH_6 ), get_comment_meta( $comment_id, 'slash_test_6', true ) ); 163 169 } 164 170 … … 173 179 add_comment_meta( $comment_id, 'slash_test_3', 'foo' ); 174 180 175 update_comment_meta( $comment_id, 'slash_test_1', $this->slash_1 );176 update_comment_meta( $comment_id, 'slash_test_2', $this->slash_3 );177 update_comment_meta( $comment_id, 'slash_test_3', $this->slash_5 );178 179 $this->assertSame( wp_unslash( $this->slash_1 ), get_comment_meta( $comment_id, 'slash_test_1', true ) );180 $this->assertSame( wp_unslash( $this->slash_3 ), get_comment_meta( $comment_id, 'slash_test_2', true ) );181 $this->assertSame( wp_unslash( $this->slash_5 ), get_comment_meta( $comment_id, 'slash_test_3', true ) );182 183 update_comment_meta( $comment_id, 'slash_test_1', $this->slash_2 );184 update_comment_meta( $comment_id, 'slash_test_2', $this->slash_4 );185 update_comment_meta( $comment_id, 'slash_test_3', $this->slash_6 );186 187 $this->assertSame( wp_unslash( $this->slash_2 ), get_comment_meta( $comment_id, 'slash_test_1', true ) );188 $this->assertSame( wp_unslash( $this->slash_4 ), get_comment_meta( $comment_id, 'slash_test_2', true ) );189 $this->assertSame( wp_unslash( $this->slash_6 ), get_comment_meta( $comment_id, 'slash_test_3', true ) );181 update_comment_meta( $comment_id, 'slash_test_1', self::SLASH_1 ); 182 update_comment_meta( $comment_id, 'slash_test_2', self::SLASH_3 ); 183 update_comment_meta( $comment_id, 'slash_test_3', self::SLASH_5 ); 184 185 $this->assertSame( wp_unslash( self::SLASH_1 ), get_comment_meta( $comment_id, 'slash_test_1', true ) ); 186 $this->assertSame( wp_unslash( self::SLASH_3 ), get_comment_meta( $comment_id, 'slash_test_2', true ) ); 187 $this->assertSame( wp_unslash( self::SLASH_5 ), get_comment_meta( $comment_id, 'slash_test_3', true ) ); 188 189 update_comment_meta( $comment_id, 'slash_test_1', self::SLASH_2 ); 190 update_comment_meta( $comment_id, 'slash_test_2', self::SLASH_4 ); 191 update_comment_meta( $comment_id, 'slash_test_3', self::SLASH_6 ); 192 193 $this->assertSame( wp_unslash( self::SLASH_2 ), get_comment_meta( $comment_id, 'slash_test_1', true ) ); 194 $this->assertSame( wp_unslash( self::SLASH_4 ), get_comment_meta( $comment_id, 'slash_test_2', true ) ); 195 $this->assertSame( wp_unslash( self::SLASH_6 ), get_comment_meta( $comment_id, 'slash_test_3', true ) ); 190 196 } 191 197 … … 196 202 $user_id = self::$user_id; 197 203 198 add_user_meta( $user_id, 'slash_test_1', $this->slash_1 );199 add_user_meta( $user_id, 'slash_test_2', $this->slash_3 );200 add_user_meta( $user_id, 'slash_test_3', $this->slash_5 );201 202 $this->assertSame( wp_unslash( $this->slash_1 ), get_user_meta( $user_id, 'slash_test_1', true ) );203 $this->assertSame( wp_unslash( $this->slash_3 ), get_user_meta( $user_id, 'slash_test_2', true ) );204 $this->assertSame( wp_unslash( $this->slash_5 ), get_user_meta( $user_id, 'slash_test_3', true ) );205 206 add_user_meta( $user_id, 'slash_test_4', $this->slash_2 );207 add_user_meta( $user_id, 'slash_test_5', $this->slash_4 );208 add_user_meta( $user_id, 'slash_test_6', $this->slash_6 );209 210 $this->assertSame( wp_unslash( $this->slash_2 ), get_user_meta( $user_id, 'slash_test_4', true ) );211 $this->assertSame( wp_unslash( $this->slash_4 ), get_user_meta( $user_id, 'slash_test_5', true ) );212 $this->assertSame( wp_unslash( $this->slash_6 ), get_user_meta( $user_id, 'slash_test_6', true ) );204 add_user_meta( $user_id, 'slash_test_1', self::SLASH_1 ); 205 add_user_meta( $user_id, 'slash_test_2', self::SLASH_3 ); 206 add_user_meta( $user_id, 'slash_test_3', self::SLASH_5 ); 207 208 $this->assertSame( wp_unslash( self::SLASH_1 ), get_user_meta( $user_id, 'slash_test_1', true ) ); 209 $this->assertSame( wp_unslash( self::SLASH_3 ), get_user_meta( $user_id, 'slash_test_2', true ) ); 210 $this->assertSame( wp_unslash( self::SLASH_5 ), get_user_meta( $user_id, 'slash_test_3', true ) ); 211 212 add_user_meta( $user_id, 'slash_test_4', self::SLASH_2 ); 213 add_user_meta( $user_id, 'slash_test_5', self::SLASH_4 ); 214 add_user_meta( $user_id, 'slash_test_6', self::SLASH_6 ); 215 216 $this->assertSame( wp_unslash( self::SLASH_2 ), get_user_meta( $user_id, 'slash_test_4', true ) ); 217 $this->assertSame( wp_unslash( self::SLASH_4 ), get_user_meta( $user_id, 'slash_test_5', true ) ); 218 $this->assertSame( wp_unslash( self::SLASH_6 ), get_user_meta( $user_id, 'slash_test_6', true ) ); 213 219 } 214 220 … … 223 229 add_user_meta( $user_id, 'slash_test_3', 'foo' ); 224 230 225 update_user_meta( $user_id, 'slash_test_1', $this->slash_1 );226 update_user_meta( $user_id, 'slash_test_2', $this->slash_3 );227 update_user_meta( $user_id, 'slash_test_3', $this->slash_5 );228 229 $this->assertSame( wp_unslash( $this->slash_1 ), get_user_meta( $user_id, 'slash_test_1', true ) );230 $this->assertSame( wp_unslash( $this->slash_3 ), get_user_meta( $user_id, 'slash_test_2', true ) );231 $this->assertSame( wp_unslash( $this->slash_5 ), get_user_meta( $user_id, 'slash_test_3', true ) );232 233 update_user_meta( $user_id, 'slash_test_1', $this->slash_2 );234 update_user_meta( $user_id, 'slash_test_2', $this->slash_4 );235 update_user_meta( $user_id, 'slash_test_3', $this->slash_6 );236 237 $this->assertSame( wp_unslash( $this->slash_2 ), get_user_meta( $user_id, 'slash_test_1', true ) );238 $this->assertSame( wp_unslash( $this->slash_4 ), get_user_meta( $user_id, 'slash_test_2', true ) );239 $this->assertSame( wp_unslash( $this->slash_6 ), get_user_meta( $user_id, 'slash_test_3', true ) );231 update_user_meta( $user_id, 'slash_test_1', self::SLASH_1 ); 232 update_user_meta( $user_id, 'slash_test_2', self::SLASH_3 ); 233 update_user_meta( $user_id, 'slash_test_3', self::SLASH_5 ); 234 235 $this->assertSame( wp_unslash( self::SLASH_1 ), get_user_meta( $user_id, 'slash_test_1', true ) ); 236 $this->assertSame( wp_unslash( self::SLASH_3 ), get_user_meta( $user_id, 'slash_test_2', true ) ); 237 $this->assertSame( wp_unslash( self::SLASH_5 ), get_user_meta( $user_id, 'slash_test_3', true ) ); 238 239 update_user_meta( $user_id, 'slash_test_1', self::SLASH_2 ); 240 update_user_meta( $user_id, 'slash_test_2', self::SLASH_4 ); 241 update_user_meta( $user_id, 'slash_test_3', self::SLASH_6 ); 242 243 $this->assertSame( wp_unslash( self::SLASH_2 ), get_user_meta( $user_id, 'slash_test_1', true ) ); 244 $this->assertSame( wp_unslash( self::SLASH_4 ), get_user_meta( $user_id, 'slash_test_2', true ) ); 245 $this->assertSame( wp_unslash( self::SLASH_6 ), get_user_meta( $user_id, 'slash_test_3', true ) ); 240 246 } 241 247 } -
trunk/tests/phpunit/tests/option/slashes.php
r52010 r53557 8 8 class Tests_Option_Slashes extends WP_UnitTestCase { 9 9 10 public function set_up() { 11 parent::set_up(); 10 /* 11 * It is important to test with both even and odd numbered slashes, 12 * as KSES does a strip-then-add slashes in some of its function calls. 13 */ 12 14 13 // It is important to test with both even and odd numbered slashes, 14 // as KSES does a strip-then-add slashes in some of its function calls. 15 $this->slash_1 = 'String with 1 slash \\'; 16 $this->slash_2 = 'String with 2 slashes \\\\'; 17 $this->slash_3 = 'String with 3 slashes \\\\\\'; 18 $this->slash_4 = 'String with 4 slashes \\\\\\\\'; 19 $this->slash_5 = 'String with 5 slashes \\\\\\\\\\'; 20 $this->slash_6 = 'String with 6 slashes \\\\\\\\\\\\'; 21 $this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\'; 22 } 15 const SLASH_1 = 'String with 1 slash \\'; 16 const SLASH_2 = 'String with 2 slashes \\\\'; 17 const SLASH_3 = 'String with 3 slashes \\\\\\'; 18 const SLASH_4 = 'String with 4 slashes \\\\\\\\'; 19 const SLASH_5 = 'String with 5 slashes \\\\\\\\\\'; 20 const SLASH_6 = 'String with 6 slashes \\\\\\\\\\\\'; 21 const SLASH_7 = 'String with 7 slashes \\\\\\\\\\\\\\'; 23 22 24 23 /** … … 26 25 */ 27 26 public function test_add_option() { 28 add_option( 'slash_test_1', $this->slash_1 );29 add_option( 'slash_test_2', $this->slash_2 );30 add_option( 'slash_test_3', $this->slash_3 );31 add_option( 'slash_test_4', $this->slash_4 );27 add_option( 'slash_test_1', self::SLASH_1 ); 28 add_option( 'slash_test_2', self::SLASH_2 ); 29 add_option( 'slash_test_3', self::SLASH_3 ); 30 add_option( 'slash_test_4', self::SLASH_4 ); 32 31 33 $this->assertSame( $this->slash_1, get_option( 'slash_test_1' ) );34 $this->assertSame( $this->slash_2, get_option( 'slash_test_2' ) );35 $this->assertSame( $this->slash_3, get_option( 'slash_test_3' ) );36 $this->assertSame( $this->slash_4, get_option( 'slash_test_4' ) );32 $this->assertSame( self::SLASH_1, get_option( 'slash_test_1' ) ); 33 $this->assertSame( self::SLASH_2, get_option( 'slash_test_2' ) ); 34 $this->assertSame( self::SLASH_3, get_option( 'slash_test_3' ) ); 35 $this->assertSame( self::SLASH_4, get_option( 'slash_test_4' ) ); 37 36 } 38 37 … … 43 42 add_option( 'slash_test_5', 'foo' ); 44 43 45 update_option( 'slash_test_5', $this->slash_1 );46 $this->assertSame( $this->slash_1, get_option( 'slash_test_5' ) );44 update_option( 'slash_test_5', self::SLASH_1 ); 45 $this->assertSame( self::SLASH_1, get_option( 'slash_test_5' ) ); 47 46 48 update_option( 'slash_test_5', $this->slash_2 );49 $this->assertSame( $this->slash_2, get_option( 'slash_test_5' ) );47 update_option( 'slash_test_5', self::SLASH_2 ); 48 $this->assertSame( self::SLASH_2, get_option( 'slash_test_5' ) ); 50 49 51 update_option( 'slash_test_5', $this->slash_3 );52 $this->assertSame( $this->slash_3, get_option( 'slash_test_5' ) );50 update_option( 'slash_test_5', self::SLASH_3 ); 51 $this->assertSame( self::SLASH_3, get_option( 'slash_test_5' ) ); 53 52 54 update_option( 'slash_test_5', $this->slash_4 );55 $this->assertSame( $this->slash_4, get_option( 'slash_test_5' ) );53 update_option( 'slash_test_5', self::SLASH_4 ); 54 $this->assertSame( self::SLASH_4, get_option( 'slash_test_5' ) ); 56 55 } 57 56 } -
trunk/tests/phpunit/tests/post/slashes.php
r52010 r53557 7 7 */ 8 8 class Tests_Post_Slashes extends WP_UnitTestCase { 9 10 /* 11 * It is important to test with both even and odd numbered slashes, 12 * as KSES does a strip-then-add slashes in some of its function calls. 13 */ 14 15 const SLASH_1 = 'String with 1 slash \\'; 16 const SLASH_2 = 'String with 2 slashes \\\\'; 17 const SLASH_3 = 'String with 3 slashes \\\\\\'; 18 const SLASH_4 = 'String with 4 slashes \\\\\\\\'; 19 const SLASH_5 = 'String with 5 slashes \\\\\\\\\\'; 20 const SLASH_6 = 'String with 6 slashes \\\\\\\\\\\\'; 21 const SLASH_7 = 'String with 7 slashes \\\\\\\\\\\\\\'; 22 9 23 protected static $author_id; 10 24 protected static $post_id; … … 19 33 20 34 wp_set_current_user( self::$author_id ); 21 22 // It is important to test with both even and odd numbered slashes,23 // as KSES does a strip-then-add slashes in some of its function calls.24 $this->slash_1 = 'String with 1 slash \\';25 $this->slash_2 = 'String with 2 slashes \\\\';26 $this->slash_3 = 'String with 3 slashes \\\\\\';27 $this->slash_4 = 'String with 4 slashes \\\\\\\\';28 $this->slash_5 = 'String with 5 slashes \\\\\\\\\\';29 $this->slash_6 = 'String with 6 slashes \\\\\\\\\\\\';30 $this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\';31 35 } 32 36 … … 39 43 $_POST = array(); 40 44 $_POST['post_ID'] = $post_id; 41 $_POST['post_title'] = $this->slash_1;42 $_POST['content'] = $this->slash_5;43 $_POST['excerpt'] = $this->slash_7;45 $_POST['post_title'] = self::SLASH_1; 46 $_POST['content'] = self::SLASH_5; 47 $_POST['excerpt'] = self::SLASH_7; 44 48 45 49 $_POST = add_magic_quotes( $_POST ); // The edit_post() function will strip slashes. … … 48 52 $post = get_post( $post_id ); 49 53 50 $this->assertSame( $this->slash_1, $post->post_title );51 $this->assertSame( $this->slash_5, $post->post_content );52 $this->assertSame( $this->slash_7, $post->post_excerpt );54 $this->assertSame( self::SLASH_1, $post->post_title ); 55 $this->assertSame( self::SLASH_5, $post->post_content ); 56 $this->assertSame( self::SLASH_7, $post->post_excerpt ); 53 57 54 58 $_POST = array(); 55 59 $_POST['post_ID'] = $post_id; 56 $_POST['post_title'] = $this->slash_2;57 $_POST['content'] = $this->slash_4;58 $_POST['excerpt'] = $this->slash_6;60 $_POST['post_title'] = self::SLASH_2; 61 $_POST['content'] = self::SLASH_4; 62 $_POST['excerpt'] = self::SLASH_6; 59 63 60 64 $_POST = add_magic_quotes( $_POST ); // The edit_post() function will strip slashes. … … 63 67 $post = get_post( $post_id ); 64 68 65 $this->assertSame( $this->slash_2, $post->post_title );66 $this->assertSame( $this->slash_4, $post->post_content );67 $this->assertSame( $this->slash_6, $post->post_excerpt );69 $this->assertSame( self::SLASH_2, $post->post_title ); 70 $this->assertSame( self::SLASH_4, $post->post_content ); 71 $this->assertSame( self::SLASH_6, $post->post_excerpt ); 68 72 } 69 73 … … 75 79 array( 76 80 'post_status' => 'publish', 77 'post_title' => $this->slash_1,78 'post_content' => $this->slash_3,79 'post_excerpt' => $this->slash_5,81 'post_title' => self::SLASH_1, 82 'post_content' => self::SLASH_3, 83 'post_excerpt' => self::SLASH_5, 80 84 'post_type' => 'post', 81 85 'slashed' => false, … … 84 88 $post = get_post( $post_id ); 85 89 86 $this->assertSame( wp_unslash( $this->slash_1 ), $post->post_title );87 $this->assertSame( wp_unslash( $this->slash_3 ), $post->post_content );88 $this->assertSame( wp_unslash( $this->slash_5 ), $post->post_excerpt );90 $this->assertSame( wp_unslash( self::SLASH_1 ), $post->post_title ); 91 $this->assertSame( wp_unslash( self::SLASH_3 ), $post->post_content ); 92 $this->assertSame( wp_unslash( self::SLASH_5 ), $post->post_excerpt ); 89 93 90 94 $post_id = wp_insert_post( 91 95 array( 92 96 'post_status' => 'publish', 93 'post_title' => $this->slash_2,94 'post_content' => $this->slash_4,95 'post_excerpt' => $this->slash_6,97 'post_title' => self::SLASH_2, 98 'post_content' => self::SLASH_4, 99 'post_excerpt' => self::SLASH_6, 96 100 'post_type' => 'post', 97 101 ) … … 99 103 $post = get_post( $post_id ); 100 104 101 $this->assertSame( wp_unslash( $this->slash_2 ), $post->post_title );102 $this->assertSame( wp_unslash( $this->slash_4 ), $post->post_content );103 $this->assertSame( wp_unslash( $this->slash_6 ), $post->post_excerpt );105 $this->assertSame( wp_unslash( self::SLASH_2 ), $post->post_title ); 106 $this->assertSame( wp_unslash( self::SLASH_4 ), $post->post_content ); 107 $this->assertSame( wp_unslash( self::SLASH_6 ), $post->post_excerpt ); 104 108 } 105 109 … … 113 117 array( 114 118 'ID' => $post_id, 115 'post_title' => $this->slash_1,116 'post_content' => $this->slash_3,117 'post_excerpt' => $this->slash_5,119 'post_title' => self::SLASH_1, 120 'post_content' => self::SLASH_3, 121 'post_excerpt' => self::SLASH_5, 118 122 ) 119 123 ); 120 124 $post = get_post( $post_id ); 121 125 122 $this->assertSame( wp_unslash( $this->slash_1 ), $post->post_title );123 $this->assertSame( wp_unslash( $this->slash_3 ), $post->post_content );124 $this->assertSame( wp_unslash( $this->slash_5 ), $post->post_excerpt );126 $this->assertSame( wp_unslash( self::SLASH_1 ), $post->post_title ); 127 $this->assertSame( wp_unslash( self::SLASH_3 ), $post->post_content ); 128 $this->assertSame( wp_unslash( self::SLASH_5 ), $post->post_excerpt ); 125 129 126 130 wp_update_post( 127 131 array( 128 132 'ID' => $post_id, 129 'post_title' => $this->slash_2,130 'post_content' => $this->slash_4,131 'post_excerpt' => $this->slash_6,133 'post_title' => self::SLASH_2, 134 'post_content' => self::SLASH_4, 135 'post_excerpt' => self::SLASH_6, 132 136 ) 133 137 ); 134 138 $post = get_post( $post_id ); 135 139 136 $this->assertSame( wp_unslash( $this->slash_2 ), $post->post_title );137 $this->assertSame( wp_unslash( $this->slash_4 ), $post->post_content );138 $this->assertSame( wp_unslash( $this->slash_6 ), $post->post_excerpt );140 $this->assertSame( wp_unslash( self::SLASH_2 ), $post->post_title ); 141 $this->assertSame( wp_unslash( self::SLASH_4 ), $post->post_content ); 142 $this->assertSame( wp_unslash( self::SLASH_6 ), $post->post_excerpt ); 139 143 } 140 144 … … 144 148 public function test_wp_trash_untrash() { 145 149 $post = array( 146 'post_title' => $this->slash_1,147 'post_content' => $this->slash_3,148 'post_excerpt' => $this->slash_5,150 'post_title' => self::SLASH_1, 151 'post_content' => self::SLASH_3, 152 'post_excerpt' => self::SLASH_5, 149 153 ); 150 154 $post_id = wp_insert_post( wp_slash( $post ) ); … … 155 159 $post = get_post( $post_id ); 156 160 157 $this->assertSame( $this->slash_1, $post->post_title );158 $this->assertSame( $this->slash_3, $post->post_content );159 $this->assertSame( $this->slash_5, $post->post_excerpt );161 $this->assertSame( self::SLASH_1, $post->post_title ); 162 $this->assertSame( self::SLASH_3, $post->post_content ); 163 $this->assertSame( self::SLASH_5, $post->post_excerpt ); 160 164 161 165 $untrashed = wp_untrash_post( $post_id ); … … 164 168 $post = get_post( $post_id ); 165 169 166 $this->assertSame( $this->slash_1, $post->post_title );167 $this->assertSame( $this->slash_3, $post->post_content );168 $this->assertSame( $this->slash_5, $post->post_excerpt );170 $this->assertSame( self::SLASH_1, $post->post_title ); 171 $this->assertSame( self::SLASH_3, $post->post_content ); 172 $this->assertSame( self::SLASH_5, $post->post_excerpt ); 169 173 } 170 174 } -
trunk/tests/phpunit/tests/term/slashes.php
r52010 r53557 7 7 */ 8 8 class Tests_Term_Slashes extends WP_Ajax_UnitTestCase { 9 10 /* 11 * It is important to test with both even and odd numbered slashes, 12 * as KSES does a strip-then-add slashes in some of its function calls. 13 */ 14 15 const SLASH_1 = 'String with 1 slash \\'; 16 const SLASH_2 = 'String with 2 slashes \\\\'; 17 const SLASH_3 = 'String with 3 slashes \\\\\\'; 18 const SLASH_4 = 'String with 4 slashes \\\\\\\\'; 19 const SLASH_5 = 'String with 5 slashes \\\\\\\\\\'; 20 const SLASH_6 = 'String with 6 slashes \\\\\\\\\\\\'; 21 const SLASH_7 = 'String with 7 slashes \\\\\\\\\\\\\\'; 22 9 23 protected static $author_id; 10 24 … … 17 31 18 32 wp_set_current_user( self::$author_id ); 19 20 $this->slash_1 = 'String with 1 slash \\';21 $this->slash_2 = 'String with 2 slashes \\\\';22 $this->slash_3 = 'String with 3 slashes \\\\\\';23 $this->slash_4 = 'String with 4 slashes \\\\\\\\';24 $this->slash_5 = 'String with 5 slashes \\\\\\\\\\';25 $this->slash_6 = 'String with 6 slashes \\\\\\\\\\\\';26 $this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\';27 33 } 28 34 … … 37 43 foreach ( $taxonomies as $taxonomy ) { 38 44 $insert = wp_insert_term( 39 $this->slash_1,45 self::SLASH_1, 40 46 $taxonomy, 41 47 array( 42 48 'slug' => 'slash_test_1_' . $taxonomy, 43 'description' => $this->slash_3,49 'description' => self::SLASH_3, 44 50 ) 45 51 ); 46 52 $term = get_term( $insert['term_id'], $taxonomy ); 47 $this->assertSame( wp_unslash( $this->slash_1 ), $term->name );48 $this->assertSame( wp_unslash( $this->slash_3 ), $term->description );53 $this->assertSame( wp_unslash( self::SLASH_1 ), $term->name ); 54 $this->assertSame( wp_unslash( self::SLASH_3 ), $term->description ); 49 55 50 56 $insert = wp_insert_term( 51 $this->slash_3,57 self::SLASH_3, 52 58 $taxonomy, 53 59 array( 54 60 'slug' => 'slash_test_2_' . $taxonomy, 55 'description' => $this->slash_5,61 'description' => self::SLASH_5, 56 62 ) 57 63 ); 58 64 $term = get_term( $insert['term_id'], $taxonomy ); 59 $this->assertSame( wp_unslash( $this->slash_3 ), $term->name );60 $this->assertSame( wp_unslash( $this->slash_5 ), $term->description );65 $this->assertSame( wp_unslash( self::SLASH_3 ), $term->name ); 66 $this->assertSame( wp_unslash( self::SLASH_5 ), $term->description ); 61 67 62 68 $insert = wp_insert_term( 63 $this->slash_2,69 self::SLASH_2, 64 70 $taxonomy, 65 71 array( 66 72 'slug' => 'slash_test_3_' . $taxonomy, 67 'description' => $this->slash_4,73 'description' => self::SLASH_4, 68 74 ) 69 75 ); 70 76 $term = get_term( $insert['term_id'], $taxonomy ); 71 $this->assertSame( wp_unslash( $this->slash_2 ), $term->name );72 $this->assertSame( wp_unslash( $this->slash_4 ), $term->description );77 $this->assertSame( wp_unslash( self::SLASH_2 ), $term->name ); 78 $this->assertSame( wp_unslash( self::SLASH_4 ), $term->description ); 73 79 } 74 80 } … … 93 99 $taxonomy, 94 100 array( 95 'name' => $this->slash_1,96 'description' => $this->slash_3,101 'name' => self::SLASH_1, 102 'description' => self::SLASH_3, 97 103 ) 98 104 ); 99 105 100 106 $term = get_term( $term_id, $taxonomy ); 101 $this->assertSame( wp_unslash( $this->slash_1 ), $term->name );102 $this->assertSame( wp_unslash( $this->slash_3 ), $term->description );107 $this->assertSame( wp_unslash( self::SLASH_1 ), $term->name ); 108 $this->assertSame( wp_unslash( self::SLASH_3 ), $term->description ); 103 109 104 110 $update = wp_update_term( … … 106 112 $taxonomy, 107 113 array( 108 'name' => $this->slash_3,109 'description' => $this->slash_5,114 'name' => self::SLASH_3, 115 'description' => self::SLASH_5, 110 116 ) 111 117 ); 112 118 $term = get_term( $term_id, $taxonomy ); 113 $this->assertSame( wp_unslash( $this->slash_3 ), $term->name );114 $this->assertSame( wp_unslash( $this->slash_5 ), $term->description );119 $this->assertSame( wp_unslash( self::SLASH_3 ), $term->name ); 120 $this->assertSame( wp_unslash( self::SLASH_5 ), $term->description ); 115 121 116 122 $update = wp_update_term( … … 118 124 $taxonomy, 119 125 array( 120 'name' => $this->slash_2,121 'description' => $this->slash_4,126 'name' => self::SLASH_2, 127 'description' => self::SLASH_4, 122 128 ) 123 129 ); 124 130 $term = get_term( $term_id, $taxonomy ); 125 $this->assertSame( wp_unslash( $this->slash_2 ), $term->name );126 $this->assertSame( wp_unslash( $this->slash_4 ), $term->description );131 $this->assertSame( wp_unslash( self::SLASH_2 ), $term->name ); 132 $this->assertSame( wp_unslash( self::SLASH_4 ), $term->description ); 127 133 } 128 134 } -
trunk/tests/phpunit/tests/user/slashes.php
r52010 r53557 7 7 */ 8 8 class Tests_User_Slashes extends WP_UnitTestCase { 9 10 /* 11 * It is important to test with both even and odd numbered slashes, 12 * as KSES does a strip-then-add slashes in some of its function calls. 13 */ 14 15 const SLASH_1 = 'String with 1 slash \\'; 16 const SLASH_2 = 'String with 2 slashes \\\\'; 17 const SLASH_3 = 'String with 3 slashes \\\\\\'; 18 const SLASH_4 = 'String with 4 slashes \\\\\\\\'; 19 const SLASH_5 = 'String with 5 slashes \\\\\\\\\\'; 20 const SLASH_6 = 'String with 6 slashes \\\\\\\\\\\\'; 21 const SLASH_7 = 'String with 7 slashes \\\\\\\\\\\\\\'; 22 9 23 protected static $author_id; 10 24 protected static $user_id; … … 19 33 20 34 wp_set_current_user( self::$author_id ); 21 22 // It is important to test with both even and odd numbered slashes,23 // as KSES does a strip-then-add slashes in some of its function calls.24 $this->slash_1 = 'String with 1 slash \\';25 $this->slash_2 = 'String with 2 slashes \\\\';26 $this->slash_3 = 'String with 3 slashes \\\\\\';27 $this->slash_4 = 'String with 4 slashes \\\\\\\\';28 $this->slash_5 = 'String with 5 slashes \\\\\\\\\\';29 $this->slash_6 = 'String with 6 slashes \\\\\\\\\\\\';30 $this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\';31 35 } 32 36 … … 43 47 $_POST['role'] = 'subscriber'; 44 48 $_POST['email'] = 'user1@example.com'; 45 $_POST['first_name'] = $this->slash_1;46 $_POST['last_name'] = $this->slash_3;47 $_POST['nickname'] = $this->slash_5;48 $_POST['display_name'] = $this->slash_7;49 $_POST['description'] = $this->slash_3;49 $_POST['first_name'] = self::SLASH_1; 50 $_POST['last_name'] = self::SLASH_3; 51 $_POST['nickname'] = self::SLASH_5; 52 $_POST['display_name'] = self::SLASH_7; 53 $_POST['description'] = self::SLASH_3; 50 54 51 55 $_POST = add_magic_quotes( $_POST ); // The add_user() function will strip slashes. … … 54 58 $user = get_user_to_edit( $user_id ); 55 59 56 $this->assertSame( $this->slash_1, $user->first_name );57 $this->assertSame( $this->slash_3, $user->last_name );58 $this->assertSame( $this->slash_5, $user->nickname );59 $this->assertSame( $this->slash_7, $user->display_name );60 $this->assertSame( $this->slash_3, $user->description );60 $this->assertSame( self::SLASH_1, $user->first_name ); 61 $this->assertSame( self::SLASH_3, $user->last_name ); 62 $this->assertSame( self::SLASH_5, $user->nickname ); 63 $this->assertSame( self::SLASH_7, $user->display_name ); 64 $this->assertSame( self::SLASH_3, $user->description ); 61 65 62 66 $_POST = array(); … … 68 72 $_POST['role'] = 'subscriber'; 69 73 $_POST['email'] = 'user2@example.com'; 70 $_POST['first_name'] = $this->slash_2;71 $_POST['last_name'] = $this->slash_4;72 $_POST['nickname'] = $this->slash_6;73 $_POST['display_name'] = $this->slash_2;74 $_POST['description'] = $this->slash_4;74 $_POST['first_name'] = self::SLASH_2; 75 $_POST['last_name'] = self::SLASH_4; 76 $_POST['nickname'] = self::SLASH_6; 77 $_POST['display_name'] = self::SLASH_2; 78 $_POST['description'] = self::SLASH_4; 75 79 76 80 $_POST = add_magic_quotes( $_POST ); // The add_user() function will strip slashes. … … 79 83 $user = get_user_to_edit( $user_id ); 80 84 81 $this->assertSame( $this->slash_2, $user->first_name );82 $this->assertSame( $this->slash_4, $user->last_name );83 $this->assertSame( $this->slash_6, $user->nickname );84 $this->assertSame( $this->slash_2, $user->display_name );85 $this->assertSame( $this->slash_4, $user->description );85 $this->assertSame( self::SLASH_2, $user->first_name ); 86 $this->assertSame( self::SLASH_4, $user->last_name ); 87 $this->assertSame( self::SLASH_6, $user->nickname ); 88 $this->assertSame( self::SLASH_2, $user->display_name ); 89 $this->assertSame( self::SLASH_4, $user->description ); 86 90 } 87 91 … … 97 101 $_POST['role'] = 'subscriber'; 98 102 $_POST['email'] = 'user1@example.com'; 99 $_POST['first_name'] = $this->slash_1;100 $_POST['last_name'] = $this->slash_3;101 $_POST['nickname'] = $this->slash_5;102 $_POST['display_name'] = $this->slash_7;103 $_POST['description'] = $this->slash_3;103 $_POST['first_name'] = self::SLASH_1; 104 $_POST['last_name'] = self::SLASH_3; 105 $_POST['nickname'] = self::SLASH_5; 106 $_POST['display_name'] = self::SLASH_7; 107 $_POST['description'] = self::SLASH_3; 104 108 105 109 $_POST = add_magic_quotes( $_POST ); // The edit_user() function will strip slashes. … … 108 112 $user = get_user_to_edit( $user_id ); 109 113 110 $this->assertSame( $this->slash_1, $user->first_name );111 $this->assertSame( $this->slash_3, $user->last_name );112 $this->assertSame( $this->slash_5, $user->nickname );113 $this->assertSame( $this->slash_7, $user->display_name );114 $this->assertSame( $this->slash_3, $user->description );114 $this->assertSame( self::SLASH_1, $user->first_name ); 115 $this->assertSame( self::SLASH_3, $user->last_name ); 116 $this->assertSame( self::SLASH_5, $user->nickname ); 117 $this->assertSame( self::SLASH_7, $user->display_name ); 118 $this->assertSame( self::SLASH_3, $user->description ); 115 119 116 120 $_POST = array(); … … 119 123 $_POST['role'] = 'subscriber'; 120 124 $_POST['email'] = 'user2@example.com'; 121 $_POST['first_name'] = $this->slash_2;122 $_POST['last_name'] = $this->slash_4;123 $_POST['nickname'] = $this->slash_6;124 $_POST['display_name'] = $this->slash_2;125 $_POST['description'] = $this->slash_4;125 $_POST['first_name'] = self::SLASH_2; 126 $_POST['last_name'] = self::SLASH_4; 127 $_POST['nickname'] = self::SLASH_6; 128 $_POST['display_name'] = self::SLASH_2; 129 $_POST['description'] = self::SLASH_4; 126 130 127 131 $_POST = add_magic_quotes( $_POST ); // The edit_user() function will strip slashes. … … 130 134 $user = get_user_to_edit( $user_id ); 131 135 132 $this->assertSame( $this->slash_2, $user->first_name );133 $this->assertSame( $this->slash_4, $user->last_name );134 $this->assertSame( $this->slash_6, $user->nickname );135 $this->assertSame( $this->slash_2, $user->display_name );136 $this->assertSame( $this->slash_4, $user->description );136 $this->assertSame( self::SLASH_2, $user->first_name ); 137 $this->assertSame( self::SLASH_4, $user->last_name ); 138 $this->assertSame( self::SLASH_6, $user->nickname ); 139 $this->assertSame( self::SLASH_2, $user->display_name ); 140 $this->assertSame( self::SLASH_4, $user->description ); 137 141 } 138 142 … … 146 150 'role' => 'subscriber', 147 151 'email' => 'user3@example.com', 148 'first_name' => $this->slash_1,149 'last_name' => $this->slash_3,150 'nickname' => $this->slash_5,151 'display_name' => $this->slash_7,152 'description' => $this->slash_3,152 'first_name' => self::SLASH_1, 153 'last_name' => self::SLASH_3, 154 'nickname' => self::SLASH_5, 155 'display_name' => self::SLASH_7, 156 'description' => self::SLASH_3, 153 157 'user_pass' => '', 154 158 ) … … 156 160 $user = get_user_to_edit( $user_id ); 157 161 158 $this->assertSame( wp_unslash( $this->slash_1 ), $user->first_name );159 $this->assertSame( wp_unslash( $this->slash_3 ), $user->last_name );160 $this->assertSame( wp_unslash( $this->slash_5 ), $user->nickname );161 $this->assertSame( wp_unslash( $this->slash_7 ), $user->display_name );162 $this->assertSame( wp_unslash( $this->slash_3 ), $user->description );162 $this->assertSame( wp_unslash( self::SLASH_1 ), $user->first_name ); 163 $this->assertSame( wp_unslash( self::SLASH_3 ), $user->last_name ); 164 $this->assertSame( wp_unslash( self::SLASH_5 ), $user->nickname ); 165 $this->assertSame( wp_unslash( self::SLASH_7 ), $user->display_name ); 166 $this->assertSame( wp_unslash( self::SLASH_3 ), $user->description ); 163 167 164 168 $user_id = wp_insert_user( … … 167 171 'role' => 'subscriber', 168 172 'email' => 'user3@example.com', 169 'first_name' => $this->slash_2,170 'last_name' => $this->slash_4,171 'nickname' => $this->slash_6,172 'display_name' => $this->slash_2,173 'description' => $this->slash_4,173 'first_name' => self::SLASH_2, 174 'last_name' => self::SLASH_4, 175 'nickname' => self::SLASH_6, 176 'display_name' => self::SLASH_2, 177 'description' => self::SLASH_4, 174 178 'user_pass' => '', 175 179 ) … … 177 181 $user = get_user_to_edit( $user_id ); 178 182 179 $this->assertSame( wp_unslash( $this->slash_2 ), $user->first_name );180 $this->assertSame( wp_unslash( $this->slash_4 ), $user->last_name );181 $this->assertSame( wp_unslash( $this->slash_6 ), $user->nickname );182 $this->assertSame( wp_unslash( $this->slash_2 ), $user->display_name );183 $this->assertSame( wp_unslash( $this->slash_4 ), $user->description );183 $this->assertSame( wp_unslash( self::SLASH_2 ), $user->first_name ); 184 $this->assertSame( wp_unslash( self::SLASH_4 ), $user->last_name ); 185 $this->assertSame( wp_unslash( self::SLASH_6 ), $user->nickname ); 186 $this->assertSame( wp_unslash( self::SLASH_2 ), $user->display_name ); 187 $this->assertSame( wp_unslash( self::SLASH_4 ), $user->description ); 184 188 } 185 189 … … 193 197 'ID' => $user_id, 194 198 'role' => 'subscriber', 195 'first_name' => $this->slash_1,196 'last_name' => $this->slash_3,197 'nickname' => $this->slash_5,198 'display_name' => $this->slash_7,199 'description' => $this->slash_3,200 ) 201 ); 202 $user = get_user_to_edit( $user_id ); 203 204 $this->assertSame( wp_unslash( $this->slash_1 ), $user->first_name );205 $this->assertSame( wp_unslash( $this->slash_3 ), $user->last_name );206 $this->assertSame( wp_unslash( $this->slash_5 ), $user->nickname );207 $this->assertSame( wp_unslash( $this->slash_7 ), $user->display_name );208 $this->assertSame( wp_unslash( $this->slash_3 ), $user->description );199 'first_name' => self::SLASH_1, 200 'last_name' => self::SLASH_3, 201 'nickname' => self::SLASH_5, 202 'display_name' => self::SLASH_7, 203 'description' => self::SLASH_3, 204 ) 205 ); 206 $user = get_user_to_edit( $user_id ); 207 208 $this->assertSame( wp_unslash( self::SLASH_1 ), $user->first_name ); 209 $this->assertSame( wp_unslash( self::SLASH_3 ), $user->last_name ); 210 $this->assertSame( wp_unslash( self::SLASH_5 ), $user->nickname ); 211 $this->assertSame( wp_unslash( self::SLASH_7 ), $user->display_name ); 212 $this->assertSame( wp_unslash( self::SLASH_3 ), $user->description ); 209 213 210 214 $user_id = wp_update_user( … … 212 216 'ID' => $user_id, 213 217 'role' => 'subscriber', 214 'first_name' => $this->slash_2,215 'last_name' => $this->slash_4,216 'nickname' => $this->slash_6,217 'display_name' => $this->slash_2,218 'description' => $this->slash_4,219 ) 220 ); 221 $user = get_user_to_edit( $user_id ); 222 223 $this->assertSame( wp_unslash( $this->slash_2 ), $user->first_name );224 $this->assertSame( wp_unslash( $this->slash_4 ), $user->last_name );225 $this->assertSame( wp_unslash( $this->slash_6 ), $user->nickname );226 $this->assertSame( wp_unslash( $this->slash_2 ), $user->display_name );227 $this->assertSame( wp_unslash( $this->slash_4 ), $user->description );218 'first_name' => self::SLASH_2, 219 'last_name' => self::SLASH_4, 220 'nickname' => self::SLASH_6, 221 'display_name' => self::SLASH_2, 222 'description' => self::SLASH_4, 223 ) 224 ); 225 $user = get_user_to_edit( $user_id ); 226 227 $this->assertSame( wp_unslash( self::SLASH_2 ), $user->first_name ); 228 $this->assertSame( wp_unslash( self::SLASH_4 ), $user->last_name ); 229 $this->assertSame( wp_unslash( self::SLASH_6 ), $user->nickname ); 230 $this->assertSame( wp_unslash( self::SLASH_2 ), $user->display_name ); 231 $this->assertSame( wp_unslash( self::SLASH_4 ), $user->description ); 228 232 } 229 233
Note: See TracChangeset
for help on using the changeset viewer.