| 102 | |
| 103 | /** |
| 104 | * @ticket 22192 |
| 105 | * @dataProvider data_update_option_type_juggling |
| 106 | */ |
| 107 | public function test_update_option_should_hit_cache_when_loosely_equal_to_existing_value( $old_value, $new_value ) { |
| 108 | global $wpdb; |
| 109 | |
| 110 | add_option( 'foo', $old_value ); |
| 111 | $num_queries = $wpdb->num_queries; |
| 112 | |
| 113 | $updated = update_option( 'foo', $new_value ); |
| 114 | |
| 115 | $this->assertFalse( $updated ); |
| 116 | $this->assertSame( $num_queries, $wpdb->num_queries ); |
| 117 | } |
| 118 | |
| 119 | public function data_update_option_type_juggling() { |
| 120 | return array( |
| 121 | // Truthy |
| 122 | array( '1', '1' ), |
| 123 | array( '1', intval( 1 ) ), |
| 124 | array( '1', floatval( 1 ) ), |
| 125 | array( '1', true ), |
| 126 | array( 1, '1' ), |
| 127 | array( 1, intval( 1 ) ), |
| 128 | array( 1, floatval( 1 ) ), |
| 129 | array( 1, true ), |
| 130 | array( floatval( 1 ), '1' ), |
| 131 | array( floatval( 1 ), intval( 1 ) ), |
| 132 | array( floatval( 1 ), floatval( 1 ) ), |
| 133 | array( floatval( 1 ), true ), |
| 134 | array( true, '1' ), |
| 135 | array( true, intval( 1 ) ), |
| 136 | array( true, floatval( 1 ) ), |
| 137 | array( true, true ), |
| 138 | |
| 139 | // Falsey |
| 140 | array( '0', '0' ), |
| 141 | array( '0', intval( 0 ) ), |
| 142 | array( '0', floatval( 0 ) ), |
| 143 | array( '0', false ), |
| 144 | array( 0, '0' ), |
| 145 | array( 0, intval( 0 ) ), |
| 146 | array( 0, floatval( 0 ) ), |
| 147 | array( 0, false ), |
| 148 | array( floatval( 0 ), '0' ), |
| 149 | array( floatval( 0 ), intval( 0 ) ), |
| 150 | array( floatval( 0 ), floatval( 0 ) ), |
| 151 | array( floatval( 0 ), false ), |
| 152 | array( false, '0' ), |
| 153 | array( false, intval( 0 ) ), |
| 154 | array( false, floatval( 0 ) ), |
| 155 | array( false, false ), |
| 156 | ); |
| 157 | } |