Changeset 53557 for trunk/tests/phpunit/tests/comment/slashes.php
- Timestamp:
- 06/23/2022 02:24:08 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.