Skip to content

Commit 48b7610

Browse files
Tests: Reset environment before performing assertions in populate_network() tests.
This aims to avoid affecting other tests in case of failure. Follow-up to [60954], [61420]. See #64225. git-svn-id: https://develop.svn.wordpress.org/trunk@61423 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 52e2cd9 commit 48b7610

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

tests/phpunit/tests/multisite/populateNetworkHooks.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,20 @@ public function test_before_populate_network_hook() {
5656
)
5757
);
5858

59+
remove_action( 'before_populate_network', array( $this, 'hook_action_counter' ), 10 );
60+
remove_action( 'after_populate_network', array( $this, 'hook_action_counter' ), 10 );
61+
62+
global $wpdb;
63+
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->sitemeta} WHERE site_id = %d", $network_id ) );
64+
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->site} WHERE id = %d", $network_id ) );
65+
5966
$this->assertSame( 1, $this->action_counts['before_populate_network'], 'before_populate_network action should fire once' );
6067
$this->assertSame( 1, $this->action_counts['after_populate_network'], 'after_populate_network action should fire once' );
6168

6269
$this->assertSame( $network_id, $this->action_args['before_populate_network']['network_id'], 'Network ID should match in before_populate_network hook' );
6370
$this->assertSame( $domain, $this->action_args['before_populate_network']['domain'], 'Domain should match in before_populate_network hook' );
6471
$this->assertSame( $network_id, $this->action_args['after_populate_network']['network_id'], 'Network ID should match in after_populate_network hook' );
6572
$this->assertSame( $domain, $this->action_args['after_populate_network']['domain'], 'Domain should match in after_populate_network hook' );
66-
67-
remove_action( 'before_populate_network', array( $this, 'hook_action_counter' ), 10 );
68-
remove_action( 'after_populate_network', array( $this, 'hook_action_counter' ), 10 );
69-
70-
global $wpdb;
71-
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->sitemeta} WHERE site_id = %d", $network_id ) );
72-
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->site} WHERE id = %d", $network_id ) );
7373
}
7474

7575
/**
@@ -90,13 +90,13 @@ public function test_populate_network_hook_filter() {
9090
)
9191
);
9292

93-
$this->assertTrue( $this->hook_called, 'The modify_domain_hook action should have been called' );
94-
9593
remove_action( 'before_populate_network', array( $this, 'modify_domain_hook' ), 10 );
9694

9795
global $wpdb;
9896
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->sitemeta} WHERE site_id = %d", $network_id ) );
9997
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->site} WHERE id = %d", $network_id ) );
98+
99+
$this->assertTrue( $this->hook_called, 'The modify_domain_hook action should have been called' );
100100
}
101101

102102
/**

0 commit comments

Comments
 (0)