| 1 | <?php |
| 2 | |
| 3 | if ( is_multisite() ) : |
| 4 | /** |
| 5 | * Test 'site_details' functionality. |
| 6 | * |
| 7 | * @group ms-site |
| 8 | * @group multisite |
| 9 | */ |
| 10 | class Tests_Multisite_Site_Details extends WP_UnitTestCase { |
| 11 | /** |
| 12 | * @dataProvider data_whitelisted_options |
| 13 | * |
| 14 | * @ticket 40063 |
| 15 | */ |
| 16 | public function test_update_whitelisted_option_deletes_site_details_cache( $whitelisted_option, $temporary_value ) { |
| 17 | $site = get_site(); |
| 18 | |
| 19 | $original_value = $site->$whitelisted_option; |
| 20 | update_option( $whitelisted_option, $temporary_value ); |
| 21 | |
| 22 | $cached_result = wp_cache_get( $site->id, 'site-details' ); |
| 23 | |
| 24 | /* Reset to original value. */ |
| 25 | update_option( $whitelisted_option, $original_value ); |
| 26 | |
| 27 | $this->assertFalse( $cached_result ); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * @dataProvider data_whitelisted_options |
| 32 | * |
| 33 | * @ticket 40063 |
| 34 | */ |
| 35 | public function test_update_whitelisted_option_deletes_blog_details_cache( $whitelisted_option, $temporary_value ) { |
| 36 | $blog_details = get_blog_details(); |
| 37 | |
| 38 | $original_value = $blog_details->$whitelisted_option; |
| 39 | update_option( $whitelisted_option, $temporary_value ); |
| 40 | |
| 41 | $cached_result = wp_cache_get( $blog_details->id, 'blog-details' ); |
| 42 | |
| 43 | /* Reset to original value. */ |
| 44 | update_option( $whitelisted_option, $original_value ); |
| 45 | |
| 46 | $this->assertFalse( $cached_result ); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * @dataProvider data_whitelisted_options |
| 51 | * |
| 52 | * @ticket 40063 |
| 53 | */ |
| 54 | public function test_update_whitelisted_option_does_not_delete_site_cache( $whitelisted_option, $temporary_value ) { |
| 55 | $site = get_site(); |
| 56 | |
| 57 | $original_value = $site->$whitelisted_option; |
| 58 | update_option( $whitelisted_option, $temporary_value ); |
| 59 | |
| 60 | $cached_result = wp_cache_get( $site->id, 'sites' ); |
| 61 | |
| 62 | /* Reset to original value. */ |
| 63 | update_option( $whitelisted_option, $original_value ); |
| 64 | |
| 65 | $this->assertNotFalse( $cached_result ); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * @dataProvider data_whitelisted_options |
| 70 | * |
| 71 | * @ticket 40063 |
| 72 | */ |
| 73 | public function test_update_whitelisted_option_does_not_delete_short_blog_details_cache( $whitelisted_option, $temporary_value ) { |
| 74 | $blog_details = get_blog_details( null, false ); |
| 75 | |
| 76 | $original_value = get_option( $whitelisted_option ); |
| 77 | update_option( $whitelisted_option, $temporary_value ); |
| 78 | |
| 79 | $cached_result = wp_cache_get( $blog_details->id . 'short', 'blog-details' ); |
| 80 | |
| 81 | /* Reset to original value. */ |
| 82 | update_option( $whitelisted_option, $original_value ); |
| 83 | |
| 84 | $this->assertNotFalse( $cached_result ); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * @dataProvider data_whitelisted_options |
| 89 | * |
| 90 | * @ticket 40063 |
| 91 | */ |
| 92 | public function test_update_whitelisted_option_does_not_update_sites_last_changed( $whitelisted_option, $temporary_value ) { |
| 93 | $last_changed = wp_cache_get_last_changed( 'sites' ); |
| 94 | |
| 95 | $original_value = get_option( $whitelisted_option ); |
| 96 | update_option( $whitelisted_option, $temporary_value ); |
| 97 | |
| 98 | $new_last_changed = wp_cache_get_last_changed( 'sites' ); |
| 99 | |
| 100 | /* Reset to original value. */ |
| 101 | update_option( $whitelisted_option, $original_value ); |
| 102 | |
| 103 | $this->assertSame( $new_last_changed, $last_changed ); |
| 104 | } |
| 105 | |
| 106 | public function data_whitelisted_options() { |
| 107 | return array( |
| 108 | array( 'blogname', 'Custom Site' ), |
| 109 | array( 'home', 'http://custom-site-url.org' ), |
| 110 | array( 'siteurl', 'http://custom-site-url.org' ), |
| 111 | array( 'post_count', '4' ), |
| 112 | ); |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * @ticket 40063 |
| 117 | */ |
| 118 | public function test_update_random_blog_option_does_not_delete_cache() { |
| 119 | $site = get_site(); |
| 120 | |
| 121 | update_option( 'foobar_option', 'foobar_value' ); |
| 122 | $cached_result = wp_cache_get( $site->id, 'sites' ); |
| 123 | |
| 124 | delete_option( 'foobar_option' ); |
| 125 | |
| 126 | $this->assertNotFalse( $cached_result ); |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | endif; |