Share fixtures across `wp_list_authors()` tests.

See #30017.

git-svn-id: https://develop.svn.wordpress.org/trunk@31676 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges 2015-03-08 15:57:02 +00:00
parent a88e5fcadb
commit 969c850149
1 changed files with 55 additions and 33 deletions

View File

@ -4,8 +4,10 @@
* @group user
*/
class Tests_User_ListAuthors extends WP_UnitTestCase {
var $users = array();
var $user_urls = array();
static $users = array();
static $fred_id;
static $posts = array();
static $user_urls = array();
/* Defaults
'orderby' => 'name',
'order' => 'ASC',
@ -21,61 +23,82 @@ class Tests_User_ListAuthors extends WP_UnitTestCase {
'style' => 'list',
'html' => true );
*/
function setUp() {
parent::setUp();
$this->users[] = $this->factory->user->create( array( 'user_login' => 'zack', 'display_name' => 'zack', 'role' => 'author', 'first_name' => 'zack', 'last_name' => 'moon' ) );
$this->users[] = $this->factory->user->create( array( 'user_login' => 'bob', 'display_name' => 'bob', 'role' => 'author', 'first_name' => 'bob', 'last_name' => 'reno' ) );
$this->users[] = $this->factory->user->create( array( 'user_login' => 'paul', 'display_name' => 'paul', 'role' => 'author', 'first_name' => 'paul', 'last_name' => 'norris' ) );
public static function setUpBeforeClass() {
$factory = new WP_UnitTest_Factory;
self::$users[] = $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::$users[] = $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' ) );
$count = 0;
foreach ( $this->users as $userid ) {
foreach ( self::$users as $userid ) {
$count = $count + 1;
for ( $i = 0; $i < $count; $i++ ) {
$this->factory->post->create( array( 'post_type' => 'post', 'post_author' => $userid ) );
self::$posts[] = $factory->post->create( array( 'post_type' => 'post', 'post_author' => $userid ) );
}
$this->user_urls[] = get_author_posts_url( $userid );
self::$user_urls[] = get_author_posts_url( $userid );
}
self::commit_transaction();
}
public static function tearDownAfterClass() {
foreach ( array_merge( self::$users, array( self::$fred_id ) ) as $user_id ) {
if ( is_multisite() ) {
wpmu_delete_user( $user_id );
} else {
wp_delete_user( $user_id );
}
}
foreach ( self::$posts as $post_id ) {
wp_delete_post( $post_id, true );
}
self::commit_transaction();
}
function test_wp_list_authors_default() {
$expected['default'] = '<li><a href="' . $this->user_urls[1] . '" title="Posts by bob">bob</a></li><li><a href="' . $this->user_urls[2] . '" title="Posts by paul">paul</a></li><li><a href="' . $this->user_urls[0] . '" title="Posts by zack">zack</a></li>';
$expected['default'] = '<li><a href="' . self::$user_urls[1] . '" title="Posts by bob">bob</a></li><li><a href="' . self::$user_urls[2] . '" title="Posts by paul">paul</a></li><li><a href="' . self::$user_urls[0] . '" title="Posts by zack">zack</a></li>';
$this->AssertEquals( $expected['default'], wp_list_authors( array( 'echo' => false ) ) );
}
function test_wp_list_authors_orderby() {
$expected['post_count'] = '<li><a href="' . $this->user_urls[0] . '" title="Posts by zack">zack</a></li><li><a href="' . $this->user_urls[1] . '" title="Posts by bob">bob</a></li><li><a href="' . $this->user_urls[2] . '" title="Posts by paul">paul</a></li>';
$expected['post_count'] = '<li><a href="' . self::$user_urls[0] . '" title="Posts by zack">zack</a></li><li><a href="' . self::$user_urls[1] . '" title="Posts by bob">bob</a></li><li><a href="' . self::$user_urls[2] . '" title="Posts by paul">paul</a></li>';
$this->AssertEquals( $expected['post_count'], wp_list_authors( array( 'echo' => false, 'orderby' => 'post_count' ) ) );
}
function test_wp_list_authors_order() {
$expected['id'] = '<li><a href="' . $this->user_urls[2] . '" title="Posts by paul">paul</a></li><li><a href="' . $this->user_urls[1] . '" title="Posts by bob">bob</a></li><li><a href="' . $this->user_urls[0] . '" title="Posts by zack">zack</a></li>';
$expected['id'] = '<li><a href="' . self::$user_urls[2] . '" title="Posts by paul">paul</a></li><li><a href="' . self::$user_urls[1] . '" title="Posts by bob">bob</a></li><li><a href="' . self::$user_urls[0] . '" title="Posts by zack">zack</a></li>';
$this->AssertEquals( $expected['id'], wp_list_authors( array( 'echo' => false, 'orderby' => 'id', 'order' => 'DESC' ) ) );
}
function test_wp_list_authors_optioncount() {
$expected['optioncount'] = '<li><a href="' . $this->user_urls[1] . '" title="Posts by bob">bob</a> (2)</li><li><a href="' . $this->user_urls[2] . '" title="Posts by paul">paul</a> (3)</li><li><a href="' . $this->user_urls[0] . '" title="Posts by zack">zack</a> (1)</li>';
$expected['optioncount'] = '<li><a href="' . self::$user_urls[1] . '" title="Posts by bob">bob</a> (2)</li><li><a href="' . self::$user_urls[2] . '" title="Posts by paul">paul</a> (3)</li><li><a href="' . self::$user_urls[0] . '" title="Posts by zack">zack</a> (1)</li>';
$this->AssertEquals( $expected['optioncount'], wp_list_authors( array( 'echo' => false, 'optioncount' => 1 ) ) );
}
function test_wp_list_authors_exclude_admin() {
$this->factory->post->create( array( 'post_type' => 'post', 'post_author' => 1 ) );
$expected['exclude_admin'] = '<li><a href="' . get_author_posts_url( 1 ) . '" title="Posts by admin">admin</a></li><li><a href="' . $this->user_urls[1] . '" title="Posts by bob">bob</a></li><li><a href="' . $this->user_urls[2] . '" title="Posts by paul">paul</a></li><li><a href="' . $this->user_urls[0] . '" title="Posts by zack">zack</a></li>';
$expected['exclude_admin'] = '<li><a href="' . get_author_posts_url( 1 ) . '" title="Posts by admin">admin</a></li><li><a href="' . self::$user_urls[1] . '" title="Posts by bob">bob</a></li><li><a href="' . self::$user_urls[2] . '" title="Posts by paul">paul</a></li><li><a href="' . self::$user_urls[0] . '" title="Posts by zack">zack</a></li>';
$this->AssertEquals( $expected['exclude_admin'], wp_list_authors( array( 'echo' => false, 'exclude_admin' => 0 ) ) );
}
function test_wp_list_authors_show_fullname() {
$expected['show_fullname'] = '<li><a href="' . $this->user_urls[1] . '" title="Posts by bob">bob reno</a></li><li><a href="' . $this->user_urls[2] . '" title="Posts by paul">paul norris</a></li><li><a href="' . $this->user_urls[0] . '" title="Posts by zack">zack moon</a></li>';
$expected['show_fullname'] = '<li><a href="' . self::$user_urls[1] . '" title="Posts by bob">bob reno</a></li><li><a href="' . self::$user_urls[2] . '" title="Posts by paul">paul norris</a></li><li><a href="' . self::$user_urls[0] . '" title="Posts by zack">zack moon</a></li>';
$this->AssertEquals( $expected['show_fullname'], wp_list_authors( array( 'echo' => false, 'show_fullname' => 1 ) ) );
}
function test_wp_list_authors_hide_empty() {
$fred_id = $this->factory->user->create( array( 'user_login' => 'fred', 'role' => 'author' ) );
$expected['hide_empty'] = '<li><a href="' . $this->user_urls[1] . '" title="Posts by bob">bob</a></li><li><a href="' . get_author_posts_url( $fred_id ) . '" title="Posts by fred">fred</a></li><li><a href="' . $this->user_urls[2] . '" title="Posts by paul">paul</a></li><li><a href="' . $this->user_urls[0] . '" title="Posts by zack">zack</a></li>';
$fred_id = self::$fred_id;
$expected['hide_empty'] = '<li><a href="' . self::$user_urls[1] . '" title="Posts by bob">bob</a></li><li><a href="' . get_author_posts_url( $fred_id ) . '" title="Posts by fred">fred</a></li><li><a href="' . self::$user_urls[2] . '" title="Posts by paul">paul</a></li><li><a href="' . self::$user_urls[0] . '" title="Posts by zack">zack</a></li>';
$this->AssertEquals( $expected['hide_empty'], wp_list_authors( array( 'echo' => false, 'hide_empty' => 0 ) ) );
}
function test_wp_list_authors_echo() {
$expected['echo'] = '<li><a href="' . $this->user_urls[1] . '" title="Posts by bob">bob</a></li><li><a href="' . $this->user_urls[2] . '" title="Posts by paul">paul</a></li><li><a href="' . $this->user_urls[0] . '" title="Posts by zack">zack</a></li>';
$expected['echo'] = '<li><a href="' . self::$user_urls[1] . '" title="Posts by bob">bob</a></li><li><a href="' . self::$user_urls[2] . '" title="Posts by paul">paul</a></li><li><a href="' . self::$user_urls[0] . '" title="Posts by zack">zack</a></li>';
ob_start();
wp_list_authors( array( 'echo' => true ) );
$actual = ob_get_clean();
@ -83,18 +106,18 @@ class Tests_User_ListAuthors extends WP_UnitTestCase {
}
function test_wp_list_authors_feed() {
$url0 = get_author_feed_link( $this->users[0] );
$url1 = get_author_feed_link( $this->users[1] );
$url2 = get_author_feed_link( $this->users[2] );
$expected['feed'] = '<li><a href="' . $this->user_urls[1] . '" title="Posts by bob">bob</a> (<a href="' . $url1 . '">link to feed</a>)</li><li><a href="' . $this->user_urls[2] . '" title="Posts by paul">paul</a> (<a href="' . $url2 . '">link to feed</a>)</li><li><a href="' . $this->user_urls[0] . '" title="Posts by zack">zack</a> (<a href="' . $url0 . '">link to feed</a>)</li>';
$url0 = get_author_feed_link( self::$users[0] );
$url1 = get_author_feed_link( self::$users[1] );
$url2 = get_author_feed_link( self::$users[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>';
$this->AssertEquals( $expected['feed'], wp_list_authors( array( 'echo' => false, 'feed' => 'link to feed' ) ) );
}
function test_wp_list_authors_feed_image() {
$url0 = get_author_feed_link( $this->users[0] );
$url1 = get_author_feed_link( $this->users[1] );
$url2 = get_author_feed_link( $this->users[2] );
$expected['feed_image'] = '<li><a href="' . $this->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="' . $this->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="' . $this->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>';
$url0 = get_author_feed_link( self::$users[0] );
$url1 = get_author_feed_link( self::$users[1] );
$url2 = get_author_feed_link( self::$users[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>';
$this->AssertEquals( $expected['feed_image'], wp_list_authors( array( 'echo' => false, 'feed_image' => WP_TESTS_DOMAIN . '/path/to/a/graphic.png' ) ) );
}
@ -102,15 +125,15 @@ class Tests_User_ListAuthors extends WP_UnitTestCase {
* @ticket 26538
*/
function test_wp_list_authors_feed_type() {
$url0 = get_author_feed_link( $this->users[0], 'atom' );
$url1 = get_author_feed_link( $this->users[1], 'atom' );
$url2 = get_author_feed_link( $this->users[2], 'atom' );
$expected['feed_type'] = '<li><a href="' . $this->user_urls[1] . '" title="Posts by bob">bob</a> (<a href="' . $url1 . '">link to feed</a>)</li><li><a href="' . $this->user_urls[2] . '" title="Posts by paul">paul</a> (<a href="' . $url2 . '">link to feed</a>)</li><li><a href="' . $this->user_urls[0] . '" title="Posts by zack">zack</a> (<a href="' . $url0 . '">link to feed</a>)</li>';
$url0 = get_author_feed_link( self::$users[0], 'atom' );
$url1 = get_author_feed_link( self::$users[1], 'atom' );
$url2 = get_author_feed_link( self::$users[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>';
$this->AssertEquals( $expected['feed_type'], wp_list_authors( array( 'echo' => false, 'feed' => 'link to feed', 'feed_type' => 'atom' ) ) );
}
function test_wp_list_authors_style() {
$expected['style'] = '<a href="' . $this->user_urls[1] . '" title="Posts by bob">bob</a>, <a href="' . $this->user_urls[2] . '" title="Posts by paul">paul</a>, <a href="' . $this->user_urls[0] . '" title="Posts by zack">zack</a>';
$expected['style'] = '<a href="' . self::$user_urls[1] . '" title="Posts by bob">bob</a>, <a href="' . self::$user_urls[2] . '" title="Posts by paul">paul</a>, <a href="' . self::$user_urls[0] . '" title="Posts by zack">zack</a>';
$this->AssertEquals( $expected['style'], wp_list_authors( array( 'echo' => false, 'style' => 'none' ) ) );
}
@ -118,5 +141,4 @@ class Tests_User_ListAuthors extends WP_UnitTestCase {
$expected['html'] = 'bob, paul, zack';
$this->AssertEquals( $expected['html'], wp_list_authors( array( 'echo' => false, 'html' => 0 ) ) );
}
}