Changeset 47122 for trunk/tests/phpunit/tests/post/meta.php
- Timestamp:
- 01/29/2020 12:43:23 AM (6 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
r46586 r47122 46 46 47 47 function test_unique_postmeta() { 48 // Add a unique post meta item 48 // Add a unique post meta item. 49 49 $this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'unique', 'value', true ) ); 50 50 51 // Check unique is enforced 51 // Check unique is enforced. 52 52 $this->assertFalse( add_post_meta( self::$post_id, 'unique', 'another value', true ) ); 53 53 54 // Check it exists54 // Check it exists. 55 55 $this->assertEquals( 'value', get_post_meta( self::$post_id, 'unique', true ) ); 56 56 $this->assertEquals( array( 'value' ), get_post_meta( self::$post_id, 'unique', false ) ); 57 57 58 // Fail to delete the wrong value58 // Fail to delete the wrong value. 59 59 $this->assertFalse( delete_post_meta( self::$post_id, 'unique', 'wrong value' ) ); 60 60 61 // Delete it61 // Delete it. 62 62 $this->assertTrue( delete_post_meta( self::$post_id, 'unique', 'value' ) ); 63 63 64 // Check it is deleted64 // Check it is deleted. 65 65 $this->assertEquals( '', get_post_meta( self::$post_id, 'unique', true ) ); 66 66 $this->assertEquals( array(), get_post_meta( self::$post_id, 'unique', false ) ); … … 69 69 70 70 function test_nonunique_postmeta() { 71 // Add two non unique post meta item71 // Add two non-unique post meta items. 72 72 $this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'nonunique', 'value' ) ); 73 73 $this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'nonunique', 'another value' ) ); 74 74 75 // Check they exists75 // Check they exist. 76 76 $this->assertEquals( 'value', get_post_meta( self::$post_id, 'nonunique', true ) ); 77 77 $this->assertEquals( array( 'value', 'another value' ), get_post_meta( self::$post_id, 'nonunique', false ) ); 78 78 79 // Fail to delete the wrong value79 // Fail to delete the wrong value. 80 80 $this->assertFalse( delete_post_meta( self::$post_id, 'nonunique', 'wrong value' ) ); 81 81 82 // Delete the first one82 // Delete the first one. 83 83 $this->assertTrue( delete_post_meta( self::$post_id, 'nonunique', 'value' ) ); 84 84 85 // Check the remainder exists85 // Check the remainder exists. 86 86 $this->assertEquals( 'another value', get_post_meta( self::$post_id, 'nonunique', true ) ); 87 87 $this->assertEquals( array( 'another value' ), get_post_meta( self::$post_id, 'nonunique', false ) ); 88 88 89 // Add a third one89 // Add a third one. 90 90 $this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'nonunique', 'someother value' ) ); 91 91 92 // Check they exists92 // Check they exist. 93 93 $expected = array( 94 94 'someother value', … … 101 101 $this->assertEquals( $expected, $actual ); 102 102 103 // Delete the lot103 // Delete the lot. 104 104 $this->assertTrue( delete_post_meta_by_key( 'nonunique' ) ); 105 105 } 106 106 107 107 function test_update_post_meta() { 108 // Add a unique post meta item 108 // Add a unique post meta item. 109 109 $this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'unique_update', 'value', true ) ); 110 110 111 // Add two non unique post meta item111 // Add two non-unique post meta items. 112 112 $this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'nonunique_update', 'value' ) ); 113 113 $this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'nonunique_update', 'another value' ) ); 114 114 115 // Check they exists115 // Check they exist. 116 116 $this->assertEquals( 'value', get_post_meta( self::$post_id, 'unique_update', true ) ); 117 117 $this->assertEquals( array( 'value' ), get_post_meta( self::$post_id, 'unique_update', false ) ); … … 119 119 $this->assertEquals( array( 'value', 'another value' ), get_post_meta( self::$post_id, 'nonunique_update', false ) ); 120 120 121 // Update them 121 // Update them. 122 122 $this->assertTrue( update_post_meta( self::$post_id, 'unique_update', 'new', 'value' ) ); 123 123 $this->assertTrue( update_post_meta( self::$post_id, 'nonunique_update', 'new', 'value' ) ); 124 124 $this->assertTrue( update_post_meta( self::$post_id, 'nonunique_update', 'another new', 'another value' ) ); 125 125 126 // Check they updated126 // Check they updated. 127 127 $this->assertEquals( 'new', get_post_meta( self::$post_id, 'unique_update', true ) ); 128 128 $this->assertEquals( array( 'new' ), get_post_meta( self::$post_id, 'unique_update', false ) ); … … 133 133 134 134 function test_delete_post_meta() { 135 // Add a unique post meta item135 // Add two unique post meta items. 136 136 $this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'unique_delete', 'value', true ) ); 137 137 $this->assertInternalType( 'integer', add_post_meta( self::$post_id_2, 'unique_delete', 'value', true ) ); 138 138 139 // Check they exists139 // Check they exist. 140 140 $this->assertEquals( 'value', get_post_meta( self::$post_id, 'unique_delete', true ) ); 141 141 $this->assertEquals( 'value', get_post_meta( self::$post_id_2, 'unique_delete', true ) ); 142 142 143 // Delete one of them143 // Delete one of them. 144 144 $this->assertTrue( delete_post_meta( self::$post_id, 'unique_delete', 'value' ) ); 145 145 146 // Check the other still exitsts146 // Check the other still exists. 147 147 $this->assertEquals( 'value', get_post_meta( self::$post_id_2, 'unique_delete', true ) ); 148 148 … … 150 150 151 151 function test_delete_post_meta_by_key() { 152 // Add a unique post meta item152 // Add two unique post meta items. 153 153 $this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'unique_delete_by_key', 'value', true ) ); 154 154 $this->assertInternalType( 'integer', add_post_meta( self::$post_id_2, 'unique_delete_by_key', 'value', true ) ); 155 155 156 // Check they exist156 // Check they exist. 157 157 $this->assertEquals( 'value', get_post_meta( self::$post_id, 'unique_delete_by_key', true ) ); 158 158 $this->assertEquals( 'value', get_post_meta( self::$post_id_2, 'unique_delete_by_key', true ) ); 159 159 160 // Delete one of them160 // Delete one of them. 161 161 $this->assertTrue( delete_post_meta_by_key( 'unique_delete_by_key' ) ); 162 162 163 // Check the other still exists163 // Check the other still exists. 164 164 $this->assertEquals( '', get_post_meta( self::$post_id_2, 'unique_delete_by_key', true ) ); 165 165 $this->assertEquals( '', get_post_meta( self::$post_id_2, 'unique_delete_by_key', true ) ); … … 197 197 198 198 function test_update_meta() { 199 // Add a unique post meta item 199 // Add a unique post meta item. 200 200 $this->assertInternalType( 'integer', $mid1 = add_post_meta( self::$post_id, 'unique_update', 'value', true ) ); 201 201 202 // Add two non unique post meta item202 // Add two non-unique post meta items. 203 203 $this->assertInternalType( 'integer', $mid2 = add_post_meta( self::$post_id, 'nonunique_update', 'value' ) ); 204 204 $this->assertInternalType( 'integer', $mid3 = add_post_meta( self::$post_id, 'nonunique_update', 'another value' ) ); 205 205 206 // Check they exist206 // Check they exist. 207 207 $this->assertEquals( 'value', get_post_meta( self::$post_id, 'unique_update', true ) ); 208 208 $this->assertEquals( array( 'value' ), get_post_meta( self::$post_id, 'unique_update', false ) ); … … 210 210 $this->assertEquals( array( 'value', 'another value' ), get_post_meta( self::$post_id, 'nonunique_update', false ) ); 211 211 212 // Update them 212 // Update them. 213 213 $this->assertTrue( update_meta( $mid1, 'unique_update', 'new' ) ); 214 214 $this->assertTrue( update_meta( $mid2, 'nonunique_update', 'new' ) ); 215 215 $this->assertTrue( update_meta( $mid3, 'nonunique_update', 'another new' ) ); 216 216 217 // Check they updated217 // Check they updated. 218 218 $this->assertEquals( 'new', get_post_meta( self::$post_id, 'unique_update', true ) ); 219 219 $this->assertEquals( array( 'new' ), get_post_meta( self::$post_id, 'unique_update', false ) ); … … 221 221 $this->assertEquals( array( 'new', 'another new' ), get_post_meta( self::$post_id, 'nonunique_update', false ) ); 222 222 223 // Slashed update 223 // Slashed update. 224 224 $data = "'quote and \slash"; 225 225 $this->assertTrue( update_meta( $mid1, 'unique_update', addslashes( $data ) ) ); … … 242 242 $funky_meta[] = $classy; 243 243 244 // Add a post meta item 244 // Add a post meta item. 245 245 $this->assertInternalType( 'integer', add_post_meta( self::$post_id, 'test_funky_post_meta', $funky_meta, true ) ); 246 246 247 // Check they exists247 // Check it exists. 248 248 $this->assertEquals( $funky_meta, get_post_meta( self::$post_id, 'test_funky_post_meta', true ) ); 249 249
Note: See TracChangeset
for help on using the changeset viewer.