Changeset 30174 for trunk/tests/phpunit/tests/multisite/site.php
- Timestamp:
- 11/01/2014 11:39:22 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/multisite/site.php
r30152 r30174 672 672 673 673 /** 674 * Test the default arguments for wp_get_sites, which should return only 675 * public sites from the current network. 676 * 674 677 * @ticket 14511 675 678 */ 676 function test_wp_get_sites() { 677 $this->factory->blog->create_many( 2, array( 'site_id' => 2, 'meta' => array( 'public' => 1 ) ) ); 678 $this->factory->blog->create_many( 3, array( 'site_id' => 3, 'meta' => array( 'public' => 0 ) ) ); 679 680 // Expect no sites when passed an invalid network_id 681 $this->assertCount( 0, wp_get_sites( array( 'network_id' => 0 ) ) ); 682 $this->assertCount( 0, wp_get_sites( array( 'network_id' => 4 ) ) ); 683 684 // Expect 1 site when no network_id is specified - defaults to current network. 679 function test_wp_get_sites_with_default_arguments() { 680 $this->factory->blog->create( array( 'site_id' => 2 ) ); 681 685 682 $this->assertCount( 1, wp_get_sites() ); 686 // Expect 6 sites when network_id = null. 687 $this->assertCount( 6, wp_get_sites( array( 'network_id' => null ) ) ); 688 689 // Expect 1 site with a network_id of 1, 2 for network_id 2, 3 for 3 690 $this->assertCount( 1, wp_get_sites( array( 'network_id' => 1 ) ) ); 691 $this->assertCount( 2, wp_get_sites( array( 'network_id' => 2 ) ) ); 692 $this->assertCount( 3, wp_get_sites( array( 'network_id' => 3 ) ) ); 693 694 // Expect 6 sites when public is null (across all networks) 695 $this->assertCount( 6, wp_get_sites( array( 'public' => null, 'network_id' => null ) ) ); 696 697 // Expect 3 sites when public is 1 698 $this->assertCount( 3, wp_get_sites( array( 'public' => 1, 'network_id' => null ) ) ); 699 700 // Expect 2 sites when public is 1 and network_id is 2 701 $this->assertCount( 2, wp_get_sites( array( 'network_id' => 2, 'public' => 1 ) ) ); 702 703 // Expect no sites when public is set to 0 and network_id is not 3 704 $this->assertCount( 0, wp_get_sites( array( 'network_id' => 1, 'public' => 0 ) ) ); 705 706 // Test public + network_id = 3 707 $this->assertCount( 0, wp_get_sites( array( 'network_id' => 3, 'public' => 1 ) ) ); 708 $this->assertCount( 3, wp_get_sites( array( 'network_id' => 3, 'public' => 0 ) ) ); 709 } 710 711 /** 712 * @ticket 14511 683 } 684 685 /** 686 * No sites should match a query that specifies an invalid network ID. 687 */ 688 function test_wp_get_sites_with_invalid_network_id() { 689 $this->assertcount( 0, wp_get_sites( array( 'network_id' => 999 ) ) ); 690 } 691 692 /** 693 * A network ID of null should query for all public sites on all networks. 694 */ 695 function test_wp_get_sites_with_network_id_null() { 696 $this->factory->blog->create( array( 'site_id' => 2 ) ); 697 698 $this->assertCount( 2, wp_get_sites( array( 'network_id' => null ) ) ); 699 } 700 701 /** 702 * Expect only sites on the specified network ID to be returned. 703 */ 704 function test_wp_get_sites_with_specific_network_id() { 705 $this->factory->blog->create( array( 'site_id' => 2 ) ); 706 707 $this->assertCount( 1, wp_get_sites( array( 'network_id' => 2 ) ) ); 708 } 709 710 /** 711 * Expect sites from both networks if both network IDs are specified. 712 */ 713 function test_wp_get_sites_with_multiple_network_ids() { 714 $this->factory->blog->create( array( 'site_id' => 2 ) ); 715 716 $this->assertCount( 2, wp_get_sites( array( 'network_id' => array( 1, 2 ) ) ) ); 717 } 718 719 /** 720 * Queries for public or non public sites should work across all networks if network ID is null. 721 */ 722 function test_wp_get_sites_with_public_meta_on_all_networks() { 723 $this->factory->blog->create( array( 'site_id' => 2, 'meta' => array( 'public' => 0 ) ) ); 724 725 $this->assertCount( 1, wp_get_sites( array( 'public' => 1, 'network_id' => null ) ) ); 726 $this->assertcount( 1, wp_get_sites( array( 'public' => 0, 'network_id' => null ) ) ); 727 } 728 729 /** 730 * If a network ID is specified, queries for public sites should be restricted to that network. 731 */ 732 function test_wp_get_sites_with_public_meta_restrict_to_one_network() { 733 $this->factory->blog->create( array( 'site_id' => 1, 'meta' => array( 'public' => 0 ) ) ); 734 735 $this->assertCount( 1, wp_get_sites( array( 'public' => 1, 'network_id' => 1 ) ) ); 736 $this->assertCount( 0, wp_get_sites( array( 'public' => 1, 'network_id' => 2 ) ) ); 737 } 738 739 /** 740 * Test the limit and offset arguments for wp_get_sites when multiple sites are available. 713 741 */ 714 742 function test_wp_get_sites_limit_offset() { 715 // Create 4 more sites (in addition to the default one) 716 $this->factory->blog->create_many( 4, array( 'meta' => array( 'public' => 1 ) ) ); 717 718 // Expect all 5 sites when no limit/offset is specified 719 $this->assertCount( 5, wp_get_sites() ); 743 // Create 2 more sites (in addition to the default one) 744 $this->factory->blog->create_many( 2 ); 720 745 721 746 // Expect first 2 sites when using limit 722 747 $this->assertCount( 2, wp_get_sites( array( 'limit' => 2 ) ) ); 723 748 724 // Expect only the last 3 sites when using offset of 2 (limit will default to 100) 725 $this->assertCount( 3, wp_get_sites( array( 'offset' => 2 ) ) ); 726 727 // Expect only the last 1 site when using offset of 4 and limit of 2 728 $this->assertCount( 1, wp_get_sites( array( 'limit' => 2, 'offset' => 4 ) ) ); 729 730 // Expect 0 sites when using an offset larger than the number of sites 749 // Expect only the last 2 sites when using offset of 1 (limit will default to 100) 750 $this->assertCount( 2, wp_get_sites( array( 'offset' => 1 ) ) ); 751 752 // Expect only the last 1 site when using offset of 2 and limit of 2 753 $this->assertCount( 1, wp_get_sites( array( 'limit' => 2, 'offset' => 2 ) ) ); 754 } 755 756 /** 757 * Expect 0 sites when using an offset larger than the total number of sites. 758 */ 759 function test_wp_get_sites_offset_greater_than_available_sites() { 731 760 $this->assertCount( 0, wp_get_sites( array( 'offset' => 20 ) ) ); 732 761 } 733 734 762 735 763 /**
Note: See TracChangeset
for help on using the changeset viewer.