Skip to content

Commit 04cfa08

Browse files
Copilotswissspidy
andcommitted
Fix multinetwork test: use example.com domain and wp-config swap
Two bugs in the previous test: 1. Wrong domain: network 2 was created with domain=localhost but the Behat test environment installs WordPress at https://example.com. 2. URL routing doesn't work: DOMAIN_CURRENT_SITE is a PHP constant hardcoded in wp-config.php, so WordPress skips the DB lookup entirely and get_current_network_id() always returns SITE_ID_CURRENT_SITE (1) regardless of --url. The --url=localhost/net2-site1/ approach could never route to network 2. Fix: create network 2 with domain=example.com, move 2 blogs to it, then swap SITE_ID_CURRENT_SITE from 1 to 2 in wp-config.php before the second run. This correctly puts WordPress into network 2 context so the command processes only the 2 network-2 sites. Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent c0f3bd3 commit 04cfa08

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

features/core-update-db.feature

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,21 +166,22 @@ Feature: Update core's database
166166
And I run `wp core download --version=5.4 --force`
167167
And I run `wp option update db_version 45805 --require=disable_sidebar_check.php`
168168
And I run `wp site option update wpmu_upgrade_site 45805`
169-
# Create two sites in network 1 (main site already exists; total 3)
169+
# Create 2 sites in network 1 (main site already exists; 3 total in network 1)
170170
And I run `wp site create --slug=net1-site1`
171171
And I run `wp site create --slug=net1-site2`
172-
# Create two sites that will be moved to a second network
172+
# Create 2 sites that will be moved to a second network
173173
And I run `wp site create --slug=net2-site1 --porcelain`
174174
And save STDOUT as {NET2_SITE1_ID}
175175
And I run `wp site create --slug=net2-site2 --porcelain`
176176
And save STDOUT as {NET2_SITE2_ID}
177-
# Register a second network and reassign those two sites to it
178-
And I run `wp eval 'global $wpdb; $wpdb->insert( $wpdb->site, [ "domain" => "localhost", "path" => "/network2/" ] ); $n2 = $wpdb->insert_id; $wpdb->update( $wpdb->blogs, [ "site_id" => $n2 ], [ "blog_id" => {NET2_SITE1_ID} ] ); $wpdb->update( $wpdb->blogs, [ "site_id" => $n2 ], [ "blog_id" => {NET2_SITE2_ID} ] );'`
177+
# Register a second network (ID=2) and reassign those two blogs to it
178+
And I run `wp eval 'global $wpdb; $wpdb->insert( $wpdb->site, [ "domain" => "example.com", "path" => "/network2/" ] );'`
179+
And I run `wp eval 'global $wpdb; $wpdb->update( $wpdb->blogs, [ "site_id" => 2 ], [ "blog_id" => {NET2_SITE1_ID} ] ); $wpdb->update( $wpdb->blogs, [ "site_id" => 2 ], [ "blog_id" => {NET2_SITE2_ID} ] );'`
179180

180181
When I run `wp site option get wpmu_upgrade_site`
181182
Then save STDOUT as {UPDATE_VERSION}
182183

183-
# Running without --url targets the current (primary) network: 3 sites in network 1
184+
# With SITE_ID_CURRENT_SITE=1, only the 3 network-1 sites are processed (not all 5)
184185
When I run `wp core update-db --network`
185186
Then STDOUT should contain:
186187
"""
@@ -193,8 +194,10 @@ Feature: Update core's database
193194
{UPDATE_VERSION}
194195
"""
195196

196-
# Running with --url targeting a network 2 site should process only network 2's 2 sites
197-
When I run `wp core update-db --network --url=localhost/net2-site1/`
197+
# Switch wp-config.php to network 2 context; only network 2's 2 sites should be processed
198+
And "define( 'SITE_ID_CURRENT_SITE', 1 );" replaced with "define( 'SITE_ID_CURRENT_SITE', 2 );" in the wp-config.php file
199+
200+
When I run `wp core update-db --network`
198201
Then STDOUT should contain:
199202
"""
200203
Success: WordPress database upgraded on 2/2 sites.

0 commit comments

Comments
 (0)