Unit Tests: `WP_UnitTest_Generator_Sequence` needs a static incrementer - otherwise, it assumes every test class is a reset, which it no longer is (it is now static).

While we're at it, remove unnecessary `tearDown()` code.

See #30017, #33968.



git-svn-id: https://develop.svn.wordpress.org/trunk@35244 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor 2015-10-17 19:24:20 +00:00
parent ae226d66b6
commit 613e88fe86
33 changed files with 74 additions and 162 deletions

View File

@ -401,11 +401,17 @@ abstract class WP_UnitTest_Factory_For_Thing {
} }
class WP_UnitTest_Generator_Sequence { class WP_UnitTest_Generator_Sequence {
var $next; static $incr = -1;
var $template_string; public $next;
public $template_string;
function __construct( $template_string = '%s', $start = 1 ) { function __construct( $template_string = '%s', $start = null ) {
$this->next = $start; if ( $start ) {
$this->next = $start;
} else {
self::$incr++;
$this->next = self::$incr;
}
$this->template_string = $template_string; $this->template_string = $template_string;
} }

View File

@ -134,11 +134,7 @@ class WP_Canonical_UnitTestCase extends WP_UnitTestCase {
* @since 4.1.0 * @since 4.1.0
*/ */
public static function delete_shared_fixtures() { public static function delete_shared_fixtures() {
if ( is_multisite() ) { self::delete_user( self::$author_id );
wpmu_delete_user( self::$author_id );
} else {
wp_delete_user( self::$author_id );
}
foreach ( self::$post_ids as $pid ) { foreach ( self::$post_ids as $pid ) {
wp_delete_post( $pid, true ); wp_delete_post( $pid, true );

View File

@ -5,11 +5,6 @@
*/ */
class Tests_Admin_includesPost extends WP_UnitTestCase { class Tests_Admin_includesPost extends WP_UnitTestCase {
function tearDown() {
wp_set_current_user( 0 );
parent::tearDown();
}
function test__wp_translate_postdata_cap_checks_contributor() { function test__wp_translate_postdata_cap_checks_contributor() {
$contributor_id = self::factory()->user->create( array( 'role' => 'contributor' ) ); $contributor_id = self::factory()->user->create( array( 'role' => 'contributor' ) );
$editor_id = self::factory()->user->create( array( 'role' => 'editor' ) ); $editor_id = self::factory()->user->create( array( 'role' => 'editor' ) );

View File

@ -40,15 +40,6 @@ class Tests_Ajax_Autosave extends WP_Ajax_UnitTestCase {
$this->_post = get_post( $post_id ); $this->_post = get_post( $post_id );
} }
/**
* Tear down the test fixture.
* Reset the current user
*/
public function tearDown() {
wp_set_current_user( 0 );
parent::tearDown();
}
/** /**
* Test autosaving a post * Test autosaving a post
* @return void * @return void

View File

@ -28,14 +28,6 @@ class Tests_Ajax_CustomizeMenus extends WP_Ajax_UnitTestCase {
$wp_customize = $this->wp_customize; $wp_customize = $this->wp_customize;
} }
/**
* Tear down the test fixture.
*/
public function tearDown() {
wp_set_current_user( 0 );
parent::tearDown();
}
/** /**
* Helper to keep it DRY * Helper to keep it DRY
* *

View File

@ -9,7 +9,6 @@ class Tests_Attachment_Slashes extends WP_UnitTestCase {
function setUp() { function setUp() {
parent::setUp(); parent::setUp();
$this->author_id = self::factory()->user->create( array( 'role' => 'editor' ) ); $this->author_id = self::factory()->user->create( array( 'role' => 'editor' ) );
$this->old_current_user = get_current_user_id();
wp_set_current_user( $this->author_id ); wp_set_current_user( $this->author_id );
// it is important to test with both even and odd numbered slashes as // it is important to test with both even and odd numbered slashes as
@ -23,12 +22,6 @@ class Tests_Attachment_Slashes extends WP_UnitTestCase {
$this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\'; $this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\';
} }
function tearDown() {
wp_set_current_user( $this->old_current_user );
wp_delete_user( $this->author_id );
parent::tearDown();
}
/** /**
* Tests the model function that expects slashed data * Tests the model function that expects slashed data
* *

View File

@ -5,21 +5,6 @@
* @group testsuite * @group testsuite
*/ */
class Tests_Basic extends WP_UnitTestCase { class Tests_Basic extends WP_UnitTestCase {
var $val;
function setUp() {
parent::setUp();
$this->val = true;
}
function tearDown() {
$this->val = false;
parent::tearDown();
}
function test_true() {
$this->assertTrue($this->val);
}
function test_license() { function test_license() {
$license = file_get_contents( ABSPATH . 'license.txt' ); $license = file_get_contents( ABSPATH . 'license.txt' );

View File

@ -4,7 +4,7 @@
* @group cache * @group cache
*/ */
class Tests_Cache extends WP_UnitTestCase { class Tests_Cache extends WP_UnitTestCase {
var $cache = NULL; var $cache = null;
function setUp() { function setUp() {
parent::setUp(); parent::setUp();

View File

@ -10,13 +10,7 @@ class Tests_Comment_Submission extends WP_UnitTestCase {
require_once ABSPATH . WPINC . '/class-phpass.php'; require_once ABSPATH . WPINC . '/class-phpass.php';
} }
function tearDown() {
wp_set_current_user( 0 );
parent::tearDown();
}
public function test_submitting_comment_to_invalid_post_returns_error() { public function test_submitting_comment_to_invalid_post_returns_error() {
$error = 'comment_id_not_found'; $error = 'comment_id_not_found';
$this->assertSame( 0, did_action( $error ) ); $this->assertSame( 0, did_action( $error ) );

View File

@ -15,7 +15,7 @@ class Tests_Comment extends WP_UnitTestCase {
} }
public static function wpTearDownAfterClass() { public static function wpTearDownAfterClass() {
wp_delete_post( self::$post_id ); wp_delete_post( self::$post_id, true );
self::delete_user( self::$user_id ); self::delete_user( self::$user_id );
} }

View File

@ -10,7 +10,6 @@ class Tests_Comment_Slashes extends WP_UnitTestCase {
parent::setUp(); parent::setUp();
// we need an admin user to bypass comment flood protection // we need an admin user to bypass comment flood protection
$this->author_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); $this->author_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
$this->old_current_user = get_current_user_id();
wp_set_current_user( $this->author_id ); wp_set_current_user( $this->author_id );
// it is important to test with both even and odd numbered slashes as // it is important to test with both even and odd numbered slashes as
@ -24,11 +23,6 @@ class Tests_Comment_Slashes extends WP_UnitTestCase {
$this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\'; $this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\';
} }
function tearDown() {
wp_set_current_user( $this->old_current_user );
parent::tearDown();
}
/** /**
* Tests the extended model function that expects slashed data * Tests the extended model function that expects slashed data
* *

View File

@ -4,12 +4,6 @@
*/ */
class Tests_Link extends WP_UnitTestCase { class Tests_Link extends WP_UnitTestCase {
function tearDown() {
global $wp_rewrite;
$wp_rewrite->init();
parent::tearDown();
}
function _get_pagenum_link_cb( $url ) { function _get_pagenum_link_cb( $url ) {
return $url . '/WooHoo'; return $url . '/WooHoo';
} }

View File

@ -10,7 +10,7 @@ class Tests_Meta_Slashes extends WP_UnitTestCase {
parent::setUp(); parent::setUp();
$this->author_id = self::factory()->user->create( array( 'role' => 'editor' ) ); $this->author_id = self::factory()->user->create( array( 'role' => 'editor' ) );
$this->post_id = self::factory()->post->create(); $this->post_id = self::factory()->post->create();
$this->old_current_user = get_current_user_id();
wp_set_current_user( $this->author_id ); wp_set_current_user( $this->author_id );
$this->slash_1 = 'String with 1 slash \\'; $this->slash_1 = 'String with 1 slash \\';
@ -22,11 +22,6 @@ class Tests_Meta_Slashes extends WP_UnitTestCase {
$this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\'; $this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\';
} }
function tearDown() {
wp_set_current_user( $this->old_current_user );
parent::tearDown();
}
/** /**
* Tests the controller function that expects slashed data * Tests the controller function that expects slashed data
* *

View File

@ -18,7 +18,6 @@ class Tests_Multisite_Get_Space_Allowed extends WP_UnitTestCase {
self::$original_site_blog_upload_space = get_site_option( 'blog_upload_space' ); self::$original_site_blog_upload_space = get_site_option( 'blog_upload_space' );
self::$original_blog_upload_space = get_option( 'blog_upload_space' ); self::$original_blog_upload_space = get_option( 'blog_upload_space' );
} }
public function setUp() { public function setUp() {

View File

@ -674,7 +674,7 @@ class Tests_Multisite_Site extends WP_UnitTestCase {
$post2 = self::factory()->post->create(); $post2 = self::factory()->post->create();
$this->assertEquals( 2, get_blog_details()->post_count ); $this->assertEquals( 2, get_blog_details()->post_count );
wp_delete_post( $post2 ); wp_delete_post( $post2, true );
$this->assertEquals( 1, get_blog_details()->post_count ); $this->assertEquals( 1, get_blog_details()->post_count );
} }

View File

@ -14,7 +14,6 @@ class Tests_User_Settings extends WP_UnitTestCase {
function tearDown() { function tearDown() {
unset( $GLOBALS['_updated_user_settings'] ); unset( $GLOBALS['_updated_user_settings'] );
delete_user_option( $this->user_id, 'user-settings' );
parent::tearDown(); parent::tearDown();
} }

View File

@ -78,7 +78,7 @@ class Tests_Post_getPages extends WP_UnitTestCase {
$last_changed = wp_cache_get( 'last_changed', 'posts' ); $last_changed = wp_cache_get( 'last_changed', 'posts' );
// This should bump last_changed. // This should bump last_changed.
wp_delete_post( $pages[0]->ID ); wp_delete_post( $pages[0]->ID, true );
$old_changed_float = $this->_microtime_to_float( $last_changed ); $old_changed_float = $this->_microtime_to_float( $last_changed );
$new_changed_float = $this->_microtime_to_float( wp_cache_get( 'last_changed', 'posts' ) ); $new_changed_float = $this->_microtime_to_float( wp_cache_get( 'last_changed', 'posts' ) );
$this->assertGreaterThan( $old_changed_float, $new_changed_float ); $this->assertGreaterThan( $old_changed_float, $new_changed_float );

View File

@ -32,12 +32,6 @@ class Tests_Post_Meta extends WP_UnitTestCase {
$this->post_id_2 = wp_insert_post($post); $this->post_id_2 = wp_insert_post($post);
} }
function tearDown() {
wp_delete_post($this->post_id);
wp_delete_post($this->post_id_2);
parent::tearDown();
}
function test_unique_postmeta() { function test_unique_postmeta() {
// Add a unique post meta item // Add a unique post meta item
$this->assertInternalType( 'integer', add_post_meta($this->post_id, 'unique', 'value', true) ); $this->assertInternalType( 'integer', add_post_meta($this->post_id, 'unique', 'value', true) );

View File

@ -9,7 +9,7 @@ class Tests_Post_Slashes extends WP_UnitTestCase {
function setUp() { function setUp() {
parent::setUp(); parent::setUp();
$this->author_id = self::factory()->user->create( array( 'role' => 'editor' ) ); $this->author_id = self::factory()->user->create( array( 'role' => 'editor' ) );
$this->old_current_user = get_current_user_id();
wp_set_current_user( $this->author_id ); wp_set_current_user( $this->author_id );
// it is important to test with both even and odd numbered slashes as // it is important to test with both even and odd numbered slashes as
@ -23,11 +23,6 @@ class Tests_Post_Slashes extends WP_UnitTestCase {
$this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\'; $this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\';
} }
function tearDown() {
wp_set_current_user( $this->old_current_user );
parent::tearDown();
}
/** /**
* Tests the controller function that expects slashed data * Tests the controller function that expects slashed data
* *

View File

@ -17,8 +17,8 @@ class Tests_Post_Thumbnail_Template extends WP_UnitTestCase {
} }
public static function wpTearDownAfterClass() { public static function wpTearDownAfterClass() {
wp_delete_post( self::$post->ID ); wp_delete_post( self::$post->ID, true );
wp_delete_attachment( self::$attachment_id ); wp_delete_attachment( self::$attachment_id, true );
} }
function test_has_post_thumbnail() { function test_has_post_thumbnail() {

View File

@ -27,13 +27,6 @@ class Tests_Query_Conditionals extends WP_UnitTestCase {
$this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
} }
function tearDown() {
global $wp_rewrite;
$wp_rewrite->init();
parent::tearDown();
}
function test_home() { function test_home() {
$this->go_to('/'); $this->go_to('/');
$this->assertQueryTrue('is_home'); $this->assertQueryTrue('is_home');

View File

@ -23,21 +23,6 @@ class Tests_Query_SetupPostdata extends WP_UnitTestCase {
} }
} }
public function tearDown() {
parent::tearDown();
return;
foreach ( $this->global_keys as $global_key ) {
if ( ! is_null( $this->global_data[ $global_key ] ) ) {
$GLOBALS[ $global_key ] = $this->global_data[ $global_key ];
} else {
unset( $GLOBALS[ $global_key ] );
}
}
$this->global_data = array();
}
public function test_id() { public function test_id() {
$p = self::factory()->post->create_and_get(); $p = self::factory()->post->create_and_get();
setup_postdata( $p ); setup_postdata( $p );

View File

@ -20,8 +20,9 @@ class Tests_Shortcode extends WP_UnitTestCase {
function tearDown() { function tearDown() {
global $shortcode_tags; global $shortcode_tags;
foreach ( $this->shortcodes as $shortcode ) foreach ( $this->shortcodes as $shortcode ) {
unset( $shortcode_tags[ $shortcode ] ); unset( $shortcode_tags[ $shortcode ] );
}
parent::tearDown(); parent::tearDown();
} }

View File

@ -12,7 +12,9 @@ class Tests_Term extends WP_UnitTestCase {
} }
public static function wpTearDownAfterClass() { public static function wpTearDownAfterClass() {
array_map( 'wp_delete_post', self::$post_ids ); foreach ( self::$post_ids as $post_id ) {
wp_delete_post( $post_id, true );
}
} }
/** /**

View File

@ -9,7 +9,7 @@ class Tests_Term_Slashes extends WP_Ajax_UnitTestCase {
function setUp() { function setUp() {
parent::setUp(); parent::setUp();
$this->author_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); $this->author_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
$this->old_current_user = get_current_user_id();
wp_set_current_user( $this->author_id ); wp_set_current_user( $this->author_id );
$this->slash_1 = 'String with 1 slash \\'; $this->slash_1 = 'String with 1 slash \\';
@ -21,11 +21,6 @@ class Tests_Term_Slashes extends WP_Ajax_UnitTestCase {
$this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\'; $this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\';
} }
function tearDown() {
wp_set_current_user( $this->old_current_user );
parent::tearDown();
}
/** /**
* Tests the model function that expects slashed data * Tests the model function that expects slashed data
* *

View File

@ -244,7 +244,11 @@ class Tests_User extends WP_UnitTestCase {
); );
foreach ( $roles as $role => $level ) { foreach ( $roles as $role => $level ) {
$user_id = self::factory()->user->create( array( 'role' => $role ) ); $user_id = self::factory()->user->create( array(
'user_email' => 'user_19265_' . $role . '@burritos.com',
'user_login' => 'user_19265_' . $role,
'role' => $role
) );
$user = new WP_User( $user_id ); $user = new WP_User( $user_id );
$this->assertTrue( isset( $user->user_level ) ); $this->assertTrue( isset( $user->user_level ) );
@ -775,6 +779,11 @@ class Tests_User extends WP_UnitTestCase {
'user_nicename' => str_repeat( 'a', 50 ), 'user_nicename' => str_repeat( 'a', 50 ),
) ); ) );
$user1 = new WP_User( $u1 );
$expected = str_repeat( 'a', 50 );
$this->assertSame( $expected, $user1->user_nicename );
$user_login = str_repeat( 'a', 55 ); $user_login = str_repeat( 'a', 55 );
$u = wp_insert_user( array( $u = wp_insert_user( array(
'user_login' => $user_login, 'user_login' => $user_login,
@ -783,19 +792,29 @@ class Tests_User extends WP_UnitTestCase {
) ); ) );
$this->assertNotEmpty( $u ); $this->assertNotEmpty( $u );
$user = new WP_User( $u ); $user2 = new WP_User( $u );
$expected = str_repeat( 'a', 48 ) . '-2'; $expected = str_repeat( 'a', 48 ) . '-2';
$this->assertSame( $expected, $user->user_nicename ); $this->assertSame( $expected, $user2->user_nicename );
} }
/** /**
* @ticket 33793 * @ticket 33793
*/ */
public function test_wp_insert_user_should_not_truncate_to_a_duplicate_user_nicename_when_suffix_has_more_than_one_character() { public function test_wp_insert_user_should_not_truncate_to_a_duplicate_user_nicename_when_suffix_has_more_than_one_character() {
$users = self::factory()->user->create_many( 4, array( $user_ids = self::factory()->user->create_many( 4, array(
'user_nicename' => str_repeat( 'a', 50 ), 'user_nicename' => str_repeat( 'a', 50 ),
) ); ) );
foreach ( $user_ids as $i => $user_id ) {
$user = new WP_User( $user_id );
if ( 0 === $i ) {
$expected = str_repeat( 'a', 50 );
} else {
$expected = str_repeat( 'a', 48 ) . '-' . ( $i + 1 );
}
$this->assertSame( $expected, $user->user_nicename );
}
$user_login = str_repeat( 'a', 55 ); $user_login = str_repeat( 'a', 55 );
$u = wp_insert_user( array( $u = wp_insert_user( array(
'user_login' => $user_login, 'user_login' => $user_login,

View File

@ -27,10 +27,11 @@ class Tests_User_CountUserPosts extends WP_UnitTestCase {
'post_author' => 12345, 'post_author' => 12345,
'post_type' => 'wptests_pt', 'post_type' => 'wptests_pt',
) ) ); ) ) );
self::$post_ids = array_merge( self::$post_ids, $factory->post->create_many( 1, array(
self::$post_ids[] = $factory->post->create( array(
'post_author' => 12345, 'post_author' => 12345,
'post_type' => 'wptests_pt', 'post_type' => 'wptests_pt',
) ) ); ) );
} }
public static function wpTearDownAfterClass() { public static function wpTearDownAfterClass() {

View File

@ -4,7 +4,7 @@
* @group user * @group user
*/ */
class Tests_User_ListAuthors extends WP_UnitTestCase { class Tests_User_ListAuthors extends WP_UnitTestCase {
static $users = array(); static $user_ids = array();
static $fred_id; static $fred_id;
static $posts = array(); static $posts = array();
static $user_urls = array(); static $user_urls = array();
@ -24,13 +24,13 @@ class Tests_User_ListAuthors extends WP_UnitTestCase {
'html' => true ); 'html' => true );
*/ */
public static function wpSetUpBeforeClass( $factory ) { public static function wpSetUpBeforeClass( $factory ) {
self::$users[] = $factory->user->create( array( 'user_login' => 'zack', 'display_name' => 'zack', 'role' => 'author', 'first_name' => 'zack', 'last_name' => 'moon' ) ); self::$user_ids[] = $factory->user->create( array( 'user_login' => 'zack', 'display_name' => 'zack', 'role' => 'author', 'first_name' => 'zack', 'last_name' => 'moon' ) );
self::$users[] = $factory->user->create( array( 'user_login' => 'bob', 'display_name' => 'bob', 'role' => 'author', 'first_name' => 'bob', 'last_name' => 'reno' ) ); self::$user_ids[] = $factory->user->create( array( 'user_login' => 'bob', 'display_name' => 'bob', 'role' => 'author', 'first_name' => 'bob', 'last_name' => 'reno' ) );
self::$users[] = $factory->user->create( array( 'user_login' => 'paul', 'display_name' => 'paul', 'role' => 'author', 'first_name' => 'paul', 'last_name' => 'norris' ) ); self::$user_ids[] = $factory->user->create( array( 'user_login' => 'paul', 'display_name' => 'paul', 'role' => 'author', 'first_name' => 'paul', 'last_name' => 'norris' ) );
self::$fred_id = $factory->user->create( array( 'user_login' => 'fred', 'role' => 'author' ) ); self::$fred_id = $factory->user->create( array( 'user_login' => 'fred', 'role' => 'author' ) );
$count = 0; $count = 0;
foreach ( self::$users as $userid ) { foreach ( self::$user_ids as $userid ) {
$count = $count + 1; $count = $count + 1;
for ( $i = 0; $i < $count; $i++ ) { for ( $i = 0; $i < $count; $i++ ) {
self::$posts[] = $factory->post->create( array( 'post_type' => 'post', 'post_author' => $userid ) ); self::$posts[] = $factory->post->create( array( 'post_type' => 'post', 'post_author' => $userid ) );
@ -41,7 +41,9 @@ class Tests_User_ListAuthors extends WP_UnitTestCase {
} }
public static function wpTearDownAfterClass() { public static function wpTearDownAfterClass() {
foreach ( array_merge( self::$users, array( self::$fred_id ) ) as $user_id ) { self::$user_ids[] = self::$fred_id;
foreach ( self::$user_ids as $user_id ) {
self::delete_user( $user_id ); self::delete_user( $user_id );
} }
@ -96,17 +98,17 @@ class Tests_User_ListAuthors extends WP_UnitTestCase {
} }
function test_wp_list_authors_feed() { function test_wp_list_authors_feed() {
$url0 = get_author_feed_link( self::$users[0] ); $url0 = get_author_feed_link( self::$user_ids[0] );
$url1 = get_author_feed_link( self::$users[1] ); $url1 = get_author_feed_link( self::$user_ids[1] );
$url2 = get_author_feed_link( self::$users[2] ); $url2 = get_author_feed_link( self::$user_ids[2] );
$expected['feed'] = '<li><a href="' . self::$user_urls[1] . '" title="Posts by bob">bob</a> (<a href="' . $url1 . '">link to feed</a>)</li><li><a href="' . self::$user_urls[2] . '" title="Posts by paul">paul</a> (<a href="' . $url2 . '">link to feed</a>)</li><li><a href="' . self::$user_urls[0] . '" title="Posts by zack">zack</a> (<a href="' . $url0 . '">link to feed</a>)</li>'; $expected['feed'] = '<li><a href="' . self::$user_urls[1] . '" title="Posts by bob">bob</a> (<a href="' . $url1 . '">link to feed</a>)</li><li><a href="' . self::$user_urls[2] . '" title="Posts by paul">paul</a> (<a href="' . $url2 . '">link to feed</a>)</li><li><a href="' . self::$user_urls[0] . '" title="Posts by zack">zack</a> (<a href="' . $url0 . '">link to feed</a>)</li>';
$this->AssertEquals( $expected['feed'], wp_list_authors( array( 'echo' => false, 'feed' => 'link to feed' ) ) ); $this->AssertEquals( $expected['feed'], wp_list_authors( array( 'echo' => false, 'feed' => 'link to feed' ) ) );
} }
function test_wp_list_authors_feed_image() { function test_wp_list_authors_feed_image() {
$url0 = get_author_feed_link( self::$users[0] ); $url0 = get_author_feed_link( self::$user_ids[0] );
$url1 = get_author_feed_link( self::$users[1] ); $url1 = get_author_feed_link( self::$user_ids[1] );
$url2 = get_author_feed_link( self::$users[2] ); $url2 = get_author_feed_link( self::$user_ids[2] );
$expected['feed_image'] = '<li><a href="' . self::$user_urls[1] . '" title="Posts by bob">bob</a> <a href="' . $url1 . '"><img src="http://' . WP_TESTS_DOMAIN . '/path/to/a/graphic.png" style="border: none;" /></a></li><li><a href="' . self::$user_urls[2] . '" title="Posts by paul">paul</a> <a href="' . $url2 . '"><img src="http://' . WP_TESTS_DOMAIN . '/path/to/a/graphic.png" style="border: none;" /></a></li><li><a href="' . self::$user_urls[0] . '" title="Posts by zack">zack</a> <a href="' . $url0 . '"><img src="http://' . WP_TESTS_DOMAIN . '/path/to/a/graphic.png" style="border: none;" /></a></li>'; $expected['feed_image'] = '<li><a href="' . self::$user_urls[1] . '" title="Posts by bob">bob</a> <a href="' . $url1 . '"><img src="http://' . WP_TESTS_DOMAIN . '/path/to/a/graphic.png" style="border: none;" /></a></li><li><a href="' . self::$user_urls[2] . '" title="Posts by paul">paul</a> <a href="' . $url2 . '"><img src="http://' . WP_TESTS_DOMAIN . '/path/to/a/graphic.png" style="border: none;" /></a></li><li><a href="' . self::$user_urls[0] . '" title="Posts by zack">zack</a> <a href="' . $url0 . '"><img src="http://' . WP_TESTS_DOMAIN . '/path/to/a/graphic.png" style="border: none;" /></a></li>';
$this->AssertEquals( $expected['feed_image'], wp_list_authors( array( 'echo' => false, 'feed_image' => WP_TESTS_DOMAIN . '/path/to/a/graphic.png' ) ) ); $this->AssertEquals( $expected['feed_image'], wp_list_authors( array( 'echo' => false, 'feed_image' => WP_TESTS_DOMAIN . '/path/to/a/graphic.png' ) ) );
} }
@ -115,9 +117,9 @@ class Tests_User_ListAuthors extends WP_UnitTestCase {
* @ticket 26538 * @ticket 26538
*/ */
function test_wp_list_authors_feed_type() { function test_wp_list_authors_feed_type() {
$url0 = get_author_feed_link( self::$users[0], 'atom' ); $url0 = get_author_feed_link( self::$user_ids[0], 'atom' );
$url1 = get_author_feed_link( self::$users[1], 'atom' ); $url1 = get_author_feed_link( self::$user_ids[1], 'atom' );
$url2 = get_author_feed_link( self::$users[2], 'atom' ); $url2 = get_author_feed_link( self::$user_ids[2], 'atom' );
$expected['feed_type'] = '<li><a href="' . self::$user_urls[1] . '" title="Posts by bob">bob</a> (<a href="' . $url1 . '">link to feed</a>)</li><li><a href="' . self::$user_urls[2] . '" title="Posts by paul">paul</a> (<a href="' . $url2 . '">link to feed</a>)</li><li><a href="' . self::$user_urls[0] . '" title="Posts by zack">zack</a> (<a href="' . $url0 . '">link to feed</a>)</li>'; $expected['feed_type'] = '<li><a href="' . self::$user_urls[1] . '" title="Posts by bob">bob</a> (<a href="' . $url1 . '">link to feed</a>)</li><li><a href="' . self::$user_urls[2] . '" title="Posts by paul">paul</a> (<a href="' . $url2 . '">link to feed</a>)</li><li><a href="' . self::$user_urls[0] . '" title="Posts by zack">zack</a> (<a href="' . $url0 . '">link to feed</a>)</li>';
$this->AssertEquals( $expected['feed_type'], wp_list_authors( array( 'echo' => false, 'feed' => 'link to feed', 'feed_type' => 'atom' ) ) ); $this->AssertEquals( $expected['feed_type'], wp_list_authors( array( 'echo' => false, 'feed' => 'link to feed', 'feed_type' => 'atom' ) ) );
} }

View File

@ -932,6 +932,8 @@ class Tests_User_Query extends WP_UnitTestCase {
*/ */
public function test_get_single_role_by_string_which_is_similar() { public function test_get_single_role_by_string_which_is_similar() {
$another_editor = self::factory()->user->create( array( $another_editor = self::factory()->user->create( array(
'user_email' => 'another_editor@another_editor.com',
'user_login' => 'another_editor',
'role' => 'another-editor', 'role' => 'another-editor',
) ); ) );

View File

@ -9,7 +9,7 @@ class Tests_User_Slashes extends WP_UnitTestCase {
function setUp() { function setUp() {
parent::setUp(); parent::setUp();
$this->author_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); $this->author_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
$this->old_current_user = get_current_user_id();
wp_set_current_user( $this->author_id ); wp_set_current_user( $this->author_id );
// it is important to test with both even and odd numbered slashes as // it is important to test with both even and odd numbered slashes as
@ -23,11 +23,6 @@ class Tests_User_Slashes extends WP_UnitTestCase {
$this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\'; $this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\';
} }
function tearDown() {
wp_set_current_user( $this->old_current_user );
parent::tearDown();
}
/** /**
* Tests the controller function that expects slashed data * Tests the controller function that expects slashed data
* *

View File

@ -41,7 +41,7 @@ class Tests_XMLRPC_mw_getRecentPosts extends WP_XMLRPC_UnitTestCase {
} }
function test_no_editable_posts() { function test_no_editable_posts() {
wp_delete_post( $this->post_id ); wp_delete_post( $this->post_id, true );
$result = $this->myxmlrpcserver->mw_getRecentPosts( array( 1, 'author', 'author' ) ); $result = $this->myxmlrpcserver->mw_getRecentPosts( array( 1, 'author', 'author' ) );
$this->assertNotInstanceOf( 'IXR_Error', $result ); $this->assertNotInstanceOf( 'IXR_Error', $result );

View File

@ -23,11 +23,6 @@ class Tests_XMLRPC_wp_getPage extends WP_XMLRPC_UnitTestCase {
$this->post_id = wp_insert_post( $this->post_data ); $this->post_id = wp_insert_post( $this->post_data );
} }
function tearDown() {
wp_delete_post( $this->post_id );
parent::tearDown();
}
function test_invalid_username_password() { function test_invalid_username_password() {
$result = $this->myxmlrpcserver->wp_getPage( array( 1, $this->post_id, 'username', 'password' ) ); $result = $this->myxmlrpcserver->wp_getPage( array( 1, $this->post_id, 'username', 'password' ) );
$this->assertInstanceOf( 'IXR_Error', $result ); $this->assertInstanceOf( 'IXR_Error', $result );

View File

@ -17,9 +17,9 @@ class Tests_XMLRPC_wp_getUser extends WP_XMLRPC_UnitTestCase {
} }
function tearDown() { function tearDown() {
if ( is_multisite() ) if ( is_multisite() ) {
revoke_super_admin( $this->administrator_id ); revoke_super_admin( $this->administrator_id );
}
parent::tearDown(); parent::tearDown();
} }