diff --git a/tests/phpunit/includes/bootstrap.php b/tests/phpunit/includes/bootstrap.php index 0fde392d1d..c70c6d65e7 100644 --- a/tests/phpunit/includes/bootstrap.php +++ b/tests/phpunit/includes/bootstrap.php @@ -129,10 +129,12 @@ class WP_PHPUnit_Util_Getopt extends PHPUnit_Util_Getopt { } $ajax_message = true; + $ms_files_message = true; foreach ( $options as $option ) { switch ( $option[0] ) { case '--exclude-group' : $ajax_message = false; + $ms_files_message = false; continue 2; case '--group' : $groups = explode( ',', $option[1] ); @@ -142,12 +144,16 @@ class WP_PHPUnit_Util_Getopt extends PHPUnit_Util_Getopt { } } $ajax_message = ! in_array( 'ajax', $groups ); + $ms_files_message = ! in_array( 'ms-files', $groups ); continue 2; } } if ( $ajax_message ) { echo "Not running ajax tests... To execute these, use --group ajax." . PHP_EOL; } + if ( $ms_files_message ) { + echo "Not running ms_files_rewriting tests... To execute these, use --group ms-files." . PHP_EOL; + } } } new WP_PHPUnit_Util_Getopt( $_SERVER['argv'] ); diff --git a/tests/phpunit/multisite.xml b/tests/phpunit/multisite.xml index b2a2633cc6..3141ade2e4 100644 --- a/tests/phpunit/multisite.xml +++ b/tests/phpunit/multisite.xml @@ -23,6 +23,7 @@ ajax + ms-files diff --git a/tests/phpunit/tests/multisite/ms-files-rewriting.php b/tests/phpunit/tests/multisite/ms-files-rewriting.php new file mode 100644 index 0000000000..3a7950b41c --- /dev/null +++ b/tests/phpunit/tests/multisite/ms-files-rewriting.php @@ -0,0 +1,60 @@ +suppress = $wpdb->suppress_errors(); + + $_SERVER[ 'REMOTE_ADDR' ] = ''; + + update_site_option( 'ms_files_rewriting', 1 ); + ms_upload_constants(); + } + + function tearDown() { + global $wpdb; + + update_site_option( 'ms_files_rewriting', 0 ); + parent::tearDown(); + $wpdb->suppress_errors( $this->suppress ); + } + + function test_switch_upload_dir() { + $this->assertTrue( is_main_site() ); + + $site = get_current_site(); + + $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) ); + $blog_id2 = $this->factory->blog->create( array( 'user_id' => $user_id ) ); + $info = wp_upload_dir(); + $this->assertEquals( 'http://' . $site->domain . '/wp-content/uploads/' . gmstrftime('%Y/%m'), $info['url'] ); + $this->assertEquals( ABSPATH . 'wp-content/uploads/' . gmstrftime('%Y/%m'), $info['path'] ); + $this->assertEquals( gmstrftime('/%Y/%m'), $info['subdir'] ); + $this->assertEquals( '', $info['error'] ); + + switch_to_blog( $blog_id2 ); + $info2 = wp_upload_dir(); + $this->assertNotEquals( $info, $info2 ); + $this->assertEquals( get_option( 'siteurl' ) . '/wp-content/blogs.dir/' . get_current_blog_id() . '/files/' . gmstrftime('%Y/%m'), $info2['url'] ); + $this->assertEquals( ABSPATH . 'wp-content/blogs.dir/' . get_current_blog_id() . '/files/' . gmstrftime('%Y/%m'), $info2['path'] ); + $this->assertEquals( gmstrftime('/%Y/%m'), $info2['subdir'] ); + $this->assertEquals( '', $info2['error'] ); + restore_current_blog(); + } +} + +endif; \ No newline at end of file diff --git a/tests/phpunit/tests/multisite/site.php b/tests/phpunit/tests/multisite/site.php index 75afe8839e..5d23fed5e2 100644 --- a/tests/phpunit/tests/multisite/site.php +++ b/tests/phpunit/tests/multisite/site.php @@ -949,27 +949,6 @@ class Tests_Multisite_Site extends WP_UnitTestCase { $this->assertEquals( ABSPATH . 'wp-content/uploads/' . gmstrftime('%Y/%m'), $info['path'] ); $this->assertEquals( gmstrftime('/%Y/%m'), $info['subdir'] ); $this->assertEquals( '', $info['error'] ); - - update_site_option( 'ms_files_rewriting', 1 ); - ms_upload_constants(); - - $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) ); - $blog_id2 = $this->factory->blog->create( array( 'user_id' => $user_id ) ); - $info = wp_upload_dir(); - $this->assertEquals( 'http://' . $site->domain . '/wp-content/uploads/' . gmstrftime('%Y/%m'), $info['url'] ); - $this->assertEquals( ABSPATH . 'wp-content/uploads/' . gmstrftime('%Y/%m'), $info['path'] ); - $this->assertEquals( gmstrftime('/%Y/%m'), $info['subdir'] ); - $this->assertEquals( '', $info['error'] ); - - switch_to_blog( $blog_id2 ); - $info2 = wp_upload_dir(); - $this->assertNotEquals( $info, $info2 ); - $this->assertEquals( get_option( 'siteurl' ) . '/wp-content/blogs.dir/' . get_current_blog_id() . '/files/' . gmstrftime('%Y/%m'), $info2['url'] ); - $this->assertEquals( ABSPATH . 'wp-content/blogs.dir/' . get_current_blog_id() . '/files/' . gmstrftime('%Y/%m'), $info2['path'] ); - $this->assertEquals( gmstrftime('/%Y/%m'), $info2['subdir'] ); - $this->assertEquals( '', $info2['error'] ); - restore_current_blog(); - update_site_option( 'ms_files_rewriting', 0 ); } /**