- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/multisite/ms-files-rewriting.php
r39173 r42343 3 3 if ( is_multisite() ) : 4 4 5 /**6 * Tests specific to the ms_files_rewriting option in multisite.7 *8 * The ms-files group tag must be used for these tests to run as the constants9 * set in ms_upload_constants() conflict with a non ms-files configuration.10 *11 * @group ms-files12 * @group multisite13 */14 class Tests_Multisite_MS_Files_Rewriting extends WP_UnitTestCase {15 protected $suppress = false;5 /** 6 * Tests specific to the ms_files_rewriting option in multisite. 7 * 8 * The ms-files group tag must be used for these tests to run as the constants 9 * set in ms_upload_constants() conflict with a non ms-files configuration. 10 * 11 * @group ms-files 12 * @group multisite 13 */ 14 class Tests_Multisite_MS_Files_Rewriting extends WP_UnitTestCase { 15 protected $suppress = false; 16 16 17 function setUp() {18 global $wpdb;19 parent::setUp();20 $this->suppress = $wpdb->suppress_errors();17 function setUp() { 18 global $wpdb; 19 parent::setUp(); 20 $this->suppress = $wpdb->suppress_errors(); 21 21 22 update_site_option( 'ms_files_rewriting', 1 ); 23 ms_upload_constants(); 22 update_site_option( 'ms_files_rewriting', 1 ); 23 ms_upload_constants(); 24 } 25 26 function tearDown() { 27 global $wpdb; 28 29 update_site_option( 'ms_files_rewriting', 0 ); 30 $wpdb->suppress_errors( $this->suppress ); 31 32 parent::tearDown(); 33 } 34 35 function test_switch_upload_dir() { 36 $this->assertTrue( is_main_site() ); 37 38 $site = get_current_site(); 39 40 $user_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); 41 $blog_id2 = self::factory()->blog->create( array( 'user_id' => $user_id ) ); 42 $info = wp_upload_dir(); 43 $this->assertEquals( 'http://' . $site->domain . '/wp-content/uploads/' . gmstrftime( '%Y/%m' ), $info['url'] ); 44 $this->assertEquals( ABSPATH . 'wp-content/uploads/' . gmstrftime( '%Y/%m' ), $info['path'] ); 45 $this->assertEquals( gmstrftime( '/%Y/%m' ), $info['subdir'] ); 46 $this->assertEquals( '', $info['error'] ); 47 48 switch_to_blog( $blog_id2 ); 49 $info2 = wp_upload_dir(); 50 $this->assertNotEquals( $info, $info2 ); 51 $this->assertEquals( get_option( 'siteurl' ) . '/wp-content/blogs.dir/' . get_current_blog_id() . '/files/' . gmstrftime( '%Y/%m' ), $info2['url'] ); 52 $this->assertEquals( ABSPATH . 'wp-content/blogs.dir/' . get_current_blog_id() . '/files/' . gmstrftime( '%Y/%m' ), $info2['path'] ); 53 $this->assertEquals( gmstrftime( '/%Y/%m' ), $info2['subdir'] ); 54 $this->assertEquals( '', $info2['error'] ); 55 restore_current_blog(); 56 } 57 58 /** 59 * When a site is deleted with wpmu_delete_blog(), only the files associated with 60 * that site should be removed. When wpmu_delete_blog() is run a second time, nothing 61 * should change with upload directories. 62 */ 63 function test_upload_directories_after_multiple_wpmu_delete_blog_with_ms_files() { 64 $filename = __FUNCTION__ . '.jpg'; 65 $contents = __FUNCTION__ . '_contents'; 66 67 // Upload a file to the main site on the network. 68 $file1 = wp_upload_bits( $filename, null, $contents ); 69 70 $blog_id = self::factory()->blog->create(); 71 72 switch_to_blog( $blog_id ); 73 $file2 = wp_upload_bits( $filename, null, $contents ); 74 restore_current_blog(); 75 76 wpmu_delete_blog( $blog_id, true ); 77 78 // The file on the main site should still exist. The file on the deleted site should not. 79 $this->assertFileExists( $file1['file'] ); 80 $this->assertFileNotExists( $file2['file'] ); 81 82 wpmu_delete_blog( $blog_id, true ); 83 84 // The file on the main site should still exist. The file on the deleted site should not. 85 $this->assertFileExists( $file1['file'] ); 86 $this->assertFileNotExists( $file2['file'] ); 87 } 24 88 } 25 89 26 function tearDown() {27 global $wpdb;28 29 update_site_option( 'ms_files_rewriting', 0 );30 $wpdb->suppress_errors( $this->suppress );31 32 parent::tearDown();33 }34 35 function test_switch_upload_dir() {36 $this->assertTrue( is_main_site() );37 38 $site = get_current_site();39 40 $user_id = self::factory()->user->create( array( 'role' => 'administrator' ) );41 $blog_id2 = self::factory()->blog->create( array( 'user_id' => $user_id ) );42 $info = wp_upload_dir();43 $this->assertEquals( 'http://' . $site->domain . '/wp-content/uploads/' . gmstrftime('%Y/%m'), $info['url'] );44 $this->assertEquals( ABSPATH . 'wp-content/uploads/' . gmstrftime('%Y/%m'), $info['path'] );45 $this->assertEquals( gmstrftime('/%Y/%m'), $info['subdir'] );46 $this->assertEquals( '', $info['error'] );47 48 switch_to_blog( $blog_id2 );49 $info2 = wp_upload_dir();50 $this->assertNotEquals( $info, $info2 );51 $this->assertEquals( get_option( 'siteurl' ) . '/wp-content/blogs.dir/' . get_current_blog_id() . '/files/' . gmstrftime('%Y/%m'), $info2['url'] );52 $this->assertEquals( ABSPATH . 'wp-content/blogs.dir/' . get_current_blog_id() . '/files/' . gmstrftime('%Y/%m'), $info2['path'] );53 $this->assertEquals( gmstrftime('/%Y/%m'), $info2['subdir'] );54 $this->assertEquals( '', $info2['error'] );55 restore_current_blog();56 }57 58 /**59 * When a site is deleted with wpmu_delete_blog(), only the files associated with60 * that site should be removed. When wpmu_delete_blog() is run a second time, nothing61 * should change with upload directories.62 */63 function test_upload_directories_after_multiple_wpmu_delete_blog_with_ms_files() {64 $filename = __FUNCTION__ . '.jpg';65 $contents = __FUNCTION__ . '_contents';66 67 // Upload a file to the main site on the network.68 $file1 = wp_upload_bits( $filename, null, $contents );69 70 $blog_id = self::factory()->blog->create();71 72 switch_to_blog( $blog_id );73 $file2 = wp_upload_bits( $filename, null, $contents );74 restore_current_blog();75 76 wpmu_delete_blog( $blog_id, true );77 78 // The file on the main site should still exist. The file on the deleted site should not.79 $this->assertFileExists( $file1['file'] );80 $this->assertFileNotExists( $file2['file'] );81 82 wpmu_delete_blog( $blog_id, true );83 84 // The file on the main site should still exist. The file on the deleted site should not.85 $this->assertFileExists( $file1['file'] );86 $this->assertFileNotExists( $file2['file'] );87 }88 }89 90 90 endif;
Note: See TracChangeset
for help on using the changeset viewer.