Skip to:
Content

bbPress.org

Changeset 7762


Ignore:
Timestamp:
10/01/2026 12:18:13 AM (7 weeks ago)
Author:
johnjamesjacoby
Message:

Tests: Expand common, search, user, and admin coverage.

Replace 58 incomplete placeholders with assertions for common helpers, search requests, user templates, and safe admin-tool paths. Add search-type and request-sanitization coverage, with fixtures restored after each test.

In trunk, for 2.7.
See #3695.

Location:
trunk/tests/phpunit/testcases
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/admin/tools.php

    r7467 r7762  
    3030
    3131        /**
    32          * @covers ::bbp_admin_repair
    33          * @todo   Implement test_bbp_admin_repair().
     32         * @covers ::bbp_admin_repair_page
    3433         */
    3534        public function test_bbp_admin_repair() {
    36                 // Remove the following lines when you implement this test.
    37                 $this->markTestIncomplete(
    38                         'This test has not been implemented yet.'
    39                 );
     35                $original_get   = $_GET;
     36                $original_tools = bbp_admin()->tools;
     37                $_GET           = array( 'page' => 'bbp-repair' );
     38                bbp_register_default_repair_tools();
     39
     40                try {
     41                        ob_start();
     42                        bbp_admin_repair_page();
     43                        $output = ob_get_clean();
     44
     45                        $this->assertStringContainsString( 'name="page" value="bbp-repair"', $output );
     46                        $this->assertStringContainsString( 'name="checked[]"', $output );
     47                        $this->assertStringContainsString( 'name="_wpnonce"', $output );
     48                } finally {
     49                        $_GET              = $original_get;
     50                        bbp_admin()->tools = $original_tools;
     51                }
    4052        }
    4153
    4254        /**
    4355         * @covers ::bbp_admin_repair_handler
    44          * @todo   Implement test_bbp_admin_repair_handler().
     56         * @ticket 3695
    4557         */
    4658        public function test_bbp_admin_repair_handler() {
    47                 // Remove the following lines when you implement this test.
    48                 $this->markTestIncomplete(
    49                         'This test has not been implemented yet.'
    50                 );
     59                $original_get             = $_GET;
     60                $original_method          = isset( $_SERVER['REQUEST_METHOD'] ) ? $_SERVER['REQUEST_METHOD'] : null;
     61                $_GET                     = array( 'action' => 'not-run' );
     62                $_SERVER['REQUEST_METHOD'] = 'GET';
     63
     64                try {
     65                        $this->assertNull( bbp_admin_repair_handler() );
     66                } finally {
     67                        $_GET = $original_get;
     68                        if ( is_null( $original_method ) ) {
     69                                unset( $_SERVER['REQUEST_METHOD'] );
     70                        } else {
     71                                $_SERVER['REQUEST_METHOD'] = $original_method;
     72                        }
     73                }
    5174        }
    5275
    5376        /**
    5477         * @covers ::bbp_admin_tools_repair_help
    55          * @todo   Implement test_bbp_admin_tools_repair_help().
     78         * @ticket 3695
    5679         */
    5780        public function test_bbp_admin_tools_repair_help() {
    58                 // Remove the following lines when you implement this test.
    59                 $this->markTestIncomplete(
    60                         'This test has not been implemented yet.'
    61                 );
     81                $previous = get_current_screen();
     82                set_current_screen( 'tools_page_bbp-repair' );
     83
     84                try {
     85                        bbp_admin_tools_repair_help();
     86                        $tabs = get_current_screen()->get_help_tabs();
     87                        $this->assertArrayHasKey( 'repair_forums', $tabs );
     88                        $this->assertStringContainsString( 'bbPress: Repair Forums', $tabs['repair_forums']['content'] );
     89                        $this->assertStringContainsString( 'bbPress Documentation', get_current_screen()->get_help_sidebar() );
     90                } finally {
     91                        $GLOBALS['current_screen'] = $previous;
     92                }
    6293        }
    6394
    6495        /**
    6596         * @covers ::bbp_admin_tools_reset_help
    66          * @todo   Implement test_bbp_admin_tools_reset_help().
     97         * @ticket 3695
    6798         */
    6899        public function test_bbp_admin_tools_reset_help() {
    69                 // Remove the following lines when you implement this test.
    70                 $this->markTestIncomplete(
    71                         'This test has not been implemented yet.'
    72                 );
     100                $previous = get_current_screen();
     101                set_current_screen( 'tools_page_bbp-reset' );
     102
     103                try {
     104                        bbp_admin_tools_reset_help();
     105                        $tabs = get_current_screen()->get_help_tabs();
     106                        $this->assertArrayHasKey( 'reset_forums', $tabs );
     107                        $this->assertStringContainsString( 'bbPress: Reset Forums', $tabs['reset_forums']['content'] );
     108                } finally {
     109                        $GLOBALS['current_screen'] = $previous;
     110                }
    73111        }
    74112
    75113        /**
    76114         * @covers ::bbp_admin_tools_converter_help
    77          * @todo   Implement test_bbp_admin_tools_converter_help().
     115         * @ticket 3695
    78116         */
    79117        public function test_bbp_admin_tools_converter_help() {
    80                 // Remove the following lines when you implement this test.
    81                 $this->markTestIncomplete(
    82                         'This test has not been implemented yet.'
    83                 );
     118                $previous = get_current_screen();
     119                set_current_screen( 'tools_page_bbp-converter' );
     120
     121                try {
     122                        bbp_admin_tools_converter_help();
     123                        $tabs = get_current_screen()->get_help_tabs();
     124                        $this->assertSame( array( 'overview', 'database_settings', 'importer_options' ), array_keys( $tabs ) );
     125                        $this->assertStringContainsString( 'bbPress: Import Forums', $tabs['overview']['content'] );
     126                } finally {
     127                        $GLOBALS['current_screen'] = $previous;
     128                }
    84129        }
    85130
    86131        /**
    87132         * @covers ::bbp_admin_tools_feedback
    88          * @todo   Implement test_bbp_admin_tools_feedback().
     133         * @ticket 3695
    89134         */
    90135        public function test_bbp_admin_tools_feedback() {
    91                 // Remove the following lines when you implement this test.
    92                 $this->markTestIncomplete(
    93                         'This test has not been implemented yet.'
    94                 );
     136                $notices = bbp_admin()->notices;
     137
     138                try {
     139                        bbp_admin_tools_feedback( 'Repair complete', 'success', false );
     140                        $this->assertStringContainsString( 'notice success', end( bbp_admin()->notices ) );
     141                        $this->assertStringContainsString( '<p>Repair complete</p>', end( bbp_admin()->notices ) );
     142                        $this->assertStringNotContainsString( 'is-dismissible', end( bbp_admin()->notices ) );
     143                        $this->assertFalse( bbp_admin_tools_feedback( array( 'invalid' ) ) );
     144                } finally {
     145                        bbp_admin()->notices = $notices;
     146                }
    95147        }
    96148
    97149        /**
    98150         * @covers ::bbp_admin_repair_list
    99          * @todo   Implement test_bbp_admin_repair_list().
     151         * @ticket 3695
    100152         */
    101153        public function test_bbp_admin_repair_list() {
    102                 // Remove the following lines when you implement this test.
    103                 $this->markTestIncomplete(
    104                         'This test has not been implemented yet.'
    105                 );
     154                $original_get   = $_GET;
     155                $original_tools = bbp_admin()->tools;
     156                $_GET           = array( 's' => 'Recount' );
     157                bbp_register_default_repair_tools();
     158
     159                try {
     160                        $list = bbp_admin_repair_list();
     161                        $this->assertNotEmpty( $list );
     162                        foreach ( $list as $tool ) {
     163                                $this->assertSame( 'repair', $tool['type'] );
     164                                $this->assertStringContainsString( 'recount', strtolower( $tool['title'] ) );
     165                        }
     166                } finally {
     167                        $_GET              = $original_get;
     168                        bbp_admin()->tools = $original_tools;
     169                }
    106170        }
    107171
  • trunk/tests/phpunit/testcases/common/functions.php

    r7713 r7762  
    1515        /**
    1616         * @covers ::bbp_number_format
    17          * @todo   Implement test_bbp_number_format().
    1817         */
    1918        public function test_bbp_number_format() {
    20                 // Remove the following lines when you implement this test.
    21                 $this->markTestIncomplete(
    22                         'This test has not been implemented yet.'
    23                 );
     19                $this->assertSame( '1,234', bbp_number_format( 1234 ) );
     20                $this->assertSame( '1 234,50', bbp_number_format( 1234.5, 2, ',', ' ' ) );
     21                $this->assertSame( '0', bbp_number_format( 'not a number' ) );
    2422        }
    2523
    2624        /**
    2725         * @covers ::bbp_number_format_i18n
    28          * @todo   Implement test_bbp_number_format_i18n().
    2926         */
    3027        public function test_bbp_number_format_i18n() {
    31                 // Remove the following lines when you implement this test.
    32                 $this->markTestIncomplete(
    33                         'This test has not been implemented yet.'
    34                 );
     28                $this->assertSame( number_format_i18n( 1234.5, 2 ), bbp_number_format_i18n( 1234.5, 2 ) );
     29                $this->assertSame( number_format_i18n( 0 ), bbp_number_format_i18n( 'not a number' ) );
    3530        }
    3631
    3732        /**
    3833         * @covers ::bbp_convert_date
    39          * @todo   Implement test_bbp_convert_date().
    4034         */
    4135        public function test_bbp_convert_date() {
    42                 // Remove the following lines when you implement this test.
    43                 $this->markTestIncomplete(
    44                         'This test has not been implemented yet.'
    45                 );
     36                $this->assertSame( '2020-01-02', bbp_convert_date( '2020-01-02 03:04:05', 'Y-m-d' ) );
     37                $this->assertSame( mysql2date( 'U', '2020-01-02 03:04:05' ), bbp_convert_date( '2020-01-02 03:04:05' ) );
    4638        }
    4739
    … …  
    562554        /**
    563555         * @covers ::bbp_format_revision_reason
    564          * @todo   Implement test_bbp_format_revision_reason().
    565556         */
    566557        public function test_bbp_format_revision_reason() {
    567                 // Remove the following lines when you implement this test.
    568                 $this->markTestIncomplete(
    569                         'This test has not been implemented yet.'
    570                 );
     558                $this->assertSame( '', bbp_format_revision_reason() );
     559                $this->assertSame( 'Correct typo', bbp_format_revision_reason( '  Correct typo...  ' ) );
     560                $this->assertSame( 'Correct typo', bbp_format_revision_reason( 'Correct typo...' ) );
    571561        }
    572562
    573563        /**
    574564         * @covers ::bbp_get_redirect_to
    575          * @todo   Implement test_bbp_get_redirect_to().
    576565         */
    577566        public function test_bbp_get_redirect_to() {
    578                 // Remove the following lines when you implement this test.
    579                 $this->markTestIncomplete(
    580                         'This test has not been implemented yet.'
    581                 );
     567                $old_request = $_REQUEST;
     568                try {
     569                        unset( $_REQUEST['redirect_to'] );
     570                        $this->assertSame( '', bbp_get_redirect_to() );
     571                        $_REQUEST['redirect_to'] = '/forums/';
     572                        $this->assertSame( '/forums/', bbp_get_redirect_to() );
     573                } finally {
     574                        $_REQUEST = $old_request;
     575                }
    582576        }
    583577
    584578        /**
    585579         * @covers ::bbp_add_view_all
    586          * @todo   Implement test_bbp_add_view_all().
    587580         */
    588581        public function test_bbp_add_view_all() {
    589                 // Remove the following lines when you implement this test.
    590                 $this->markTestIncomplete(
    591                         'This test has not been implemented yet.'
    592                 );
     582                $url = 'https://example.org/forums/?paged=2';
     583                $this->assertSame( $url, bbp_add_view_all( $url ) );
     584                $this->assertSame( 'https://example.org/forums/?paged=2&view=all', bbp_add_view_all( $url, true ) );
    593585        }
    594586
    595587        /**
    596588         * @covers ::bbp_remove_view_all
    597          * @todo   Implement test_bbp_remove_view_all().
    598589         */
    599590        public function test_bbp_remove_view_all() {
    600                 // Remove the following lines when you implement this test.
    601                 $this->markTestIncomplete(
    602                         'This test has not been implemented yet.'
    603                 );
     591                $this->assertSame( 'https://example.org/forums/?paged=2', bbp_remove_view_all( 'https://example.org/forums/?paged=2&view=all' ) );
     592                $this->assertSame( 'https://example.org/forums/', bbp_remove_view_all( 'https://example.org/forums/' ) );
    604593        }
    605594
    606595        /**
    607596         * @covers ::bbp_get_view_all
    608          * @todo   Implement test_bbp_get_view_all().
    609597         */
    610598        public function test_bbp_get_view_all() {
    611                 // Remove the following lines when you implement this test.
    612                 $this->markTestIncomplete(
    613                         'This test has not been implemented yet.'
    614                 );
     599                $old_get  = $_GET;
     600                $old_user = get_current_user_id();
     601                try {
     602                        $_GET['view'] = 'all';
     603                        wp_set_current_user( 0 );
     604                        $this->assertFalse( bbp_get_view_all() );
     605                        $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
     606                        bbp_set_user_role( $user_id, bbp_get_keymaster_role() );
     607                        wp_set_current_user( $user_id );
     608                        $this->assertTrue( current_user_can( 'moderate' ) );
     609                        $this->assertTrue( bbp_get_view_all() );
     610                        $_GET['view'] = 'single';
     611                        $this->assertFalse( bbp_get_view_all() );
     612                } finally {
     613                        $_GET = $old_get;
     614                        wp_set_current_user( $old_user );
     615                }
    615616        }
    616617
    617618        /**
    618619         * @covers ::bbp_get_paged
    619          * @todo   Implement test_bbp_get_paged().
    620620         */
    621621        public function test_bbp_get_paged() {
    622                 // Remove the following lines when you implement this test.
    623                 $this->markTestIncomplete(
    624                         'This test has not been implemented yet.'
    625                 );
     622                $wp_query      = bbp_get_wp_query();
     623                $old_query     = $wp_query->query;
     624                $old_query_var = get_query_var( 'paged' );
     625                try {
     626                        unset( $wp_query->query['paged'] );
     627                        set_query_var( 'paged', 0 );
     628                        $this->assertSame( 1, bbp_get_paged() );
     629                        $wp_query->query['paged'] = '3';
     630                        $this->assertSame( 3, bbp_get_paged() );
     631                        set_query_var( 'paged', '2' );
     632                        $this->assertSame( 2, bbp_get_paged() );
     633                } finally {
     634                        $wp_query->query = $old_query;
     635                        set_query_var( 'paged', $old_query_var );
     636                }
    626637        }
    627638
    628639        /**
    629640         * @covers ::bbp_fix_post_author
    630          * @todo   Implement test_bbp_fix_post_author().
    631641         */
    632642        public function test_bbp_fix_post_author() {
    633                 // Remove the following lines when you implement this test.
    634                 $this->markTestIncomplete(
    635                         'This test has not been implemented yet.'
    636                 );
     643                $author_id = $this->factory->user->create();
     644                $topic_id  = $this->factory->topic->create( array( 'post_author' => 0 ) );
     645                $data      = array( 'post_type' => bbp_get_topic_post_type(), 'post_author' => $author_id );
     646                $this->assertSame( 0, bbp_fix_post_author( $data, array( 'ID' => $topic_id ) )['post_author'] );
     647                $this->assertSame( $data, bbp_fix_post_author( $data, array() ) );
     648                $authored_topic = $this->factory->topic->create( array( 'post_author' => $author_id ) );
     649                $this->assertSame( $data, bbp_fix_post_author( $data, array( 'ID' => $authored_topic ) ) );
     650                $non_bbp_data = array( 'post_type' => 'post', 'post_author' => $author_id );
     651                $this->assertSame( $non_bbp_data, bbp_fix_post_author( $non_bbp_data, array( 'ID' => $this->factory->post->create() ) ) );
    637652        }
    638653
    … …  
    781796        /**
    782797         * @covers ::bbp_filter_anonymous_post_data
    783          * @todo   Implement test_bbp_filter_anonymous_post_data().
    784798         */
    785799        public function test_bbp_filter_anonymous_post_data() {
    786                 // Remove the following lines when you implement this test.
    787                 $this->markTestIncomplete(
    788                         'This test has not been implemented yet.'
     800                $error_messages = bbpress()->errors->get_error_messages();
     801                $result = bbp_filter_anonymous_post_data( array(
     802                        'bbp_anonymous_name'    => 'Forum Visitor',
     803                        'bbp_anonymous_email'   => 'visitor@example.org',
     804                        'bbp_anonymous_website' => '',
     805                ) );
     806                $this->assertSame( 'Forum Visitor', $result['bbp_anonymous_name'] );
     807                $this->assertSame( 'visitor@example.org', $result['bbp_anonymous_email'] );
     808                $this->assertSame( '', $result['bbp_anonymous_website'] );
     809                $this->assertSame( $error_messages, bbpress()->errors->get_error_messages() );
     810        }
     811
     812        /**
     813         * @covers ::bbp_check_for_duplicate
     814         */
     815        public function test_bbp_check_for_duplicate() {
     816                $author_id = $this->factory->user->create();
     817                $topic_id  = $this->factory->topic->create( array(
     818                        'post_author'  => $author_id,
     819                        'post_content' => 'Duplicate topic text',
     820                        'post_status'  => 'publish',
     821                ) );
     822                $post_data = array(
     823                        'post_author'  => $author_id,
     824                        'post_type'    => bbp_get_topic_post_type(),
     825                        'post_content' => 'Duplicate topic text',
    789826                );
    790         }
    791 
    792         /**
    793          * @covers ::bbp_check_for_duplicate
    794          * @todo   Implement test_bbp_check_for_duplicate().
    795          */
    796         public function test_bbp_check_for_duplicate() {
    797                 // Remove the following lines when you implement this test.
    798                 $this->markTestIncomplete(
    799                         'This test has not been implemented yet.'
    800                 );
     827                $this->assertFalse( bbp_check_for_duplicate( $post_data ) );
     828                $post_data['post_content'] = 'A different topic';
     829                $this->assertTrue( bbp_check_for_duplicate( $post_data ) );
     830                $this->assertSame( $author_id, (int) get_post_field( 'post_author', $topic_id ) );
    801831        }
    802832
    803833        /**
    804834         * @covers ::bbp_check_for_flood
    805          * @todo   Implement test_bbp_check_for_flood().
    806835         */
    807836        public function test_bbp_check_for_flood() {
    808                 // Remove the following lines when you implement this test.
    809                 $this->markTestIncomplete(
    810                         'This test has not been implemented yet.'
    811                 );
     837                $old_throttle = get_option( '_bbp_throttle_time', null );
     838                $key          = '_bbp_' . bbp_current_author_ip() . '_last_posted';
     839                $old_posted   = get_transient( $key );
     840                try {
     841                        update_option( '_bbp_throttle_time', 60 );
     842                        set_transient( $key, time() );
     843                        $this->assertFalse( bbp_check_for_flood( array( 'bbp_anonymous_email' => 'visitor@example.org' ) ) );
     844                        set_transient( $key, time() - 120 );
     845                        $this->assertTrue( bbp_check_for_flood( array( 'bbp_anonymous_email' => 'visitor@example.org' ) ) );
     846                } finally {
     847                        if ( is_null( $old_throttle ) ) {
     848                                delete_option( '_bbp_throttle_time' );
     849                        } else {
     850                                update_option( '_bbp_throttle_time', $old_throttle );
     851                        }
     852                        if ( false === $old_posted ) {
     853                                delete_transient( $key );
     854                        } else {
     855                                set_transient( $key, $old_posted );
     856                        }
     857                }
    812858        }
    813859
    … …  
    15551601        /**
    15561602         * @covers ::bbp_notify_subscribers
    1557          * @todo   Implement test_bbp_notify_subscribers().
    15581603         */
    15591604        public function test_bbp_notify_subscribers() {
    1560                 // Remove the following lines when you implement this test.
    1561                 $this->markTestIncomplete(
    1562                         'This test has not been implemented yet.'
    1563                 );
     1605                $this->assertFalse( bbp_notify_subscribers() );
    15641606        }
    15651607
    15661608        /**
    15671609         * @covers ::bbp_logout_url
    1568          * @todo   Implement test_bbp_logout_url().
    15691610         */
    15701611        public function test_bbp_logout_url() {
    1571                 // Remove the following lines when you implement this test.
    1572                 $this->markTestIncomplete(
    1573                         'This test has not been implemented yet.'
    1574                 );
     1612                $url      = 'https://example.org/logout/';
     1613                $redirect = home_url( '/forums/' );
     1614                $result   = bbp_logout_url( $url, $redirect );
     1615                $query    = array();
     1616                wp_parse_str( wp_parse_url( $result, PHP_URL_QUERY ), $query );
     1617
     1618                $this->assertSame( $redirect . '?loggedout=true', $query['redirect_to'] );
     1619                $this->assertSame( $url . '?redirect_to=already-set', bbp_logout_url( $url . '?redirect_to=already-set', $redirect ) );
    15751620        }
    15761621
    15771622        /**
    15781623         * @covers ::bbp_parse_args
    1579          * @todo   Implement test_bbp_parse_args().
    15801624         */
    15811625        public function test_bbp_parse_args() {
    1582                 // Remove the following lines when you implement this test.
    1583                 $this->markTestIncomplete(
    1584                         'This test has not been implemented yet.'
    1585                 );
     1626                $defaults = array( 'count' => 1, 'order' => 'ASC' );
     1627                $this->assertSame( array( 'count' => 2, 'order' => 'ASC' ), bbp_parse_args( array( 'count' => 2 ), $defaults ) );
     1628                $this->assertSame( array( 'count' => '3', 'order' => 'DESC' ), bbp_parse_args( 'count=3&order=DESC', $defaults ) );
     1629
     1630                $before = function( $args ) {
     1631                        $args['count'] = 4;
     1632                        return $args;
     1633                };
     1634                $after = function( $args ) {
     1635                        $args['order'] = 'DESC';
     1636                        return $args;
     1637                };
     1638                add_filter( 'bbp_before_common_test_parse_args', $before );
     1639                add_filter( 'bbp_after_common_test_parse_args', $after );
     1640                try {
     1641                        $this->assertSame( array( 'count' => 4, 'order' => 'DESC' ), bbp_parse_args( array(), $defaults, 'common_test' ) );
     1642                } finally {
     1643                        remove_filter( 'bbp_before_common_test_parse_args', $before );
     1644                        remove_filter( 'bbp_after_common_test_parse_args', $after );
     1645                }
    15861646        }
    15871647
    15881648        /**
    15891649         * @covers ::bbp_get_global_post_field
    1590          * @todo   Implement test_bbp_get_global_post_field().
    15911650         */
    15921651        public function test_bbp_get_global_post_field() {
    1593                 // Remove the following lines when you implement this test.
    1594                 $this->markTestIncomplete(
    1595                         'This test has not been implemented yet.'
    1596                 );
     1652                global $post;
     1653                $old_post = $post;
     1654                $post_id  = $this->factory->post->create( array( 'post_title' => 'Global field title' ) );
     1655                try {
     1656                        $post = get_post( $post_id );
     1657                        $this->assertSame( $post_id, bbp_get_global_post_field() );
     1658                        $this->assertSame( 'Global field title', bbp_get_global_post_field( 'post_title', 'raw' ) );
     1659                        $this->assertSame( '', bbp_get_global_post_field( 'not_a_field' ) );
     1660                } finally {
     1661                        $post = $old_post;
     1662                }
    15971663        }
    15981664
    15991665        /**
    16001666         * @covers ::bbp_verify_nonce_request
    1601          * @todo   Implement test_bbp_verify_nonce_request().
    16021667         */
    16031668        public function test_bbp_verify_nonce_request() {
    1604                 // Remove the following lines when you implement this test.
    1605                 $this->markTestIncomplete(
    1606                         'This test has not been implemented yet.'
    1607                 );
     1669                $old_request = $_REQUEST;
     1670                $action      = 'common-functions-nonce';
     1671                $match       = function() {
     1672                        return home_url( '/forums/' );
     1673                };
     1674                add_filter( 'bbp_verify_nonce_request_url', $match );
     1675                try {
     1676                        $_REQUEST['_wpnonce'] = wp_create_nonce( $action );
     1677                        $this->assertNotFalse( bbp_verify_nonce_request( $action ) );
     1678                        $this->assertFalse( bbp_verify_nonce_request( 'wrong-action' ) );
     1679                        unset( $_REQUEST['_wpnonce'] );
     1680                        $this->assertFalse( bbp_verify_nonce_request( $action ) );
     1681                } finally {
     1682                        remove_filter( 'bbp_verify_nonce_request_url', $match );
     1683                        $_REQUEST = $old_request;
     1684                }
    16081685        }
    16091686
    16101687        /**
    16111688         * @covers ::bbp_request_feed_trap
    1612          * @todo   Implement test_bbp_request_feed_trap().
    16131689         */
    16141690        public function test_bbp_request_feed_trap() {
    1615                 // Remove the following lines when you implement this test.
    1616                 $this->markTestIncomplete(
    1617                         'This test has not been implemented yet.'
    1618                 );
     1691                $query_vars = array( 'post_type' => bbp_get_topic_post_type(), 'paged' => 2 );
     1692                $this->assertSame( $query_vars, bbp_request_feed_trap( $query_vars ) );
     1693                $this->assertSame( array( 'feed' => 'rss2', 'post_type' => 'post' ), bbp_request_feed_trap( array( 'feed' => 'rss2', 'post_type' => 'post' ) ) );
    16191694        }
    16201695
    16211696        /**
    16221697         * @covers ::bbp_get_page_by_path
    1623          * @todo   Implement test_bbp_get_page_by_path().
    16241698         */
    16251699        public function test_bbp_get_page_by_path() {
    1626                 // Remove the following lines when you implement this test.
    1627                 $this->markTestIncomplete(
    1628                         'This test has not been implemented yet.'
    1629                 );
     1700                global $wp_rewrite;
     1701                $old_permalinks = $wp_rewrite->permalink_structure;
     1702                $wp_rewrite->set_permalink_structure( '/%postname%/' );
     1703                $slug = 'common-test-page';
     1704                try {
     1705                        $this->assertFalse( bbp_get_page_by_path( $slug ) );
     1706                        $page_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_name' => $slug, 'post_status' => 'publish' ) );
     1707                        $this->assertSame( $page_id, bbp_get_page_by_path( $slug )->ID );
     1708                } finally {
     1709                        $wp_rewrite->set_permalink_structure( $old_permalinks );
     1710                }
    16301711        }
    16311712
    … …  
    17891870        /**
    17901871         * @covers ::bbp_set_404
    1791          * @todo   Implement test_bbp_set_404().
    17921872         */
    17931873        public function test_bbp_set_404() {
    1794                 // Remove the following lines when you implement this test.
    1795                 $this->markTestIncomplete(
    1796                         'This test has not been implemented yet.'
    1797                 );
     1874                $query = new WP_Query();
     1875                bbp_set_404( $query );
     1876                $this->assertTrue( $query->is_404() );
    17981877        }
    17991878}
  • trunk/tests/phpunit/testcases/search/functions/search.php

    r5754 r7762  
    1111        /**
    1212         * @covers ::bbp_search_query
    13          * @todo   Implement test_bbp_search_query().
    1413         */
    1514        public function test_bbp_search_query() {
    16                 // Remove the following lines when you implement this test.
    17                 $this->markTestIncomplete(
    18                         'This test has not been implemented yet.'
    19                 );
     15                $old_search_query = bbpress()->search_query;
     16                $defaults         = function() {
     17                        return array( 's' => 'bbp-3695-default-no-results', 'posts_per_page' => 10 );
     18                };
     19
     20                add_filter( 'bbp_get_search_query_args', $defaults );
     21                try {
     22                        $this->assertFalse( bbp_search_query() );
     23                        $this->assertSame( 'bbp-3695-default-no-results', bbpress()->search_query->get( 's' ) );
     24                        $this->assertSame( 10, bbpress()->search_query->get( 'posts_per_page' ) );
     25
     26                        $this->assertFalse( bbp_search_query( array( 's' => 'bbp-3695-no-results', 'posts_per_page' => 2 ) ) );
     27                        $this->assertSame( 'bbp-3695-no-results', bbpress()->search_query->get( 's' ) );
     28                        $this->assertSame( 2, bbpress()->search_query->get( 'posts_per_page' ) );
     29                } finally {
     30                        remove_filter( 'bbp_get_search_query_args', $defaults );
     31                        bbpress()->search_query = $old_search_query;
     32                }
    2033        }
    2134
    2235        /**
    2336         * @covers ::bbp_get_search_query_args
    24          * @todo   Implement test_bbp_get_search_query_args().
    2537         */
    2638        public function test_bbp_get_search_query_args() {
    27                 // Remove the following lines when you implement this test.
    28                 $this->markTestIncomplete(
    29                         'This test has not been implemented yet.'
    30                 );
     39                $terms = function() {
     40                        return 'bbpress-needle';
     41                };
     42                $filtered = function( $args ) {
     43                        $this->assertSame( array( 's' => 'bbpress-needle' ), $args );
     44                        return array( 's' => 'filtered' );
     45                };
     46
     47                $no_terms = function() {
     48                        return false;
     49                };
     50                add_filter( 'bbp_get_search_terms', $no_terms );
     51                try {
     52                        $this->assertSame( array(), bbp_get_search_query_args() );
     53                } finally {
     54                        remove_filter( 'bbp_get_search_terms', $no_terms );
     55                }
     56                add_filter( 'bbp_get_search_terms', $terms );
     57                try {
     58                        $this->assertSame( array( 's' => 'bbpress-needle' ), bbp_get_search_query_args() );
     59                        add_filter( 'bbp_get_search_query_args', $filtered );
     60                        try {
     61                                $this->assertSame( array( 's' => 'filtered' ), bbp_get_search_query_args() );
     62                        } finally {
     63                                remove_filter( 'bbp_get_search_query_args', $filtered );
     64                        }
     65                } finally {
     66                        remove_filter( 'bbp_get_search_terms', $terms );
     67                }
    3168        }
    3269
    3370        /**
    3471         * @covers ::bbp_search_results_redirect
    35          * @todo   Implement test_bbp_search_results_redirect().
    3672         */
    3773        public function test_bbp_search_results_redirect() {
    38                 // Remove the following lines when you implement this test.
    39                 $this->markTestIncomplete(
    40                         'This test has not been implemented yet.'
    41                 );
     74                $action         = isset( $_GET['action'] ) ? $_GET['action'] : null;
     75                $pretty_calls   = 0;
     76                $url_calls      = 0;
     77                $pretty_filter  = function( $pretty ) use ( &$pretty_calls ) {
     78                        $pretty_calls++;
     79                        return $pretty;
     80                };
     81                $url_filter     = function() use ( &$url_calls ) {
     82                        $url_calls++;
     83                        return '';
     84                };
     85
     86                add_filter( 'bbp_pretty_urls', $pretty_filter );
     87                add_filter( 'bbp_get_search_results_url', $url_filter );
     88                try {
     89                        unset( $_GET['action'] );
     90                        $this->assertNull( bbp_search_results_redirect() );
     91                        $_GET['action'] = 'other';
     92                        $this->assertNull( bbp_search_results_redirect() );
     93                        $this->assertSame( 0, $pretty_calls );
     94
     95                        $_GET['action'] = 'bbp-search-request';
     96                        $this->assertNull( bbp_search_results_redirect() );
     97                        $this->assertSame( 1, $pretty_calls );
     98                        $this->assertSame( 0, $url_calls );
     99
     100                        add_filter( 'bbp_pretty_urls', '__return_true', 20 );
     101                        try {
     102                                $this->assertNull( bbp_search_results_redirect() );
     103                                $this->assertSame( 1, $url_calls );
     104                        } finally {
     105                                remove_filter( 'bbp_pretty_urls', '__return_true', 20 );
     106                        }
     107                } finally {
     108                        remove_filter( 'bbp_get_search_results_url', $url_filter );
     109                        remove_filter( 'bbp_pretty_urls', $pretty_filter );
     110                        if ( is_null( $action ) ) {
     111                                unset( $_GET['action'] );
     112                        } else {
     113                                $_GET['action'] = $action;
     114                        }
     115                }
     116        }
     117
     118        /**
     119         * @covers ::bbp_get_search_type_ids
     120         */
     121        public function test_bbp_get_search_type_ids() {
     122                $this->assertSame( array( 's', 'fs', 'ts', 'rs' ), bbp_get_search_type_ids() );
     123
     124                $filter = function() {
     125                        return array( 'custom' );
     126                };
     127                add_filter( 'bbp_get_search_types', $filter );
     128                try {
     129                        $this->assertSame( array( 'custom' ), bbp_get_search_type_ids() );
     130                } finally {
     131                        remove_filter( 'bbp_get_search_types', $filter );
     132                }
     133        }
     134
     135        /**
     136         * @covers ::bbp_sanitize_search_request
     137         */
     138        public function test_bbp_sanitize_search_request() {
     139                $request = $_REQUEST;
     140                $filter  = function( $terms, $query_arg ) {
     141                        $this->assertSame( 's', $query_arg );
     142                        $this->assertSame( 'alpha beta', $terms );
     143                        return 'filtered';
     144                };
     145
     146                try {
     147                        $_REQUEST = array();
     148                        $this->assertFalse( bbp_sanitize_search_request( 'invalid' ) );
     149                        $this->assertFalse( bbp_sanitize_search_request() );
     150
     151                        $_REQUEST['s'] = ' <strong>alpha</strong> beta ';
     152                        $this->assertSame( 'alpha beta', bbp_sanitize_search_request() );
     153
     154                        $_REQUEST['s'] = array( 'alpha', array( 'ignored' ), 'beta' );
     155                        $this->assertSame( 'alpha beta', bbp_sanitize_search_request() );
     156                        add_filter( 'bbp_sanitize_search_request', $filter, 10, 2 );
     157                        try {
     158                                $this->assertSame( 'filtered', bbp_sanitize_search_request() );
     159                        } finally {
     160                                remove_filter( 'bbp_sanitize_search_request', $filter );
     161                        }
     162                } finally {
     163                        $_REQUEST = $request;
     164                }
    42165        }
    43166}
  • trunk/tests/phpunit/testcases/users/template/user.php

    r7698 r7762  
    6565         * @covers ::bbp_displayed_user_id
    6666         * @covers ::bbp_get_displayed_user_id
    67          * @todo   Implement test_bbp_get_displayed_user_id().
    6867         */
    6968        public function test_bbp_get_displayed_user_id() {
    70                 // Remove the following lines when you implement this test.
    71                 $this->markTestIncomplete(
    72                         'This test has not been implemented yet.'
    73                 );
     69                $old_displayed_user       = bbpress()->displayed_user;
     70                bbpress()->displayed_user = $this->keymaster_userdata;
     71
     72                try {
     73                        $this->assertSame( $this->keymaster_id, bbp_get_displayed_user_id() );
     74                        $this->expectOutputString( (string) $this->keymaster_id );
     75                        bbp_displayed_user_id();
     76                } finally {
     77                        bbpress()->displayed_user = $old_displayed_user;
     78                }
    7479        }
    7580
    … …  
    7782         * @covers ::bbp_displayed_user_field
    7883         * @covers ::bbp_get_displayed_user_field
    79          * @todo   Implement test_bbp_get_displayed_user_field().
    8084         */
    8185        public function test_bbp_get_displayed_user_field() {
    82                 // Remove the following lines when you implement this test.
    83                 $this->markTestIncomplete(
    84                         'This test has not been implemented yet.'
    85                 );
     86                $old_displayed_user       = bbpress()->displayed_user;
     87                bbpress()->displayed_user = $this->keymaster_userdata;
     88                $old_filter              = $this->keymaster_userdata->filter;
     89
     90                try {
     91                        $expected_display_name = sanitize_user_field( 'display_name', $this->keymaster_userdata->display_name, $this->keymaster_id, 'display' );
     92                        $this->assertSame( $expected_display_name, bbp_get_displayed_user_field( 'display_name' ) );
     93                        $this->assertSame( $old_filter, $this->keymaster_userdata->filter );
     94                        $this->assertSame( $this->keymaster_userdata->user_email, bbp_get_displayed_user_field( 'user_email', 'raw' ) );
     95                        $this->assertSame( $old_filter, $this->keymaster_userdata->filter );
     96                        $this->expectOutputString( $expected_display_name );
     97                        bbp_displayed_user_field( 'display_name' );
     98                } finally {
     99                        bbpress()->displayed_user = $old_displayed_user;
     100                }
    86101        }
    87102
    … …  
    335350         * @covers ::bbp_author_display_name
    336351         * @covers ::bbp_get_author_display_name
    337          * @todo   Implement test_bbp_get_author_display_name().
    338352         */
    339353        public function test_bbp_get_author_display_name() {
    340                 // Remove the following lines when you implement this test.
    341                 $this->markTestIncomplete(
    342                         'This test has not been implemented yet.'
    343                 );
     354                $this->assertSame( '', bbp_get_author_display_name() );
     355                $this->expectOutputString( '' );
     356                bbp_author_display_name();
    344357        }
    345358
    … …  
    347360         * @covers ::bbp_author_email
    348361         * @covers ::bbp_get_author_email
    349          * @todo   Implement test_bbp_get_author_email().
    350362         */
    351363        public function test_bbp_get_author_email() {
    352                 // Remove the following lines when you implement this test.
    353                 $this->markTestIncomplete(
    354                         'This test has not been implemented yet.'
    355                 );
     364                $this->assertSame( '', bbp_get_author_email() );
     365                $this->expectOutputString( '' );
     366                bbp_author_email();
    356367        }
    357368
    … …  
    359370         * @covers ::bbp_author_url
    360371         * @covers ::bbp_get_author_url
    361          * @todo   Implement test_bbp_get_author_url().
    362372         */
    363373        public function test_bbp_get_author_url() {
    364                 // Remove the following lines when you implement this test.
    365                 $this->markTestIncomplete(
    366                         'This test has not been implemented yet.'
    367                 );
     374                $this->assertSame( '', bbp_get_author_url() );
     375                $this->expectOutputString( '' );
     376                bbp_author_url();
    368377        }
    369378
    … …  
    415424         * @covers ::bbp_user_favorites_link
    416425         * @covers ::bbp_get_user_favorites_link
    417          * @todo   Implement test_bbp_get_user_favorites_link().
    418426         */
    419427        public function test_bbp_get_user_favorites_link() {
    420                 // Remove the following lines when you implement this test.
    421                 $this->markTestIncomplete(
    422                         'This test has not been implemented yet.'
    423                 );
     428                $this->assertFalse( bbp_get_user_favorites_link( array( 'object_id' => 0 ) ) );
     429                $this->expectOutputString( '' );
     430                bbp_user_favorites_link( array( 'object_id' => 0 ) );
    424431        }
    425432
    … …  
    471478         * @covers ::bbp_user_subscribe_link
    472479         * @covers ::bbp_get_user_subscribe_link
    473          * @todo   Implement test_bbp_get_user_subscribe_link().
    474480         */
    475481        public function test_bbp_get_user_subscribe_link() {
    476                 // Remove the following lines when you implement this test.
    477                 $this->markTestIncomplete(
    478                         'This test has not been implemented yet.'
    479                 );
     482                $this->assertFalse( bbp_get_user_subscribe_link( array( 'object_id' => 0 ) ) );
     483                $this->expectOutputString( '' );
     484                bbp_user_subscribe_link( array( 'object_id' => 0 ) );
    480485        }
    481486
    482487        /**
    483488         * @covers ::bbp_notice_edit_user_success
    484          * @todo   Implement test_bbp_notice_edit_user_success().
    485489         */
    486490        public function test_bbp_notice_edit_user_success() {
    487                 // Remove the following lines when you implement this test.
    488                 $this->markTestIncomplete(
    489                         'This test has not been implemented yet.'
    490                 );
     491                ob_start();
     492                bbp_notice_edit_user_success();
     493                $this->assertSame( '', ob_get_clean() );
     494
     495                $_GET['updated'] = '1';
     496                add_filter( 'bbp_is_single_user_edit', '__return_true' );
     497                try {
     498                        ob_start();
     499                        bbp_notice_edit_user_success();
     500                        $this->assertStringContainsString( 'User updated.', ob_get_clean() );
     501                } finally {
     502                        remove_filter( 'bbp_is_single_user_edit', '__return_true' );
     503                        unset( $_GET['updated'] );
     504                }
    491505        }
    492506
    493507        /**
    494508         * @covers ::bbp_notice_edit_user_pending_email
    495          * @todo   Implement test_bbp_notice_edit_user_pending_email().
    496509         */
    497510        public function test_bbp_notice_edit_user_pending_email() {
    498                 // Remove the following lines when you implement this test.
    499                 $this->markTestIncomplete(
    500                         'This test has not been implemented yet.'
    501                 );
     511                ob_start();
     512                bbp_notice_edit_user_pending_email();
     513                $this->assertSame( '', ob_get_clean() );
     514
     515                $old_displayed_user       = bbpress()->displayed_user;
     516                bbpress()->displayed_user = $this->keymaster_userdata;
     517                add_filter( 'bbp_is_user_home_edit', '__return_true' );
     518                update_user_meta( $this->keymaster_id, '_new_email', array( 'newemail' => 'new@example.org' ) );
     519                try {
     520                        ob_start();
     521                        bbp_notice_edit_user_pending_email();
     522                        $output = ob_get_clean();
     523                        $this->assertStringContainsString( '<code>new@example.org</code>', $output );
     524                        $this->assertStringContainsString( 'Cancel', $output );
     525                } finally {
     526                        delete_user_meta( $this->keymaster_id, '_new_email' );
     527                        remove_filter( 'bbp_is_user_home_edit', '__return_true' );
     528                        bbpress()->displayed_user = $old_displayed_user;
     529                }
    502530        }
    503531
    504532        /**
    505533         * @covers ::bbp_notice_edit_user_is_super_admin
    506          * @todo   Implement test_bbp_notice_edit_user_is_super_admin().
    507534         */
    508535        public function test_bbp_notice_edit_user_is_super_admin() {
    509                 // Remove the following lines when you implement this test.
    510                 $this->markTestIncomplete(
    511                         'This test has not been implemented yet.'
    512                 );
     536                ob_start();
     537                bbp_notice_edit_user_is_super_admin();
     538                $this->assertSame( '', ob_get_clean() );
    513539        }
    514540
    … …  
    538564        /**
    539565         * @covers ::bbp_edit_user_blog_role
    540          * @todo   Implement test_bbp_edit_user_blog_role().
    541566         */
    542567        public function test_bbp_edit_user_blog_role() {
    543                 // Remove the following lines when you implement this test.
    544                 $this->markTestIncomplete(
    545                         'This test has not been implemented yet.'
    546                 );
     568                ob_start();
     569                bbp_edit_user_blog_role();
     570                $this->assertSame( '', ob_get_clean() );
     571
     572                $old_displayed_user       = bbpress()->displayed_user;
     573                bbpress()->displayed_user = $this->keymaster_userdata;
     574                add_filter( 'bbp_is_single_user_edit', '__return_true' );
     575                try {
     576                        ob_start();
     577                        bbp_edit_user_blog_role();
     578                        $output = ob_get_clean();
     579                        $this->assertStringContainsString( '<select name="role" id="role">', $output );
     580                        $this->assertStringContainsString( 'value="administrator"', $output );
     581                } finally {
     582                        remove_filter( 'bbp_is_single_user_edit', '__return_true' );
     583                        bbpress()->displayed_user = $old_displayed_user;
     584                }
    547585        }
    548586
    549587        /**
    550588         * @covers ::bbp_edit_user_forums_role
    551          * @todo   Implement test_bbp_edit_user_forums_role().
    552589         */
    553590        public function test_bbp_edit_user_forums_role() {
    554                 // Remove the following lines when you implement this test.
    555                 $this->markTestIncomplete(
    556                         'This test has not been implemented yet.'
    557                 );
     591                ob_start();
     592                bbp_edit_user_forums_role();
     593                $this->assertSame( '', ob_get_clean() );
     594
     595                $old_displayed_user       = bbpress()->displayed_user;
     596                bbpress()->displayed_user = $this->keymaster_userdata;
     597                add_filter( 'bbp_is_single_user_edit', '__return_true' );
     598                try {
     599                        ob_start();
     600                        bbp_edit_user_forums_role();
     601                        $output = ob_get_clean();
     602                        $this->assertStringContainsString( '<select name="bbp-forums-role" id="bbp-forums-role">', $output );
     603                        $this->assertStringContainsString( 'value="bbp_keymaster"', $output );
     604                } finally {
     605                        remove_filter( 'bbp_is_single_user_edit', '__return_true' );
     606                        bbpress()->displayed_user = $old_displayed_user;
     607                }
    558608        }
    559609
    560610        /**
    561611         * @covers ::bbp_edit_user_contact_methods
    562          * @todo   Implement test_bbp_edit_user_contact_methods().
    563612         */
    564613        public function test_bbp_edit_user_contact_methods() {
    565                 // Remove the following lines when you implement this test.
    566                 $this->markTestIncomplete(
    567                         'This test has not been implemented yet.'
    568                 );
     614                $old_displayed_user       = bbpress()->displayed_user;
     615                bbpress()->displayed_user = $this->keymaster_userdata;
     616
     617                try {
     618                        $this->assertSame( wp_get_user_contact_methods( $this->keymaster_userdata ), bbp_edit_user_contact_methods() );
     619                } finally {
     620                        bbpress()->displayed_user = $old_displayed_user;
     621                }
    569622        }
    570623
    … …  
    659712        /**
    660713         * @covers ::bbp_login_notices
    661          * @todo   Implement test_bbp_login_notices().
    662714         */
    663715        public function test_bbp_login_notices() {
    664                 // Remove the following lines when you implement this test.
    665                 $this->markTestIncomplete(
    666                         'This test has not been implemented yet.'
    667                 );
     716                $old_errors       = bbpress()->errors;
     717                bbpress()->errors = new WP_Error();
     718
     719                try {
     720                        bbp_login_notices();
     721                        $this->assertFalse( bbp_has_errors() );
     722
     723                        $_GET['loggedout'] = 'true';
     724                        bbp_login_notices();
     725                        $this->assertSame( 'message', bbpress()->errors->get_error_data( 'loggedout' ) );
     726                        $this->assertSame( 'You are now logged out.', bbpress()->errors->get_error_message( 'loggedout' ) );
     727                } finally {
     728                        unset( $_GET['loggedout'] );
     729                        bbpress()->errors = $old_errors;
     730                }
    668731        }
    669732
    670733        /**
    671734         * @covers ::bbp_logged_in_redirect
    672          * @todo   Implement test_bbp_logged_in_redirect().
    673735         */
    674736        public function test_bbp_logged_in_redirect() {
    675                 // Remove the following lines when you implement this test.
    676                 $this->markTestIncomplete(
    677                         'This test has not been implemented yet.'
    678                 );
     737                $this->set_current_user( 0 );
     738                $this->assertNull( bbp_logged_in_redirect( 'https://example.org/' ) );
    679739        }
    680740
    681741        /**
    682742         * @covers ::bbp_user_login_fields
    683          * @todo   Implement test_bbp_user_login_fields().
    684743         */
    685744        public function test_bbp_user_login_fields() {
    686                 // Remove the following lines when you implement this test.
    687                 $this->markTestIncomplete(
    688                         'This test has not been implemented yet.'
    689                 );
     745                ob_start();
     746                bbp_user_login_fields();
     747                $output = ob_get_clean();
     748                $this->assertStringContainsString( 'name="user-cookie" value="1"', $output );
     749                $this->assertStringContainsString( 'name="_wpnonce"', $output );
     750                $this->assertStringContainsString( 'name="_wp_http_referer"', $output );
    690751        }
    691752
    692753        /**
    693754         * @covers ::bbp_user_register_fields
    694          * @todo   Implement test_bbp_user_register_fields().
    695755         */
    696756        public function test_bbp_user_register_fields() {
    697                 // Remove the following lines when you implement this test.
    698                 $this->markTestIncomplete(
    699                         'This test has not been implemented yet.'
    700                 );
     757                ob_start();
     758                bbp_user_register_fields();
     759                $output = ob_get_clean();
     760                $this->assertStringContainsString( 'name="action"      value="register"', $output );
     761                $this->assertStringContainsString( 'name="user-cookie" value="1"', $output );
     762                $this->assertStringContainsString( 'name="_wpnonce"', $output );
     763                $this->assertStringContainsString( 'checkemail=registered', $output );
    701764        }
    702765
    703766        /**
    704767         * @covers ::bbp_user_lost_pass_fields
    705          * @todo   Implement test_bbp_user_lost_pass_fields().
    706768         */
    707769        public function test_bbp_user_lost_pass_fields() {
    708                 // Remove the following lines when you implement this test.
    709                 $this->markTestIncomplete(
    710                         'This test has not been implemented yet.'
    711                 );
     770                ob_start();
     771                bbp_user_lost_pass_fields();
     772                $output = ob_get_clean();
     773                $this->assertStringContainsString( 'name="user-cookie" value="1"', $output );
     774                $this->assertStringContainsString( 'name="_wpnonce"', $output );
     775                $this->assertStringContainsString( 'checkemail=confirm', $output );
    712776        }
    713777
    … …  
    754818        /**
    755819         * @covers ::bbp_user_can_view_forum
    756          * @todo   Implement test_bbp_user_can_view_forum().
    757820         */
    758821        public function test_bbp_user_can_view_forum() {
    759                 // Remove the following lines when you implement this test.
    760                 $this->markTestIncomplete(
    761                         'This test has not been implemented yet.'
    762                 );
     822                $public_id  = $this->factory->forum->create();
     823                $private_id = $this->factory->forum->create( array( 'post_status' => bbp_get_private_status_id() ) );
     824                $hidden_id  = $this->factory->forum->create( array( 'post_status' => bbp_get_hidden_status_id() ) );
     825                $child_id   = $this->factory->forum->create( array( 'post_parent' => $hidden_id ) );
     826
     827                $participant_id = $this->factory->user->create();
     828                bbp_set_user_role( $participant_id, bbp_get_participant_role() );
     829                $moderator_id = $this->factory->user->create();
     830                bbp_set_user_role( $moderator_id, bbp_get_moderator_role() );
     831
     832                $this->assertTrue( bbp_user_can_view_forum( array( 'user_id' => 0, 'forum_id' => $public_id ) ) );
     833                $this->assertFalse( bbp_user_can_view_forum( array( 'user_id' => 0, 'forum_id' => $private_id ) ) );
     834                $this->assertFalse( bbp_user_can_view_forum( array( 'user_id' => $participant_id, 'forum_id' => $hidden_id ) ) );
     835                $this->assertFalse( bbp_user_can_view_forum( array( 'user_id' => 0, 'forum_id' => $child_id ) ) );
     836                $this->assertTrue( bbp_user_can_view_forum( array( 'user_id' => 0, 'forum_id' => $child_id, 'check_ancestors' => false ) ) );
     837                $this->assertTrue( bbp_user_can_view_forum( array( 'user_id' => $moderator_id, 'forum_id' => $private_id ) ) );
     838                $this->assertTrue( bbp_user_can_view_forum( array( 'user_id' => $moderator_id, 'forum_id' => $hidden_id ) ) );
     839                $this->assertTrue( bbp_user_can_view_forum( array( 'user_id' => $this->keymaster_id, 'forum_id' => $hidden_id ) ) );
    763840        }
    764841
    765842        /**
    766843         * @covers ::bbp_current_user_can_publish_forums
    767          * @todo   Implement test_bbp_current_user_can_publish_forums().
    768844         */
    769845        public function test_bbp_current_user_can_publish_forums() {
    770                 // Remove the following lines when you implement this test.
    771                 $this->markTestIncomplete(
    772                         'This test has not been implemented yet.'
    773                 );
     846                $this->assertTrue( bbp_current_user_can_publish_forums() );
     847                $this->set_current_user( 0 );
     848                $this->assertFalse( bbp_current_user_can_publish_forums() );
    774849        }
    775850
    776851        /**
    777852         * @covers ::bbp_current_user_can_publish_topics
    778          * @todo   Implement test_bbp_current_user_can_publish_topics().
    779853         */
    780854        public function test_bbp_current_user_can_publish_topics() {
    781                 // Remove the following lines when you implement this test.
    782                 $this->markTestIncomplete(
    783                         'This test has not been implemented yet.'
    784                 );
     855                $this->assertTrue( bbp_current_user_can_publish_topics() );
     856                $this->set_current_user( 0 );
     857                $this->assertSame( bbp_allow_anonymous(), bbp_current_user_can_publish_topics() );
    785858        }
    786859
    787860        /**
    788861         * @covers ::bbp_current_user_can_publish_replies
    789          * @todo   Implement test_bbp_current_user_can_publish_replies().
    790862         */
    791863        public function test_bbp_current_user_can_publish_replies() {
    792                 // Remove the following lines when you implement this test.
    793                 $this->markTestIncomplete(
    794                         'This test has not been implemented yet.'
    795                 );
     864                $this->assertTrue( bbp_current_user_can_publish_replies() );
     865                $this->set_current_user( 0 );
     866                $this->assertSame( bbp_allow_anonymous(), bbp_current_user_can_publish_replies() );
    796867        }
    797868
    798869        /**
    799870         * @covers ::bbp_get_forums_for_current_user
    800          * @todo   Implement test_bbp_get_forums_for_current_user().
    801871         */
    802872        public function test_bbp_get_forums_for_current_user() {
    803                 // Remove the following lines when you implement this test.
    804                 $this->markTestIncomplete(
    805                         'This test has not been implemented yet.'
    806                 );
     873                $this->assertFalse( bbp_get_forums_for_current_user() );
     874                $forum_id = $this->factory->forum->create();
     875                $forums   = bbp_get_forums_for_current_user();
     876                $this->assertCount( 1, $forums );
     877                $this->assertSame( $forum_id, $forums[0]->ID );
    807878        }
    808879
    809880        /**
    810881         * @covers ::bbp_current_user_can_access_create_forum_form
    811          * @todo   Implement test_bbp_current_user_can_access_create_forum_form().
    812882         */
    813883        public function test_bbp_current_user_can_access_create_forum_form() {
    814                 // Remove the following lines when you implement this test.
    815                 $this->markTestIncomplete(
    816                         'This test has not been implemented yet.'
    817                 );
     884                $this->assertTrue( bbp_current_user_can_access_create_forum_form() );
     885                $this->set_current_user( 0 );
     886                $this->assertFalse( bbp_current_user_can_access_create_forum_form() );
    818887        }
    819888
    820889        /**
    821890         * @covers ::bbp_current_user_can_access_create_topic_form
    822          * @todo   Implement test_bbp_current_user_can_access_create_topic_form().
    823891         */
    824892        public function test_bbp_current_user_can_access_create_topic_form() {
    825                 // Remove the following lines when you implement this test.
    826                 $this->markTestIncomplete(
    827                         'This test has not been implemented yet.'
    828                 );
     893                $this->assertTrue( bbp_current_user_can_access_create_topic_form() );
     894                $this->set_current_user( 0 );
     895                $this->assertFalse( bbp_current_user_can_access_create_topic_form() );
    829896        }
    830897
    831898        /**
    832899         * @covers ::bbp_current_user_can_access_create_reply_form
    833          * @todo   Implement test_bbp_current_user_can_access_create_reply_form().
    834900         */
    835901        public function test_bbp_current_user_can_access_create_reply_form() {
    836                 // Remove the following lines when you implement this test.
    837                 $this->markTestIncomplete(
    838                         'This test has not been implemented yet.'
    839                 );
     902                $this->assertTrue( bbp_current_user_can_access_create_reply_form() );
     903                $this->set_current_user( 0 );
     904                $this->assertFalse( bbp_current_user_can_access_create_reply_form() );
    840905        }
    841906
    842907        /**
    843908         * @covers ::bbp_current_user_can_access_anonymous_user_form
    844          * @todo   Implement test_bbp_current_user_can_access_anonymous_user_form().
    845909         */
    846910        public function test_bbp_current_user_can_access_anonymous_user_form() {
    847                 // Remove the following lines when you implement this test.
    848                 $this->markTestIncomplete(
    849                         'This test has not been implemented yet.'
    850                 );
     911                $this->assertFalse( bbp_current_user_can_access_anonymous_user_form() );
     912                $this->set_current_user( 0 );
     913                $this->assertSame( bbp_allow_anonymous(), bbp_current_user_can_access_anonymous_user_form() );
    851914        }
    852915}
Note: See TracChangeset for help on using the changeset viewer.