Make WordPress Core


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

    r46586 r60148  
    11<?php
    22
    3 if ( is_multisite() ) :
     3/**
     4 * @group ms-required
     5 * @group multisite
     6 */
     7class Tests_Multisite_IsEmailAddressUnsafe extends WP_UnitTestCase {
     8
     9    public function test_string_domain_list_should_be_split_on_line_breaks() {
     10        update_site_option( 'banned_email_domains', "foo.com\nbar.org\nbaz.gov" );
     11        $this->assertTrue( is_email_address_unsafe( 'foo@bar.org' ) );
     12        $this->assertFalse( is_email_address_unsafe( 'foo@example.org' ) );
     13    }
    414
    515    /**
    6      * @group multisite
     16     * @dataProvider data_unsafe
     17     * @ticket 25046
     18     * @ticket 21570
    719     */
    8     class Tests_Multisite_IsEmailAddressUnsafe extends WP_UnitTestCase {
    9         public function test_string_domain_list_should_be_split_on_line_breaks() {
    10             update_site_option( 'banned_email_domains', "foo.com\nbar.org\nbaz.gov" );
    11             $this->assertTrue( is_email_address_unsafe( 'foo@bar.org' ) );
    12             $this->assertFalse( is_email_address_unsafe( 'foo@example.org' ) );
    13         }
    14 
    15         /**
    16          * @dataProvider data_unsafe
    17          * @ticket 25046
    18          * @ticket 21570
    19          */
    20         public function test_unsafe_emails( $banned, $email ) {
    21             update_site_option( 'banned_email_domains', $banned );
    22             $this->assertTrue( is_email_address_unsafe( $email ) );
    23         }
    24 
    25         /**
    26          * @dataProvider data_safe
    27          * @ticket 25046
    28          * @ticket 21570
    29          */
    30         public function test_safe_emails( $banned, $email ) {
    31             update_site_option( 'banned_email_domains', $banned );
    32             $this->assertFalse( is_email_address_unsafe( $email ) );
    33         }
    34 
    35         public function data_unsafe() {
    36             return array(
    37                 // 25046
    38                 'case_insensitive_1' => array(
    39                     array( 'baR.com' ),
    40                     'test@Bar.com',
    41                 ),
    42                 'case_insensitive_2' => array(
    43                     array( 'baR.com' ),
    44                     'tEst@bar.com',
    45                 ),
    46                 'case_insensitive_3' => array(
    47                     array( 'barfoo.COM' ),
    48                     'test@barFoo.com',
    49                 ),
    50                 'case_insensitive_4' => array(
    51                     array( 'baR.com' ),
    52                     'tEst@foo.bar.com',
    53                 ),
    54                 'case_insensitive_5' => array(
    55                     array( 'BAZ.com' ),
    56                     'test@baz.Com',
    57                 ),
    58 
    59                 // 21570
    60                 array(
    61                     array( 'bar.com', 'foo.co' ),
    62                     'test@bar.com',
    63                 ),
    64                 'subdomain_1'        => array(
    65                     array( 'bar.com', 'foo.co' ),
    66                     'test@foo.bar.com',
    67                 ),
    68                 array(
    69                     array( 'bar.com', 'foo.co' ),
    70                     'test@foo.co',
    71                 ),
    72                 'subdomain_2'        => array(
    73                     array( 'bar.com', 'foo.co' ),
    74                     'test@subdomain.foo.co',
    75                 ),
    76             );
    77         }
    78 
    79         public function data_safe() {
    80             return array(
    81                 // 25046
    82                 array(
    83                     array( 'baR.com', 'Foo.co', 'barfoo.COM', 'BAZ.com' ),
    84                     'test@Foobar.com',
    85                 ),
    86                 array(
    87                     array( 'baR.com', 'Foo.co', 'barfoo.COM', 'BAZ.com' ),
    88                     'test@Foo-bar.com',
    89                 ),
    90                 array(
    91                     array( 'baR.com', 'Foo.co', 'barfoo.COM', 'BAZ.com' ),
    92                     'tEst@foobar.com',
    93                 ),
    94                 array(
    95                     array( 'baR.com', 'Foo.co', 'barfoo.COM', 'BAZ.com' ),
    96                     'test@Subdomain.Foo.com',
    97                 ),
    98                 array(
    99                     array( 'baR.com', 'Foo.co', 'barfoo.COM', 'BAZ.com' ),
    100                     'test@feeBAz.com',
    101                 ),
    102 
    103                 // 21570
    104                 array(
    105                     array( 'bar.com', 'foo.co' ),
    106                     'test@foobar.com',
    107                 ),
    108                 array(
    109                     array( 'bar.com', 'foo.co' ),
    110                     'test@foo-bar.com',
    111                 ),
    112                 array(
    113                     array( 'bar.com', 'foo.co' ),
    114                     'test@foo.com',
    115                 ),
    116                 array(
    117                     array( 'bar.com', 'foo.co' ),
    118                     'test@subdomain.foo.com',
    119                 ),
    120             );
    121         }
    122 
    123         public function test_email_with_only_top_level_domain_returns_safe() {
    124             update_site_option( 'banned_email_domains', 'bar.com' );
    125             $safe = is_email_address_unsafe( 'email@localhost' );
    126             delete_site_option( 'banned_email_domains' );
    127 
    128             $this->assertFalse( $safe );
    129         }
    130 
    131         public function test_invalid_email_without_domain_returns_safe() {
    132             update_site_option( 'banned_email_domains', 'bar.com' );
    133             $safe = is_email_address_unsafe( 'invalid-email' );
    134             delete_site_option( 'bar.com' );
    135 
    136             $this->assertFalse( $safe );
    137         }
     20    public function test_unsafe_emails( $banned, $email ) {
     21        update_site_option( 'banned_email_domains', $banned );
     22        $this->assertTrue( is_email_address_unsafe( $email ) );
    13823    }
    13924
    140 endif;
     25    /**
     26     * @dataProvider data_safe
     27     * @ticket 25046
     28     * @ticket 21570
     29     */
     30    public function test_safe_emails( $banned, $email ) {
     31        update_site_option( 'banned_email_domains', $banned );
     32        $this->assertFalse( is_email_address_unsafe( $email ) );
     33    }
     34
     35    public function data_unsafe() {
     36        return array(
     37            // 25046
     38            'case_insensitive_1' => array(
     39                array( 'baR.com' ),
     40                'test@Bar.com',
     41            ),
     42            'case_insensitive_2' => array(
     43                array( 'baR.com' ),
     44                'tEst@bar.com',
     45            ),
     46            'case_insensitive_3' => array(
     47                array( 'barfoo.COM' ),
     48                'test@barFoo.com',
     49            ),
     50            'case_insensitive_4' => array(
     51                array( 'baR.com' ),
     52                'tEst@foo.bar.com',
     53            ),
     54            'case_insensitive_5' => array(
     55                array( 'BAZ.com' ),
     56                'test@baz.Com',
     57            ),
     58
     59            // 21570
     60            array(
     61                array( 'bar.com', 'foo.co' ),
     62                'test@bar.com',
     63            ),
     64            'subdomain_1'        => array(
     65                array( 'bar.com', 'foo.co' ),
     66                'test@foo.bar.com',
     67            ),
     68            array(
     69                array( 'bar.com', 'foo.co' ),
     70                'test@foo.co',
     71            ),
     72            'subdomain_2'        => array(
     73                array( 'bar.com', 'foo.co' ),
     74                'test@subdomain.foo.co',
     75            ),
     76        );
     77    }
     78
     79    public function data_safe() {
     80        return array(
     81            // 25046
     82            array(
     83                array( 'baR.com', 'Foo.co', 'barfoo.COM', 'BAZ.com' ),
     84                'test@Foobar.com',
     85            ),
     86            array(
     87                array( 'baR.com', 'Foo.co', 'barfoo.COM', 'BAZ.com' ),
     88                'test@Foo-bar.com',
     89            ),
     90            array(
     91                array( 'baR.com', 'Foo.co', 'barfoo.COM', 'BAZ.com' ),
     92                'tEst@foobar.com',
     93            ),
     94            array(
     95                array( 'baR.com', 'Foo.co', 'barfoo.COM', 'BAZ.com' ),
     96                'test@Subdomain.Foo.com',
     97            ),
     98            array(
     99                array( 'baR.com', 'Foo.co', 'barfoo.COM', 'BAZ.com' ),
     100                'test@feeBAz.com',
     101            ),
     102
     103            // 21570
     104            array(
     105                array( 'bar.com', 'foo.co' ),
     106                'test@foobar.com',
     107            ),
     108            array(
     109                array( 'bar.com', 'foo.co' ),
     110                'test@foo-bar.com',
     111            ),
     112            array(
     113                array( 'bar.com', 'foo.co' ),
     114                'test@foo.com',
     115            ),
     116            array(
     117                array( 'bar.com', 'foo.co' ),
     118                'test@subdomain.foo.com',
     119            ),
     120        );
     121    }
     122
     123    public function test_email_with_only_top_level_domain_returns_safe() {
     124        update_site_option( 'banned_email_domains', 'bar.com' );
     125        $safe = is_email_address_unsafe( 'email@localhost' );
     126        delete_site_option( 'banned_email_domains' );
     127
     128        $this->assertFalse( $safe );
     129    }
     130
     131    public function test_invalid_email_without_domain_returns_safe() {
     132        update_site_option( 'banned_email_domains', 'bar.com' );
     133        $safe = is_email_address_unsafe( 'invalid-email' );
     134        delete_site_option( 'bar.com' );
     135
     136        $this->assertFalse( $safe );
     137    }
     138}
Note: See TracChangeset for help on using the changeset viewer.