Changeset 27719
- Timestamp:
- 03/25/2014 06:22:49 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/option.php
r27365 r27719 643 643 $result = add_option( $transient, $value, '', $autoload ); 644 644 } else { 645 if ( $expiration ) 646 update_option( $transient_timeout, time() + $expiration ); 647 $result = update_option( $transient, $value ); 645 // If expiration is requested, but the transient has no timeout option, 646 // delete, then re-create transient rather than update. 647 $update = true; 648 if ( $expiration ) { 649 if ( false === get_option( $transient_timeout ) ) { 650 delete_option( $transient ); 651 add_option( $transient_timeout, time() + $expiration, '', 'no' ); 652 $result = add_option( $transient, $value, '', 'no' ); 653 $update = false; 654 } else { 655 update_option( $transient_timeout, time() + $expiration ); 656 } 657 } 658 if ( $update ) { 659 $result = update_option( $transient, $value ); 660 } 648 661 } 649 662 } -
trunk/tests/phpunit/tests/option/transient.php
r25002 r27719 34 34 $this->assertTrue( delete_transient( $key ) ); 35 35 } 36 37 /** 38 * @ticket 22807 39 */ 40 function test_transient_data_with_timeout() { 41 $key = rand_str(); 42 $value = rand_str(); 43 $value2 = rand_str(); 44 45 $this->assertFalse( get_option( '_transient_timeout_' . $key ) ); 46 $now = time(); 47 48 $this->assertTrue( set_transient( $key, $value, 100 ) ); 49 50 // Ensure the transient timeout is set for 100-101 seconds in the future. 51 $this->assertGreaterThanOrEqual( $now + 100, get_option( '_transient_timeout_' . $key ) ); 52 $this->assertLessThanOrEqual( $now + 101, get_option( '_transient_timeout_' . $key ) ); 53 54 // Update the timeout to a second in the past and watch the transient be invalidated. 55 update_option( '_transient_timeout_' . $key, $now - 1 ); 56 $this->assertFalse( get_transient( $key ) ); 57 } 58 59 /** 60 * @ticket 22807 61 */ 62 function test_transient_add_timeout() { 63 $key = rand_str(); 64 $value = rand_str(); 65 $value2 = rand_str(); 66 $this->assertTrue( set_transient( $key, $value ) ); 67 $this->assertEquals( $value, get_transient( $key ) ); 68 69 $this->assertFalse( get_option( '_transient_timeout_' . $key ) ); 70 71 $now = time(); 72 // Add timeout to existing timeout-less transient. 73 $this->assertTrue( set_transient( $key, $value2, 1 ) ); 74 $this->assertGreaterThanOrEqual( $now, get_option( '_transient_timeout_' . $key ) ); 75 76 update_option( '_transient_timeout_' . $key, $now - 1 ); 77 $this->assertFalse( get_transient( $key ) ); 78 } 36 79 }
Note: See TracChangeset
for help on using the changeset viewer.