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