mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 12:20:22 +00:00
Move PHPUnit tests into a tests/phpunit directory.
wp-tests-config.php can/should reside in the root of a develop checkout. `phpunit` should be run from the root. see #25088. git-svn-id: https://develop.svn.wordpress.org/trunk@25165 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Test functions in wp-includes/author.php, author-template.php
|
||||
*
|
||||
* @group author
|
||||
* @group user
|
||||
*/
|
||||
class Tests_User_Author extends WP_UnitTestCase {
|
||||
protected $old_post_id = 0;
|
||||
protected $author_id = 0;
|
||||
protected $post_id = 0;
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->author_id = $this->factory->user->create( array(
|
||||
'role' => 'author',
|
||||
'user_login' => 'test_author',
|
||||
'description' => 'test_author',
|
||||
) );
|
||||
$user = new WP_User( $this->author_id );
|
||||
|
||||
$post = array(
|
||||
'post_author' => $this->author_id,
|
||||
'post_status' => 'publish',
|
||||
'post_content' => rand_str(),
|
||||
'post_title' => rand_str(),
|
||||
'post_type' => 'post'
|
||||
);
|
||||
|
||||
// insert a post and make sure the ID is ok
|
||||
$this->post_id = $this->factory->post->create( $post );
|
||||
|
||||
setup_postdata( get_post( $this->post_id ) );
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
wp_reset_postdata();
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
function test_get_the_author() {
|
||||
$author_name = get_the_author();
|
||||
$user = new WP_User( $this->author_id );
|
||||
|
||||
$this->assertEquals( $user->display_name, $author_name );
|
||||
$this->assertEquals( 'test_author', $author_name );
|
||||
}
|
||||
|
||||
function test_get_the_author_meta() {
|
||||
$this->assertEquals( 'test_author', get_the_author_meta( 'login' ) );
|
||||
$this->assertEquals( 'test_author', get_the_author_meta( 'user_login' ) );
|
||||
$this->assertEquals( 'test_author', get_the_author_meta( 'display_name' ) );
|
||||
|
||||
$this->assertEquals( 'test_author', get_the_author_meta( 'description' ) );
|
||||
$this->assertEquals( 'test_author', get_the_author_meta( 'user_description' ) );
|
||||
add_user_meta( $this->author_id, 'user_description', 'user description' );
|
||||
$this->assertEquals( 'user description', get_user_meta( $this->author_id, 'user_description', true ) );
|
||||
// user_description in meta is ignored. The content of description is returned instead.
|
||||
// See #20285
|
||||
$this->assertEquals( 'test_author', get_the_author_meta( 'user_description' ) );
|
||||
$this->assertEquals( 'test_author', get_the_author_meta( 'description' ) );
|
||||
update_user_meta( $this->author_id, 'user_description', '' );
|
||||
$this->assertEquals( '', get_user_meta( $this->author_id, 'user_description', true ) );
|
||||
$this->assertEquals( 'test_author', get_the_author_meta( 'user_description' ) );
|
||||
$this->assertEquals( 'test_author', get_the_author_meta( 'description' ) );
|
||||
|
||||
$this->assertEquals( '', get_the_author_meta( 'does_not_exist' ) );
|
||||
}
|
||||
|
||||
function test_get_the_author_meta_no_authordata() {
|
||||
unset( $GLOBALS['authordata'] );
|
||||
$this->assertEquals( '', get_the_author_meta( 'id' ) );
|
||||
$this->assertEquals( '', get_the_author_meta( 'user_login' ) );
|
||||
$this->assertEquals( '', get_the_author_meta( 'does_not_exist' ) );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user