Changeset 42343 for trunk/tests/phpunit/tests/multisite/siteDetails.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/multisite/siteDetails.php
r41883 r42343 2 2 3 3 if ( is_multisite() ) : 4 /**5 * Test 'site_details' functionality.6 *7 * @group ms-site8 * @group multisite9 */10 class Tests_Multisite_Site_Details extends WP_UnitTestCase {11 4 /** 12 * @dataProvider data_whitelisted_options5 * Test 'site_details' functionality. 13 6 * 14 * @ticket 40063 7 * @group ms-site 8 * @group multisite 15 9 */ 16 public function test_update_whitelisted_option_deletes_site_details_cache( $whitelisted_option, $temporary_value ) { 17 $site = get_site(); 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 18 19 $original_value = $site->$whitelisted_option;20 update_option( $whitelisted_option, $temporary_value );19 $original_value = $site->$whitelisted_option; 20 update_option( $whitelisted_option, $temporary_value ); 21 21 22 $cached_result = wp_cache_get( $site->id, 'site-details' );22 $cached_result = wp_cache_get( $site->id, 'site-details' ); 23 23 24 /* Reset to original value. */25 update_option( $whitelisted_option, $original_value );24 /* Reset to original value. */ 25 update_option( $whitelisted_option, $original_value ); 26 26 27 $this->assertFalse( $cached_result ); 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 * @ticket 40247 131 */ 132 public function test_site_details_cached_including_false_values() { 133 $id = self::factory()->blog->create(); 134 135 $site = get_site( $id ); 136 137 // Trigger retrieving site details (post_count is not set on new sites) 138 $post_count = $site->post_count; 139 140 $cached_details = wp_cache_get( $site->id, 'site-details' ); 141 142 wpmu_delete_blog( $id, true ); 143 wp_update_network_site_counts(); 144 145 $this->assertNotFalse( $cached_details ); 146 } 147 148 public function test_site_details_filter_with_blogname() { 149 add_filter( 'site_details', array( $this, '_filter_site_details_blogname' ) ); 150 $site = get_site(); 151 $blogname = $site->blogname; 152 remove_filter( 'site_details', array( $this, '_filter_site_details_blogname' ) ); 153 154 $this->assertSame( 'Foo Bar', $blogname ); 155 } 156 157 public function _filter_site_details_blogname( $details ) { 158 $details->blogname = 'Foo Bar'; 159 return $details; 160 } 161 162 /** 163 * @ticket 40458 164 */ 165 public function test_site_details_filter_with_custom_value_isetter() { 166 add_filter( 'site_details', array( $this, '_filter_site_details_custom_value' ) ); 167 $site = get_site(); 168 $custom_value_isset = isset( $site->custom_value ); 169 remove_filter( 'site_details', array( $this, '_filter_site_details_custom_value' ) ); 170 171 $this->assertTrue( $custom_value_isset ); 172 } 173 174 /** 175 * @ticket 40458 176 */ 177 public function test_site_details_filter_with_custom_value_getter() { 178 add_filter( 'site_details', array( $this, '_filter_site_details_custom_value' ) ); 179 $site = get_site(); 180 $custom_value = $site->custom_value; 181 remove_filter( 'site_details', array( $this, '_filter_site_details_custom_value' ) ); 182 183 $this->assertSame( 'foo', $custom_value ); 184 } 185 186 public function _filter_site_details_custom_value( $details ) { 187 $details->custom_value = 'foo'; 188 return $details; 189 } 28 190 } 29 191 30 /**31 * @dataProvider data_whitelisted_options32 *33 * @ticket 4006334 */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_options51 *52 * @ticket 4006353 */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_options70 *71 * @ticket 4006372 */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_options89 *90 * @ticket 4006391 */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 40063117 */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 * @ticket 40247131 */132 public function test_site_details_cached_including_false_values() {133 $id = self::factory()->blog->create();134 135 $site = get_site( $id );136 137 // Trigger retrieving site details (post_count is not set on new sites)138 $post_count = $site->post_count;139 140 $cached_details = wp_cache_get( $site->id, 'site-details' );141 142 wpmu_delete_blog( $id, true );143 wp_update_network_site_counts();144 145 $this->assertNotFalse( $cached_details );146 }147 148 public function test_site_details_filter_with_blogname() {149 add_filter( 'site_details', array( $this, '_filter_site_details_blogname' ) );150 $site = get_site();151 $blogname = $site->blogname;152 remove_filter( 'site_details', array( $this, '_filter_site_details_blogname' ) );153 154 $this->assertSame( 'Foo Bar', $blogname );155 }156 157 public function _filter_site_details_blogname( $details ) {158 $details->blogname = 'Foo Bar';159 return $details;160 }161 162 /**163 * @ticket 40458164 */165 public function test_site_details_filter_with_custom_value_isetter() {166 add_filter( 'site_details', array( $this, '_filter_site_details_custom_value' ) );167 $site = get_site();168 $custom_value_isset = isset( $site->custom_value );169 remove_filter( 'site_details', array( $this, '_filter_site_details_custom_value' ) );170 171 $this->assertTrue( $custom_value_isset );172 }173 174 /**175 * @ticket 40458176 */177 public function test_site_details_filter_with_custom_value_getter() {178 add_filter( 'site_details', array( $this, '_filter_site_details_custom_value' ) );179 $site = get_site();180 $custom_value = $site->custom_value;181 remove_filter( 'site_details', array( $this, '_filter_site_details_custom_value' ) );182 183 $this->assertSame( 'foo', $custom_value );184 }185 186 public function _filter_site_details_custom_value( $details ) {187 $details->custom_value = 'foo';188 return $details;189 }190 }191 192 192 endif;
Note: See TracChangeset
for help on using the changeset viewer.