- Timestamp:
- 04/09/2025 01:29:39 PM (5 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/multisite/updateBlogDetails.php
r56547 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_UpdateBlogDetails extends WP_UnitTestCase { 4 9 5 10 /** 6 * @group ms-site7 * @group multisite11 * If `update_blog_details()` is called with any kind of empty arguments, it 12 * should return false. 8 13 */ 9 class Tests_Multisite_UpdateBlogDetails extends WP_UnitTestCase { 14 public function test_update_blog_details_with_empty_args() { 15 $result = update_blog_details( 1, array() ); 16 $this->assertFalse( $result ); 17 } 10 18 11 /** 12 * If `update_blog_details()` is called with any kind of empty arguments, it 13 * should return false. 14 */ 15 public function test_update_blog_details_with_empty_args() { 16 $result = update_blog_details( 1, array() ); 17 $this->assertFalse( $result ); 19 /** 20 * If the ID passed is not that of a current site, we should expect false. 21 */ 22 public function test_update_blog_details_invalid_blog_id() { 23 $result = update_blog_details( 999, array( 'domain' => 'example.com' ) ); 24 $this->assertFalse( $result ); 25 } 26 27 public function test_update_blog_details() { 28 $blog_id = self::factory()->blog->create(); 29 30 $result = update_blog_details( 31 $blog_id, 32 array( 33 'domain' => 'example.com', 34 'path' => 'my_path/', 35 ) 36 ); 37 38 $this->assertTrue( $result ); 39 40 $blog = get_site( $blog_id ); 41 42 $this->assertSame( 'example.com', $blog->domain ); 43 $this->assertSame( '/my_path/', $blog->path ); 44 $this->assertSame( '0', $blog->spam ); 45 } 46 47 /** 48 * Test each of the actions that should fire in update_blog_details() depending on 49 * the flag and flag value being set. Each action should fire once and should not 50 * fire if a flag is already set for the given flag value. 51 * 52 * @param string $flag The name of the flag being set or unset on a site. 53 * @param string $flag_value '0' or '1'. The value of the flag being set. 54 * @param string $action The hook expected to fire for the flag name and flag combination. 55 * 56 * @dataProvider data_flag_hooks 57 */ 58 public function test_update_blog_details_flag_action( $flag, $flag_value, $hook ) { 59 $test_action_counter = new MockAction(); 60 61 $blog_id = self::factory()->blog->create(); 62 63 // Set an initial value of '1' for the flag when '0' is the flag value being tested. 64 if ( '0' === $flag_value ) { 65 update_blog_details( $blog_id, array( $flag => '1' ) ); 18 66 } 19 67 20 /** 21 * If the ID passed is not that of a current site, we should expect false. 22 */ 23 public function test_update_blog_details_invalid_blog_id() { 24 $result = update_blog_details( 999, array( 'domain' => 'example.com' ) ); 25 $this->assertFalse( $result ); 26 } 68 add_action( $hook, array( $test_action_counter, 'action' ) ); 27 69 28 public function test_update_blog_details() {29 $blog_id = self::factory()->blog->create();70 update_blog_details( $blog_id, array( $flag => $flag_value ) ); 71 $blog = get_site( $blog_id ); 30 72 31 $result = update_blog_details( 32 $blog_id, 33 array( 34 'domain' => 'example.com', 35 'path' => 'my_path/', 36 ) 37 ); 73 $this->assertSame( $flag_value, $blog->{$flag} ); 38 74 39 $this->assertTrue( $result ); 75 // The hook attached to this flag should have fired once during update_blog_details(). 76 $this->assertSame( 1, $test_action_counter->get_call_count() ); 40 77 41 $blog = get_site( $blog_id ); 78 // Update the site to the exact same flag value for this flag. 79 update_blog_details( $blog_id, array( $flag => $flag_value ) ); 42 80 43 $this->assertSame( 'example.com', $blog->domain ); 44 $this->assertSame( '/my_path/', $blog->path ); 45 $this->assertSame( '0', $blog->spam ); 46 } 81 // The hook attached to this flag should not have fired again. 82 $this->assertSame( 1, $test_action_counter->get_call_count() ); 83 } 47 84 48 /** 49 * Test each of the actions that should fire in update_blog_details() depending on 50 * the flag and flag value being set. Each action should fire once and should not 51 * fire if a flag is already set for the given flag value. 52 * 53 * @param string $flag The name of the flag being set or unset on a site. 54 * @param string $flag_value '0' or '1'. The value of the flag being set. 55 * @param string $action The hook expected to fire for the flag name and flag combination. 56 * 57 * @dataProvider data_flag_hooks 58 */ 59 public function test_update_blog_details_flag_action( $flag, $flag_value, $hook ) { 60 $test_action_counter = new MockAction(); 85 public function data_flag_hooks() { 86 return array( 87 array( 'spam', '0', 'make_ham_blog' ), 88 array( 'spam', '1', 'make_spam_blog' ), 89 array( 'archived', '1', 'archive_blog' ), 90 array( 'archived', '0', 'unarchive_blog' ), 91 array( 'deleted', '1', 'make_delete_blog' ), 92 array( 'deleted', '0', 'make_undelete_blog' ), 93 array( 'mature', '1', 'mature_blog' ), 94 array( 'mature', '0', 'unmature_blog' ), 95 ); 96 } 61 97 62 $blog_id = self::factory()->blog->create(); 98 /** 99 * When the path for a site is updated with update_blog_details(), the final path 100 * should have a leading and trailing slash. 101 * 102 * @dataProvider data_single_directory_path 103 */ 104 public function test_update_blog_details_single_directory_path( $path, $expected ) { 105 update_blog_details( 1, array( 'path' => $path ) ); 106 $site = get_site( 1 ); 63 107 64 // Set an initial value of '1' for the flag when '0' is the flag value being tested. 65 if ( '0' === $flag_value ) { 66 update_blog_details( $blog_id, array( $flag => '1' ) ); 67 } 108 $this->assertSame( $expected, $site->path ); 109 } 68 110 69 add_action( $hook, array( $test_action_counter, 'action' ) ); 111 public function data_single_directory_path() { 112 return array( 113 array( 'my_path', '/my_path/' ), 114 array( 'my_path//', '/my_path/' ), 115 array( '//my_path', '/my_path/' ), 116 array( 'my_path/', '/my_path/' ), 117 array( '/my_path', '/my_path/' ), 118 array( '/my_path/', '/my_path/' ), 70 119 71 update_blog_details( $blog_id, array( $flag => $flag_value ) ); 72 $blog = get_site( $blog_id ); 120 array( 'multiple/dirs', '/multiple/dirs/' ), 121 array( '/multiple/dirs', '/multiple/dirs/' ), 122 array( 'multiple/dirs/', '/multiple/dirs/' ), 123 array( '/multiple/dirs/', '/multiple/dirs/' ), 73 124 74 $this->assertSame( $flag_value, $blog->{$flag} ); 75 76 // The hook attached to this flag should have fired once during update_blog_details(). 77 $this->assertSame( 1, $test_action_counter->get_call_count() ); 78 79 // Update the site to the exact same flag value for this flag. 80 update_blog_details( $blog_id, array( $flag => $flag_value ) ); 81 82 // The hook attached to this flag should not have fired again. 83 $this->assertSame( 1, $test_action_counter->get_call_count() ); 84 } 85 86 public function data_flag_hooks() { 87 return array( 88 array( 'spam', '0', 'make_ham_blog' ), 89 array( 'spam', '1', 'make_spam_blog' ), 90 array( 'archived', '1', 'archive_blog' ), 91 array( 'archived', '0', 'unarchive_blog' ), 92 array( 'deleted', '1', 'make_delete_blog' ), 93 array( 'deleted', '0', 'make_undelete_blog' ), 94 array( 'mature', '1', 'mature_blog' ), 95 array( 'mature', '0', 'unmature_blog' ), 96 ); 97 } 98 99 /** 100 * When the path for a site is updated with update_blog_details(), the final path 101 * should have a leading and trailing slash. 102 * 103 * @dataProvider data_single_directory_path 104 */ 105 public function test_update_blog_details_single_directory_path( $path, $expected ) { 106 update_blog_details( 1, array( 'path' => $path ) ); 107 $site = get_site( 1 ); 108 109 $this->assertSame( $expected, $site->path ); 110 } 111 112 public function data_single_directory_path() { 113 return array( 114 array( 'my_path', '/my_path/' ), 115 array( 'my_path//', '/my_path/' ), 116 array( '//my_path', '/my_path/' ), 117 array( 'my_path/', '/my_path/' ), 118 array( '/my_path', '/my_path/' ), 119 array( '/my_path/', '/my_path/' ), 120 121 array( 'multiple/dirs', '/multiple/dirs/' ), 122 array( '/multiple/dirs', '/multiple/dirs/' ), 123 array( 'multiple/dirs/', '/multiple/dirs/' ), 124 array( '/multiple/dirs/', '/multiple/dirs/' ), 125 126 // update_blog_details() does not resolve multiple slashes in the middle of a path string. 127 array( 'multiple///dirs', '/multiple///dirs/' ), 128 ); 129 } 125 // update_blog_details() does not resolve multiple slashes in the middle of a path string. 126 array( 'multiple///dirs', '/multiple///dirs/' ), 127 ); 130 128 } 131 endif; 129 }
Note: See TracChangeset
for help on using the changeset viewer.