Make WordPress Core


Ignore:
Timestamp:
04/27/2018 11:40:35 AM (8 years ago)
Author:
flixos90
Message:

Multisite: Add meta query functionality to WP_Site_Query.

After the introduction of site metadata in [42836], it should be possible to query sites by that data.

Fixes #40229.

File:
1 edited

Legend:

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

    r42836 r43010  
    257257        $this->assertSame( $num_queries + 1, $wpdb->num_queries);
    258258    }
     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    }
    259375}
    260376
Note: See TracChangeset for help on using the changeset viewer.