Make WordPress Core


Ignore:
Timestamp:
08/17/2018 01:50:26 AM (8 years ago)
Author:
pento
Message:

Coding Standards: Upgrade WPCS to 1.0.0

WPCS 1.0.0 includes a bunch of new auto-fixers, which drops the number of coding standards issues across WordPress significantly. Prior to running the auto-fixers, there were 15,312 issues detected. With this commit, we now drop to 4,769 issues.

This change includes three notable additions:

  • Multiline function calls must now put each parameter on a new line.
  • Auto-formatting files is now part of the grunt precommit script.
  • Auto-fixable coding standards issues will now cause Travis failures.

Fixes #44600.

File:
1 edited

Legend:

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

    r43010 r43571  
    33if ( is_multisite() ) :
    44
    5 /**
    6  * @group ms-site
    7  * @group multisite
    8  * @group meta
    9  * @ticket 37923
    10  */
    11 class Tests_Multisite_Site_Meta extends WP_UnitTestCase {
    12         protected static $site_id;
    13         protected static $site_id2;
    14         protected static $flag_was_set;
    15 
    16         public static function wpSetUpBeforeClass( $factory ) {
    17                 self::$site_id = $factory->blog->create( array( 'domain' => 'wordpress.org', 'path' => '/' ) );
    18                 self::$site_id2 = $factory->blog->create( array( 'domain' => 'wordpress.org', 'path' => '/foo/' ) );
    19 
    20                 // Populate the main network flag as necessary.
    21                 self::$flag_was_set = true;
    22                 if ( false === get_network_option( get_main_network_id(), 'site_meta_supported', false ) ) {
    23                         self::$flag_was_set = false;
    24                         is_site_meta_supported();
     5        /**
     6         * @group ms-site
     7         * @group multisite
     8         * @group meta
     9         * @ticket 37923
     10         */
     11        class Tests_Multisite_Site_Meta extends WP_UnitTestCase {
     12                protected static $site_id;
     13                protected static $site_id2;
     14                protected static $flag_was_set;
     15
     16                public static function wpSetUpBeforeClass( $factory ) {
     17                        self::$site_id  = $factory->blog->create(
     18                                array(
     19                                        'domain' => 'wordpress.org',
     20                                        'path'   => '/',
     21                                )
     22                        );
     23                        self::$site_id2 = $factory->blog->create(
     24                                array(
     25                                        'domain' => 'wordpress.org',
     26                                        'path'   => '/foo/',
     27                                )
     28                        );
     29
     30                        // Populate the main network flag as necessary.
     31                        self::$flag_was_set = true;
     32                        if ( false === get_network_option( get_main_network_id(), 'site_meta_supported', false ) ) {
     33                                self::$flag_was_set = false;
     34                                is_site_meta_supported();
     35                        }
     36                }
     37
     38                public static function wpTearDownAfterClass() {
     39                        // Delete the possibly previously populated main network flag.
     40                        if ( ! self::$flag_was_set ) {
     41                                delete_network_option( get_main_network_id(), 'site_meta_supported' );
     42                        }
     43
     44                        wpmu_delete_blog( self::$site_id, true );
     45                        wpmu_delete_blog( self::$site_id2, true );
     46
     47                        wp_update_network_site_counts();
     48                }
     49
     50                public function test_is_site_meta_supported() {
     51                        $this->assertTrue( is_site_meta_supported() );
     52                }
     53
     54                public function test_is_site_meta_supported_filtered() {
     55                        add_filter( 'pre_site_option_site_meta_supported', '__return_zero' );
     56                        $this->assertFalse( is_site_meta_supported() );
     57                }
     58
     59                public function test_add() {
     60                        if ( ! is_site_meta_supported() ) {
     61                                $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
     62                        }
     63
     64                        $this->assertNotEmpty( add_site_meta( self::$site_id, 'foo', 'bar' ) );
     65                        $this->assertSame( 'bar', get_site_meta( self::$site_id, 'foo', true ) );
     66                }
     67
     68                public function test_add_unique() {
     69                        if ( ! is_site_meta_supported() ) {
     70                                $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
     71                        }
     72
     73                        $this->assertNotEmpty( add_site_meta( self::$site_id, 'foo', 'bar' ) );
     74                        $this->assertFalse( add_site_meta( self::$site_id, 'foo', 'bar', true ) );
     75                }
     76
     77                public function test_delete() {
     78                        if ( ! is_site_meta_supported() ) {
     79                                $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
     80                        }
     81
     82                        add_site_meta( self::$site_id, 'foo', 'bar' );
     83
     84                        $this->assertTrue( delete_site_meta( self::$site_id, 'foo' ) );
     85                        $this->assertEmpty( get_site_meta( self::$site_id, 'foo', true ) );
     86                }
     87
     88                public function test_delete_with_invalid_meta_key_should_return_false() {
     89                        if ( ! is_site_meta_supported() ) {
     90                                $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
     91                        }
     92
     93                        $this->assertFalse( delete_site_meta( self::$site_id, 'foo' ) );
     94                }
     95
     96                public function test_delete_should_respect_meta_value() {
     97                        if ( ! is_site_meta_supported() ) {
     98                                $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
     99                        }
     100
     101                        add_site_meta( self::$site_id, 'foo', 'bar' );
     102                        add_site_meta( self::$site_id, 'foo', 'baz' );
     103
     104                        $this->assertTrue( delete_site_meta( self::$site_id, 'foo', 'bar' ) );
     105
     106                        $metas = get_site_meta( self::$site_id, 'foo' );
     107                        $this->assertSame( array( 'baz' ), $metas );
     108                }
     109
     110                public function test_get_with_no_key_should_fetch_all_keys() {
     111                        if ( ! is_site_meta_supported() ) {
     112                                $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
     113                        }
     114
     115                        add_site_meta( self::$site_id, 'foo', 'bar' );
     116                        add_site_meta( self::$site_id, 'foo1', 'baz' );
     117
     118                        $found    = get_site_meta( self::$site_id );
     119                        $expected = array(
     120                                'foo'  => array( 'bar' ),
     121                                'foo1' => array( 'baz' ),
     122                        );
     123
     124                        $this->assertEqualSets( $expected, $found );
     125                }
     126
     127                public function test_get_with_key_should_fetch_all_for_key() {
     128                        if ( ! is_site_meta_supported() ) {
     129                                $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
     130                        }
     131
     132                        add_site_meta( self::$site_id, 'foo', 'bar' );
     133                        add_site_meta( self::$site_id, 'foo', 'baz' );
     134                        add_site_meta( self::$site_id, 'foo1', 'baz' );
     135
     136                        $found    = get_site_meta( self::$site_id, 'foo' );
     137                        $expected = array( 'bar', 'baz' );
     138
     139                        $this->assertEqualSets( $expected, $found );
     140                }
     141
     142                public function test_get_should_respect_single_true() {
     143                        if ( ! is_site_meta_supported() ) {
     144                                $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
     145                        }
     146
     147                        add_site_meta( self::$site_id, 'foo', 'bar' );
     148                        add_site_meta( self::$site_id, 'foo', 'baz' );
     149
     150                        $found = get_site_meta( self::$site_id, 'foo', true );
     151                        $this->assertSame( 'bar', $found );
     152                }
     153
     154                public function test_update_should_pass_to_add_when_no_value_exists_for_key() {
     155                        if ( ! is_site_meta_supported() ) {
     156                                $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
     157                        }
     158
     159                        $actual = update_site_meta( self::$site_id, 'foo', 'bar' );
     160                        $this->assertInternalType( 'int', $actual );
     161                        $this->assertNotEmpty( $actual );
     162
     163                        $meta = get_site_meta( self::$site_id, 'foo', true );
     164                        $this->assertSame( 'bar', $meta );
     165                }
     166
     167                public function test_update_should_return_true_when_updating_existing_value_for_key() {
     168                        if ( ! is_site_meta_supported() ) {
     169                                $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
     170                        }
     171
     172                        add_site_meta( self::$site_id, 'foo', 'bar' );
     173
     174                        $actual = update_site_meta( self::$site_id, 'foo', 'baz' );
     175                        $this->assertTrue( $actual );
     176
     177                        $meta = get_site_meta( self::$site_id, 'foo', true );
     178                        $this->assertSame( 'baz', $meta );
     179                }
     180
     181                public function test_delete_by_key() {
     182                        if ( ! is_site_meta_supported() ) {
     183                                $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
     184                        }
     185
     186                        add_site_meta( self::$site_id, 'unique_delete_by_key', 'value', true );
     187                        add_site_meta( self::$site_id2, 'unique_delete_by_key', 'value', true );
     188
     189                        $this->assertEquals( 'value', get_site_meta( self::$site_id, 'unique_delete_by_key', true ) );
     190                        $this->assertEquals( 'value', get_site_meta( self::$site_id2, 'unique_delete_by_key', true ) );
     191
     192                        $this->assertTrue( delete_site_meta_by_key( 'unique_delete_by_key' ) );
     193
     194                        $this->assertEquals( '', get_site_meta( self::$site_id, 'unique_delete_by_key', true ) );
     195                        $this->assertEquals( '', get_site_meta( self::$site_id2, 'unique_delete_by_key', true ) );
     196                }
     197
     198                public function test_site_meta_should_be_deleted_when_site_is_deleted() {
     199                        if ( ! is_site_meta_supported() ) {
     200                                $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
     201                        }
     202
     203                        $site_id = self::factory()->blog->create(
     204                                array(
     205                                        'domain' => 'foo.org',
     206                                        'path'   => '/',
     207                                )
     208                        );
     209
     210                        add_site_meta( $site_id, 'foo', 'bar' );
     211                        add_site_meta( $site_id, 'foo1', 'bar' );
     212
     213                        $this->assertSame( 'bar', get_site_meta( $site_id, 'foo', true ) );
     214                        $this->assertSame( 'bar', get_site_meta( $site_id, 'foo1', true ) );
     215
     216                        wpmu_delete_blog( $site_id, true );
     217
     218                        $this->assertSame( '', get_site_meta( $site_id, 'foo', true ) );
     219                        $this->assertSame( '', get_site_meta( $site_id, 'foo1', true ) );
     220                }
     221
     222                public function test_update_site_meta_cache() {
     223                        global $wpdb;
     224
     225                        if ( ! is_site_meta_supported() ) {
     226                                $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
     227                        }
     228
     229                        update_site_meta( self::$site_id, 'foo', 'bar' );
     230                        update_sitemeta_cache( array( self::$site_id ) );
     231
     232                        $num_queries = $wpdb->num_queries;
     233                        get_site_meta( self::$site_id, 'foo', true );
     234                        $this->assertSame( $num_queries, $wpdb->num_queries );
     235                }
     236
     237                public function test_query_update_site_meta_cache_true() {
     238                        global $wpdb;
     239
     240                        if ( ! is_site_meta_supported() ) {
     241                                $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
     242                        }
     243
     244                        update_site_meta( self::$site_id, 'foo', 'bar' );
     245
     246                        // Do not include 'update_site_meta_cache' as true as its the default.
     247                        new WP_Site_Query(
     248                                array(
     249                                        'ID' => self::$site_id,
     250                                )
     251                        );
     252
     253                        $num_queries = $wpdb->num_queries;
     254                        get_site_meta( self::$site_id, 'foo', true );
     255                        $this->assertSame( $num_queries, $wpdb->num_queries );
     256                }
     257
     258                public function test_query_update_site_meta_cache_false() {
     259                        global $wpdb;
     260
     261                        if ( ! is_site_meta_supported() ) {
     262                                $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
     263                        }
     264
     265                        update_site_meta( self::$site_id, 'foo', 'bar' );
     266
     267                        new WP_Site_Query(
     268                                array(
     269                                        'ID'                     => self::$site_id,
     270                                        'update_site_meta_cache' => false,
     271                                )
     272                        );
     273
     274                        $num_queries = $wpdb->num_queries;
     275                        get_site_meta( self::$site_id, 'foo', true );
     276                        $this->assertSame( $num_queries + 1, $wpdb->num_queries );
     277                }
     278
     279                /**
     280                 * @ticket 40229
     281                 */
     282                public function test_add_site_meta_should_bust_get_sites_cache() {
     283                        if ( ! is_site_meta_supported() ) {
     284                                $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
     285                        }
     286
     287                        add_site_meta( self::$site_id, 'foo', 'bar' );
     288
     289                        // Prime cache.
     290                        $found = get_sites(
     291                                array(
     292                                        'fields'     => 'ids',
     293                                        'meta_query' => array(
     294                                                array(
     295                                                        'key'   => 'foo',
     296                                                        'value' => 'bar',
     297                                                ),
     298                                        ),
     299                                )
     300                        );
     301
     302                        $this->assertEqualSets( array( self::$site_id ), $found );
     303
     304                        add_site_meta( self::$site_id2, 'foo', 'bar' );
     305
     306                        $found = get_sites(
     307                                array(
     308                                        'fields'     => 'ids',
     309                                        'meta_query' => array(
     310                                                array(
     311                                                        'key'   => 'foo',
     312                                                        'value' => 'bar',
     313                                                ),
     314                                        ),
     315                                )
     316                        );
     317
     318                        $this->assertEqualSets( array( self::$site_id, self::$site_id2 ), $found );
     319                }
     320
     321                /**
     322                 * @ticket 40229
     323                 */
     324                public function test_update_site_meta_should_bust_get_sites_cache() {
     325                        if ( ! is_site_meta_supported() ) {
     326                                $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
     327                        }
     328
     329                        add_site_meta( self::$site_id, 'foo', 'bar' );
     330                        add_site_meta( self::$site_id2, 'foo', 'baz' );
     331
     332                        // Prime cache.
     333                        $found = get_sites(
     334                                array(
     335                                        'fields'     => 'ids',
     336                                        'meta_query' => array(
     337                                                array(
     338                                                        'key'   => 'foo',
     339                                                        'value' => 'bar',
     340                                                ),
     341                                        ),
     342                                )
     343                        );
     344
     345                        $this->assertEqualSets( array( self::$site_id ), $found );
     346
     347                        update_site_meta( self::$site_id2, 'foo', 'bar' );
     348
     349                        $found = get_sites(
     350                                array(
     351                                        'fields'     => 'ids',
     352                                        'meta_query' => array(
     353                                                array(
     354                                                        'key'   => 'foo',
     355                                                        'value' => 'bar',
     356                                                ),
     357                                        ),
     358                                )
     359                        );
     360
     361                        $this->assertEqualSets( array( self::$site_id, self::$site_id2 ), $found );
     362                }
     363
     364                /**
     365                 * @ticket 40229
     366                 */
     367                public function test_delete_site_meta_should_bust_get_sites_cache() {
     368                        if ( ! is_site_meta_supported() ) {
     369                                $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
     370                        }
     371
     372                        add_site_meta( self::$site_id, 'foo', 'bar' );
     373                        add_site_meta( self::$site_id2, 'foo', 'bar' );
     374
     375                        // Prime cache.
     376                        $found = get_sites(
     377                                array(
     378                                        'fields'     => 'ids',
     379                                        'meta_query' => array(
     380                                                array(
     381                                                        'key'   => 'foo',
     382                                                        'value' => 'bar',
     383                                                ),
     384                                        ),
     385                                )
     386                        );
     387
     388                        $this->assertEqualSets( array( self::$site_id, self::$site_id2 ), $found );
     389
     390                        delete_site_meta( self::$site_id2, 'foo', 'bar' );
     391
     392                        $found = get_sites(
     393                                array(
     394                                        'fields'     => 'ids',
     395                                        'meta_query' => array(
     396                                                array(
     397                                                        'key'   => 'foo',
     398                                                        'value' => 'bar',
     399                                                ),
     400                                        ),
     401                                )
     402                        );
     403
     404                        $this->assertEqualSets( array( self::$site_id ), $found );
    25405                }
    26406        }
    27407
    28         public static function wpTearDownAfterClass() {
    29                 // Delete the possibly previously populated main network flag.
    30                 if ( ! self::$flag_was_set ) {
    31                         delete_network_option( get_main_network_id(), 'site_meta_supported' );
    32                 }
    33 
    34                 wpmu_delete_blog( self::$site_id, true );
    35                 wpmu_delete_blog( self::$site_id2, true );
    36 
    37                 wp_update_network_site_counts();
    38         }
    39 
    40         public function test_is_site_meta_supported() {
    41                 $this->assertTrue( is_site_meta_supported() );
    42         }
    43 
    44         public function test_is_site_meta_supported_filtered() {
    45                 add_filter( 'pre_site_option_site_meta_supported', '__return_zero' );
    46                 $this->assertFalse( is_site_meta_supported() );
    47         }
    48 
    49         public function test_add() {
    50                 if ( ! is_site_meta_supported() ) {
    51                         $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
    52                 }
    53 
    54                 $this->assertNotEmpty( add_site_meta( self::$site_id, 'foo', 'bar' ) );
    55                 $this->assertSame( 'bar', get_site_meta( self::$site_id, 'foo', true ) );
    56         }
    57 
    58         public function test_add_unique() {
    59                 if ( ! is_site_meta_supported() ) {
    60                         $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
    61                 }
    62 
    63                 $this->assertNotEmpty( add_site_meta( self::$site_id, 'foo', 'bar' ) );
    64                 $this->assertFalse( add_site_meta( self::$site_id, 'foo', 'bar', true ) );
    65         }
    66 
    67         public function test_delete() {
    68                 if ( ! is_site_meta_supported() ) {
    69                         $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
    70                 }
    71 
    72                 add_site_meta( self::$site_id, 'foo', 'bar' );
    73 
    74                 $this->assertTrue( delete_site_meta( self::$site_id, 'foo' ) );
    75                 $this->assertEmpty( get_site_meta( self::$site_id, 'foo', true ) );
    76         }
    77 
    78         public function test_delete_with_invalid_meta_key_should_return_false() {
    79                 if ( ! is_site_meta_supported() ) {
    80                         $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
    81                 }
    82 
    83                 $this->assertFalse( delete_site_meta( self::$site_id, 'foo' ) );
    84         }
    85 
    86         public function test_delete_should_respect_meta_value() {
    87                 if ( ! is_site_meta_supported() ) {
    88                         $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
    89                 }
    90 
    91                 add_site_meta( self::$site_id, 'foo', 'bar' );
    92                 add_site_meta( self::$site_id, 'foo', 'baz' );
    93 
    94                 $this->assertTrue( delete_site_meta( self::$site_id, 'foo', 'bar' ) );
    95 
    96                 $metas = get_site_meta( self::$site_id, 'foo' );
    97                 $this->assertSame( array( 'baz' ), $metas );
    98         }
    99 
    100         public function test_get_with_no_key_should_fetch_all_keys() {
    101                 if ( ! is_site_meta_supported() ) {
    102                         $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
    103                 }
    104 
    105                 add_site_meta( self::$site_id, 'foo', 'bar' );
    106                 add_site_meta( self::$site_id, 'foo1', 'baz' );
    107 
    108                 $found = get_site_meta( self::$site_id );
    109                 $expected = array(
    110                         'foo'  => array( 'bar' ),
    111                         'foo1' => array( 'baz' ),
    112                 );
    113 
    114                 $this->assertEqualSets( $expected, $found );
    115         }
    116 
    117         public function test_get_with_key_should_fetch_all_for_key() {
    118                 if ( ! is_site_meta_supported() ) {
    119                         $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
    120                 }
    121 
    122                 add_site_meta( self::$site_id, 'foo', 'bar' );
    123                 add_site_meta( self::$site_id, 'foo', 'baz' );
    124                 add_site_meta( self::$site_id, 'foo1', 'baz' );
    125 
    126                 $found = get_site_meta( self::$site_id, 'foo' );
    127                 $expected = array( 'bar', 'baz' );
    128 
    129                 $this->assertEqualSets( $expected, $found );
    130         }
    131 
    132         public function test_get_should_respect_single_true() {
    133                 if ( ! is_site_meta_supported() ) {
    134                         $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
    135                 }
    136 
    137                 add_site_meta( self::$site_id, 'foo', 'bar' );
    138                 add_site_meta( self::$site_id, 'foo', 'baz' );
    139 
    140                 $found = get_site_meta( self::$site_id, 'foo', true );
    141                 $this->assertSame( 'bar', $found );
    142         }
    143 
    144         public function test_update_should_pass_to_add_when_no_value_exists_for_key() {
    145                 if ( ! is_site_meta_supported() ) {
    146                         $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
    147                 }
    148 
    149                 $actual = update_site_meta( self::$site_id, 'foo', 'bar' );
    150                 $this->assertInternalType( 'int', $actual );
    151                 $this->assertNotEmpty( $actual );
    152 
    153                 $meta = get_site_meta( self::$site_id, 'foo', true );
    154                 $this->assertSame( 'bar', $meta );
    155         }
    156 
    157         public function test_update_should_return_true_when_updating_existing_value_for_key() {
    158                 if ( ! is_site_meta_supported() ) {
    159                         $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
    160                 }
    161 
    162                 add_site_meta( self::$site_id, 'foo', 'bar' );
    163 
    164                 $actual = update_site_meta( self::$site_id, 'foo', 'baz' );
    165                 $this->assertTrue( $actual );
    166 
    167                 $meta = get_site_meta( self::$site_id, 'foo', true );
    168                 $this->assertSame( 'baz', $meta );
    169         }
    170 
    171         public function test_delete_by_key() {
    172                 if ( ! is_site_meta_supported() ) {
    173                         $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
    174                 }
    175 
    176                 add_site_meta( self::$site_id, 'unique_delete_by_key', 'value', true );
    177                 add_site_meta( self::$site_id2, 'unique_delete_by_key', 'value', true );
    178 
    179                 $this->assertEquals( 'value', get_site_meta( self::$site_id, 'unique_delete_by_key', true ) );
    180                 $this->assertEquals( 'value', get_site_meta( self::$site_id2, 'unique_delete_by_key', true ) );
    181 
    182                 $this->assertTrue( delete_site_meta_by_key( 'unique_delete_by_key' ) );
    183 
    184                 $this->assertEquals( '', get_site_meta( self::$site_id, 'unique_delete_by_key', true ) );
    185                 $this->assertEquals( '', get_site_meta( self::$site_id2, 'unique_delete_by_key', true ) );
    186         }
    187 
    188         public function test_site_meta_should_be_deleted_when_site_is_deleted() {
    189                 if ( ! is_site_meta_supported() ) {
    190                         $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
    191                 }
    192 
    193                 $site_id = self::factory()->blog->create( array( 'domain' => 'foo.org', 'path' => '/' ) );
    194 
    195                 add_site_meta( $site_id, 'foo', 'bar' );
    196                 add_site_meta( $site_id, 'foo1', 'bar' );
    197 
    198                 $this->assertSame( 'bar', get_site_meta( $site_id, 'foo', true ) );
    199                 $this->assertSame( 'bar', get_site_meta( $site_id, 'foo1', true ) );
    200 
    201                 wpmu_delete_blog( $site_id, true );
    202 
    203                 $this->assertSame( '', get_site_meta( $site_id, 'foo', true ) );
    204                 $this->assertSame( '', get_site_meta( $site_id, 'foo1', true ) );
    205         }
    206 
    207         public function test_update_site_meta_cache() {
    208                 global $wpdb;
    209 
    210                 if ( ! is_site_meta_supported() ) {
    211                         $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
    212                 }
    213 
    214                 update_site_meta( self::$site_id, 'foo', 'bar' );
    215                 update_sitemeta_cache( array( self::$site_id ) );
    216 
    217                 $num_queries = $wpdb->num_queries;
    218                 get_site_meta( self::$site_id, 'foo', true );
    219                 $this->assertSame( $num_queries, $wpdb->num_queries);
    220         }
    221 
    222         public function test_query_update_site_meta_cache_true() {
    223                 global $wpdb;
    224 
    225                 if ( ! is_site_meta_supported() ) {
    226                         $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
    227                 }
    228 
    229                 update_site_meta( self::$site_id, 'foo', 'bar' );
    230 
    231                 // Do not include 'update_site_meta_cache' as true as its the default.
    232                 new WP_Site_Query( array(
    233                         'ID' => self::$site_id,
    234                 ) );
    235 
    236                 $num_queries = $wpdb->num_queries;
    237                 get_site_meta( self::$site_id, 'foo', true );
    238                 $this->assertSame( $num_queries, $wpdb->num_queries);
    239         }
    240 
    241         public function test_query_update_site_meta_cache_false() {
    242                 global $wpdb;
    243 
    244                 if ( ! is_site_meta_supported() ) {
    245                         $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
    246                 }
    247 
    248                 update_site_meta( self::$site_id, 'foo', 'bar' );
    249 
    250                 new WP_Site_Query( array(
    251                         'ID'                     => self::$site_id,
    252                         'update_site_meta_cache' => false,
    253                 ) );
    254 
    255                 $num_queries = $wpdb->num_queries;
    256                 get_site_meta( self::$site_id, 'foo', true );
    257                 $this->assertSame( $num_queries + 1, $wpdb->num_queries);
    258         }
    259 
    260         /**
    261          * @ticket 40229
    262          */
    263         public function test_add_site_meta_should_bust_get_sites_cache() {
    264                 if ( ! is_site_meta_supported() ) {
    265                         $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
    266                 }
    267 
    268                 add_site_meta( self::$site_id, 'foo', 'bar' );
    269 
    270                 // Prime cache.
    271                 $found = get_sites( array(
    272                         'fields' => 'ids',
    273                         'meta_query' => array(
    274                                 array(
    275                                         'key' => 'foo',
    276                                         'value' => 'bar',
    277                                 ),
    278                         ),
    279                 ) );
    280 
    281                 $this->assertEqualSets( array( self::$site_id ), $found );
    282 
    283                 add_site_meta( self::$site_id2, 'foo', 'bar' );
    284 
    285                 $found = get_sites( array(
    286                         'fields' => 'ids',
    287                         'meta_query' => array(
    288                                 array(
    289                                         'key' => 'foo',
    290                                         'value' => 'bar',
    291                                 ),
    292                         ),
    293                 ) );
    294 
    295                 $this->assertEqualSets( array( self::$site_id, self::$site_id2 ), $found );
    296         }
    297 
    298         /**
    299          * @ticket 40229
    300          */
    301         public function test_update_site_meta_should_bust_get_sites_cache() {
    302                 if ( ! is_site_meta_supported() ) {
    303                         $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
    304                 }
    305 
    306                 add_site_meta( self::$site_id, 'foo', 'bar' );
    307                 add_site_meta( self::$site_id2, 'foo', 'baz' );
    308 
    309                 // Prime cache.
    310                 $found = get_sites( array(
    311                         'fields' => 'ids',
    312                         'meta_query' => array(
    313                                 array(
    314                                         'key' => 'foo',
    315                                         'value' => 'bar',
    316                                 ),
    317                         ),
    318                 ) );
    319 
    320                 $this->assertEqualSets( array( self::$site_id ), $found );
    321 
    322                 update_site_meta( self::$site_id2, 'foo', 'bar' );
    323 
    324                 $found = get_sites( array(
    325                         'fields' => 'ids',
    326                         'meta_query' => array(
    327                                 array(
    328                                         'key' => 'foo',
    329                                         'value' => 'bar',
    330                                 ),
    331                         ),
    332                 ) );
    333 
    334                 $this->assertEqualSets( array( self::$site_id, self::$site_id2 ), $found );
    335         }
    336 
    337         /**
    338          * @ticket 40229
    339          */
    340         public function test_delete_site_meta_should_bust_get_sites_cache() {
    341                 if ( ! is_site_meta_supported() ) {
    342                         $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
    343                 }
    344 
    345                 add_site_meta( self::$site_id, 'foo', 'bar' );
    346                 add_site_meta( self::$site_id2, 'foo', 'bar' );
    347 
    348                 // Prime cache.
    349                 $found = get_sites( array(
    350                         'fields' => 'ids',
    351                         'meta_query' => array(
    352                                 array(
    353                                         'key' => 'foo',
    354                                         'value' => 'bar',
    355                                 ),
    356                         ),
    357                 ) );
    358 
    359                 $this->assertEqualSets( array( self::$site_id, self::$site_id2 ), $found );
    360 
    361                 delete_site_meta( self::$site_id2, 'foo', 'bar' );
    362 
    363                 $found = get_sites( array(
    364                         'fields' => 'ids',
    365                         'meta_query' => array(
    366                                 array(
    367                                         'key' => 'foo',
    368                                         'value' => 'bar',
    369                                 ),
    370                         ),
    371                 ) );
    372 
    373                 $this->assertEqualSets( array( self::$site_id ), $found );
    374         }
    375 }
    376 
    377408endif;
Note: See TracChangeset for help on using the changeset viewer.