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(
|
2017-12-01 00:09:33 +01:00
|
|
|
'domain' => $current_site->domain,
|
|
|
|
'path' => new WP_UnitTest_Generator_Sequence( $base . 'testpath%s' ),
|
|
|
|
'title' => new WP_UnitTest_Generator_Sequence( 'Site %s' ),
|
2016-01-19 04:55:19 +01:00
|
|
|
'site_id' => $current_site->id,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-01-09 06:43:14 +01:00
|
|
|
/**
|
|
|
|
* Creates a blog object.
|
|
|
|
*
|
|
|
|
* @param array $args Arguments for the site object.
|
|
|
|
*
|
|
|
|
* @return int|WP_Error Returns WP_Error object on failure, the site ID on success.
|
|
|
|
*/
|
2019-03-15 13:15:08 +01:00
|
|
|
public function create_object( $args ) {
|
2016-01-19 04:55:19 +01:00
|
|
|
global $wpdb;
|
2017-12-01 00:09:33 +01:00
|
|
|
$meta = isset( $args['meta'] ) ? $args['meta'] : array( 'public' => 1 );
|
2016-01-19 04:55:19 +01:00
|
|
|
$user_id = isset( $args['user_id'] ) ? $args['user_id'] : get_current_user_id();
|
|
|
|
// temp tables will trigger db errors when we attempt to reference them as new temp tables
|
|
|
|
$suppress = $wpdb->suppress_errors();
|
2017-12-01 00:09:33 +01:00
|
|
|
$blog = wpmu_create_blog( $args['domain'], $args['path'], $args['title'], $user_id, $meta, $args['site_id'] );
|
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
|
|
|
/**
|
|
|
|
* Updates a blog object. Not implemented.
|
|
|
|
*
|
|
|
|
* @param int $blog_id The blog id to update.
|
|
|
|
* @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
|
|
|
/**
|
|
|
|
* Retrieves a site by given blog id.
|
|
|
|
*
|
|
|
|
* @param int $blog_id The blog id to retrieve.
|
|
|
|
*
|
|
|
|
* @return null|WP_Site The site object or null if not found.
|
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
}
|