Make WordPress Core

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#36567 closed enhancement (fixed)

Allow overriding constants in testing framework

Reported by: rmccue's profile rmccue Owned by: jeremyfelt's profile jeremyfelt
Milestone: 4.6 Priority: normal
Severity: normal Version:
Component: Build/Test Tools Keywords: has-patch
Focuses: multisite Cc:

Description

bootstrap.php in our testing harness sets some constants, and it's impossible to override these (without warnings, at least). In particular, you can define WP_TESTS_MULTISITE to set multisite, but you can't set SUBDOMAIN_INSTALL. This makes it impossible to test sites which need multisite, or to test plugins which do subdomain-specific things (such as domain mapping and aliasing).

These should only be defined if not already, rather than forcing them.

Attachments (1)

36567.diff (1.2 KB) - added by rmccue 8 years ago.
Allow overriding constants in config

Download all attachments as: .zip

Change History (11)

@rmccue
8 years ago

Allow overriding constants in config

#1 @rmccue
8 years ago

  • Keywords has-patch added

Attached patch splits the conditional into a more readable form using the variable directly, and allows defining MULTISITE and SUBDOMAIN_INSTALL in your wp-config.php directly.

This ticket was mentioned in Slack in #core-multisite by rmccue. View the logs.


8 years ago

#3 @jeremyfelt
8 years ago

  • Focuses multisite added

#4 follow-ups: @jeremyfelt
8 years ago

  • Keywords needs-patch added; has-patch removed

Yeah.

If you define SUBDOMAIN_INSTALL as true in wp-tests-config.php:

  • wp-tests-config.php is passed to the the test installer, which loads wp-settings.php.
  • In wp-settings.php, wp_not_installed() fires, which checks is_multisite().
  • is_multisite() falls back to SUBDOMAIN_INSTALL if MULTISITE has not been defined, so passes.
  • is_blog_installed() is then checked.
  • $wpdb->options is wptests_1_options, because $wpdb->get_blog_prefix() checks MULTISITE, not SUBDOMAIN_INSTALL.
  • wptests_1_options doesn't exist, nor do any of the wptests_1_* tables, and so dead_db() is fired.
  • A bunch of HTML outputs to show the error page, which is more annoying than anything because the tests work just fine if you've already run everything once before setting SUBDOMAIN_INSTALL.

So I guess the first question is: Why do we not use is_multisite() in $wpdb->get_blog_prefix, because changing that appears to fix this and allows the tests to install fresh if you recreate the DB.

Last edited 8 years ago by jeremyfelt (previous) (diff)

#5 in reply to: ↑ 4 @rmccue
8 years ago

You can define it without any issues by wrapping in a WP_INSTALLING check:

if ( ! defined( 'WP_INSTALLING' ) ) {
	define( 'MULTISITE', true );
	define( 'SUBDOMAIN_INSTALL', true );
}

Sub-optimal, I agree, and I get bitten by that every time.

#6 @jeremyfelt
8 years ago

Oh, heh. I thought I tried that.

We've required more sub-optimal than that... :)

#7 in reply to: ↑ 4 ; follow-up: @pento
8 years ago

Replying to jeremyfelt:

So I guess the first question is: Why do we not use is_multisite() in $wpdb->get_blog_prefix, because changing that appears to fix this and allows the tests to install fresh if you recreate the DB.

This became that when MU was merged, then @nacin added an is_multisite() check, then nothing has changed since then, because we're all too scared to touch that code.

#8 in reply to: ↑ 7 ; follow-up: @jeremyfelt
8 years ago

  • Keywords has-patch added; needs-patch removed
  • Owner set to jeremyfelt
  • Status changed from new to reviewing

For the most part, tests work with SUBDOMAIN_INSTALL enabled. There are 4 failing tests in tests/multisite/site.php due to the way our blog factory assumes a subdirectory configuration and how tests handle that. We should be able to fix this as part of #36566.

#9 @jeremyfelt
8 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 37266:

Tests: Allow override of MULTISITE and SUBDOMAIN_INSTALL constants

Props rmccue.
Fixes #36567.

#10 in reply to: ↑ 8 @rmccue
8 years ago

Replying to jeremyfelt:

For the most part, tests work with SUBDOMAIN_INSTALL enabled. There are 4 failing tests in tests/multisite/site.php due to the way our blog factory assumes a subdirectory configuration and how tests handle that. We should be able to fix this as part of #36566.

FWIW, I'm happy for core tests to fail; the main issue was that this occurred any time you use core's bootstrapping, i.e. for plugin or site testing. So long as the framework works, rmccue-likes.

Note: See TracTickets for help on using tickets.