12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- class WP_UnitTest_Factory_For_Blog extends WP_UnitTest_Factory_For_Thing {
- public function __construct( $factory = null ) {
- global $current_site, $base;
- parent::__construct( $factory );
- $this->default_generation_definitions = array(
- '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,
- );
- }
-
- public function create_object( $args ) {
- global $wpdb;
-
- if ( isset( $args['site_id'] ) ) {
- $args['network_id'] = $args['site_id'];
- unset( $args['site_id'] );
- }
- if ( isset( $args['meta'] ) ) {
-
- $allowed_data_fields = array( 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id' );
- foreach ( $args['meta'] as $key => $value ) {
-
- if ( in_array( $key, $allowed_data_fields, true ) ) {
- $args[ $key ] = $value;
- } else {
- $args['options'][ $key ] = $value;
- }
- }
- unset( $args['meta'] );
- }
-
- $suppress = $wpdb->suppress_errors();
- $blog = wp_insert_site( $args );
- $wpdb->suppress_errors( $suppress );
-
- wp_installing( false );
- return $blog;
- }
-
- public function update_object( $blog_id, $fields ) {}
-
- public function get_object_by_id( $blog_id ) {
- return get_site( $blog_id );
- }
- }
|