From 211c7ac373d1702f49836ad61d920b786603a401 Mon Sep 17 00:00:00 2001 From: Jeremy Felt Date: Sat, 8 Nov 2014 21:07:05 +0000 Subject: [PATCH] Move tests for ms_files_rewriting to separate group, ms-files When the `ms_files_rewriting` flag is enabled, `ms_upload_constants()` is required to properly set upload directory constants. Once this fires, it is impossible to clean up for a non `ms_files_rewriting` test by turning the option back off. Excluding these tests by default offer a more consistent environment overall. Any tests written for uploaded files in multisite should ideally have a correspondign test in this area. This commit also moves existing `ms_files_rewriting` tests for `test_switch_upload_dir()`. Fixes #30256 git-svn-id: https://develop.svn.wordpress.org/trunk@30286 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/includes/bootstrap.php | 6 ++ tests/phpunit/multisite.xml | 1 + .../tests/multisite/ms-files-rewriting.php | 60 +++++++++++++++++++ tests/phpunit/tests/multisite/site.php | 21 ------- 4 files changed, 67 insertions(+), 21 deletions(-) create mode 100644 tests/phpunit/tests/multisite/ms-files-rewriting.php 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 ); } /**