Make WordPress Core


Ignore:
Timestamp:
04/09/2025 01:29:39 PM (8 months ago)
Author:
SergeyBiryukov
Message:

Tests: Use the ms-required group where appropriate.

This replaces the if ( is_multisite() ) conditional wrapping entire test classes with the ms-required group for more consistency across the test suite.

Follow-up to [40520].

See #63167.

File:
1 edited

Legend:

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

    r54864 r60148  
    11<?php
    22
    3 if ( is_multisite() ) :
     3/**
     4 * Tests specific to the ms_files_rewriting option in multisite.
     5 *
     6 * The ms-files group tag must be used for these tests to run as the constants
     7 * set in ms_upload_constants() conflict with a non ms-files configuration.
     8 *
     9 * @group ms-files
     10 * @group ms-required
     11 * @group multisite
     12 */
     13class Tests_Multisite_msFilesRewriting extends WP_UnitTestCase {
     14
     15    public function set_up() {
     16        parent::set_up();
     17        update_site_option( 'ms_files_rewriting', 1 );
     18        ms_upload_constants();
     19    }
     20
     21    public function test_switch_upload_dir() {
     22        $this->assertTrue( is_main_site() );
     23
     24        $site = get_current_site();
     25        $date = date_format( date_create( 'now' ), 'Y/m' );
     26
     27        $user_id  = self::factory()->user->create( array( 'role' => 'administrator' ) );
     28        $blog_id2 = self::factory()->blog->create( array( 'user_id' => $user_id ) );
     29        $info     = wp_upload_dir();
     30        $this->assertSame( 'http://' . $site->domain . '/wp-content/uploads/' . $date, $info['url'] );
     31        $this->assertSame( ABSPATH . 'wp-content/uploads/' . $date, $info['path'] );
     32        $this->assertSame( '/' . $date, $info['subdir'] );
     33        $this->assertFalse( $info['error'] );
     34
     35        switch_to_blog( $blog_id2 );
     36        $info2 = wp_upload_dir();
     37        $this->assertNotEquals( $info, $info2 );
     38        $this->assertSame( get_option( 'siteurl' ) . '/wp-content/blogs.dir/' . get_current_blog_id() . '/files/' . $date, $info2['url'] );
     39        $this->assertSame( ABSPATH . 'wp-content/blogs.dir/' . get_current_blog_id() . '/files/' . $date, $info2['path'] );
     40        $this->assertSame( '/' . $date, $info2['subdir'] );
     41        $this->assertFalse( $info2['error'] );
     42        restore_current_blog();
     43    }
    444
    545    /**
    6      * Tests specific to the ms_files_rewriting option in multisite.
    7      *
    8      * The ms-files group tag must be used for these tests to run as the constants
    9      * set in ms_upload_constants() conflict with a non ms-files configuration.
    10      *
    11      * @group ms-files
    12      * @group multisite
     46     * When a site is deleted with wpmu_delete_blog(), only the files associated with
     47     * that site should be removed. When wpmu_delete_blog() is run a second time, nothing
     48     * should change with upload directories.
    1349     */
    14     class Tests_Multisite_msFilesRewriting extends WP_UnitTestCase {
     50    public function test_upload_directories_after_multiple_wpmu_delete_blog_with_ms_files() {
     51        $filename = __FUNCTION__ . '.jpg';
     52        $contents = __FUNCTION__ . '_contents';
    1553
    16         public function set_up() {
    17             parent::set_up();
    18             update_site_option( 'ms_files_rewriting', 1 );
    19             ms_upload_constants();
    20         }
     54        // Upload a file to the main site on the network.
     55        $file1 = wp_upload_bits( $filename, null, $contents );
    2156
    22         public function test_switch_upload_dir() {
    23             $this->assertTrue( is_main_site() );
     57        $blog_id = self::factory()->blog->create();
    2458
    25             $site = get_current_site();
    26             $date = date_format( date_create( 'now' ), 'Y/m' );
     59        switch_to_blog( $blog_id );
     60        $file2 = wp_upload_bits( $filename, null, $contents );
     61        restore_current_blog();
    2762
    28             $user_id  = self::factory()->user->create( array( 'role' => 'administrator' ) );
    29             $blog_id2 = self::factory()->blog->create( array( 'user_id' => $user_id ) );
    30             $info     = wp_upload_dir();
    31             $this->assertSame( 'http://' . $site->domain . '/wp-content/uploads/' . $date, $info['url'] );
    32             $this->assertSame( ABSPATH . 'wp-content/uploads/' . $date, $info['path'] );
    33             $this->assertSame( '/' . $date, $info['subdir'] );
    34             $this->assertFalse( $info['error'] );
     63        wpmu_delete_blog( $blog_id, true );
    3564
    36             switch_to_blog( $blog_id2 );
    37             $info2 = wp_upload_dir();
    38             $this->assertNotEquals( $info, $info2 );
    39             $this->assertSame( get_option( 'siteurl' ) . '/wp-content/blogs.dir/' . get_current_blog_id() . '/files/' . $date, $info2['url'] );
    40             $this->assertSame( ABSPATH . 'wp-content/blogs.dir/' . get_current_blog_id() . '/files/' . $date, $info2['path'] );
    41             $this->assertSame( '/' . $date, $info2['subdir'] );
    42             $this->assertFalse( $info2['error'] );
    43             restore_current_blog();
    44         }
     65        // The file on the main site should still exist. The file on the deleted site should not.
     66        $this->assertFileExists( $file1['file'] );
     67        $this->assertFileDoesNotExist( $file2['file'] );
    4568
    46         /**
    47          * When a site is deleted with wpmu_delete_blog(), only the files associated with
    48          * that site should be removed. When wpmu_delete_blog() is run a second time, nothing
    49          * should change with upload directories.
    50          */
    51         public function test_upload_directories_after_multiple_wpmu_delete_blog_with_ms_files() {
    52             $filename = __FUNCTION__ . '.jpg';
    53             $contents = __FUNCTION__ . '_contents';
     69        wpmu_delete_blog( $blog_id, true );
    5470
    55             // Upload a file to the main site on the network.
    56             $file1 = wp_upload_bits( $filename, null, $contents );
     71        // The file on the main site should still exist. The file on the deleted site should not.
     72        $this->assertFileExists( $file1['file'] );
     73        $this->assertFileDoesNotExist( $file2['file'] );
    5774
    58             $blog_id = self::factory()->blog->create();
    59 
    60             switch_to_blog( $blog_id );
    61             $file2 = wp_upload_bits( $filename, null, $contents );
    62             restore_current_blog();
    63 
    64             wpmu_delete_blog( $blog_id, true );
    65 
    66             // The file on the main site should still exist. The file on the deleted site should not.
    67             $this->assertFileExists( $file1['file'] );
    68             $this->assertFileDoesNotExist( $file2['file'] );
    69 
    70             wpmu_delete_blog( $blog_id, true );
    71 
    72             // The file on the main site should still exist. The file on the deleted site should not.
    73             $this->assertFileExists( $file1['file'] );
    74             $this->assertFileDoesNotExist( $file2['file'] );
    75 
    76             unlink( $file1['file'] );
    77         }
     75        unlink( $file1['file'] );
    7876    }
    79 
    80 endif;
     77}
Note: See TracChangeset for help on using the changeset viewer.