Skip to content
Permalink
Browse files

Users: Make `wp_list_authors()` unit tests more readable.

See #23498.

git-svn-id: https://develop.svn.wordpress.org/trunk@45795 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information...
SergeyBiryukov committed Aug 14, 2019
1 parent 5bcd25a commit d4a305292f07c314ea8ec1fa677bc78cef525130
Showing with 78 additions and 22 deletions.
  1. +78 −22 tests/phpunit/tests/user/listAuthors.php
@@ -75,12 +75,20 @@ public static function wpSetUpBeforeClass( $factory ) {
}
function test_wp_list_authors_default() {
$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>';
$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="' . 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>';
$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(
@@ -93,7 +101,11 @@ function test_wp_list_authors_orderby() {
}
function test_wp_list_authors_order() {
$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>';
$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(
@@ -107,7 +119,11 @@ function test_wp_list_authors_order() {
}
function test_wp_list_authors_optioncount() {
$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>';
$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(
@@ -126,7 +142,13 @@ function test_wp_list_authors_exclude_admin() {
'post_author' => 1,
)
);
$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>';
$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(
@@ -139,7 +161,11 @@ function test_wp_list_authors_exclude_admin() {
}
function test_wp_list_authors_show_fullname() {
$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>';
$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(
@@ -152,8 +178,14 @@ function test_wp_list_authors_show_fullname() {
}
function test_wp_list_authors_hide_empty() {
$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>';
$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(
@@ -166,16 +198,25 @@ function test_wp_list_authors_hide_empty() {
}
function test_wp_list_authors_echo() {
$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>';
$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>';
$this->expectOutputString( $expected['echo'] );
wp_list_authors( array( 'echo' => true ) );
}
function test_wp_list_authors_feed() {
$url0 = get_author_feed_link( self::$user_ids[0] );
$url1 = get_author_feed_link( self::$user_ids[1] );
$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>';
$url0 = get_author_feed_link( self::$user_ids[0] );
$url1 = get_author_feed_link( self::$user_ids[1] );
$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>';
$this->AssertEquals(
$expected['feed'],
wp_list_authors(
@@ -188,10 +229,15 @@ function test_wp_list_authors_feed() {
}
function test_wp_list_authors_feed_image() {
$url0 = get_author_feed_link( self::$user_ids[0] );
$url1 = get_author_feed_link( self::$user_ids[1] );
$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>';
$url0 = get_author_feed_link( self::$user_ids[0] );
$url1 = get_author_feed_link( self::$user_ids[1] );
$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>';
$this->AssertEquals(
$expected['feed_image'],
wp_list_authors(
@@ -207,10 +253,15 @@ function test_wp_list_authors_feed_image() {
* @ticket 26538
*/
function test_wp_list_authors_feed_type() {
$url0 = get_author_feed_link( self::$user_ids[0], 'atom' );
$url1 = get_author_feed_link( self::$user_ids[1], '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>';
$url0 = get_author_feed_link( self::$user_ids[0], 'atom' );
$url1 = get_author_feed_link( self::$user_ids[1], '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>';
$this->AssertEquals(
$expected['feed_type'],
wp_list_authors(
@@ -224,7 +275,11 @@ function test_wp_list_authors_feed_type() {
}
function test_wp_list_authors_style() {
$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>';
$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(
@@ -238,6 +293,7 @@ function test_wp_list_authors_style() {
function test_wp_list_authors_html() {
$expected['html'] = 'bob, paul, zack';
$this->AssertEquals(
$expected['html'],
wp_list_authors(

0 comments on commit d4a3052

Please sign in to comment.
You can’t perform that action at this time.