WordPress.org

Make WordPress Core

Ticket #26538: wp-list-author-unit-tests.3.diff

File wp-list-author-unit-tests.3.diff, 9.6 KB (added by MikeHansenMe, 6 years ago)

Added another ticket number

  • phpunit/tests/author/author-template.php

     
     1<?php
     2
     3class Tests_Author_Template extends WP_UnitTestCase {
     4        var $users;
     5                /* Defaults
     6                'orderby'       => 'name',
     7                'order'         => 'ASC',
     8                'number'        => null,
     9                'optioncount'   => false,
     10                'exclude_admin' => true,
     11                'show_fullname' => false,
     12                'hide_empty'    => true,
     13                'echo'          => true,
     14                'feed'          => [empty string],
     15                'feed_image'    => [empty string],
     16                'feed_type'     => [empty string],
     17                'style'         => 'list',
     18                'html'          => true );
     19                */
     20        function setUp() {
     21                parent::setUp();
     22                $users = array();
     23                $this->users[] = $this->factory->user->create( array( 'user_login' => 'zack', 'display_name' => 'zack', 'role' => 'author', 'first_name' => 'zack', 'last_name' => 'moon' ) );
     24                $this->users[] = $this->factory->user->create( array( 'user_login' => 'bob', 'display_name' => 'bob', 'role' => 'author', 'first_name' => 'bob', 'last_name' => 'reno' ) );
     25                $this->users[] = $this->factory->user->create( array( 'user_login' => 'paul', 'display_name' => 'paul', 'role' => 'author', 'first_name' => 'paul', 'last_name' => 'norris' ) );
     26                $count = 0;
     27                foreach ( $this->users as $userid ) {
     28                        $count = $count + 5;
     29                        for ( $i=0; $i < $count; $i++ ) {
     30                                $post_id = $this->factory->post->create( array( 'post_type' => 'post', 'post_author' => $userid ) );
     31                        }
     32                }
     33        }
     34
     35        function test_wp_list_authors_default() {
     36                $expected['default'] = '<li><a href="http://example.org/?author=' . $this->users[1] . '" title="Posts by bob">bob</a></li><li><a href="http://example.org/?author=' . $this->users[2] . '" title="Posts by paul">paul</a></li><li><a href="http://example.org/?author=' . $this->users[0] . '" title="Posts by zack">zack</a></li>';
     37                $this->AssertEquals( $expected['default'], wp_list_authors( array( 'echo' => false ) ) );
     38        }
     39
     40        function test_wp_list_authors_orderby() {
     41                $expected['post_count'] = '<li><a href="http://example.org/?author=' . $this->users[0] . '" title="Posts by zack">zack</a></li><li><a href="http://example.org/?author=' . $this->users[1] . '" title="Posts by bob">bob</a></li><li><a href="http://example.org/?author=' . $this->users[2] . '" title="Posts by paul">paul</a></li>';
     42                $this->AssertEquals( $expected['post_count'], wp_list_authors( array( 'echo' => false, 'orderby' => 'post_count' ) ) );
     43        }
     44
     45        function test_wp_list_authors_order() {
     46                $expected['id'] = '<li><a href="http://example.org/?author=' . $this->users[2] . '" title="Posts by paul">paul</a></li><li><a href="http://example.org/?author=' . $this->users[1] . '" title="Posts by bob">bob</a></li><li><a href="http://example.org/?author=' . $this->users[0] . '" title="Posts by zack">zack</a></li>';
     47                $this->AssertEquals( $expected['id'], wp_list_authors( array( 'echo' => false, 'orderby' => 'id', 'order' => 'DESC' ) ) );
     48        }
     49       
     50        /**
     51         * @ticket 23498
     52         */
     53        function test_wp_list_authors_number() {
     54                $expected['number'] = '<li><a href="http://example.org/?author=' . $this->users[1] . '" title="Posts by bob">bob</a></li><li><a href="http://example.org/?author=' . $this->users[2] . '" title="Posts by paul">paul</a></li>';
     55                $this->AssertEquals( $expected['number'], wp_list_authors( array( 'echo' => false, 'number' => 2 ) ) );
     56        }
     57
     58        function test_wp_list_authors_optioncount() {
     59                $expected['optioncount'] = '<li><a href="http://example.org/?author=' . $this->users[1] . '" title="Posts by bob">bob</a> (10)</li><li><a href="http://example.org/?author=' . $this->users[2] . '" title="Posts by paul">paul</a> (15)</li><li><a href="http://example.org/?author=' . $this->users[0] . '" title="Posts by zack">zack</a> (5)</li>';
     60                $this->AssertEquals( $expected['optioncount'], wp_list_authors( array( 'echo' => false, 'optioncount' => 1 ) ) );
     61        }
     62
     63        function test_wp_list_authors_exclude_admin() {
     64                $this->factory->post->create( array( 'post_type' => 'post', 'post_author' => 1 ) );
     65                $expected['exclude_admin'] = '<li><a href="http://example.org/?author=1" title="Posts by admin">admin</a></li><li><a href="http://example.org/?author=' . $this->users[1] . '" title="Posts by bob">bob</a></li><li><a href="http://example.org/?author=' . $this->users[2] . '" title="Posts by paul">paul</a></li><li><a href="http://example.org/?author=' . $this->users[0] . '" title="Posts by zack">zack</a></li>';
     66                $this->AssertEquals( $expected['exclude_admin'], wp_list_authors( array( 'echo' => false, 'exclude_admin' => 0 ) ) );
     67        }
     68
     69        function test_wp_list_authors_show_fullname() {
     70                $expected['show_fullname'] = '<li><a href="http://example.org/?author=' . $this->users[1] . '" title="Posts by bob">bob reno</a></li><li><a href="http://example.org/?author=' . $this->users[2] . '" title="Posts by paul">paul norris</a></li><li><a href="http://example.org/?author=' . $this->users[0] . '" title="Posts by zack">zack moon</a></li>';
     71                $this->AssertEquals( $expected['show_fullname'], wp_list_authors( array( 'echo' => false, 'show_fullname' => 1 ) ) );
     72        }
     73
     74        function test_wp_list_authors_hide_empty() {
     75                $fred_id = $this->factory->user->create( array( 'user_login' => 'fred', 'role' => 'author' ) );
     76                $expected['hide_empty'] = '<li><a href="http://example.org/?author=' . $this->users[1] . '" title="Posts by bob">bob</a></li><li><a href="http://example.org/?author=' . $fred_id . '" title="Posts by fred">fred</a></li><li><a href="http://example.org/?author=' . $this->users[2] . '" title="Posts by paul">paul</a></li><li><a href="http://example.org/?author=' . $this->users[0] . '" title="Posts by zack">zack</a></li>';
     77                $this->AssertEquals( $expected['hide_empty'], wp_list_authors( array( 'echo' => false, 'hide_empty' => 0 ) ) );
     78        }
     79
     80        function test_wp_list_authors_echo() {
     81                $expected['echo'] = '<li><a href="http://example.org/?author=' . $this->users[1] . '" title="Posts by bob">bob</a></li><li><a href="http://example.org/?author=' . $this->users[2] . '" title="Posts by paul">paul</a></li><li><a href="http://example.org/?author=' . $this->users[0] . '" title="Posts by zack">zack</a></li>';
     82                ob_start();
     83                wp_list_authors( array( 'echo' => true ) );
     84                $actual = ob_get_clean();
     85                $this->AssertEquals( $expected['echo'], $actual );
     86        }
     87       
     88        function test_wp_list_authors_feed() {
     89                $expected['feed'] = '<li><a href="http://example.org/?author=' . $this->users[1] . '" title="Posts by bob">bob</a> (<a href="http://example.org/?feed=rss2&amp;author=' . $this->users[1] . '" title="link to feed">link to feed</a>)</li><li><a href="http://example.org/?author=' . $this->users[2] . '" title="Posts by paul">paul</a> (<a href="http://example.org/?feed=rss2&amp;author=' . $this->users[2] . '" title="link to feed">link to feed</a>)</li><li><a href="http://example.org/?author=' . $this->users[0] . '" title="Posts by zack">zack</a> (<a href="http://example.org/?feed=rss2&amp;author=' . $this->users[0] . '" title="link to feed">link to feed</a>)</li>';
     90                $this->AssertEquals( $expected['feed'], wp_list_authors( array( 'echo' => false, 'feed' => 'link to feed' ) ) );
     91        }
     92
     93        function test_wp_list_authors_feed_image() {
     94                $expected['feed_image'] = '<li><a href="http://example.org/?author=' . $this->users[1] . '" title="Posts by bob">bob</a> <a href="http://example.org/?feed=rss2&amp;author=' . $this->users[1] . '"><img src="http://example.com/path/to/a/graphic.png" style="border: none;" /></a></li><li><a href="http://example.org/?author=' . $this->users[2] . '" title="Posts by paul">paul</a> <a href="http://example.org/?feed=rss2&amp;author=' . $this->users[2] . '"><img src="http://example.com/path/to/a/graphic.png" style="border: none;" /></a></li><li><a href="http://example.org/?author=' . $this->users[0] . '" title="Posts by zack">zack</a> <a href="http://example.org/?feed=rss2&amp;author=' . $this->users[0] . '"><img src="http://example.com/path/to/a/graphic.png" style="border: none;" /></a></li>';
     95                $this->AssertEquals( $expected['feed_image'], wp_list_authors( array( 'echo' => false, 'feed_image' => 'example.com/path/to/a/graphic.png' ) ) );
     96        }
     97
     98        /**
     99         * @ticket 26538
     100         */
     101        function test_wp_list_authors_feed_type() {
     102                $expected['feed_type'] = '<li><a href="http://example.org/?author=' . $this->users[1] . '" title="Posts by bob">bob</a> (<a href="http://example.org/?feed=atom&amp;author=' . $this->users[1] . '" title="link to feed">link to feed</a>)</li><li><a href="http://example.org/?author=' . $this->users[2] . '" title="Posts by paul">paul</a> (<a href="http://example.org/?feed=atom&amp;author=' . $this->users[2] . '" title="link to feed">link to feed</a>)</li><li><a href="http://example.org/?author=' . $this->users[0] . '" title="Posts by zack">zack</a> (<a href="http://example.org/?feed=atom&amp;author=' . $this->users[0] . '" title="link to feed">link to feed</a>)</li>';
     103                $this->AssertEquals( $expected['feed_type'], wp_list_authors( array( 'echo' => false, 'feed' => 'link to feed', 'feed_type' => 'atom' ) ) );
     104        }
     105
     106        function test_wp_list_authors_style() {
     107                $expected['style'] = '<a href="http://example.org/?author=' . $this->users[1] . '" title="Posts by bob">bob</a>, <a href="http://example.org/?author=' . $this->users[2] . '" title="Posts by paul">paul</a>, <a href="http://example.org/?author=' . $this->users[0] . '" title="Posts by zack">zack</a>';
     108                $this->AssertEquals( $expected['style'], wp_list_authors( array( 'echo' => false, 'style' => 'none' ) ) );
     109        }
     110
     111        function test_wp_list_authors_html() {
     112                $expected['html'] = 'bob, paul, zack';
     113                $this->AssertEquals( $expected['html'], wp_list_authors( array( 'echo' => false, 'html' => 0 ) ) );
     114        }
     115
     116}
     117 No newline at end of file