| 86 | |
| 87 | /** |
| 88 | * If get_option( $transient_timeout ) returns false, don't bother trying to delete the transient. |
| 89 | * |
| 90 | * @ticket 30380 |
| 91 | */ |
| 92 | function test_nonexistent_key_dont_delete_if_false() { |
| 93 | // Create a bogus a transient |
| 94 | $key = 'test_transient'; |
| 95 | set_transient( $key, 'test', 60 * 10 ); |
| 96 | $this->assertEquals( 'test', get_transient( $key ) ); |
| 97 | |
| 98 | // Useful variables for tracking |
| 99 | $transient_option = '_transient_' . $key; |
| 100 | $transient_timeout = '_transient_timeout_' . $key; |
| 101 | |
| 102 | // Make sure the timeout option returns false |
| 103 | add_filter( 'option_' . $transient_timeout, '__return_false' ); |
| 104 | |
| 105 | // Add some actions to make sure options are _not_ deleted |
| 106 | $options = array(); |
| 107 | add_action( 'delete_option', function( $option ) use ( &$options ) { |
| 108 | $options[] = $option; |
| 109 | } ); |
| 110 | |
| 111 | // Act |
| 112 | get_transient( $key ); |
| 113 | |
| 114 | // Make sure delete option was not called for both the transient and the timeout |
| 115 | $this->assertNotContains( $transient_timeout, $options ); |
| 116 | $this->assertNotContains( $transient_option, $options ); |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * @ticket 30380 |
| 121 | */ |
| 122 | function test_nonexistent_key_old_timeout() { |
| 123 | // Create a transient |
| 124 | $key = 'test_transient'; |
| 125 | set_transient( $key, 'test', 60 * 10 ); |
| 126 | $this->assertEquals( 'test', get_transient( $key ) ); |
| 127 | |
| 128 | // Make sure the timeout option returns false |
| 129 | $timeout = '_transient_timeout_' . $key; |
| 130 | $transient_option = '_transient_' . $key; |
| 131 | add_filter( 'option_' . $timeout, function() { return time() - 60; } ); |
| 132 | |
| 133 | // Add some actions to make sure options are deleted |
| 134 | $options = array(); |
| 135 | add_action( 'delete_option', function( $option ) use ( &$options ) { |
| 136 | $options[] = $option; |
| 137 | } ); |
| 138 | |
| 139 | // Act |
| 140 | get_transient( $key ); |
| 141 | |
| 142 | // Make sure delete option was called for both the transient and the timeout |
| 143 | $this->assertContains( $timeout, $options ); |
| 144 | $this->assertContains( $transient_option, $options ); |
| 145 | } |