Make WordPress Core


Ignore:
Timestamp:
04/09/2025 01:29:39 PM (18 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/avoidBlogPagePermalinkCollision.php

    r57987 r60148  
    11<?php
    22
    3 if ( is_multisite() ) :
     3/**
     4 * Tests specific to `avoid_blog_page_permalink_collision()` in multisite.
     5 *
     6 * @group ms-required
     7 * @group multisite
     8 * @group post
     9 */
     10class Tests_Multisite_AvoidBlogPagePermalinkCollision extends WP_UnitTestCase {
     11
     12        protected static $site_id;
     13        protected static $root_page;
     14        protected static $child_page;
     15        protected static $post_and_blog_path = 'permalink-collision';
    416
    517        /**
    6          * Tests specific to `avoid_blog_page_permalink_collision()` in multisite.
    7          *
    8          * @group multisite
    9          * @group post
     18         * Create a blog and the pages we need to test the collision.
    1019         */
    11         class Tests_Multisite_AvoidBlogPagePermalinkCollision extends WP_UnitTestCase {
    12                 protected static $site_id;
    13                 protected static $root_page;
    14                 protected static $child_page;
    15                 protected static $post_and_blog_path = 'permalink-collision';
     20        public static function wpSetUpBeforeClass( $factory ) {
     21                self::$site_id = self::factory()->blog->create(
     22                        array(
     23                                'path' => '/' . self::$post_and_blog_path,
     24                        )
     25                );
    1626
    17                 /**
    18                  * Create a blog and the pages we need to test the collision.
    19                  */
    20                 public static function wpSetUpBeforeClass( $factory ) {
    21                         self::$site_id = self::factory()->blog->create(
    22                                 array(
    23                                         'path' => '/' . self::$post_and_blog_path,
    24                                 )
    25                         );
     27                self::$root_page = self::factory()->post->create_and_get(
     28                        array(
     29                                'post_type'  => 'page',
     30                                'post_title' => 'Bar',
     31                                'post_name'  => self::$post_and_blog_path,
     32                        )
     33                );
    2634
    27                         self::$root_page = self::factory()->post->create_and_get(
    28                                 array(
    29                                         'post_type'  => 'page',
    30                                         'post_title' => 'Bar',
    31                                         'post_name'  => self::$post_and_blog_path,
    32                                 )
    33                         );
    34 
    35                         self::$child_page = self::factory()->post->create_and_get(
    36                                 array(
    37                                         'post_parent' => self::$root_page->ID,
    38                                         'post_type'   => 'page',
    39                                         'post_title'  => 'Bar',
    40                                         'post_name'   => self::$post_and_blog_path,
    41                                 )
    42                         );
    43                 }
    44 
    45                 /**
    46                  * Delete blog and pages we created.
    47                  */
    48                 public static function wpTearDownAfterClass() {
    49                         wp_delete_site( self::$site_id );
    50 
    51                         wp_delete_post( self::$root_page->ID );
    52                         wp_delete_post( self::$child_page->ID );
    53                 }
    54 
    55                 public function test_avoid_blog_page_permalink_collision_renames_post_name() {
    56                         $this->assertNotSame( self::$post_and_blog_path, self::$root_page->post_name );
    57                 }
    58 
    59                 /**
    60                  * Ensure `avoid_blog_page_permalink_collision()` doesn't rename child pages' post_name.
    61                  *
    62                  * @ticket 51147
    63                  */
    64                 public function test_avoid_blog_page_permalink_collision_doesnt_rename_child_pages() {
    65                         $this->assertSame( self::$post_and_blog_path, self::$child_page->post_name );
    66                 }
     35                self::$child_page = self::factory()->post->create_and_get(
     36                        array(
     37                                'post_parent' => self::$root_page->ID,
     38                                'post_type'   => 'page',
     39                                'post_title'  => 'Bar',
     40                                'post_name'   => self::$post_and_blog_path,
     41                        )
     42                );
    6743        }
    6844
    69 endif;
     45        /**
     46         * Delete blog and pages we created.
     47         */
     48        public static function wpTearDownAfterClass() {
     49                wp_delete_site( self::$site_id );
     50
     51                wp_delete_post( self::$root_page->ID );
     52                wp_delete_post( self::$child_page->ID );
     53        }
     54
     55        public function test_avoid_blog_page_permalink_collision_renames_post_name() {
     56                $this->assertNotSame( self::$post_and_blog_path, self::$root_page->post_name );
     57        }
     58
     59        /**
     60         * Ensure `avoid_blog_page_permalink_collision()` doesn't rename child pages' post_name.
     61         *
     62         * @ticket 51147
     63         */
     64        public function test_avoid_blog_page_permalink_collision_doesnt_rename_child_pages() {
     65                $this->assertSame( self::$post_and_blog_path, self::$child_page->post_name );
     66        }
     67}
Note: See TracChangeset for help on using the changeset viewer.