- Timestamp:
- 04/09/2025 01:29:39 PM (6 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/multisite/updateBlogStatus.php
r59964 r60148 1 1 <?php 2 2 3 if ( is_multisite() ) : 3 /** 4 * @group ms-required 5 * @group ms-site 6 * @group multisite 7 */ 8 class Tests_Multisite_UpdateBlogStatus extends WP_UnitTestCase { 4 9 5 10 /** 6 * @group ms-site 7 * @group multisite 11 * Updating a field returns the same value that was passed. 8 12 */ 9 class Tests_Multisite_UpdateBlogStatus extends WP_UnitTestCase { 10 11 /** 12 * Updating a field returns the same value that was passed. 13 */ 14 public function test_update_blog_status() { 15 $result = update_blog_status( 1, 'spam', 0 ); 16 $this->assertSame( 0, $result ); 17 } 18 19 /** 20 * Updating an invalid field returns the same value that was passed. 21 */ 22 public function test_update_blog_status_invalid_status() { 23 $result = update_blog_status( 1, 'doesnotexist', 'invalid' ); 24 $this->assertSame( 'invalid', $result ); 25 } 26 27 public function test_update_blog_status_make_ham_blog_action() { 28 $test_action_counter = new MockAction(); 29 30 $blog_id = self::factory()->blog->create(); 31 update_blog_details( $blog_id, array( 'spam' => 1 ) ); 32 33 add_action( 'make_ham_blog', array( $test_action_counter, 'action' ) ); 34 update_blog_status( $blog_id, 'spam', 0 ); 35 $blog = get_site( $blog_id ); 36 37 $this->assertSame( '0', $blog->spam ); 38 $this->assertSame( 1, $test_action_counter->get_call_count() ); 39 40 // The action should not fire if the status of 'spam' stays the same. 41 update_blog_status( $blog_id, 'spam', 0 ); 42 $blog = get_site( $blog_id ); 43 44 $this->assertSame( '0', $blog->spam ); 45 $this->assertSame( 1, $test_action_counter->get_call_count() ); 46 } 47 48 /** 49 * @group external-http 50 */ 51 public function test_content_from_spam_blog_is_not_available() { 52 $spam_blog_id = self::factory()->blog->create(); 53 switch_to_blog( $spam_blog_id ); 54 $post_data = array( 55 'post_title' => 'Hello World!', 56 'post_content' => 'Hello world content', 57 ); 58 $post_id = self::factory()->post->create( $post_data ); 59 $post = get_post( $post_id ); 60 $spam_permalink = site_url() . '/?p=' . $post->ID; 61 $spam_embed_url = get_post_embed_url( $post_id ); 62 63 restore_current_blog(); 64 $this->assertNotEmpty( $spam_permalink ); 65 $this->assertSame( $post_data['post_title'], $post->post_title ); 66 67 update_blog_status( $spam_blog_id, 'spam', 1 ); 68 69 $post_id = self::factory()->post->create( 70 array( 71 'post_content' => "\n $spam_permalink \n", 72 ) 73 ); 74 $post = get_post( $post_id ); 75 $content = apply_filters( 'the_content', $post->post_content ); 76 77 $this->assertStringNotContainsString( $post_data['post_title'], $content ); 78 $this->assertStringNotContainsString( "src=\"{$spam_embed_url}#?", $content ); 79 } 80 81 public function test_update_blog_status_make_spam_blog_action() { 82 $test_action_counter = new MockAction(); 83 84 $blog_id = self::factory()->blog->create(); 85 86 add_action( 'make_spam_blog', array( $test_action_counter, 'action' ) ); 87 update_blog_status( $blog_id, 'spam', 1 ); 88 $blog = get_site( $blog_id ); 89 90 $this->assertSame( '1', $blog->spam ); 91 $this->assertSame( 1, $test_action_counter->get_call_count() ); 92 93 // The action should not fire if the status of 'spam' stays the same. 94 update_blog_status( $blog_id, 'spam', 1 ); 95 $blog = get_site( $blog_id ); 96 97 $this->assertSame( '1', $blog->spam ); 98 $this->assertSame( 1, $test_action_counter->get_call_count() ); 99 } 100 101 public function test_update_blog_status_archive_blog_action() { 102 $test_action_counter = new MockAction(); 103 104 $blog_id = self::factory()->blog->create(); 105 106 add_action( 'archive_blog', array( $test_action_counter, 'action' ) ); 107 update_blog_status( $blog_id, 'archived', 1 ); 108 $blog = get_site( $blog_id ); 109 110 $this->assertSame( '1', $blog->archived ); 111 $this->assertSame( 1, $test_action_counter->get_call_count() ); 112 113 // The action should not fire if the status of 'archived' stays the same. 114 update_blog_status( $blog_id, 'archived', 1 ); 115 $blog = get_site( $blog_id ); 116 117 $this->assertSame( '1', $blog->archived ); 118 $this->assertSame( 1, $test_action_counter->get_call_count() ); 119 } 120 121 public function test_update_blog_status_unarchive_blog_action() { 122 $test_action_counter = new MockAction(); 123 124 $blog_id = self::factory()->blog->create(); 125 update_blog_details( $blog_id, array( 'archived' => 1 ) ); 126 127 add_action( 'unarchive_blog', array( $test_action_counter, 'action' ) ); 128 update_blog_status( $blog_id, 'archived', 0 ); 129 $blog = get_site( $blog_id ); 130 131 $this->assertSame( '0', $blog->archived ); 132 $this->assertSame( 1, $test_action_counter->get_call_count() ); 133 134 // The action should not fire if the status of 'archived' stays the same. 135 update_blog_status( $blog_id, 'archived', 0 ); 136 $blog = get_site( $blog_id ); 137 $this->assertSame( '0', $blog->archived ); 138 $this->assertSame( 1, $test_action_counter->get_call_count() ); 139 } 140 141 public function test_update_blog_status_make_delete_blog_action() { 142 $test_action_counter = new MockAction(); 143 144 $blog_id = self::factory()->blog->create(); 145 146 add_action( 'make_delete_blog', array( $test_action_counter, 'action' ) ); 147 update_blog_status( $blog_id, 'deleted', 1 ); 148 $blog = get_site( $blog_id ); 149 150 $this->assertSame( '1', $blog->deleted ); 151 $this->assertSame( 1, $test_action_counter->get_call_count() ); 152 153 // The action should not fire if the status of 'deleted' stays the same. 154 update_blog_status( $blog_id, 'deleted', 1 ); 155 $blog = get_site( $blog_id ); 156 157 $this->assertSame( '1', $blog->deleted ); 158 $this->assertSame( 1, $test_action_counter->get_call_count() ); 159 } 160 161 public function test_update_blog_status_make_undelete_blog_action() { 162 $test_action_counter = new MockAction(); 163 164 $blog_id = self::factory()->blog->create(); 165 update_blog_details( $blog_id, array( 'deleted' => 1 ) ); 166 167 add_action( 'make_undelete_blog', array( $test_action_counter, 'action' ) ); 168 update_blog_status( $blog_id, 'deleted', 0 ); 169 $blog = get_site( $blog_id ); 170 171 $this->assertSame( '0', $blog->deleted ); 172 $this->assertSame( 1, $test_action_counter->get_call_count() ); 173 174 // The action should not fire if the status of 'deleted' stays the same. 175 update_blog_status( $blog_id, 'deleted', 0 ); 176 $blog = get_site( $blog_id ); 177 178 $this->assertSame( '0', $blog->deleted ); 179 $this->assertSame( 1, $test_action_counter->get_call_count() ); 180 } 181 182 public function test_update_blog_status_mature_blog_action() { 183 $test_action_counter = new MockAction(); 184 185 $blog_id = self::factory()->blog->create(); 186 187 add_action( 'mature_blog', array( $test_action_counter, 'action' ) ); 188 update_blog_status( $blog_id, 'mature', 1 ); 189 $blog = get_site( $blog_id ); 190 191 $this->assertSame( '1', $blog->mature ); 192 $this->assertSame( 1, $test_action_counter->get_call_count() ); 193 194 // The action should not fire if the status of 'mature' stays the same. 195 update_blog_status( $blog_id, 'mature', 1 ); 196 $blog = get_site( $blog_id ); 197 198 $this->assertSame( '1', $blog->mature ); 199 $this->assertSame( 1, $test_action_counter->get_call_count() ); 200 } 201 202 public function test_update_blog_status_unmature_blog_action() { 203 $test_action_counter = new MockAction(); 204 205 $blog_id = self::factory()->blog->create(); 206 update_blog_details( $blog_id, array( 'mature' => 1 ) ); 207 208 add_action( 'unmature_blog', array( $test_action_counter, 'action' ) ); 209 update_blog_status( $blog_id, 'mature', 0 ); 210 211 $blog = get_site( $blog_id ); 212 $this->assertSame( '0', $blog->mature ); 213 $this->assertSame( 1, $test_action_counter->get_call_count() ); 214 215 // The action should not fire if the status of 'mature' stays the same. 216 update_blog_status( $blog_id, 'mature', 0 ); 217 $blog = get_site( $blog_id ); 218 219 $this->assertSame( '0', $blog->mature ); 220 $this->assertSame( 1, $test_action_counter->get_call_count() ); 221 } 222 223 public function test_update_blog_status_update_blog_public_action() { 224 $test_action_counter = new MockAction(); 225 226 $blog_id = self::factory()->blog->create(); 227 228 add_action( 'update_blog_public', array( $test_action_counter, 'action' ) ); 229 update_blog_status( $blog_id, 'public', 0 ); 230 231 $blog = get_site( $blog_id ); 232 $this->assertSame( '0', $blog->public ); 233 $this->assertSame( 1, $test_action_counter->get_call_count() ); 234 235 // The action should not fire if the status of 'mature' stays the same. 236 update_blog_status( $blog_id, 'public', 0 ); 237 $blog = get_site( $blog_id ); 238 239 $this->assertSame( '0', $blog->public ); 240 $this->assertSame( 1, $test_action_counter->get_call_count() ); 241 } 242 } 243 244 endif; 13 public function test_update_blog_status() { 14 $result = update_blog_status( 1, 'spam', 0 ); 15 $this->assertSame( 0, $result ); 16 } 17 18 /** 19 * Updating an invalid field returns the same value that was passed. 20 */ 21 public function test_update_blog_status_invalid_status() { 22 $result = update_blog_status( 1, 'doesnotexist', 'invalid' ); 23 $this->assertSame( 'invalid', $result ); 24 } 25 26 public function test_update_blog_status_make_ham_blog_action() { 27 $test_action_counter = new MockAction(); 28 29 $blog_id = self::factory()->blog->create(); 30 update_blog_details( $blog_id, array( 'spam' => 1 ) ); 31 32 add_action( 'make_ham_blog', array( $test_action_counter, 'action' ) ); 33 update_blog_status( $blog_id, 'spam', 0 ); 34 $blog = get_site( $blog_id ); 35 36 $this->assertSame( '0', $blog->spam ); 37 $this->assertSame( 1, $test_action_counter->get_call_count() ); 38 39 // The action should not fire if the status of 'spam' stays the same. 40 update_blog_status( $blog_id, 'spam', 0 ); 41 $blog = get_site( $blog_id ); 42 43 $this->assertSame( '0', $blog->spam ); 44 $this->assertSame( 1, $test_action_counter->get_call_count() ); 45 } 46 47 /** 48 * @group external-http 49 */ 50 public function test_content_from_spam_blog_is_not_available() { 51 $spam_blog_id = self::factory()->blog->create(); 52 switch_to_blog( $spam_blog_id ); 53 $post_data = array( 54 'post_title' => 'Hello World!', 55 'post_content' => 'Hello world content', 56 ); 57 $post_id = self::factory()->post->create( $post_data ); 58 $post = get_post( $post_id ); 59 $spam_permalink = site_url() . '/?p=' . $post->ID; 60 $spam_embed_url = get_post_embed_url( $post_id ); 61 62 restore_current_blog(); 63 $this->assertNotEmpty( $spam_permalink ); 64 $this->assertSame( $post_data['post_title'], $post->post_title ); 65 66 update_blog_status( $spam_blog_id, 'spam', 1 ); 67 68 $post_id = self::factory()->post->create( 69 array( 70 'post_content' => "\n $spam_permalink \n", 71 ) 72 ); 73 $post = get_post( $post_id ); 74 $content = apply_filters( 'the_content', $post->post_content ); 75 76 $this->assertStringNotContainsString( $post_data['post_title'], $content ); 77 $this->assertStringNotContainsString( "src=\"{$spam_embed_url}#?", $content ); 78 } 79 80 public function test_update_blog_status_make_spam_blog_action() { 81 $test_action_counter = new MockAction(); 82 83 $blog_id = self::factory()->blog->create(); 84 85 add_action( 'make_spam_blog', array( $test_action_counter, 'action' ) ); 86 update_blog_status( $blog_id, 'spam', 1 ); 87 $blog = get_site( $blog_id ); 88 89 $this->assertSame( '1', $blog->spam ); 90 $this->assertSame( 1, $test_action_counter->get_call_count() ); 91 92 // The action should not fire if the status of 'spam' stays the same. 93 update_blog_status( $blog_id, 'spam', 1 ); 94 $blog = get_site( $blog_id ); 95 96 $this->assertSame( '1', $blog->spam ); 97 $this->assertSame( 1, $test_action_counter->get_call_count() ); 98 } 99 100 public function test_update_blog_status_archive_blog_action() { 101 $test_action_counter = new MockAction(); 102 103 $blog_id = self::factory()->blog->create(); 104 105 add_action( 'archive_blog', array( $test_action_counter, 'action' ) ); 106 update_blog_status( $blog_id, 'archived', 1 ); 107 $blog = get_site( $blog_id ); 108 109 $this->assertSame( '1', $blog->archived ); 110 $this->assertSame( 1, $test_action_counter->get_call_count() ); 111 112 // The action should not fire if the status of 'archived' stays the same. 113 update_blog_status( $blog_id, 'archived', 1 ); 114 $blog = get_site( $blog_id ); 115 116 $this->assertSame( '1', $blog->archived ); 117 $this->assertSame( 1, $test_action_counter->get_call_count() ); 118 } 119 120 public function test_update_blog_status_unarchive_blog_action() { 121 $test_action_counter = new MockAction(); 122 123 $blog_id = self::factory()->blog->create(); 124 update_blog_details( $blog_id, array( 'archived' => 1 ) ); 125 126 add_action( 'unarchive_blog', array( $test_action_counter, 'action' ) ); 127 update_blog_status( $blog_id, 'archived', 0 ); 128 $blog = get_site( $blog_id ); 129 130 $this->assertSame( '0', $blog->archived ); 131 $this->assertSame( 1, $test_action_counter->get_call_count() ); 132 133 // The action should not fire if the status of 'archived' stays the same. 134 update_blog_status( $blog_id, 'archived', 0 ); 135 $blog = get_site( $blog_id ); 136 $this->assertSame( '0', $blog->archived ); 137 $this->assertSame( 1, $test_action_counter->get_call_count() ); 138 } 139 140 public function test_update_blog_status_make_delete_blog_action() { 141 $test_action_counter = new MockAction(); 142 143 $blog_id = self::factory()->blog->create(); 144 145 add_action( 'make_delete_blog', array( $test_action_counter, 'action' ) ); 146 update_blog_status( $blog_id, 'deleted', 1 ); 147 $blog = get_site( $blog_id ); 148 149 $this->assertSame( '1', $blog->deleted ); 150 $this->assertSame( 1, $test_action_counter->get_call_count() ); 151 152 // The action should not fire if the status of 'deleted' stays the same. 153 update_blog_status( $blog_id, 'deleted', 1 ); 154 $blog = get_site( $blog_id ); 155 156 $this->assertSame( '1', $blog->deleted ); 157 $this->assertSame( 1, $test_action_counter->get_call_count() ); 158 } 159 160 public function test_update_blog_status_make_undelete_blog_action() { 161 $test_action_counter = new MockAction(); 162 163 $blog_id = self::factory()->blog->create(); 164 update_blog_details( $blog_id, array( 'deleted' => 1 ) ); 165 166 add_action( 'make_undelete_blog', array( $test_action_counter, 'action' ) ); 167 update_blog_status( $blog_id, 'deleted', 0 ); 168 $blog = get_site( $blog_id ); 169 170 $this->assertSame( '0', $blog->deleted ); 171 $this->assertSame( 1, $test_action_counter->get_call_count() ); 172 173 // The action should not fire if the status of 'deleted' stays the same. 174 update_blog_status( $blog_id, 'deleted', 0 ); 175 $blog = get_site( $blog_id ); 176 177 $this->assertSame( '0', $blog->deleted ); 178 $this->assertSame( 1, $test_action_counter->get_call_count() ); 179 } 180 181 public function test_update_blog_status_mature_blog_action() { 182 $test_action_counter = new MockAction(); 183 184 $blog_id = self::factory()->blog->create(); 185 186 add_action( 'mature_blog', array( $test_action_counter, 'action' ) ); 187 update_blog_status( $blog_id, 'mature', 1 ); 188 $blog = get_site( $blog_id ); 189 190 $this->assertSame( '1', $blog->mature ); 191 $this->assertSame( 1, $test_action_counter->get_call_count() ); 192 193 // The action should not fire if the status of 'mature' stays the same. 194 update_blog_status( $blog_id, 'mature', 1 ); 195 $blog = get_site( $blog_id ); 196 197 $this->assertSame( '1', $blog->mature ); 198 $this->assertSame( 1, $test_action_counter->get_call_count() ); 199 } 200 201 public function test_update_blog_status_unmature_blog_action() { 202 $test_action_counter = new MockAction(); 203 204 $blog_id = self::factory()->blog->create(); 205 update_blog_details( $blog_id, array( 'mature' => 1 ) ); 206 207 add_action( 'unmature_blog', array( $test_action_counter, 'action' ) ); 208 update_blog_status( $blog_id, 'mature', 0 ); 209 210 $blog = get_site( $blog_id ); 211 $this->assertSame( '0', $blog->mature ); 212 $this->assertSame( 1, $test_action_counter->get_call_count() ); 213 214 // The action should not fire if the status of 'mature' stays the same. 215 update_blog_status( $blog_id, 'mature', 0 ); 216 $blog = get_site( $blog_id ); 217 218 $this->assertSame( '0', $blog->mature ); 219 $this->assertSame( 1, $test_action_counter->get_call_count() ); 220 } 221 222 public function test_update_blog_status_update_blog_public_action() { 223 $test_action_counter = new MockAction(); 224 225 $blog_id = self::factory()->blog->create(); 226 227 add_action( 'update_blog_public', array( $test_action_counter, 'action' ) ); 228 update_blog_status( $blog_id, 'public', 0 ); 229 230 $blog = get_site( $blog_id ); 231 $this->assertSame( '0', $blog->public ); 232 $this->assertSame( 1, $test_action_counter->get_call_count() ); 233 234 // The action should not fire if the status of 'mature' stays the same. 235 update_blog_status( $blog_id, 'public', 0 ); 236 $blog = get_site( $blog_id ); 237 238 $this->assertSame( '0', $blog->public ); 239 $this->assertSame( 1, $test_action_counter->get_call_count() ); 240 } 241 }
Note: See TracChangeset
for help on using the changeset viewer.