| 86 | |
| 87 | /** |
| 88 | * Tests if you don't hit the database if you update a meta right after you added it |
| 89 | * @ticket 22192 |
| 90 | */ |
| 91 | function test_updating_after_saving() { |
| 92 | global $wpdb; |
| 93 | |
| 94 | $start_count = $wpdb->num_queries; |
| 95 | $values = array( 'somevalue', 1, 0, true, false, 60, array() ); |
| 96 | $update_result = false; |
| 97 | |
| 98 | foreach ( $values as $key => $value ) { |
| 99 | add_post_meta( $this->post_id, 'unique-' . $key, $value ); |
| 100 | $update_result = $update_result || update_post_meta( $this->post_id, 'unique-' . $key, $value ); |
| 101 | } |
| 102 | |
| 103 | $total_queries = $wpdb->num_queries - $start_count; |
| 104 | |
| 105 | // There should be only 1 query each because we save with "add_post_meta" |
| 106 | // and update_post_meta should see it in the cache |
| 107 | // |
| 108 | // And 1 query extra for filling the cache all the meta values ( filling the cache ) |
| 109 | $this->assertEquals( count( $values ) + 1, $total_queries ); |
| 110 | $this->assertFalse( $update_result ); |
| 111 | |
| 112 | } |