Changeset 31676
- Timestamp:
- 03/08/2015 03:57:02 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/user/listAuthors.php
r29992 r31676 5 5 */ 6 6 class Tests_User_ListAuthors extends WP_UnitTestCase { 7 var $users = array(); 8 var $user_urls = array(); 7 static $users = array(); 8 static $fred_id; 9 static $posts = array(); 10 static $user_urls = array(); 9 11 /* Defaults 10 12 'orderby' => 'name', … … 22 24 'html' => true ); 23 25 */ 24 function setUp() { 25 parent::setUp(); 26 $this->users[] = $this->factory->user->create( array( 'user_login' => 'zack', 'display_name' => 'zack', 'role' => 'author', 'first_name' => 'zack', 'last_name' => 'moon' ) ); 27 $this->users[] = $this->factory->user->create( array( 'user_login' => 'bob', 'display_name' => 'bob', 'role' => 'author', 'first_name' => 'bob', 'last_name' => 'reno' ) ); 28 $this->users[] = $this->factory->user->create( array( 'user_login' => 'paul', 'display_name' => 'paul', 'role' => 'author', 'first_name' => 'paul', 'last_name' => 'norris' ) ); 26 public static function setUpBeforeClass() { 27 $factory = new WP_UnitTest_Factory; 28 29 self::$users[] = $factory->user->create( array( 'user_login' => 'zack', 'display_name' => 'zack', 'role' => 'author', 'first_name' => 'zack', 'last_name' => 'moon' ) ); 30 self::$users[] = $factory->user->create( array( 'user_login' => 'bob', 'display_name' => 'bob', 'role' => 'author', 'first_name' => 'bob', 'last_name' => 'reno' ) ); 31 self::$users[] = $factory->user->create( array( 'user_login' => 'paul', 'display_name' => 'paul', 'role' => 'author', 'first_name' => 'paul', 'last_name' => 'norris' ) ); 32 self::$fred_id = $factory->user->create( array( 'user_login' => 'fred', 'role' => 'author' ) ); 33 29 34 $count = 0; 30 foreach ( $this->users as $userid ) {35 foreach ( self::$users as $userid ) { 31 36 $count = $count + 1; 32 37 for ( $i = 0; $i < $count; $i++ ) { 33 $this->factory->post->create( array( 'post_type' => 'post', 'post_author' => $userid ) );38 self::$posts[] = $factory->post->create( array( 'post_type' => 'post', 'post_author' => $userid ) ); 34 39 } 35 40 36 $this->user_urls[] = get_author_posts_url( $userid );41 self::$user_urls[] = get_author_posts_url( $userid ); 37 42 } 43 44 self::commit_transaction(); 45 } 46 47 public static function tearDownAfterClass() { 48 foreach ( array_merge( self::$users, array( self::$fred_id ) ) as $user_id ) { 49 if ( is_multisite() ) { 50 wpmu_delete_user( $user_id ); 51 } else { 52 wp_delete_user( $user_id ); 53 } 54 } 55 56 foreach ( self::$posts as $post_id ) { 57 wp_delete_post( $post_id, true ); 58 } 59 60 self::commit_transaction(); 38 61 } 39 62 40 63 function test_wp_list_authors_default() { 41 $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>';64 $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>'; 42 65 $this->AssertEquals( $expected['default'], wp_list_authors( array( 'echo' => false ) ) ); 43 66 } 44 67 45 68 function test_wp_list_authors_orderby() { 46 $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>';69 $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>'; 47 70 $this->AssertEquals( $expected['post_count'], wp_list_authors( array( 'echo' => false, 'orderby' => 'post_count' ) ) ); 48 71 } 49 72 50 73 function test_wp_list_authors_order() { 51 $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>';74 $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>'; 52 75 $this->AssertEquals( $expected['id'], wp_list_authors( array( 'echo' => false, 'orderby' => 'id', 'order' => 'DESC' ) ) ); 53 76 } 54 77 55 78 function test_wp_list_authors_optioncount() { 56 $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>';79 $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>'; 57 80 $this->AssertEquals( $expected['optioncount'], wp_list_authors( array( 'echo' => false, 'optioncount' => 1 ) ) ); 58 81 } … … 60 83 function test_wp_list_authors_exclude_admin() { 61 84 $this->factory->post->create( array( 'post_type' => 'post', 'post_author' => 1 ) ); 62 $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>';85 $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>'; 63 86 $this->AssertEquals( $expected['exclude_admin'], wp_list_authors( array( 'echo' => false, 'exclude_admin' => 0 ) ) ); 64 87 } 65 88 66 89 function test_wp_list_authors_show_fullname() { 67 $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>';90 $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>'; 68 91 $this->AssertEquals( $expected['show_fullname'], wp_list_authors( array( 'echo' => false, 'show_fullname' => 1 ) ) ); 69 92 } 70 93 71 94 function test_wp_list_authors_hide_empty() { 72 $fred_id = $this->factory->user->create( array( 'user_login' => 'fred', 'role' => 'author' ) );73 $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>';95 $fred_id = self::$fred_id; 96 $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>'; 74 97 $this->AssertEquals( $expected['hide_empty'], wp_list_authors( array( 'echo' => false, 'hide_empty' => 0 ) ) ); 75 98 } 76 99 77 100 function test_wp_list_authors_echo() { 78 $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>';101 $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>'; 79 102 ob_start(); 80 103 wp_list_authors( array( 'echo' => true ) ); … … 84 107 85 108 function test_wp_list_authors_feed() { 86 $url0 = get_author_feed_link( $this->users[0] );87 $url1 = get_author_feed_link( $this->users[1] );88 $url2 = get_author_feed_link( $this->users[2] );89 $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>';109 $url0 = get_author_feed_link( self::$users[0] ); 110 $url1 = get_author_feed_link( self::$users[1] ); 111 $url2 = get_author_feed_link( self::$users[2] ); 112 $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>'; 90 113 $this->AssertEquals( $expected['feed'], wp_list_authors( array( 'echo' => false, 'feed' => 'link to feed' ) ) ); 91 114 } 92 115 93 116 function test_wp_list_authors_feed_image() { 94 $url0 = get_author_feed_link( $this->users[0] );95 $url1 = get_author_feed_link( $this->users[1] );96 $url2 = get_author_feed_link( $this->users[2] );97 $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>';117 $url0 = get_author_feed_link( self::$users[0] ); 118 $url1 = get_author_feed_link( self::$users[1] ); 119 $url2 = get_author_feed_link( self::$users[2] ); 120 $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>'; 98 121 $this->AssertEquals( $expected['feed_image'], wp_list_authors( array( 'echo' => false, 'feed_image' => WP_TESTS_DOMAIN . '/path/to/a/graphic.png' ) ) ); 99 122 } … … 103 126 */ 104 127 function test_wp_list_authors_feed_type() { 105 $url0 = get_author_feed_link( $this->users[0], 'atom' );106 $url1 = get_author_feed_link( $this->users[1], 'atom' );107 $url2 = get_author_feed_link( $this->users[2], 'atom' );108 $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>';128 $url0 = get_author_feed_link( self::$users[0], 'atom' ); 129 $url1 = get_author_feed_link( self::$users[1], 'atom' ); 130 $url2 = get_author_feed_link( self::$users[2], 'atom' ); 131 $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>'; 109 132 $this->AssertEquals( $expected['feed_type'], wp_list_authors( array( 'echo' => false, 'feed' => 'link to feed', 'feed_type' => 'atom' ) ) ); 110 133 } 111 134 112 135 function test_wp_list_authors_style() { 113 $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>';136 $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>'; 114 137 $this->AssertEquals( $expected['style'], wp_list_authors( array( 'echo' => false, 'style' => 'none' ) ) ); 115 138 } … … 119 142 $this->AssertEquals( $expected['html'], wp_list_authors( array( 'echo' => false, 'html' => 0 ) ) ); 120 143 } 121 122 144 }
Note: See TracChangeset
for help on using the changeset viewer.