Make WordPress Core

Opened 14 months ago

Last modified 3 months ago

#59981 new enhancement

PHPUnit tests for is_main_network

Reported by: pbearne's profile pbearne Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Networks and Sites Keywords: has-patch has-unit-tests
Focuses: multisite Cc:

Description


Change History (6)

#1 @pbearne
14 months ago

  • Summary changed from PHPUnit tests for is_site_meta_supported to PHPUnit tests for is_main_network

This ticket was mentioned in Slack in #core-test by pbearne. View the logs.


14 months ago

#3 @pbearne
14 months ago

npm run test:php -- -c tests/phpunit/multisite.xml --group ms-site --filter Tests_MultiSite_is_main_network

#4 @swissspidy
11 months ago

  • Focuses multisite added
  • Keywords needs-patch added

#5 @desrosj
3 months ago

  • Component changed from Build/Test Tools to Networks and Sites
  • Type changed from defect (bug) to enhancement

Since this is about adding tests and not a general build or test tooling change, I'm reassigning it to the relevant component.

This ticket was mentioned in PR #7571 on WordPress/wordpress-develop by @debarghyabanerjee.


3 months ago
#6

  • Keywords has-patch has-unit-tests added; needs-patch removed

Trac Ticket: Core-59981

## Description:

  • This pull request introduces the initial set of unit tests for the is_main_network() function. The tests are designed to verify the function's behavior in both multisite and single-site scenarios.

## Changes Made:

  • Added Multisite Tests:
  • Class: Tests_Multisite_IsMainNetwork
  • Purpose: Tests the behavior of is_main_network() for valid and invalid network IDs within a multisite environment.
  • Test Cases:
  • Valid network IDs that should return true:
    • null
    • 1 (main network)


  • Invalid network IDs that should return false:
    • 2
    • 0
    • Empty string
  • Added Single-Site Tests:
  • Class: Tests_Functions_IsMainNetwork
  • Purpose: Tests the behavior of is_main_network() in a single-site context.
  • Test Cases:
  • Valid network IDs that should return true:
    • null
    • 1
    • 0
    • Empty string
    • Non-main network ID (2) which is also tested to ensure the function handles it correctly.

## Benefits:

  • Coverage for Multisite and Single-Site
  • Ensures that the is_main_network() function is thoroughly tested in different contexts.
  • Early Detection of Issues
  • The introduction of these tests will help catch any bugs or unexpected behavior early in the development process.

## Testing:

  • The tests are designed to be run in the WordPress environment using PHPUnit.
  • All tests have been verified to pass successfully.

## Commands

### Multisite

npm run test:php -- -c tests/phpunit/multisite.xml --group ms-site --filter Tests_MultiSite_is_main_network

### Single SIte

npm run test:php --filter Tests_Multisite_IsMainNetwork::test_should_return_true_for_valid_network_id
Note: See TracTickets for help on using tickets.