2016-01-19 04:55:19 +01:00
|
|
|
<?php
|
|
|
|
|
2017-06-30 06:35:39 +02:00
|
|
|
/**
|
|
|
|
* Unit test factory for sites on a multisite network.
|
|
|
|
*
|
|
|
|
* Note: The below @method notations are defined solely for the benefit of IDEs,
|
|
|
|
* as a way to indicate expected return values from the given factory methods.
|
|
|
|
*
|
|
|
|
* @method int create( $args = array(), $generation_definitions = null )
|
|
|
|
* @method WP_Site create_and_get( $args = array(), $generation_definitions = null )
|
|
|
|
* @method int[] create_many( $count, $args = array(), $generation_definitions = null )
|
|
|
|
*/
|
2016-01-19 04:55:19 +01:00
|
|
|
class WP_UnitTest_Factory_For_Blog extends WP_UnitTest_Factory_For_Thing {
|
|
|
|
|
2019-03-15 13:15:08 +01:00
|
|
|
public function __construct( $factory = null ) {
|
2016-01-19 04:55:19 +01:00
|
|
|
global $current_site, $base;
|
|
|
|
parent::__construct( $factory );
|
|
|
|
$this->default_generation_definitions = array(
|
2019-12-26 01:25:20 +01:00
|
|
|
'domain' => $current_site->domain,
|
|
|
|
'path' => new WP_UnitTest_Generator_Sequence( $base . 'testpath%s' ),
|
|
|
|
'title' => new WP_UnitTest_Generator_Sequence( 'Site %s' ),
|
|
|
|
'network_id' => $current_site->id,
|
2016-01-19 04:55:19 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-01-09 06:43:14 +01:00
|
|
|
/**
|
2019-12-18 01:17:54 +01:00
|
|
|
* Creates a site object.
|
2019-01-09 06:43:14 +01:00
|
|
|
*
|
|
|
|
* @param array $args Arguments for the site object.
|
|
|
|
*
|
2019-12-18 01:17:54 +01:00
|
|
|
* @return int|WP_Error The site ID on success, WP_Error object on failure.
|
2019-01-09 06:43:14 +01:00
|
|
|
*/
|
2019-03-15 13:15:08 +01:00
|
|
|
public function create_object( $args ) {
|
2016-01-19 04:55:19 +01:00
|
|
|
global $wpdb;
|
2019-12-25 19:10:19 +01:00
|
|
|
|
2019-12-25 22:39:46 +01:00
|
|
|
// Map some arguments for backward compatibility with `wpmu_create_blog()` previously used here.
|
2019-12-26 01:25:20 +01:00
|
|
|
if ( isset( $args['site_id'] ) ) {
|
2019-12-25 19:10:19 +01:00
|
|
|
$args['network_id'] = $args['site_id'];
|
|
|
|
unset( $args['site_id'] );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( isset( $args['meta'] ) ) {
|
General: Remove “whitelist” and “blacklist” in favor of more clear and inclusive language.
“The WordPress open source community cares about diversity. We strive to maintain a welcoming environment where everyone can feel included.”
With this commit, all occurrences of “whitelist” and “blacklist” (with the single exception of the `$new_whitelist_options` global variable) are removed. A new ticket has been opened to explore renaming the `$new_whitelist_options` variable (#50434).
Changing to more specific names or rewording sentences containing these terms not only makes the code more inclusive, but also helps provide clarity. These terms are often ambiguous. What is being blocked or allowed is not always immediately clear. This can make it more difficult for non-native English speakers to read through the codebase.
Words matter. If one contributor feels more welcome because these terms are removed, this was worth the effort.
Props strangerstudios, jorbin, desrosj, joemcgill, timothyblynjacobs, ocean90, ayeshrajans, davidbaumwald, earnjam.
See #48900, #50434.
Fixes #50413.
git-svn-id: https://develop.svn.wordpress.org/trunk@48121 602fd350-edb4-49c9-b593-d223f7449a82
2020-06-22 19:24:34 +02:00
|
|
|
// The `$allowed_data_fields` matches the one used in `wpmu_create_blog()`.
|
|
|
|
$allowed_data_fields = array( 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id' );
|
2019-12-25 19:10:19 +01:00
|
|
|
|
|
|
|
foreach ( $args['meta'] as $key => $value ) {
|
General: Remove “whitelist” and “blacklist” in favor of more clear and inclusive language.
“The WordPress open source community cares about diversity. We strive to maintain a welcoming environment where everyone can feel included.”
With this commit, all occurrences of “whitelist” and “blacklist” (with the single exception of the `$new_whitelist_options` global variable) are removed. A new ticket has been opened to explore renaming the `$new_whitelist_options` variable (#50434).
Changing to more specific names or rewording sentences containing these terms not only makes the code more inclusive, but also helps provide clarity. These terms are often ambiguous. What is being blocked or allowed is not always immediately clear. This can make it more difficult for non-native English speakers to read through the codebase.
Words matter. If one contributor feels more welcome because these terms are removed, this was worth the effort.
Props strangerstudios, jorbin, desrosj, joemcgill, timothyblynjacobs, ocean90, ayeshrajans, davidbaumwald, earnjam.
See #48900, #50434.
Fixes #50413.
git-svn-id: https://develop.svn.wordpress.org/trunk@48121 602fd350-edb4-49c9-b593-d223f7449a82
2020-06-22 19:24:34 +02:00
|
|
|
// Promote allowed keys to top-level arguments, add others to the options array.
|
|
|
|
if ( in_array( $key, $allowed_data_fields, true ) ) {
|
2019-12-25 19:10:19 +01:00
|
|
|
$args[ $key ] = $value;
|
|
|
|
} else {
|
|
|
|
$args['options'][ $key ] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unset( $args['meta'] );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Temporary tables will trigger DB errors when we attempt to reference them as new temporary tables.
|
2016-01-19 04:55:19 +01:00
|
|
|
$suppress = $wpdb->suppress_errors();
|
2019-12-25 19:10:19 +01:00
|
|
|
|
|
|
|
$blog = wp_insert_site( $args );
|
|
|
|
|
2016-01-19 04:55:19 +01:00
|
|
|
$wpdb->suppress_errors( $suppress );
|
|
|
|
|
|
|
|
// Tell WP we're done installing.
|
|
|
|
wp_installing( false );
|
|
|
|
|
|
|
|
return $blog;
|
|
|
|
}
|
|
|
|
|
2019-01-09 06:43:14 +01:00
|
|
|
/**
|
2019-12-18 01:17:54 +01:00
|
|
|
* Updates a site object. Not implemented.
|
2019-01-09 06:43:14 +01:00
|
|
|
*
|
2019-12-18 01:17:54 +01:00
|
|
|
* @param int $blog_id ID of the site to update.
|
2019-01-09 06:43:14 +01:00
|
|
|
* @param array $fields The fields to update.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-03-15 13:15:08 +01:00
|
|
|
public function update_object( $blog_id, $fields ) {}
|
2016-01-19 04:55:19 +01:00
|
|
|
|
2019-01-09 06:43:14 +01:00
|
|
|
/**
|
2019-12-18 01:17:54 +01:00
|
|
|
* Retrieves a site by a given ID.
|
2019-01-09 06:43:14 +01:00
|
|
|
*
|
2019-12-18 01:17:54 +01:00
|
|
|
* @param int $blog_id ID of the site to retrieve.
|
2019-01-09 06:43:14 +01:00
|
|
|
*
|
2019-12-18 01:17:54 +01:00
|
|
|
* @return WP_Site|null The site object on success, null on failure.
|
2019-01-09 06:43:14 +01:00
|
|
|
*/
|
2019-03-15 13:15:08 +01:00
|
|
|
public function get_object_by_id( $blog_id ) {
|
2016-10-26 01:03:15 +02:00
|
|
|
return get_site( $blog_id );
|
2016-01-19 04:55:19 +01:00
|
|
|
}
|
|
|
|
}
|