Changeset 37234 for trunk/tests/phpunit/tests/multisite/bootstrap.php
- Timestamp:
- 04/18/2016 01:37:47 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/multisite/bootstrap.php
r35242 r37234 10 10 */ 11 11 class Tests_Multisite_Bootstrap extends WP_UnitTestCase { 12 protected $suppress = false; 13 14 function setUp() { 15 global $wpdb; 16 parent::setUp(); 17 $this->suppress = $wpdb->suppress_errors(); 18 } 19 20 function tearDown() { 21 global $wpdb; 22 $wpdb->suppress_errors( $this->suppress ); 23 parent::tearDown(); 24 } 25 26 27 /** 28 * @ticket 27003 29 */ 30 function test_get_network_by_path() { 31 global $wpdb; 32 33 $ids = array( 12 protected static $network_ids; 13 protected static $site_ids; 14 15 public static function wpSetUpBeforeClass( $factory ) { 16 self::$network_ids = array( 34 17 'wordpress.org/' => array( 'domain' => 'wordpress.org', 'path' => '/' ), 18 'make.wordpress.org/' => array( 'domain' => 'make.wordpress.org', 'path' => '/' ), 35 19 'wordpress.org/one/' => array( 'domain' => 'wordpress.org', 'path' => '/one/' ), 36 20 'wordpress.net/' => array( 'domain' => 'wordpress.net', 'path' => '/' ), … … 40 24 ); 41 25 42 foreach ( $ids as &$id ) {43 $id = self::factory()->network->create( $id );26 foreach ( self::$network_ids as &$id ) { 27 $id = $factory->network->create( $id ); 44 28 } 45 29 unset( $id ); 46 30 47 $this->assertEquals( $ids['www.wordpress.net/'], 48 get_network_by_path( 'www.wordpress.net', '/notapath/' )->id ); 49 50 $this->assertEquals( $ids['www.wordpress.net/two/'], 51 get_network_by_path( 'www.wordpress.net', '/two/' )->id ); 52 53 // This should find /one/ despite the www. 54 $this->assertEquals( $ids['wordpress.org/one/'], 55 get_network_by_path( 'www.wordpress.org', '/one/' )->id ); 56 57 // This should not find /one/ because the domains don't match. 58 $this->assertEquals( $ids['wordpress.org/'], 59 get_network_by_path( 'site1.wordpress.org', '/one/' )->id ); 60 61 $this->assertEquals( $ids['wordpress.net/three/'], 62 get_network_by_path( 'wordpress.net', '/three/' )->id ); 63 64 $this->assertEquals( $ids['wordpress.net/'], 65 get_network_by_path( 'wordpress.net', '/notapath/' )->id ); 66 67 $this->assertEquals( $ids['wordpress.net/'], 68 get_network_by_path( 'site1.wordpress.net', '/notapath/' )->id ); 69 70 $this->assertEquals( $ids['wordpress.net/'], 71 get_network_by_path( 'site1.wordpress.net', '/three/' )->id ); 72 } 73 74 /** 75 * @ticket 27003 76 * @ticket 27927 77 */ 78 function test_get_site_by_path() { 79 $ids = array( 80 'wordpress.org/' => array( 'domain' => 'wordpress.org', 'path' => '/' ), 81 'wordpress.org/foo/' => array( 'domain' => 'wordpress.org', 'path' => '/foo/' ), 82 'wordpress.org/foo/bar/' => array( 'domain' => 'wordpress.org', 'path' => '/foo/bar/' ), 83 'make.wordpress.org/' => array( 'domain' => 'make.wordpress.org', 'path' => '/' ), 84 'make.wordpress.org/foo/' => array( 'domain' => 'make.wordpress.org', 'path' => '/foo/' ), 31 self::$site_ids = array( 32 'wordpress.org/' => array( 'domain' => 'wordpress.org', 'path' => '/', 'site_id' => self::$network_ids['wordpress.org/'] ), 33 'wordpress.org/foo/' => array( 'domain' => 'wordpress.org', 'path' => '/foo/', 'site_id' => self::$network_ids['wordpress.org/'] ), 34 'wordpress.org/foo/bar/' => array( 'domain' => 'wordpress.org', 'path' => '/foo/bar/', 'site_id' => self::$network_ids['wordpress.org/'] ), 35 'make.wordpress.org/' => array( 'domain' => 'make.wordpress.org', 'path' => '/', 'site_id' => self::$network_ids['make.wordpress.org/'] ), 36 'make.wordpress.org/foo/' => array( 'domain' => 'make.wordpress.org', 'path' => '/foo/', 'site_id' => self::$network_ids['make.wordpress.org/'] ), 85 37 'www.w.org/' => array( 'domain' => 'www.w.org', 'path' => '/' ), 86 38 'www.w.org/foo/' => array( 'domain' => 'www.w.org', 'path' => '/foo/' ), … … 88 40 ); 89 41 90 foreach ( $ids as &$id ) {91 $id = self::factory()->blog->create( $id );42 foreach ( self::$site_ids as &$id ) { 43 $id = $factory->blog->create( $id ); 92 44 } 93 45 unset( $id ); 94 95 $this->assertEquals( $ids['wordpress.org/'], 46 } 47 48 public static function wpTearDownAfterClass() { 49 global $wpdb; 50 51 foreach( self::$site_ids as $id ) { 52 wpmu_delete_blog( $id, true ); 53 } 54 55 foreach( self::$network_ids as $id ) { 56 $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->sitemeta} WHERE site_id = %d", $id ) ); 57 $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->site} WHERE id= %d", $id ) ); 58 } 59 60 wp_update_network_site_counts(); 61 } 62 63 /** 64 * @ticket 27003 65 */ 66 function test_get_network_by_path() { 67 $this->assertEquals( self::$network_ids['www.wordpress.net/'], 68 get_network_by_path( 'www.wordpress.net', '/notapath/' )->id ); 69 70 $this->assertEquals( self::$network_ids['www.wordpress.net/two/'], 71 get_network_by_path( 'www.wordpress.net', '/two/' )->id ); 72 73 // This should find /one/ despite the www. 74 $this->assertEquals( self::$network_ids['wordpress.org/one/'], 75 get_network_by_path( 'www.wordpress.org', '/one/' )->id ); 76 77 // This should not find /one/ because the domains don't match. 78 $this->assertEquals( self::$network_ids['wordpress.org/'], 79 get_network_by_path( 'site1.wordpress.org', '/one/' )->id ); 80 81 $this->assertEquals( self::$network_ids['wordpress.net/three/'], 82 get_network_by_path( 'wordpress.net', '/three/' )->id ); 83 84 $this->assertEquals( self::$network_ids['wordpress.net/'], 85 get_network_by_path( 'wordpress.net', '/notapath/' )->id ); 86 87 $this->assertEquals( self::$network_ids['wordpress.net/'], 88 get_network_by_path( 'site1.wordpress.net', '/notapath/' )->id ); 89 90 $this->assertEquals( self::$network_ids['wordpress.net/'], 91 get_network_by_path( 'site1.wordpress.net', '/three/' )->id ); 92 } 93 94 /** 95 * @ticket 27003 96 * @ticket 27927 97 */ 98 function test_get_site_by_path() { 99 $this->assertEquals( self::$site_ids['wordpress.org/'], 96 100 get_site_by_path( 'wordpress.org', '/notapath/' )->blog_id ); 97 101 98 $this->assertEquals( $ids['wordpress.org/'],102 $this->assertEquals( self::$site_ids['wordpress.org/'], 99 103 get_site_by_path( 'www.wordpress.org', '/notapath/' )->blog_id ); 100 104 101 $this->assertEquals( $ids['wordpress.org/foo/bar/'],105 $this->assertEquals( self::$site_ids['wordpress.org/foo/bar/'], 102 106 get_site_by_path( 'wordpress.org', '/foo/bar/baz/' )->blog_id ); 103 107 104 $this->assertEquals( $ids['wordpress.org/foo/bar/'],108 $this->assertEquals( self::$site_ids['wordpress.org/foo/bar/'], 105 109 get_site_by_path( 'www.wordpress.org', '/foo/bar/baz/' )->blog_id ); 106 110 107 $this->assertEquals( $ids['wordpress.org/foo/bar/'],111 $this->assertEquals( self::$site_ids['wordpress.org/foo/bar/'], 108 112 get_site_by_path( 'wordpress.org', '/foo/bar/baz/', 3 )->blog_id ); 109 113 110 $this->assertEquals( $ids['wordpress.org/foo/bar/'],114 $this->assertEquals( self::$site_ids['wordpress.org/foo/bar/'], 111 115 get_site_by_path( 'www.wordpress.org', '/foo/bar/baz/', 3 )->blog_id ); 112 116 113 $this->assertEquals( $ids['wordpress.org/foo/bar/'],117 $this->assertEquals( self::$site_ids['wordpress.org/foo/bar/'], 114 118 get_site_by_path( 'wordpress.org', '/foo/bar/baz/', 2 )->blog_id ); 115 119 116 $this->assertEquals( $ids['wordpress.org/foo/bar/'],120 $this->assertEquals( self::$site_ids['wordpress.org/foo/bar/'], 117 121 get_site_by_path( 'www.wordpress.org', '/foo/bar/baz/', 2 )->blog_id ); 118 122 119 $this->assertEquals( $ids['wordpress.org/foo/'],123 $this->assertEquals( self::$site_ids['wordpress.org/foo/'], 120 124 get_site_by_path( 'wordpress.org', '/foo/bar/baz/', 1 )->blog_id ); 121 125 122 $this->assertEquals( $ids['wordpress.org/foo/'],126 $this->assertEquals( self::$site_ids['wordpress.org/foo/'], 123 127 get_site_by_path( 'www.wordpress.org', '/foo/bar/baz/', 1 )->blog_id ); 124 128 125 $this->assertEquals( $ids['wordpress.org/'],129 $this->assertEquals( self::$site_ids['wordpress.org/'], 126 130 get_site_by_path( 'wordpress.org', '/', 0 )->blog_id ); 127 131 128 $this->assertEquals( $ids['wordpress.org/'],132 $this->assertEquals( self::$site_ids['wordpress.org/'], 129 133 get_site_by_path( 'www.wordpress.org', '/', 0 )->blog_id ); 130 134 131 $this->assertEquals( $ids['make.wordpress.org/foo/'],135 $this->assertEquals( self::$site_ids['make.wordpress.org/foo/'], 132 136 get_site_by_path( 'make.wordpress.org', '/foo/bar/baz/qux/', 4 )->blog_id ); 133 137 134 $this->assertEquals( $ids['make.wordpress.org/foo/'],138 $this->assertEquals( self::$site_ids['make.wordpress.org/foo/'], 135 139 get_site_by_path( 'www.make.wordpress.org', '/foo/bar/baz/qux/', 4 )->blog_id ); 136 140 137 $this->assertEquals( $ids['www.w.org/'],141 $this->assertEquals( self::$site_ids['www.w.org/'], 138 142 get_site_by_path( 'www.w.org', '/', 0 )->blog_id ); 139 143 140 $this->assertEquals( $ids['www.w.org/'],144 $this->assertEquals( self::$site_ids['www.w.org/'], 141 145 get_site_by_path( 'www.w.org', '/notapath/' )->blog_id ); 142 146 143 $this->assertEquals( $ids['www.w.org/foo/bar/'],147 $this->assertEquals( self::$site_ids['www.w.org/foo/bar/'], 144 148 get_site_by_path( 'www.w.org', '/foo/bar/baz/' )->blog_id ); 145 149 146 $this->assertEquals( $ids['www.w.org/foo/'],150 $this->assertEquals( self::$site_ids['www.w.org/foo/'], 147 151 get_site_by_path( 'www.w.org', '/foo/bar/baz/', 1 )->blog_id ); 148 152 … … 164 168 global $current_blog; 165 169 166 $network_ids = array(167 'wordpress.org/' => array( 'domain' => 'wordpress.org', 'path' => '/' ),168 'make.wordpress.org/' => array( 'domain' => 'make.wordpress.org', 'path' => '/' ),169 );170 171 foreach ( $network_ids as &$id ) {172 $id = self::factory()->network->create( $id );173 }174 unset( $id );175 176 $ids = array(177 'wordpress.org/' => array( 'domain' => 'wordpress.org', 'path' => '/', 'site_id' => $network_ids['wordpress.org/'] ),178 'wordpress.org/foo/' => array( 'domain' => 'wordpress.org', 'path' => '/foo/', 'site_id' => $network_ids['wordpress.org/'] ),179 'wordpress.org/foo/bar/' => array( 'domain' => 'wordpress.org', 'path' => '/foo/bar/', 'site_id' => $network_ids['wordpress.org/'] ),180 'make.wordpress.org/' => array( 'domain' => 'make.wordpress.org', 'path' => '/', 'site_id' => $network_ids['make.wordpress.org/'] ),181 'make.wordpress.org/foo/' => array( 'domain' => 'make.wordpress.org', 'path' => '/foo/', 'site_id' => $network_ids['make.wordpress.org/'] ),182 );183 184 foreach ( $ids as &$id ) {185 $id = self::factory()->blog->create( $id );186 }187 unset( $id );188 189 170 $this->_setup_host_request( 'wordpress.org', '/' ); 190 $this->assertEquals( $ids['wordpress.org/'], $current_blog->blog_id );191 $this->assertEquals( $network_ids['wordpress.org/'], $current_blog->site_id );171 $this->assertEquals( self::$site_ids['wordpress.org/'], $current_blog->blog_id ); 172 $this->assertEquals( self::$network_ids['wordpress.org/'], $current_blog->site_id ); 192 173 193 174 $this->_setup_host_request( 'wordpress.org', '/2014/04/23/hello-world/' ); 194 $this->assertEquals( $ids['wordpress.org/'], $current_blog->blog_id );195 $this->assertEquals( $network_ids['wordpress.org/'], $current_blog->site_id );175 $this->assertEquals( self::$site_ids['wordpress.org/'], $current_blog->blog_id ); 176 $this->assertEquals( self::$network_ids['wordpress.org/'], $current_blog->site_id ); 196 177 197 178 $this->_setup_host_request( 'wordpress.org', '/sample-page/' ); 198 $this->assertEquals( $ids['wordpress.org/'], $current_blog->blog_id );199 $this->assertEquals( $network_ids['wordpress.org/'], $current_blog->site_id );179 $this->assertEquals( self::$site_ids['wordpress.org/'], $current_blog->blog_id ); 180 $this->assertEquals( self::$network_ids['wordpress.org/'], $current_blog->site_id ); 200 181 201 182 $this->_setup_host_request( 'wordpress.org', '/?p=1' ); 202 $this->assertEquals( $ids['wordpress.org/'], $current_blog->blog_id );203 $this->assertEquals( $network_ids['wordpress.org/'], $current_blog->site_id );183 $this->assertEquals( self::$site_ids['wordpress.org/'], $current_blog->blog_id ); 184 $this->assertEquals( self::$network_ids['wordpress.org/'], $current_blog->site_id ); 204 185 205 186 $this->_setup_host_request( 'wordpress.org', '/wp-admin/' ); 206 $this->assertEquals( $ids['wordpress.org/'], $current_blog->blog_id );207 $this->assertEquals( $network_ids['wordpress.org/'], $current_blog->site_id );187 $this->assertEquals( self::$site_ids['wordpress.org/'], $current_blog->blog_id ); 188 $this->assertEquals( self::$network_ids['wordpress.org/'], $current_blog->site_id ); 208 189 209 190 $this->_setup_host_request( 'wordpress.org', '/foo/' ); 210 $this->assertEquals( $ids['wordpress.org/foo/'], $current_blog->blog_id );211 $this->assertEquals( $network_ids['wordpress.org/'], $current_blog->site_id );191 $this->assertEquals( self::$site_ids['wordpress.org/foo/'], $current_blog->blog_id ); 192 $this->assertEquals( self::$network_ids['wordpress.org/'], $current_blog->site_id ); 212 193 213 194 $this->_setup_host_request( 'wordpress.org', '/FOO/' ); 214 $this->assertEquals( $ids['wordpress.org/foo/'], $current_blog->blog_id );215 $this->assertEquals( $network_ids['wordpress.org/'], $current_blog->site_id );195 $this->assertEquals( self::$site_ids['wordpress.org/foo/'], $current_blog->blog_id ); 196 $this->assertEquals( self::$network_ids['wordpress.org/'], $current_blog->site_id ); 216 197 217 198 $this->_setup_host_request( 'wordpress.org', '/foo/2014/04/23/hello-world/' ); 218 $this->assertEquals( $ids['wordpress.org/foo/'], $current_blog->blog_id );219 $this->assertEquals( $network_ids['wordpress.org/'], $current_blog->site_id );199 $this->assertEquals( self::$site_ids['wordpress.org/foo/'], $current_blog->blog_id ); 200 $this->assertEquals( self::$network_ids['wordpress.org/'], $current_blog->site_id ); 220 201 221 202 $this->_setup_host_request( 'wordpress.org', '/foo/sample-page/' ); 222 $this->assertEquals( $ids['wordpress.org/foo/'], $current_blog->blog_id );223 $this->assertEquals( $network_ids['wordpress.org/'], $current_blog->site_id );203 $this->assertEquals( self::$site_ids['wordpress.org/foo/'], $current_blog->blog_id ); 204 $this->assertEquals( self::$network_ids['wordpress.org/'], $current_blog->site_id ); 224 205 225 206 $this->_setup_host_request( 'wordpress.org', '/foo/?p=1' ); 226 $this->assertEquals( $ids['wordpress.org/foo/'], $current_blog->blog_id );227 $this->assertEquals( $network_ids['wordpress.org/'], $current_blog->site_id );207 $this->assertEquals( self::$site_ids['wordpress.org/foo/'], $current_blog->blog_id ); 208 $this->assertEquals( self::$network_ids['wordpress.org/'], $current_blog->site_id ); 228 209 229 210 $this->_setup_host_request( 'wordpress.org', '/foo/wp-admin/' ); 230 $this->assertEquals( $ids['wordpress.org/foo/'], $current_blog->blog_id );231 $this->assertEquals( $network_ids['wordpress.org/'], $current_blog->site_id );211 $this->assertEquals( self::$site_ids['wordpress.org/foo/'], $current_blog->blog_id ); 212 $this->assertEquals( self::$network_ids['wordpress.org/'], $current_blog->site_id ); 232 213 233 214 // @todo not currently passing. … … 237 218 238 219 $this->_setup_host_request( 'make.wordpress.org', '/' ); 239 $this->assertEquals( $ids['make.wordpress.org/'], $current_blog->blog_id );240 $this->assertEquals( $network_ids['make.wordpress.org/'], $current_blog->site_id );220 $this->assertEquals( self::$site_ids['make.wordpress.org/'], $current_blog->blog_id ); 221 $this->assertEquals( self::$network_ids['make.wordpress.org/'], $current_blog->site_id ); 241 222 242 223 $this->_setup_host_request( 'make.wordpress.org', '/foo/' ); 243 $this->assertEquals( $ids['make.wordpress.org/foo/'], $current_blog->blog_id );244 $this->assertEquals( $network_ids['make.wordpress.org/'], $current_blog->site_id );224 $this->assertEquals( self::$site_ids['make.wordpress.org/foo/'], $current_blog->blog_id ); 225 $this->assertEquals( self::$network_ids['make.wordpress.org/'], $current_blog->site_id ); 245 226 246 227 // Request the original tests domain and path to unpollute the stack.
Note: See TracChangeset
for help on using the changeset viewer.