WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#36566 closed task (blessed) (fixed)

Improve unit tests around multisite's bootstrap, networks, and sites

Reported by: jeremyfelt Owned by: jeremyfelt
Milestone: 4.6 Priority: normal
Severity: normal Version:
Component: Networks and Sites Keywords:
Focuses: multisite Cc:

Description

In the process of working toward #34941, and in the spirit of #30017, many of the multisite bootstrap, network, and sites related tests can use some improvement.

  • Use shared test fixtures where possible.
  • Use data providers where possible.
  • Make tests comprehensive where not.
  • Fix bugs where found.

Change History (22)

#1 @jeremyfelt
4 years ago

In 37233:

Tests: Improve get_blog_count() tests

  • Use wp_update_network_counts() to update the database with the most current data before testing.
  • Use wp_update_network_counts() to update the database with the most current data after deleting the sites created during the test.
  • Create only 1 extra site in each test rather than 4. This shaves several seconds off the test time.
  • Stop testing for an extra count now that we update the network counts properly. Previously we looked at $site_count_start + 9 rather than 8. Now this is + 1, which aligns with the actual number of sites created.
  • Test 3 explicit conditions - default, filter applied as true, and filter applied as false.
  • Reset data before testing assertion to avoid a suspended state.

See #36566.

#2 @jeremyfelt
4 years ago

In 37234:

Tests: Share test fixtures in multisite bootstrap tests

  • Remove unnecessary setUp and tearDown methods.
  • Create networks and sites in wpSetupBeforeClass to share throughout.
  • Destroy networks and sites in wpTearDownAfterClass to unpollute.

See #36566, #34941.

#3 @jeremyfelt
4 years ago

In 37236:

Tests: Use a data provider to test get_network_by_path()

See #36566, #34941.

#4 @jeremyfelt
4 years ago

In 37237:

Tests: Use a data provider in get_site_by_path() tests

See #36566, #34941.

#5 @jeremyfelt
4 years ago

In 37238:

Tests: Use a data provider to test multisite's bootstrap

This also helps to get things in order before the introduction of a more testable multisite bootstrap function in #34941.

A @todo has been temporarily removed, to be re-introduced as a working test.

See #36566.

#6 @jeremyfelt
4 years ago

In 37239:

Tests: Add missing params to doc blocks

  • These should have been included in [37236] and [37238].
  • Simplifies parameter names in test_get_network_by_path()

See #36566.

#7 @jeremyfelt
4 years ago

In 37241:

Tests: Add test for multiple site path segments in bootstrap

This fixes a @todo that has been around since the introduction of these tests in [28910].

See #36566.

#8 @jeremyfelt
4 years ago

In 37267:

Tests: Add speedTrapListener to multisite's PHPUnit config

See #36566, #30017.

#9 @jeremyfelt
4 years ago

In 37269:

Tests: Exclude ms-files test group from default PHPUnit config

Multisite specific tests run as normal with phpunit.xml.dist and multisite constants defined. The ms-files group causes pollution when mixed with the rest of the tests, so it should be excluded here too.

See #36566.

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


4 years ago

#11 @jeremyfelt
4 years ago

In 37300:

Tests: Account for flexible IDs in main network deletion test

After [37299], the network IDs encountered by this test may be larger than "100".

This adjusts the test to respond accordingly until we have a better way to delete networks.

See #36566.

#12 @jeremyfelt
4 years ago

In 37318:

Tests: Reduce unnecessary count in create_many() in multisite user tests

The tests for is_blog_user() and is_user_member_of_blog() should be refactored. Until then, we can shave several seconds from the test time by avoiding unnecessary loops of the same tests.

See #36566.

#13 @jeremyfelt
4 years ago

In 37418:

Tests: Set public to 1 in the default blog factory

When no $meta arguments are passed to wpmu_create_blog(), public is set to 0 in the database for new sites. This is fine, but also does not match the default implied when most sites are created via site-new.php.

The only current use of the $meta argument in the tests is to (re)mark public as 0. All existing tests pass with this change. Tests for WP_Site_Query can now rely on better default expectations.

See #36566.

#14 @jeremyfelt
4 years ago

  • Owner set to jeremyfelt
  • Status changed from new to accepted

#15 @jeremyfelt
4 years ago

In 37660:

Tests: Move wp_get_sites() tests to their own file

See #36566.

#16 @jeremyfelt
4 years ago

In 37662:

Tests: User a data provider for wp_get_sites() tests.

  • Convert existing tests into a data provider and clarify expectations.
  • Add shared test fixtures in preparation for future tests.

This passes with the wp_get_sites() from 4.5 and the deprecated version in trunk.

See #36566.

#17 @jeremyfelt
4 years ago

In 37665:

Tests: Move get_blog_details() tests to their own file

See #36566.

#18 @jeremyfelt
4 years ago

In 37666:

Tests: Split get_blog_details() test into individual tests

  • One test per method
  • Clarify existing tests.
  • Add test for passing a "blog slug" string to get_blog_details().
  • Shared fixture of sites.
  • Reduce number of sites created to only those necessary.
  • Remove unnecessary networks creation.

See #36566.

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


4 years ago

This ticket was mentioned in Slack in #core by jeremyfelt. View the logs.


4 years ago

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


4 years ago

#22 @jeremyfelt
4 years ago

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

Closing this for the 4.6 cycle. We can use new tickets for future tests.

Note: See TracTickets for help on using tickets.