Ticket #4948: unittests.patch
File unittests.patch, 5.9 KB (added by , 12 years ago) |
---|
-
tests/includes/testcase.php
class BP_UnitTestCase extends WP_UnitTestCase { 23 23 buddypress()->current_user = new stdClass(); 24 24 buddypress()->displayed_user = new stdClass(); 25 25 buddypress()->loggedin_user = new stdClass(); 26 buddypress()->avatar = new stdClass(); 26 27 27 28 parent::clean_up_global_scope(); 28 29 } … … class BP_UnitTestCase extends WP_UnitTestCase { 36 37 } 37 38 38 39 function go_to( $url ) { 39 // Set this for bp_core_set_uri_globals()40 $GLOBALS['_SERVER']['REQUEST_URI'] = $url = str_replace( network_home_url(), '', $url );41 42 40 // note: the WP and WP_Query classes like to silently fetch parameters 43 41 // from all over the place (globals, GET, etc), which makes it tricky 44 42 // to run them more than once without very carefully clearing everything … … class BP_UnitTestCase extends WP_UnitTestCase { 48 46 } 49 47 $parts = parse_url($url); 50 48 if (isset($parts['scheme'])) { 49 // set the HTTP_HOST 50 $GLOBALS['_SERVER']['HTTP_HOST'] = $parts['host']; 51 51 52 $req = $parts['path']; 52 53 if (isset($parts['query'])) { 53 54 $req .= '?' . $parts['query']; … … class BP_UnitTestCase extends WP_UnitTestCase { 68 69 unset( $_SERVER['HTTPS'] ); 69 70 } 70 71 71 $ _SERVER['REQUEST_URI'] = $req;72 $GLOBALS['_SERVER']['REQUEST_URI'] = $req; 72 73 unset($_SERVER['PATH_INFO']); 73 74 74 $this->flush_cache(); 75 // setup $current_site and $current_blog globals for multisite based on 76 // REQUEST_URI; mostly copied from /wp-includes/ms-settings.php 77 if ( is_multisite() ) { 78 $domain = addslashes( $_SERVER['HTTP_HOST'] ); 79 if ( false !== strpos( $domain, ':' ) ) { 80 if ( substr( $domain, -3 ) == ':80' ) { 81 $domain = substr( $domain, 0, -3 ); 82 $_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -3 ); 83 } elseif ( substr( $domain, -4 ) == ':443' ) { 84 $domain = substr( $domain, 0, -4 ); 85 $_SERVER['HTTP_HOST'] = substr( $_SERVER['HTTP_HOST'], 0, -4 ); 86 } 87 } 88 89 $domain = rtrim( $domain, '.' ); 90 $cookie_domain = $domain; 91 if ( substr( $cookie_domain, 0, 4 ) == 'www.' ) 92 $cookie_domain = substr( $cookie_domain, 4 ); 93 94 $path = preg_replace( '|([a-z0-9-]+.php.*)|', '', $GLOBALS['_SERVER']['REQUEST_URI'] ); 95 $path = str_replace ( '/wp-admin/', '/', $path ); 96 $path = preg_replace( '|(/[a-z0-9-]+?/).*|', '$1', $path ); 97 98 $GLOBALS['current_site'] = wpmu_current_site(); 99 if ( ! isset( $GLOBALS['current_site']->blog_id ) ) 100 $GLOBALS['current_site']->blog_id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s", $GLOBALS['current_site']->domain, $GLOBALS['current_site']->path ) ); 101 102 // unit tests only support subdirectory install at the moment 103 // removed object cache references 104 if ( ! is_subdomain_install() ) { 105 $blogname = htmlspecialchars( substr( $GLOBALS['_SERVER']['REQUEST_URI'], strlen( $path ) ) ); 106 if ( false !== strpos( $blogname, '/' ) ) 107 $blogname = substr( $blogname, 0, strpos( $blogname, '/' ) ); 108 if ( false !== strpos( $blogname, '?' ) ) 109 $blogname = substr( $blogname, 0, strpos( $blogname, '?' ) ); 110 $reserved_blognames = array( 'page', 'comments', 'blog', 'wp-admin', 'wp-includes', 'wp-content', 'files', 'feed' ); 111 if ( $blogname != '' && ! in_array( $blogname, $reserved_blognames ) && ! is_file( $blogname ) ) 112 $path .= $blogname . '/'; 113 114 $GLOBALS['current_blog'] = get_blog_details( array( 'domain' => $domain, 'path' => $path ), false ); 115 116 unset($reserved_blognames); 117 } 118 119 $GLOBALS['blog_id'] = $GLOBALS['current_blog']->blog_id; 120 } 121 75 122 unset($GLOBALS['wp_query'], $GLOBALS['wp_the_query']); 76 123 $GLOBALS['wp_the_query'] =& new WP_Query(); 77 124 $GLOBALS['wp_query'] =& $GLOBALS['wp_the_query']; … … class BP_UnitTestCase extends WP_UnitTestCase { 87 134 88 135 $GLOBALS['wp']->main($parts['query']); 89 136 137 // nuke BP! kaboom! 138 unset( $GLOBALS['bp'] ); 139 140 // reload BP 141 $GLOBALS['bp'] = buddypress(); 142 143 // unset some variables that need to be reloaded 144 // this doesn't quite work yet due to reliance on defines 145 unset( $GLOBALS['bp']->avatar->url, $GLOBALS['bp']->avatar->upload_path ); 146 90 147 // For BuddyPress, James. 91 do_action( ' bp_init' );148 do_action( 'init' ); 92 149 } 93 150 94 151 protected function checkRequirements() { -
tests/testcases/core/avatars.php
new file mode 100644
1 <?php 2 /** 3 * @group core 4 * @group avatars 5 */ 6 class BP_Tests_Avatars extends BP_UnitTestCase { 7 protected $old_current_user = 0; 8 9 public function setUp() { 10 parent::setUp(); 11 12 $this->old_current_user = get_current_user_id(); 13 $this->administrator = $this->factory->user->create( array( 'role' => 'administrator' ) ); 14 wp_set_current_user( $this->administrator ); 15 } 16 17 public function tearDown() { 18 parent::tearDown(); 19 wp_set_current_user( $this->old_current_user ); 20 } 21 22 /** 23 * @ticket 4948 24 */ 25 function test_avatars_on_non_root_blog() { 26 // Do not pass 'Go', do not collect $200 27 if ( ! is_multisite() ) { 28 return; 29 } 30 31 // switch to BP root blog if necessary 32 if ( bp_get_root_blog_id() != get_current_blog_id() ) { 33 switch_to_blog( get_current_blog_id() ); 34 } 35 36 // get BP root blog's upload directory data 37 $upload_dir = wp_upload_dir(); 38 39 restore_current_blog(); 40 41 // create new subsite 42 $blog_id = $this->factory->blog->create( array( 43 'user_id' => $this->administrator, 44 'path' => PATH_CURRENT_SITE . 'test_blogname/', 45 'title' => 'Test Title' 46 ) ); 47 48 // emulate a page load on the new sub-site 49 $this->go_to( get_blogaddress_by_name('test_blogname') );; 50 51 // test to see if the upload dir is correct 52 $this->assertEquals( bp_core_avatar_url(), $upload_dir['baseurl'] ); 53 } 54 }