1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
<?php
/**
* Unit test factory for networks.
*
* 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|WP_Error create( $args = array(), $generation_definitions = null )
* @method WP_Network|WP_Error create_and_get( $args = array(), $generation_definitions = null )
* @method (int|WP_Error)[] create_many( $count, $args = array(), $generation_definitions = null )
*/
class WP_UnitTest_Factory_For_Network extends WP_UnitTest_Factory_For_Thing {
public function __construct( $factory = null ) {
parent::__construct( $factory );
$this->default_generation_definitions = array(
'domain' => WP_TESTS_DOMAIN,
'title' => new WP_UnitTest_Generator_Sequence( 'Network %s' ),
'path' => new WP_UnitTest_Generator_Sequence( '/testpath%s/' ),
'network_id' => new WP_UnitTest_Generator_Sequence( '%s', 2 ),
'subdomain_install' => false,
);
}
/**
* Creates a network object.
*
* @since 3.9.0
* @since 6.2.0 Returns a WP_Error object on failure.
*
* @param array $args Arguments for the network object.
*
* @return int|WP_Error The network ID on success, WP_Error object on failure.
*/
public function create_object( $args ) {
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
if ( ! isset( $args['user'] ) ) {
$email = WP_TESTS_EMAIL;
} else {
$email = get_userdata( $args['user'] )->user_email;
}
$result = populate_network(
$args['network_id'],
$args['domain'],
$email,
$args['title'],
$args['path'],
$args['subdomain_install']
);
if ( is_wp_error( $result ) ) {
return $result;
}
return (int) $args['network_id'];
}
/**
* Updates a network object. Not implemented.
*
* @since 3.9.0
*
* @param int $network_id ID of the network to update.
* @param array $fields The fields to update.
*/
public function update_object( $network_id, $fields ) {}
/**
* Retrieves a network by a given ID.
*
* @since 3.9.0
*
* @param int $network_id ID of the network to retrieve.
*
* @return WP_Network|null The network object on success, null on failure.
*/
public function get_object_by_id( $network_id ) {
return get_network( $network_id );
}
}
|