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
This commit is contained in:
Jeremy Felt 2014-11-08 21:07:05 +00:00
parent ffcfc0573b
commit 211c7ac373
4 changed files with 67 additions and 21 deletions

View File

@ -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'] );

View File

@ -23,6 +23,7 @@
<groups>
<exclude>
<group>ajax</group>
<group>ms-files</group>
</exclude>
</groups>
<php>

View File

@ -0,0 +1,60 @@
<?php
if ( is_multisite() ) :
/**
* Tests specific to the ms_files_rewriting option in multisite.
*
* The ms-files group tag must be used for these tests to run as the constants
* set in ms_upload_constants() conflict with a non ms-files configuration.
*
* @group ms-files
* @group multisite
*/
class Tests_Multisite_MS_Files_Rewriting extends WP_UnitTestCase {
protected $suppress = false;
function setUp() {
global $wpdb;
parent::setUp();
$this->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;

View File

@ -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 );
}
/**