Make WordPress Core


Ignore:
Timestamp:
09/05/2018 10:44:02 AM (8 years ago)
Author:
flixos90
Message:

Upgrade/Install: Introduce populate_network_meta(), moving logic out of populate_network().

Fixes #44895. See #41333.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/admin/includesSchema.php

    r43627 r43628  
    11<?php
     2// phpcs:ignoreFile WordPress.WP.PreparedSQL.NotPrepared
    23
    34/**
     
    78
    89        private static $options;
     10        private static $sitemeta;
    911
    1012        /**
     
    1517
    1618                self::$options  = 'testprefix_options';
    17 
    18                 $options = self::$options;
     19                self::$sitemeta = 'testprefix_sitemeta';
     20
     21                $options  = self::$options;
     22                $sitemeta = self::$sitemeta;
    1923
    2024                require_once( ABSPATH . 'wp-admin/includes/schema.php' );
     
    3539                        "
    3640                );
     41                $wpdb->query(
     42                        "
     43                        CREATE TABLE {$sitemeta} (
     44                                meta_id bigint(20) unsigned NOT NULL auto_increment,
     45                                site_id bigint(20) unsigned NOT NULL default '0',
     46                                meta_key varchar(255) default NULL,
     47                                meta_value longtext,
     48                                PRIMARY KEY  (meta_id),
     49                                KEY meta_key (meta_key({$max_index_length})),
     50                                KEY site_id (site_id)
     51                        ) {$charset_collate}
     52                        "
     53                );
    3754        }
    3855
     
    4360                global $wpdb;
    4461
    45                 $options = self::$options;
     62                $options  = self::$options;
     63                $sitemeta = self::$sitemeta;
    4664
    4765                $wpdb->query( "DROP TABLE IF EXISTS {$options}" );
     66                $wpdb->query( "DROP TABLE IF EXISTS {$sitemeta}" );
    4867        }
    4968
     
    5473        function test_populate_options( $options, $expected ) {
    5574                global $wpdb;
    56 
    57                 remove_all_filters( 'option_admin_email' );
    58                 remove_all_filters( 'pre_option_admin_email' );
    59                 remove_all_filters( 'default_option_admin_email' );
    6075
    6176                $orig_options  = $wpdb->options;
     
    93108                        array(
    94109                                array(
    95                                         'posts_per_rss'    => 7,
    96                                         'rss_use_excerpt'  => 1,
     110                                        'posts_per_rss'   => 7,
     111                                        'rss_use_excerpt' => 1,
    97112                                ),
    98113                                array(
     
    130145                        array(
    131146                                array(
    132                                         'rss_0123456789abcdef0123456789abcdef'    => '1',
     147                                        'rss_0123456789abcdef0123456789abcdef' => '1',
    133148                                        'rss_0123456789abcdef0123456789abcdef_ts' => '1',
    134149                                ),
    135150                                array(
    136151                                        // These options would be obsolete magpie cache data and should never exist.
    137                                         'rss_0123456789abcdef0123456789abcdef'    => false,
     152                                        'rss_0123456789abcdef0123456789abcdef' => false,
    138153                                        'rss_0123456789abcdef0123456789abcdef_ts' => false,
    139154                                ),
     
    141156                );
    142157        }
     158
     159        /**
     160         * @ticket 44895
     161         * @dataProvider data_populate_network_meta
     162         */
     163        function test_populate_network_meta( $meta, $expected ) {
     164                global $wpdb;
     165
     166                $orig_sitemeta  = $wpdb->sitemeta;
     167                $wpdb->sitemeta = self::$sitemeta;
     168
     169                populate_network_meta( 42, $meta );
     170
     171                $results = array();
     172                foreach ( $expected as $meta_key => $value ) {
     173                        if ( is_multisite() ) {
     174                                $results[ $meta_key ] = get_network_option( 42, $meta_key );
     175                        } else {
     176                                $results[ $meta_key ] = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $meta_key, 42 ) );
     177                        }
     178                }
     179
     180                $wpdb->query( "TRUNCATE TABLE {$wpdb->sitemeta}" );
     181
     182                $wpdb->sitemeta = $orig_sitemeta;
     183
     184                $this->assertEquals( $expected, $results );
     185        }
     186
     187        public function data_populate_network_meta() {
     188                return array(
     189                        array(
     190                                array(),
     191                                array(
     192                                        // Random meta to check.
     193                                        'registration'      => 'none',
     194                                        'blog_upload_space' => 100,
     195                                        'fileupload_maxk'   => 1500,
     196                                ),
     197                        ),
     198                        array(
     199                                array(
     200                                        'site_name' => 'My Great Network',
     201                                        'WPLANG'    => 'fr_FR',
     202                                ),
     203                                array(
     204                                        // Random meta to check.
     205                                        'site_name'         => 'My Great Network',
     206                                        'registration'      => 'none',
     207                                        'blog_upload_space' => 100,
     208                                        'fileupload_maxk'   => 1500,
     209                                        'WPLANG'            => 'fr_FR',
     210                                ),
     211                        ),
     212                        array(
     213                                array(
     214                                        'custom_meta' => '1',
     215                                ),
     216                                array(
     217                                        // Random meta to check.
     218                                        'custom_meta'       => '1',
     219                                        'registration'      => 'none',
     220                                        'blog_upload_space' => 100,
     221                                        'fileupload_maxk'   => 1500,
     222                                ),
     223                        ),
     224                );
     225        }
    143226}
Note: See TracChangeset for help on using the changeset viewer.