Changeset 9980
- Timestamp:
- 06/29/2015 09:42:43 PM (9 years ago)
- Location:
- trunk/tests/phpunit
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/includes/testcase.php
r9913 r9980 14 14 protected static $cached_SERVER_NAME = null; 15 15 16 /** 17 * A flag indicating whether an autocommit has been detected inside of a test. 18 * 19 * @since BuddyPress (2.4.0) 20 * 21 * @var bool 22 */ 23 protected $autocommitted = false; 24 16 25 public static function setUpBeforeClass() { 17 26 // Fake WP mail globals, to avoid errors … … 23 32 parent::setUp(); 24 33 25 // There's a bug in the multisite tests that causes the26 // transaction rollback to fail for the first user created,27 // which busts every other attempt to create users. This is a28 // hack workaround.29 global $wpdb;30 if ( is_multisite() ) {31 $user_1 = get_user_by( 'login', 'user 1' );32 if ( $user_1 ) {33 $wpdb->delete( $wpdb->users, array( 'ID' => $user_1->ID ) );34 clean_user_cache( $user_1 );35 }36 }37 38 39 34 $this->factory = new BP_UnitTest_Factory; 40 35 41 36 // Fixes warnings in multisite functions 42 37 $_SERVER['REMOTE_ADDR'] = ''; 38 global $wpdb; 39 40 // Clean up after autocommits. 41 add_action( 'bp_blogs_recorded_existing_blogs', array( $this, 'set_autocommit_flag' ) ); 42 } 43 44 public function tearDown() { 45 global $wpdb; 46 47 remove_action( 'bp_blogs_recorded_existing_blogs', array( $this, 'set_autocommit_flag' ) ); 48 49 parent::tearDown(); 50 51 // If we detect that a COMMIT has been triggered during the test, clean up blog and user fixtures. 52 if ( $this->autocommitted ) { 53 if ( is_multisite() ) { 54 foreach ( $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs WHERE blog_id != 1" ) as $blog_id ) { 55 wpmu_delete_blog( $blog_id, true ); 56 } 57 } 58 59 foreach ( $wpdb->get_col( "SELECT ID FROM $wpdb->users WHERE ID != 1" ) as $user_id ) { 60 if ( is_multisite() ) { 61 wpmu_delete_user( $user_id ); 62 } else { 63 wp_delete_user( $user_id ); 64 } 65 } 66 } 67 68 $this->commit_transaction(); 43 69 } 44 70 … … 54 80 55 81 parent::clean_up_global_scope(); 56 }57 58 function tearDown() {59 parent::tearDown();60 61 /**62 * Sites created by the WP_UnitTest_Factory_For_Blog sometimes are not removed when the current63 * transaction is rolled back. This requires further investigation to understand the root cause64 * but for now, we'll empty out the blogs table manually.65 */66 global $wpdb;67 68 if ( is_multisite() ) {69 $blogs = wp_get_sites();70 foreach ( $blogs as $blog ) {71 if ( (int) $blog['blog_id'] !== 1 ) {72 wpmu_delete_blog( $blog['blog_id'], true );73 }74 }75 }76 82 } 77 83 … … 449 455 @rmdir( $dir ); 450 456 } 457 458 /** 459 * Set a flag that an autocommit has taken place inside of a test method. 460 * 461 * @since BuddyPress (2.4.0) 462 */ 463 public function set_autocommit_flag() { 464 $this->autocommitted = true; 465 } 451 466 } -
trunk/tests/phpunit/testcases/blogs/class-bp-blogs-blog.php
r9819 r9980 28 28 29 29 $this->assertEquals( array( $b ), $blog_ids ); 30 31 $this->set_current_user( $old_user );32 wpmu_delete_blog( $b, true );33 30 } 34 31 … … 61 58 $this->assertEquals( array( $b ), $blog_ids ); 62 59 $this->assertEquals( 1, $blogs['total'] ); 63 64 $this->set_current_user( $old_user );65 wpmu_delete_blog( $b, true );66 60 } 67 61 … … 89 83 90 84 $this->assertEquals( array( $b ), $blog_ids ); 91 92 $this->set_current_user( $old_user );93 wpmu_delete_blog( $b, true );94 85 } 95 86 … … 120 111 121 112 $this->assertEquals( array( $b ), $blog_ids ); 122 123 $this->set_current_user( $old_user );124 wpmu_delete_blog( $b, true );125 113 } 126 114 … … 182 170 183 171 $this->set_current_user( $old_user ); 184 185 foreach ( $bs as $d ) {186 wpmu_delete_blog( $d, true );187 }188 172 } 189 173 }
Note: See TracChangeset
for help on using the changeset viewer.