class-wp-unittest-factory-for-network.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * Unit test factory for networks.
  4. *
  5. * Note: The below @method notations are defined solely for the benefit of IDEs,
  6. * as a way to indicate expected return values from the given factory methods.
  7. *
  8. * @method int create( $args = array(), $generation_definitions = null )
  9. * @method WP_Network create_and_get( $args = array(), $generation_definitions = null )
  10. * @method int[] create_many( $count, $args = array(), $generation_definitions = null )
  11. */
  12. class WP_UnitTest_Factory_For_Network extends WP_UnitTest_Factory_For_Thing {
  13. public function __construct( $factory = null ) {
  14. parent::__construct( $factory );
  15. $this->default_generation_definitions = array(
  16. 'domain' => WP_TESTS_DOMAIN,
  17. 'title' => new WP_UnitTest_Generator_Sequence( 'Network %s' ),
  18. 'path' => new WP_UnitTest_Generator_Sequence( '/testpath%s/' ),
  19. 'network_id' => new WP_UnitTest_Generator_Sequence( '%s', 2 ),
  20. 'subdomain_install' => false,
  21. );
  22. }
  23. public function create_object( $args ) {
  24. require_once ABSPATH . 'wp-admin/includes/upgrade.php';
  25. if ( ! isset( $args['user'] ) ) {
  26. $email = WP_TESTS_EMAIL;
  27. } else {
  28. $email = get_userdata( $args['user'] )->user_email;
  29. }
  30. populate_network( $args['network_id'], $args['domain'], $email, $args['title'], $args['path'], $args['subdomain_install'] );
  31. return (int) $args['network_id'];
  32. }
  33. public function update_object( $network_id, $fields ) {}
  34. public function get_object_by_id( $network_id ) {
  35. return get_network( $network_id );
  36. }
  37. }