<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[840] trunk/wp-testcase/test_ms.php: Fix multisite tests.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://unit-tests.trac.wordpress.org/changeset/840">840</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2012-07-01 22:12:57 +0000 (Sun, 01 Jul 2012)</dd>
</dl>
<h3>Log Message</h3>
<pre>Fix multisite tests. see <a href="http://unit-tests.trac.wordpress.org/ticket/82">#82</a>, see <a href="http://unit-tests.trac.wordpress.org/ticket/100">#100</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwptestcasetest_msphp">trunk/wp-testcase/test_ms.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwptestcasetest_msphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-testcase/test_ms.php (839 => 840)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-testcase/test_ms.php        2012-07-01 22:10:46 UTC (rev 839)
+++ trunk/wp-testcase/test_ms.php        2012-07-01 22:12:57 UTC (rev 840)
</span><span class="lines">@@ -1,13 +1,16 @@
</span><span class="cx"> <?php
</span><span class="cx">
</span><del>-// A set of unit tests for WordPress MultiSite
-
</del><span class="cx"> if ( is_multisite() ) :
</span><span class="cx">
</span><del>-$plugin_hook = 0;
-define('TEST_BLOGS_COUNT', 10);
</del><ins>+/**
+ * A set of unit tests for WordPress Multisite
+ *
+ * @group multisite
+ */
+class WPTestMS extends WP_UnitTestCase {
</ins><span class="cx">
</span><del>-class WPTestMS extends _WPEmptyBlog {
</del><ins>+        const test_blogs = 4;
+        protected $plugin_hook_count = 0;
</ins><span class="cx">
</span><span class="cx">         function setUp() {
</span><span class="cx">                 parent::setUp();
</span><span class="lines">@@ -20,35 +23,25 @@
</span><span class="cx">         function test_create_and_delete_blog() {
</span><span class="cx">                 global $wpdb, $current_site;
</span><span class="cx">
</span><del>-                // initialise the users
-                $user1_id = $this->_make_user('administrator');
-                $user2_id = $this->_make_user('administrator');
-                $user1 = new WP_User($user1_id);
-                $user2 = new WP_User($user2_id);
-                $blog_ids = array();
-
-                for ( $i=1; $i <= TEST_BLOGS_COUNT; $i++ ) {
-                        $id = ( $i & 1 ) ? $user1_id : $user2_id;
-                        $blog_id = wpmu_create_blog( $current_site->domain, 'path'.$i, "Title".$i, $id );
</del><ins>+                $blog_ids = $this->factory->blog->create_many( self::test_blogs );
+                foreach ( $blog_ids as $blog_id ) {
</ins><span class="cx">                         $this->assertInternalType( 'int', $blog_id );
</span><del>-
</del><span class="cx">                         $prefix = $wpdb->get_blog_prefix( $blog_id );
</span><ins>+
</ins><span class="cx">                         foreach ( $wpdb->tables( 'blog', false ) as $table ) {
</span><span class="cx">                                 $table_fields = $wpdb->get_results( "DESCRIBE $prefix$table;" );
</span><span class="cx">                                 $this->assertNotEmpty( $table_fields );
</span><del>-                                $result = $wpdb->get_results( "SELECT * FROM $prefix$table LIMIT 1");
</del><ins>+                                $result = $wpdb->get_results( "SELECT * FROM $prefix$table LIMIT 1" );
</ins><span class="cx">                                 if ( 'commentmeta' == $table )
</span><span class="cx">                                         $this->assertEmpty( $result );
</span><span class="cx">                                 else
</span><span class="cx">                                         $this->assertNotEmpty( $result );
</span><span class="cx">                         }
</span><del>-
-                        $blog_ids[] = $blog_id;
</del><span class="cx">                 }
</span><span class="cx">
</span><span class="cx">                 // update the blog count cache to use get_blog_count()
</span><span class="cx">                 wp_update_network_counts();
</span><del>-                $this->assertEquals( TEST_BLOGS_COUNT + 1, (int) get_blog_count() );
</del><ins>+                $this->assertEquals( self::test_blogs + 1, (int) get_blog_count() );
</ins><span class="cx">
</span><span class="cx">                 $drop_tables = false;
</span><span class="cx">                 // delete all blogs
</span><span class="lines">@@ -63,13 +56,13 @@
</span><span class="cx">                                 if ( $drop_tables )
</span><span class="cx">                                         $this->assertEmpty( $table_fields );
</span><span class="cx">                                 else
</span><del>-                                        $this->assertNotEmpty( $table_fields );
</del><ins>+                                        $this->assertNotEmpty( $table_fields, $prefix . $table );
</ins><span class="cx">                         }
</span><span class="cx">                 }
</span><span class="cx">
</span><span class="cx">                 // update the blog count cache to use get_blog_count()
</span><span class="cx">                 wp_update_network_counts();
</span><del>-                $this->assertEquals( 1 , get_blog_count() );
</del><ins>+                $this->assertEquals( 1, get_blog_count() );
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         function test_get_blogs_of_user() {
</span><span class="lines">@@ -78,14 +71,11 @@
</span><span class="cx">                 // Logged out users don't have blogs.
</span><span class="cx">                 $this->assertEquals( array(), get_blogs_of_user( 0 ) );
</span><span class="cx">
</span><del>-                $user1_id = $this->_make_user('administrator');
</del><ins>+                $user1_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
+                $blog_ids = $this->factory->blog->create_many( 10, array( 'user_id' => $user1_id ) );
</ins><span class="cx">
</span><del>-                $blog_ids = array();
-                for ( $i=1; $i <= 10; $i++ ) {
-                        $blog_id = wpmu_create_blog( $current_site->domain, 'testpath'.$i, "testTitle".$i, $user1_id );
</del><ins>+                foreach ( $blog_ids as $blog_id )
</ins><span class="cx">                         $this->assertInternalType( 'int', $blog_id );
</span><del>-                        $blog_ids[] = $blog_id;
-                }
</del><span class="cx">
</span><span class="cx">                 $blogs_of_user = array_keys( get_blogs_of_user( $user1_id, $all = false ) );
</span><span class="cx">                 sort( $blogs_of_user );
</span><span class="lines">@@ -102,15 +92,12 @@
</span><span class="cx">                 $user = new WP_User( $user1_id );
</span><span class="cx">                 $this->assertFalse( $user->exists(), 'WP_User->exists' );
</span><span class="cx">                 $this->assertEquals( array(), get_blogs_of_user( $user1_id ) );
</span><del>-
-                foreach ( $blog_ids as $blog_id )
-                        wpmu_delete_blog( $blog_id );
</del><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         function test_is_blog_user() {
</span><span class="cx">                 global $current_site, $wpdb;
</span><span class="cx">
</span><del>-                $user1_id = $this->_make_user('administrator');
</del><ins>+                $user1_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
</ins><span class="cx">
</span><span class="cx">                 $old_current = get_current_user_id();
</span><span class="cx">                 wp_set_current_user( $user1_id );
</span><span class="lines">@@ -120,28 +107,21 @@
</span><span class="cx">
</span><span class="cx">                 $blog_ids = array();
</span><span class="cx">
</span><del>-                for ( $i=1; $i <= 5; $i++ ) {
-                        $blog_id = wpmu_create_blog( $current_site->domain, 'testpath'.$i, "testTitle".$i, $user1_id );
</del><ins>+                $blog_ids = $this->factory->blog->create_many( 5 );
+                foreach ( $blog_ids as $blog_id ) {
</ins><span class="cx">                         $this->assertInternalType( 'int', $blog_id );
</span><del>-                        $blog_ids[] = $blog_id;
</del><span class="cx">                         $this->assertTrue( is_blog_user( $blog_id ) );
</span><del>-                }
-
-                foreach ( $blog_ids as $blog_id ) {
</del><span class="cx">                         $this->assertTrue( remove_user_from_blog( $user1_id, $blog_id ) );
</span><span class="cx">                         $this->assertFalse( is_blog_user( $blog_id ) );
</span><span class="cx">                 }
</span><span class="cx">
</span><span class="cx">                 wp_set_current_user( $old_current );
</span><del>-
-                foreach ( $blog_ids as $blog_id )
-                        wpmu_delete_blog( $blog_id );
</del><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         function test_is_user_member_of_blog() {
</span><span class="cx">                 global $current_site, $wpdb;
</span><span class="cx">
</span><del>-                $user1_id = $this->_make_user('administrator');
</del><ins>+                $user1_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
</ins><span class="cx">
</span><span class="cx">                 $old_current = get_current_user_id();
</span><span class="cx">                 wp_set_current_user( $user1_id );
</span><span class="lines">@@ -152,16 +132,10 @@
</span><span class="cx">                 $this->assertTrue( is_user_member_of_blog( $user1_id ) );
</span><span class="cx">                 $this->assertTrue( is_user_member_of_blog( $user1_id, $wpdb->blogid ) );
</span><span class="cx">
</span><del>-                $blog_ids = array();
-
-                for ( $i=1; $i <= 5; $i++ ) {
-                        $blog_id = wpmu_create_blog( $current_site->domain, 'testpath'.$i, "testTitle".$i, $user1_id );
</del><ins>+                $blog_ids = $this->factory->blog->create_many( 5 );
+                foreach ( $blog_ids as $blog_id ) {
</ins><span class="cx">                         $this->assertInternalType( 'int', $blog_id );
</span><del>-                        $blog_ids[] = $blog_id;
</del><span class="cx">                         $this->assertTrue( is_user_member_of_blog( $user1_id, $blog_id ) );
</span><del>-                }
-
-                foreach ( $blog_ids as $blog_id ) {
</del><span class="cx">                         $this->assertTrue( remove_user_from_blog( $user1_id, $blog_id ) );
</span><span class="cx">                         $this->assertFalse( is_user_member_of_blog( $user1_id, $blog_id ) );
</span><span class="cx">                 }
</span><span class="lines">@@ -172,9 +146,6 @@
</span><span class="cx">                 $this->assertFalse( is_user_member_of_blog( $user1_id ), 'is_user_member_of_blog' );
</span><span class="cx">
</span><span class="cx">                 wp_set_current_user( $old_current );
</span><del>-
-                foreach ( $blog_ids as $blog_id )
-                        wpmu_delete_blog( $blog_id );
</del><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         function test_active_network_plugins() {
</span><span class="lines">@@ -185,7 +156,7 @@
</span><span class="cx">                 $active_plugins = wp_get_active_network_plugins();
</span><span class="cx">                 $this->assertEquals( Array(), $active_plugins );
</span><span class="cx">
</span><del>-                add_action( 'deactivated_plugin', 'helper_deactivate_hook', 10, 2);
</del><ins>+                add_action( 'deactivated_plugin', array( $this, '_helper_deactivate_hook' ) );
</ins><span class="cx">
</span><span class="cx">                 // activate the plugin sitewide
</span><span class="cx">                 activate_plugin($path, '', $network_wide = true);
</span><span class="lines">@@ -197,21 +168,24 @@
</span><span class="cx">                 $active_plugins = wp_get_active_network_plugins();
</span><span class="cx">                 $this->assertEquals( Array(), $active_plugins );
</span><span class="cx">
</span><del>-                global $plugin_hook;
-                $this->assertEquals( 1, $plugin_hook ); // testing actions and silent mode
</del><ins>+                $this->assertEquals( 1, $this->plugin_hook_count ); // testing actions and silent mode
</ins><span class="cx">
</span><span class="cx">                 activate_plugin($path, '', $network_wide = true);
</span><span class="cx">                 deactivate_plugins($path, true); // silent
</span><span class="cx">
</span><del>-                $this->assertEquals( 1, $plugin_hook ); // testing actions and silent mode
</del><ins>+                $this->assertEquals( 1, $this->plugin_hook_count ); // testing actions and silent mode
</ins><span class="cx">         }
</span><span class="cx">
</span><ins>+        function _helper_deactivate_hook() {
+                $this->plugin_hook_count++;
+        }
+
</ins><span class="cx">         function test_get_user_count() {
</span><span class="cx">                 // Refresh the cache
</span><span class="cx">                 wp_update_network_counts();
</span><span class="cx">                 $start_count = get_user_count();
</span><span class="cx">
</span><del>-                $this->_make_user('administrator');
</del><ins>+                $this->factory->user->create( array( 'role' => 'administrator' ) );
</ins><span class="cx">
</span><span class="cx">                 $count = get_user_count(); // No change, cache not refreshed
</span><span class="cx">                 $this->assertEquals( $start_count, $count );
</span><span class="lines">@@ -253,15 +227,14 @@
</span><span class="cx">                 $dashboard_blog = get_dashboard_blog();
</span><span class="cx">                 $this->assertEquals( 1, $dashboard_blog->blog_id );
</span><span class="cx">
</span><del>-                $user_id = $this->_make_user('administrator');
-                $blog_id = wpmu_create_blog( $current_site->domain, 'testpath999', "testTitle999", $user_id );
</del><ins>+                $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
+                $blog_id = $this->factory->blog->create( array( 'user_id' => $user_id ) );
</ins><span class="cx">                 $this->assertInternalType( 'int', $blog_id );
</span><span class="cx">
</span><span class="cx">                 // set the dashboard blog to another one
</span><span class="cx">                 update_site_option( 'dashboard_blog', $blog_id );
</span><span class="cx">                 $dashboard_blog = get_dashboard_blog();
</span><span class="cx">                 $this->assertEquals( $blog_id, $dashboard_blog->blog_id );
</span><del>-                wpmu_delete_blog( $blog_id );
</del><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         function test_wpmu_log_new_registrations() {
</span><span class="lines">@@ -299,6 +272,15 @@
</span><span class="cx">                 $this->assertFalse( upload_is_user_over_quota( $echo ) );
</span><span class="cx">                 $this->assertTrue( is_upload_space_available() );
</span><span class="cx">
</span><ins>+                if ( ! file_exists( BLOGSUPLOADDIR ) )
+                        $this->markTestSkipped( 'This test is broken when blogs.dir does not exist. ');
+
+                /*
+                This is broken when blogs.dir does not exist, as get_upload_space_available()
+                simply returns the value of blog_upload_space (converted to bytes), which would
+                be negative but still not false. When blogs.dir does exist, < 0 is returned as 0.
+                */
+
</ins><span class="cx">                 update_site_option( 'blog_upload_space', -1 );
</span><span class="cx">                 $this->assertTrue( upload_is_user_over_quota( $echo ) );
</span><span class="cx">                 $this->assertEquals( -1, get_space_allowed() );
</span><span class="lines">@@ -336,22 +318,20 @@
</span><span class="cx">                 $this->assertEquals( $current_site->domain, $blog->domain );
</span><span class="cx">                 $this->assertEquals( '/', $blog->path );
</span><span class="cx">
</span><del>-                $user_id = $this->_make_user('administrator');
-                $blog_id = wpmu_create_blog( $current_site->domain, '/test_blogname', "Test Title", $user_id );
</del><ins>+                $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
+                $blog_id = $this->factory->blog->create( array( 'user_id' => $user_id, 'path' => '/test_blogname', 'title' => 'Test Title' ) );
</ins><span class="cx">                 $this->assertInternalType( 'int', $blog_id );
</span><span class="cx">
</span><span class="cx">                 $this->assertEquals( 'http://' . DOMAIN_CURRENT_SITE . PATH_CURRENT_SITE . 'test_blogname/', get_blogaddress_by_name('test_blogname') );
</span><span class="cx">
</span><span class="cx">                 $this->assertEquals( $blog_id, get_id_from_blogname('test_blogname') );
</span><del>-
-                wpmu_delete_blog( $blog_id );
</del><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         function test_update_blog_details() {
</span><span class="cx">                 global $current_site;
</span><span class="cx">
</span><del>-                $user_id = $this->_make_user('administrator');
-                $blog_id = wpmu_create_blog( $current_site->domain, 'test_blogpath', "Test Title", $user_id );
</del><ins>+                $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
+                $blog_id = $this->factory->blog->create( array( 'user_id' => $user_id, 'path' => '/test_blogpath', 'title' => 'Test Title' ) );
</ins><span class="cx">                 $this->assertInternalType( 'int', $blog_id );
</span><span class="cx">
</span><span class="cx">                 $result = update_blog_details( $blog_id, array('domain' => 'example.com', 'path' => 'my_path/') );
</span><span class="lines">@@ -379,12 +359,4 @@
</span><span class="cx">         }
</span><span class="cx"> }
</span><span class="cx">
</span><del>-/*
-Helper for plugin testing, helpful with silent mode testing
-*/
-function helper_deactivate_hook($plugin, $network_wide) {
-        global $plugin_hook;
-        $plugin_hook++;
-}
-
</del><span class="cx"> endif;
</span></span></pre>
</div>
</div>
</body>
</html>