Make WordPress Core

Changeset 61423


Ignore:
Timestamp:
01/02/2026 10:10:33 PM (3 months ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/multisite/populateNetworkHooks.php

    r61420 r61423  
    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' );
     
    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
     
    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
     
    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
Note: See TracChangeset for help on using the changeset viewer.