| 473 | |
| 474 | /** |
| 475 | * @ticket 40489 |
| 476 | * @dataProvider data_wp_is_large_network |
| 477 | */ |
| 478 | public function test_wp_is_large_network( $using, $count, $expected, $different_network ) { |
| 479 | $network_id = $different_network ? self::$different_network_id : null; |
| 480 | $network_option = 'users' === $using ? 'user_count' : 'blog_count'; |
| 481 | |
| 482 | update_network_option( $network_id, $network_option, $count ); |
| 483 | |
| 484 | $result = wp_is_large_network( $using, $network_id ); |
| 485 | if ( $expected ) { |
| 486 | $this->assertTrue( $result ); |
| 487 | } else { |
| 488 | $this->assertFalse( $result ); |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | public function data_wp_is_large_network() { |
| 493 | return array( |
| 494 | array( 'sites', 10000, false, false ), |
| 495 | array( 'sites', 10001, true, false ), |
| 496 | array( 'users', 10000, false, false ), |
| 497 | array( 'users', 10001, true, false ), |
| 498 | array( 'sites', 10000, false, true ), |
| 499 | array( 'sites', 10001, true, true ), |
| 500 | array( 'users', 10000, false, true ), |
| 501 | array( 'users', 10001, true, true ), |
| 502 | ); |
| 503 | } |
| 504 | |
| 505 | /** |
| 506 | * @ticket 40489 |
| 507 | * @dataProvider data_wp_is_large_network_filtered_by_component |
| 508 | */ |
| 509 | public function test_wp_is_large_network_filtered_by_component( $using, $count, $expected, $different_network ) { |
| 510 | $network_id = $different_network ? self::$different_network_id : null; |
| 511 | $network_option = 'users' === $using ? 'user_count' : 'blog_count'; |
| 512 | |
| 513 | update_network_option( $network_id, $network_option, $count ); |
| 514 | |
| 515 | add_filter( 'wp_is_large_network', array( $this, 'filter_wp_is_large_network_for_users' ), 10, 3 ); |
| 516 | $result = wp_is_large_network( $using, $network_id ); |
| 517 | remove_filter( 'wp_is_large_network', array( $this, 'filter_wp_is_large_network_for_users' ), 10 ); |
| 518 | |
| 519 | if ( $expected ) { |
| 520 | $this->assertTrue( $result ); |
| 521 | } else { |
| 522 | $this->assertFalse( $result ); |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | public function data_wp_is_large_network_filtered_by_component() { |
| 527 | return array( |
| 528 | array( 'sites', 10000, false, false ), |
| 529 | array( 'sites', 10001, true, false ), |
| 530 | array( 'users', 1000, false, false ), |
| 531 | array( 'users', 1001, true, false ), |
| 532 | array( 'sites', 10000, false, true ), |
| 533 | array( 'sites', 10001, true, true ), |
| 534 | array( 'users', 1000, false, true ), |
| 535 | array( 'users', 1001, true, true ), |
| 536 | ); |
| 537 | } |
| 538 | |
| 539 | public function filter_wp_is_large_network_for_users( $is_large_network, $using, $count ) { |
| 540 | if ( 'users' === $using ) { |
| 541 | return $count > 1000; |
| 542 | } |
| 543 | |
| 544 | return $is_large_network; |
| 545 | } |
| 546 | |
| 547 | /** |
| 548 | * @ticket 40489 |
| 549 | * @dataProvider data_wp_is_large_network_filtered_by_network |
| 550 | */ |
| 551 | public function test_wp_is_large_network_filtered_by_network( $using, $count, $expected, $different_network ) { |
| 552 | $network_id = $different_network ? self::$different_network_id : null; |
| 553 | $network_option = 'users' === $using ? 'user_count' : 'blog_count'; |
| 554 | |
| 555 | update_network_option( $network_id, $network_option, $count ); |
| 556 | |
| 557 | add_filter( 'wp_is_large_network', array( $this, 'filter_wp_is_large_network_on_different_network' ), 10, 4 ); |
| 558 | $result = wp_is_large_network( $using, $network_id ); |
| 559 | remove_filter( 'wp_is_large_network', array( $this, 'filter_wp_is_large_network_on_different_network' ), 10 ); |
| 560 | |
| 561 | if ( $expected ) { |
| 562 | $this->assertTrue( $result ); |
| 563 | } else { |
| 564 | $this->assertFalse( $result ); |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | public function data_wp_is_large_network_filtered_by_network() { |
| 569 | return array( |
| 570 | array( 'sites', 10000, false, false ), |
| 571 | array( 'sites', 10001, true, false ), |
| 572 | array( 'users', 10000, false, false ), |
| 573 | array( 'users', 10001, true, false ), |
| 574 | array( 'sites', 1000, false, true ), |
| 575 | array( 'sites', 1001, true, true ), |
| 576 | array( 'users', 1000, false, true ), |
| 577 | array( 'users', 1001, true, true ), |
| 578 | ); |
| 579 | } |
| 580 | |
| 581 | public function filter_wp_is_large_network_on_different_network( $is_large_network, $using, $count, $network_id ) { |
| 582 | if ( $network_id === (int) self::$different_network_id ) { |
| 583 | return $count > 1000; |
| 584 | } |
| 585 | |
| 586 | return $is_large_network; |
| 587 | } |