mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
Upgrade/Install: Introduce populate_network_meta(), moving logic out of populate_network().
Fixes #44895. See #41333. git-svn-id: https://develop.svn.wordpress.org/trunk@43628 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
// phpcs:ignoreFile WordPress.WP.PreparedSQL.NotPrepared
|
||||
|
||||
/**
|
||||
* @group admin
|
||||
@@ -6,6 +7,7 @@
|
||||
class Tests_Admin_Includes_Schema extends WP_UnitTestCase {
|
||||
|
||||
private static $options;
|
||||
private static $sitemeta;
|
||||
|
||||
/**
|
||||
* Make sure the schema code is loaded before the tests are run.
|
||||
@@ -14,8 +16,10 @@ class Tests_Admin_Includes_Schema extends WP_UnitTestCase {
|
||||
global $wpdb;
|
||||
|
||||
self::$options = 'testprefix_options';
|
||||
self::$sitemeta = 'testprefix_sitemeta';
|
||||
|
||||
$options = self::$options;
|
||||
$options = self::$options;
|
||||
$sitemeta = self::$sitemeta;
|
||||
|
||||
require_once( ABSPATH . 'wp-admin/includes/schema.php' );
|
||||
|
||||
@@ -34,6 +38,19 @@ class Tests_Admin_Includes_Schema extends WP_UnitTestCase {
|
||||
) {$charset_collate}
|
||||
"
|
||||
);
|
||||
$wpdb->query(
|
||||
"
|
||||
CREATE TABLE {$sitemeta} (
|
||||
meta_id bigint(20) unsigned NOT NULL auto_increment,
|
||||
site_id bigint(20) unsigned NOT NULL default '0',
|
||||
meta_key varchar(255) default NULL,
|
||||
meta_value longtext,
|
||||
PRIMARY KEY (meta_id),
|
||||
KEY meta_key (meta_key({$max_index_length})),
|
||||
KEY site_id (site_id)
|
||||
) {$charset_collate}
|
||||
"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,9 +59,11 @@ class Tests_Admin_Includes_Schema extends WP_UnitTestCase {
|
||||
public static function wpTearDownAfterClass() {
|
||||
global $wpdb;
|
||||
|
||||
$options = self::$options;
|
||||
$options = self::$options;
|
||||
$sitemeta = self::$sitemeta;
|
||||
|
||||
$wpdb->query( "DROP TABLE IF EXISTS {$options}" );
|
||||
$wpdb->query( "DROP TABLE IF EXISTS {$sitemeta}" );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,10 +73,6 @@ class Tests_Admin_Includes_Schema extends WP_UnitTestCase {
|
||||
function test_populate_options( $options, $expected ) {
|
||||
global $wpdb;
|
||||
|
||||
remove_all_filters( 'option_admin_email' );
|
||||
remove_all_filters( 'pre_option_admin_email' );
|
||||
remove_all_filters( 'default_option_admin_email' );
|
||||
|
||||
$orig_options = $wpdb->options;
|
||||
$wpdb->options = self::$options;
|
||||
|
||||
@@ -92,8 +107,8 @@ class Tests_Admin_Includes_Schema extends WP_UnitTestCase {
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'posts_per_rss' => 7,
|
||||
'rss_use_excerpt' => 1,
|
||||
'posts_per_rss' => 7,
|
||||
'rss_use_excerpt' => 1,
|
||||
),
|
||||
array(
|
||||
// Random options to check.
|
||||
@@ -129,15 +144,83 @@ class Tests_Admin_Includes_Schema extends WP_UnitTestCase {
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'rss_0123456789abcdef0123456789abcdef' => '1',
|
||||
'rss_0123456789abcdef0123456789abcdef' => '1',
|
||||
'rss_0123456789abcdef0123456789abcdef_ts' => '1',
|
||||
),
|
||||
array(
|
||||
// These options would be obsolete magpie cache data and should never exist.
|
||||
'rss_0123456789abcdef0123456789abcdef' => false,
|
||||
'rss_0123456789abcdef0123456789abcdef' => false,
|
||||
'rss_0123456789abcdef0123456789abcdef_ts' => false,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 44895
|
||||
* @dataProvider data_populate_network_meta
|
||||
*/
|
||||
function test_populate_network_meta( $meta, $expected ) {
|
||||
global $wpdb;
|
||||
|
||||
$orig_sitemeta = $wpdb->sitemeta;
|
||||
$wpdb->sitemeta = self::$sitemeta;
|
||||
|
||||
populate_network_meta( 42, $meta );
|
||||
|
||||
$results = array();
|
||||
foreach ( $expected as $meta_key => $value ) {
|
||||
if ( is_multisite() ) {
|
||||
$results[ $meta_key ] = get_network_option( 42, $meta_key );
|
||||
} else {
|
||||
$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 ) );
|
||||
}
|
||||
}
|
||||
|
||||
$wpdb->query( "TRUNCATE TABLE {$wpdb->sitemeta}" );
|
||||
|
||||
$wpdb->sitemeta = $orig_sitemeta;
|
||||
|
||||
$this->assertEquals( $expected, $results );
|
||||
}
|
||||
|
||||
public function data_populate_network_meta() {
|
||||
return array(
|
||||
array(
|
||||
array(),
|
||||
array(
|
||||
// Random meta to check.
|
||||
'registration' => 'none',
|
||||
'blog_upload_space' => 100,
|
||||
'fileupload_maxk' => 1500,
|
||||
),
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'site_name' => 'My Great Network',
|
||||
'WPLANG' => 'fr_FR',
|
||||
),
|
||||
array(
|
||||
// Random meta to check.
|
||||
'site_name' => 'My Great Network',
|
||||
'registration' => 'none',
|
||||
'blog_upload_space' => 100,
|
||||
'fileupload_maxk' => 1500,
|
||||
'WPLANG' => 'fr_FR',
|
||||
),
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'custom_meta' => '1',
|
||||
),
|
||||
array(
|
||||
// Random meta to check.
|
||||
'custom_meta' => '1',
|
||||
'registration' => 'none',
|
||||
'blog_upload_space' => 100,
|
||||
'fileupload_maxk' => 1500,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user