Changeset 42343 for trunk/tests/phpunit/tests/post/meta.php
- Timestamp:
- 11/30/2017 11:09:33 PM (9 years ago)
- File:
-
- 1 edited
-
trunk/tests/phpunit/tests/post/meta.php (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/post/meta.php
r35244 r42343 12 12 13 13 $post = array( 14 'post_author' => $this->author->ID,15 'post_status' => 'publish',14 'post_author' => $this->author->ID, 15 'post_status' => 'publish', 16 16 'post_content' => rand_str(), 17 'post_title' => rand_str(),17 'post_title' => rand_str(), 18 18 ); 19 19 20 20 // insert a post 21 $this->post_id = wp_insert_post($post); 22 21 $this->post_id = wp_insert_post( $post ); 23 22 24 23 $post = array( 25 'post_author' => $this->author->ID,26 'post_status' => 'publish',24 'post_author' => $this->author->ID, 25 'post_status' => 'publish', 27 26 'post_content' => rand_str(), 28 'post_title' => rand_str(),27 'post_title' => rand_str(), 29 28 ); 30 29 31 30 // insert a post 32 $this->post_id_2 = wp_insert_post( $post);31 $this->post_id_2 = wp_insert_post( $post ); 33 32 } 34 33 35 34 function test_unique_postmeta() { 36 35 // Add a unique post meta item 37 $this->assertInternalType( 'integer', add_post_meta( $this->post_id, 'unique', 'value', true) );36 $this->assertInternalType( 'integer', add_post_meta( $this->post_id, 'unique', 'value', true ) ); 38 37 39 38 // Check unique is enforced 40 $this->assertFalse( add_post_meta($this->post_id, 'unique', 'another value', true));39 $this->assertFalse( add_post_meta( $this->post_id, 'unique', 'another value', true ) ); 41 40 42 41 //Check it exists 43 $this->assertEquals( 'value', get_post_meta($this->post_id, 'unique', true));44 $this->assertEquals( array('value'), get_post_meta($this->post_id, 'unique', false));42 $this->assertEquals( 'value', get_post_meta( $this->post_id, 'unique', true ) ); 43 $this->assertEquals( array( 'value' ), get_post_meta( $this->post_id, 'unique', false ) ); 45 44 46 45 //Fail to delete the wrong value 47 $this->assertFalse( delete_post_meta($this->post_id, 'unique', 'wrong value'));46 $this->assertFalse( delete_post_meta( $this->post_id, 'unique', 'wrong value' ) ); 48 47 49 48 //Delete it 50 $this->assertTrue( delete_post_meta($this->post_id, 'unique', 'value'));49 $this->assertTrue( delete_post_meta( $this->post_id, 'unique', 'value' ) ); 51 50 52 51 //Check it is deleted 53 $this->assertEquals( '', get_post_meta($this->post_id, 'unique', true));54 $this->assertEquals( array(), get_post_meta($this->post_id, 'unique', false));52 $this->assertEquals( '', get_post_meta( $this->post_id, 'unique', true ) ); 53 $this->assertEquals( array(), get_post_meta( $this->post_id, 'unique', false ) ); 55 54 56 55 } … … 58 57 function test_nonunique_postmeta() { 59 58 // Add two non unique post meta item 60 $this->assertInternalType( 'integer', add_post_meta( $this->post_id, 'nonunique', 'value') );61 $this->assertInternalType( 'integer', add_post_meta( $this->post_id, 'nonunique', 'another value'));62 63 //Check they exists 64 $this->assertEquals( 'value', get_post_meta($this->post_id, 'nonunique', true));65 $this->assertEquals( array('value', 'another value'), get_post_meta($this->post_id, 'nonunique', false));59 $this->assertInternalType( 'integer', add_post_meta( $this->post_id, 'nonunique', 'value' ) ); 60 $this->assertInternalType( 'integer', add_post_meta( $this->post_id, 'nonunique', 'another value' ) ); 61 62 //Check they exists 63 $this->assertEquals( 'value', get_post_meta( $this->post_id, 'nonunique', true ) ); 64 $this->assertEquals( array( 'value', 'another value' ), get_post_meta( $this->post_id, 'nonunique', false ) ); 66 65 67 66 //Fail to delete the wrong value 68 $this->assertFalse( delete_post_meta($this->post_id, 'nonunique', 'wrong value'));67 $this->assertFalse( delete_post_meta( $this->post_id, 'nonunique', 'wrong value' ) ); 69 68 70 69 //Delete the first one 71 $this->assertTrue( delete_post_meta($this->post_id, 'nonunique', 'value'));70 $this->assertTrue( delete_post_meta( $this->post_id, 'nonunique', 'value' ) ); 72 71 73 72 //Check the remainder exists 74 $this->assertEquals( 'another value', get_post_meta($this->post_id, 'nonunique', true));75 $this->assertEquals( array('another value'), get_post_meta($this->post_id, 'nonunique', false));73 $this->assertEquals( 'another value', get_post_meta( $this->post_id, 'nonunique', true ) ); 74 $this->assertEquals( array( 'another value' ), get_post_meta( $this->post_id, 'nonunique', false ) ); 76 75 77 76 //Add a third one 78 $this->assertInternalType( 'integer', add_post_meta( $this->post_id, 'nonunique', 'someother value') );77 $this->assertInternalType( 'integer', add_post_meta( $this->post_id, 'nonunique', 'someother value' ) ); 79 78 80 79 //Check they exists 81 80 $expected = array( 82 81 'someother value', 83 'another value' 82 'another value', 84 83 ); 85 84 sort( $expected ); … … 90 89 91 90 //Delete the lot 92 $this->assertTrue( delete_post_meta_by_key('nonunique'));91 $this->assertTrue( delete_post_meta_by_key( 'nonunique' ) ); 93 92 } 94 93 95 94 function test_update_post_meta() { 96 95 // Add a unique post meta item 97 $this->assertInternalType( 'integer', add_post_meta( $this->post_id, 'unique_update', 'value', true) );96 $this->assertInternalType( 'integer', add_post_meta( $this->post_id, 'unique_update', 'value', true ) ); 98 97 99 98 // Add two non unique post meta item 100 $this->assertInternalType( 'integer', add_post_meta( $this->post_id, 'nonunique_update', 'value') );101 $this->assertInternalType( 'integer', add_post_meta( $this->post_id, 'nonunique_update', 'another value') );102 103 //Check they exists 104 $this->assertEquals( 'value', get_post_meta($this->post_id, 'unique_update', true));105 $this->assertEquals( array('value'), get_post_meta($this->post_id, 'unique_update', false));106 $this->assertEquals( 'value', get_post_meta($this->post_id, 'nonunique_update', true));107 $this->assertEquals( array('value', 'another value'), get_post_meta($this->post_id, 'nonunique_update', false));99 $this->assertInternalType( 'integer', add_post_meta( $this->post_id, 'nonunique_update', 'value' ) ); 100 $this->assertInternalType( 'integer', add_post_meta( $this->post_id, 'nonunique_update', 'another value' ) ); 101 102 //Check they exists 103 $this->assertEquals( 'value', get_post_meta( $this->post_id, 'unique_update', true ) ); 104 $this->assertEquals( array( 'value' ), get_post_meta( $this->post_id, 'unique_update', false ) ); 105 $this->assertEquals( 'value', get_post_meta( $this->post_id, 'nonunique_update', true ) ); 106 $this->assertEquals( array( 'value', 'another value' ), get_post_meta( $this->post_id, 'nonunique_update', false ) ); 108 107 109 108 // Update them 110 $this->assertTrue( update_post_meta($this->post_id, 'unique_update', 'new', 'value'));111 $this->assertTrue( update_post_meta($this->post_id, 'nonunique_update', 'new', 'value'));112 $this->assertTrue( update_post_meta($this->post_id, 'nonunique_update', 'another new', 'another value'));109 $this->assertTrue( update_post_meta( $this->post_id, 'unique_update', 'new', 'value' ) ); 110 $this->assertTrue( update_post_meta( $this->post_id, 'nonunique_update', 'new', 'value' ) ); 111 $this->assertTrue( update_post_meta( $this->post_id, 'nonunique_update', 'another new', 'another value' ) ); 113 112 114 113 //Check they updated 115 $this->assertEquals( 'new', get_post_meta($this->post_id, 'unique_update', true));116 $this->assertEquals( array('new'), get_post_meta($this->post_id, 'unique_update', false));117 $this->assertEquals( 'new', get_post_meta($this->post_id, 'nonunique_update', true));118 $this->assertEquals( array('new', 'another new'), get_post_meta($this->post_id, 'nonunique_update', false));114 $this->assertEquals( 'new', get_post_meta( $this->post_id, 'unique_update', true ) ); 115 $this->assertEquals( array( 'new' ), get_post_meta( $this->post_id, 'unique_update', false ) ); 116 $this->assertEquals( 'new', get_post_meta( $this->post_id, 'nonunique_update', true ) ); 117 $this->assertEquals( array( 'new', 'another new' ), get_post_meta( $this->post_id, 'nonunique_update', false ) ); 119 118 120 119 } … … 122 121 function test_delete_post_meta() { 123 122 // Add a unique post meta item 124 $this->assertInternalType( 'integer', add_post_meta( $this->post_id, 'unique_delete', 'value', true) );125 $this->assertInternalType( 'integer', add_post_meta( $this->post_id_2, 'unique_delete', 'value', true) );126 127 //Check they exists 128 $this->assertEquals( 'value', get_post_meta($this->post_id, 'unique_delete', true));129 $this->assertEquals( 'value', get_post_meta($this->post_id_2, 'unique_delete', true));123 $this->assertInternalType( 'integer', add_post_meta( $this->post_id, 'unique_delete', 'value', true ) ); 124 $this->assertInternalType( 'integer', add_post_meta( $this->post_id_2, 'unique_delete', 'value', true ) ); 125 126 //Check they exists 127 $this->assertEquals( 'value', get_post_meta( $this->post_id, 'unique_delete', true ) ); 128 $this->assertEquals( 'value', get_post_meta( $this->post_id_2, 'unique_delete', true ) ); 130 129 131 130 //Delete one of them 132 $this->assertTrue( delete_post_meta($this->post_id, 'unique_delete', 'value'));131 $this->assertTrue( delete_post_meta( $this->post_id, 'unique_delete', 'value' ) ); 133 132 134 133 //Check the other still exitsts 135 $this->assertEquals('value', get_post_meta($this->post_id_2, 'unique_delete', true)); 136 134 $this->assertEquals( 'value', get_post_meta( $this->post_id_2, 'unique_delete', true ) ); 137 135 138 136 } … … 140 138 function test_delete_post_meta_by_key() { 141 139 // Add a unique post meta item 142 $this->assertInternalType( 'integer', add_post_meta( $this->post_id, 'unique_delete_by_key', 'value', true) );143 $this->assertInternalType( 'integer', add_post_meta( $this->post_id_2, 'unique_delete_by_key', 'value', true) );140 $this->assertInternalType( 'integer', add_post_meta( $this->post_id, 'unique_delete_by_key', 'value', true ) ); 141 $this->assertInternalType( 'integer', add_post_meta( $this->post_id_2, 'unique_delete_by_key', 'value', true ) ); 144 142 145 143 //Check they exist 146 $this->assertEquals( 'value', get_post_meta($this->post_id, 'unique_delete_by_key', true));147 $this->assertEquals( 'value', get_post_meta($this->post_id_2, 'unique_delete_by_key', true));144 $this->assertEquals( 'value', get_post_meta( $this->post_id, 'unique_delete_by_key', true ) ); 145 $this->assertEquals( 'value', get_post_meta( $this->post_id_2, 'unique_delete_by_key', true ) ); 148 146 149 147 //Delete one of them 150 $this->assertTrue( delete_post_meta_by_key('unique_delete_by_key'));148 $this->assertTrue( delete_post_meta_by_key( 'unique_delete_by_key' ) ); 151 149 152 150 //Check the other still exists 153 $this->assertEquals( '', get_post_meta($this->post_id_2, 'unique_delete_by_key', true));154 $this->assertEquals( '', get_post_meta($this->post_id_2, 'unique_delete_by_key', true));151 $this->assertEquals( '', get_post_meta( $this->post_id_2, 'unique_delete_by_key', true ) ); 152 $this->assertEquals( '', get_post_meta( $this->post_id_2, 'unique_delete_by_key', true ) ); 155 153 } 156 154 … … 159 157 $this->assertInternalType( 'integer', $mid ); 160 158 161 $mobj = new stdClass;162 $mobj->meta_id = $mid;163 $mobj->post_id = $this->post_id;164 $mobj->meta_key = 'get_post_meta_by_key';159 $mobj = new stdClass; 160 $mobj->meta_id = $mid; 161 $mobj->post_id = $this->post_id; 162 $mobj->meta_key = 'get_post_meta_by_key'; 165 163 $mobj->meta_value = 'get_post_meta_by_key_value'; 166 164 $this->assertEquals( $mobj, get_post_meta_by_id( $mid ) ); … … 169 167 $mid = add_post_meta( $this->post_id, 'get_post_meta_by_key', array( 'foo', 'bar' ), true ); 170 168 $this->assertInternalType( 'integer', $mid ); 171 $mobj->meta_id = $mid;169 $mobj->meta_id = $mid; 172 170 $mobj->meta_value = array( 'foo', 'bar' ); 173 171 $this->assertEquals( $mobj, get_post_meta_by_id( $mid ) ); … … 187 185 function test_update_meta() { 188 186 // Add a unique post meta item 189 $this->assertInternalType( 'integer', $mid1 = add_post_meta( $this->post_id, 'unique_update', 'value', true) );187 $this->assertInternalType( 'integer', $mid1 = add_post_meta( $this->post_id, 'unique_update', 'value', true ) ); 190 188 191 189 // Add two non unique post meta item 192 $this->assertInternalType( 'integer', $mid2 = add_post_meta( $this->post_id, 'nonunique_update', 'value') );193 $this->assertInternalType( 'integer', $mid3 = add_post_meta( $this->post_id, 'nonunique_update', 'another value') );190 $this->assertInternalType( 'integer', $mid2 = add_post_meta( $this->post_id, 'nonunique_update', 'value' ) ); 191 $this->assertInternalType( 'integer', $mid3 = add_post_meta( $this->post_id, 'nonunique_update', 'another value' ) ); 194 192 195 193 //Check they exist 196 $this->assertEquals( 'value', get_post_meta($this->post_id, 'unique_update', true));197 $this->assertEquals( array('value'), get_post_meta($this->post_id, 'unique_update', false));198 $this->assertEquals( 'value', get_post_meta($this->post_id, 'nonunique_update', true));199 $this->assertEquals( array('value', 'another value'), get_post_meta($this->post_id, 'nonunique_update', false));194 $this->assertEquals( 'value', get_post_meta( $this->post_id, 'unique_update', true ) ); 195 $this->assertEquals( array( 'value' ), get_post_meta( $this->post_id, 'unique_update', false ) ); 196 $this->assertEquals( 'value', get_post_meta( $this->post_id, 'nonunique_update', true ) ); 197 $this->assertEquals( array( 'value', 'another value' ), get_post_meta( $this->post_id, 'nonunique_update', false ) ); 200 198 201 199 // Update them … … 205 203 206 204 //Check they updated 207 $this->assertEquals( 'new', get_post_meta($this->post_id, 'unique_update', true));208 $this->assertEquals( array('new'), get_post_meta($this->post_id, 'unique_update', false));209 $this->assertEquals( 'new', get_post_meta($this->post_id, 'nonunique_update', true));210 $this->assertEquals( array('new', 'another new'), get_post_meta($this->post_id, 'nonunique_update', false));205 $this->assertEquals( 'new', get_post_meta( $this->post_id, 'unique_update', true ) ); 206 $this->assertEquals( array( 'new' ), get_post_meta( $this->post_id, 'unique_update', false ) ); 207 $this->assertEquals( 'new', get_post_meta( $this->post_id, 'nonunique_update', true ) ); 208 $this->assertEquals( array( 'new', 'another new' ), get_post_meta( $this->post_id, 'nonunique_update', false ) ); 211 209 212 210 // Slashed update … … 221 219 */ 222 220 function test_funky_post_meta() { 223 $classy = new StdClass();224 $classy->ID = 1;225 $classy->stringy = "I love slashes\\\\";226 $funky_meta[] = $classy;227 228 $classy = new StdClass();229 $classy->ID = 2;230 $classy->stringy = "I love slashes\\\\ more";231 $funky_meta[] = $classy;221 $classy = new StdClass(); 222 $classy->ID = 1; 223 $classy->stringy = 'I love slashes\\\\'; 224 $funky_meta[] = $classy; 225 226 $classy = new StdClass(); 227 $classy->ID = 2; 228 $classy->stringy = 'I love slashes\\\\ more'; 229 $funky_meta[] = $classy; 232 230 233 231 // Add a post meta item 234 $this->assertInternalType( 'integer', add_post_meta( $this->post_id, 'test_funky_post_meta', $funky_meta, true) );235 236 //Check they exists 237 $this->assertEquals( $funky_meta, get_post_meta($this->post_id, 'test_funky_post_meta', true));232 $this->assertInternalType( 'integer', add_post_meta( $this->post_id, 'test_funky_post_meta', $funky_meta, true ) ); 233 234 //Check they exists 235 $this->assertEquals( $funky_meta, get_post_meta( $this->post_id, 'test_funky_post_meta', true ) ); 238 236 239 237 }
Note: See TracChangeset
for help on using the changeset viewer.