Skip to:
Content

bbPress.org

Changeset 5902


Ignore:
Timestamp:
08/10/2015 01:30:56 PM (11 years ago)
Author:
johnjamesjacoby
Message:

Users: Add tests for user permalink functions. Props thebrandonallen. See #2831.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/users/template/user.php

    r5897 r5902  
    2525    }
    2626
     27    private function set_permalink_structure( $permalink_structure = '/%year%/%monthnum%/%day%/%postname%/' ) {
     28        global $wp_rewrite;
     29        $wp_rewrite->set_permalink_structure( $permalink_structure );
     30    }
     31
    2732    /**
    2833     * @covers ::bbp_user_id
     
    104109     */
    105110    public function test_bbp_get_current_user_avatar() {
    106         $current_user = wp_get_current_user();
     111        $current_user = get_current_user_id();
    107112        $size = 40;
    108113        $wp_avatar = get_avatar( $current_user, $size );
     
    123128    public function test_bbp_get_user_profile_link() {
    124129        $display_name = $this->keymaster_userdata->display_name;
    125         $profile_link = '<a href="http://' . WP_TESTS_DOMAIN . '/?bbp_user=' . $this->keymaster_id . '" rel="nofollow">' . $display_name . '</a>';
    126 
     130
     131        // Pretty permalinks
     132        $this->set_permalink_structure();
     133
     134        $profile_link      = '<a href="http://' . WP_TESTS_DOMAIN . '/forums/user/' . $this->keymaster_userdata->user_nicename . '/" rel="nofollow">' . $display_name . '</a>';
    127135        $user_profile_link = bbp_get_user_profile_link( $this->keymaster_id );
    128136
     
    133141        $this->expectOutputString( $profile_link );
    134142        bbp_user_profile_link( $this->keymaster_id );
     143
     144        ob_clean();
     145
     146        // Ugly permalinks
     147        $this->set_permalink_structure( '' );
     148
     149        $profile_link      = '<a href="http://' . WP_TESTS_DOMAIN . '/?bbp_user=' . $this->keymaster_id . '" rel="nofollow">' . $display_name . '</a>';
     150        $user_profile_link = bbp_get_user_profile_link( $this->keymaster_id );
     151
     152        // String.
     153        $this->assertSame( $profile_link, $user_profile_link );
     154
     155        // Output.
     156        $this->expectOutputString( $profile_link );
     157        bbp_user_profile_link( $this->keymaster_id );
    135158    }
    136159
     
    155178     */
    156179    public function test_bbp_get_user_profile_url() {
    157         $profile_url = 'http://' . WP_TESTS_DOMAIN . '/?bbp_user=' . $this->keymaster_id;
    158 
     180
     181        // Pretty permalinks
     182        $this->set_permalink_structure();
     183        $profile_url      = 'http://' . WP_TESTS_DOMAIN . '/forums/user/' . $this->keymaster_userdata->user_nicename . '/';
    159184        $user_profile_url = bbp_get_user_profile_url( $this->keymaster_id );
    160185
     
    165190        $this->expectOutputString( $profile_url );
    166191        bbp_user_profile_url( $this->keymaster_id );
     192
     193        ob_clean();
     194
     195        // Ugly permalinks
     196        $this->set_permalink_structure( '' );
     197
     198        $profile_url      = 'http://' . WP_TESTS_DOMAIN . '/?bbp_user=' . $this->keymaster_id;
     199        $user_profile_url = bbp_get_user_profile_url( $this->keymaster_id );
     200
     201        // String.
     202        $this->assertSame( $profile_url, $user_profile_url );
     203
     204        // Output.
     205        $this->expectOutputString( $profile_url );
     206        bbp_user_profile_url( $this->keymaster_id );
    167207    }
    168208
     
    173213    public function test_bbp_get_user_profile_edit_link() {
    174214        $display_name = $this->keymaster_userdata->display_name;
    175         $profile_edit_link = '<a href="http://' . WP_TESTS_DOMAIN . '/?bbp_user=' . $this->keymaster_id . '" rel="nofollow">' . $display_name . '</a>';
    176 
     215
     216        // Pretty permalinks
     217        $this->set_permalink_structure();
     218        $profile_edit_link      = '<a href="http://' . WP_TESTS_DOMAIN . '/forums/user/' . $this->keymaster_userdata->user_nicename . '/edit/" rel="nofollow">' . $display_name . '</a>';
    177219        $user_profile_edit_link = bbp_get_user_profile_edit_link( $this->keymaster_id );
    178220
     
    183225        $this->expectOutputString( $profile_edit_link );
    184226        bbp_user_profile_edit_link( $this->keymaster_id );
     227
     228        ob_clean();
     229
     230        // Ugly permalinks
     231        $this->set_permalink_structure( '' );
     232        $profile_edit_link      = '<a href="http://' . WP_TESTS_DOMAIN . '/?bbp_user=' . $this->keymaster_id . '&#038;edit=1" rel="nofollow">' . $display_name . '</a>';
     233        $user_profile_edit_link = bbp_get_user_profile_edit_link( $this->keymaster_id );
     234
     235        // String.
     236        $this->assertSame( $profile_edit_link, $user_profile_edit_link );
     237
     238        // Output.
     239        $this->expectOutputString( $profile_edit_link );
     240        bbp_user_profile_edit_link( $this->keymaster_id );
    185241    }
    186242
     
    189245     */
    190246    public function test_bbp_user_profile_edit_url() {
    191         $profile_edit_url = 'http://' . WP_TESTS_DOMAIN . '/?bbp_user=' . $this->keymaster_id . '&#038;edit=1';
     247
     248        // Pretty permalinks
     249        $this->set_permalink_structure();
     250        $profile_edit_url = 'http://' . WP_TESTS_DOMAIN . '/forums/user/' . $this->keymaster_userdata->user_nicename . '/edit/';
    192251
    193252        // Output.
    194253        $this->expectOutputString( $profile_edit_url );
    195254        bbp_user_profile_edit_url( $this->keymaster_id );
     255
     256        ob_clean();
     257
     258        // Ugly permalinks
     259        $this->set_permalink_structure( '' );
     260        $profile_edit_url = 'http://' . WP_TESTS_DOMAIN . '/?bbp_user=' . $this->keymaster_id . '&#038;edit=1';
     261
     262        // Output.
     263        $this->expectOutputString( $profile_edit_url );
     264        bbp_user_profile_edit_url( $this->keymaster_id );
    196265    }
    197266
     
    200269     */
    201270    public function test_bbp_get_user_profile_edit_url() {
     271
     272        // Pretty permalinks
     273        $this->set_permalink_structure();
     274        $profile_edit_url = 'http://' . WP_TESTS_DOMAIN . '/forums/user/' . $this->keymaster_userdata->user_nicename . '/edit/';
     275
     276        // String.
     277        $this->assertSame( $profile_edit_url, bbp_get_user_profile_edit_url( $this->keymaster_id ) );
     278
     279        // Ugly permalinks
     280        $this->set_permalink_structure( '' );
    202281        $profile_edit_url = 'http://' . WP_TESTS_DOMAIN . '/?bbp_user=' . $this->keymaster_id . '&edit=1';
    203282
     
    291370    }
    292371
    293     /**
    294      * @covers ::bbp_favorites_permalink
    295      * @covers ::bbp_get_favorites_permalink
    296      * @todo   Implement test_bbp_get_favorites_permalink().
    297      */
    298     public function test_bbp_get_favorites_permalink() {
    299         // Remove the following lines when you implement this test.
    300         $this->markTestIncomplete(
    301             'This test has not been implemented yet.'
    302         );
    303     }
     372    /**
     373     * @covers ::bbp_favorites_permalink
     374     */
     375    public function test_bbp_favorites_permalink() {
     376
     377        // Pretty permalinks
     378        $this->set_permalink_structure();
     379        $favorites_url = 'http://' . WP_TESTS_DOMAIN . '/forums/user/' . $this->keymaster_userdata->user_nicename . '/favorites/';
     380
     381        // Output.
     382        $this->expectOutputString( $favorites_url );
     383        bbp_favorites_permalink( $this->keymaster_id );
     384
     385        ob_clean();
     386
     387        // Ugly permalinks
     388        $this->set_permalink_structure( '' );
     389        $favorites_url = 'http://' . WP_TESTS_DOMAIN . '/?bbp_user=' . $this->keymaster_id . '&#038;bbp_favs=favorites';
     390
     391        // Output.
     392        $this->expectOutputString( $favorites_url );
     393        bbp_favorites_permalink( $this->keymaster_id );
     394    }
     395
     396    /**
     397     * @covers ::bbp_get_favorites_permalink
     398     */
     399    public function test_bbp_get_favorites_permalink() {
     400
     401        // Pretty permalinks
     402        $this->set_permalink_structure();
     403        $favorites_url = 'http://' . WP_TESTS_DOMAIN . '/forums/user/' . $this->keymaster_userdata->user_nicename . '/favorites/';
     404
     405        // String.
     406        $this->assertSame( $favorites_url, bbp_get_favorites_permalink( $this->keymaster_id ) );
     407
     408        // Ugly permalinks
     409        $this->set_permalink_structure( '' );
     410        $favorites_url = 'http://' . WP_TESTS_DOMAIN . '/?bbp_user=' . $this->keymaster_id . '&bbp_favs=favorites';
     411
     412        // String.
     413        $this->assertSame( $favorites_url, bbp_get_favorites_permalink( $this->keymaster_id ) );
     414    }
    304415
    305416    /**
     
    315426    }
    316427
    317     /**
    318      * @covers ::bbp_subscriptions_permalink
    319      * @covers ::bbp_get_subscriptions_permalink
    320      * @todo   Implement test_bbp_get_subscriptions_permalink().
    321      */
    322     public function test_bbp_get_subscriptions_permalink() {
    323         // Remove the following lines when you implement this test.
    324         $this->markTestIncomplete(
    325             'This test has not been implemented yet.'
    326         );
    327     }
     428    /**
     429     * @covers ::bbp_subscriptions_permalink
     430     */
     431    public function test_bbp_subscriptions_permalink() {
     432
     433        // Pretty permalinks
     434        $this->set_permalink_structure();
     435        $subscriptions_url = 'http://' . WP_TESTS_DOMAIN . '/forums/user/' . $this->keymaster_userdata->user_nicename . '/subscriptions/';
     436
     437        // Output.
     438        $this->expectOutputString( $subscriptions_url );
     439        bbp_subscriptions_permalink( $this->keymaster_id );
     440
     441        ob_clean();
     442
     443        // Ugly permalinks
     444        $this->set_permalink_structure( '' );
     445        $subscriptions_url = 'http://' . WP_TESTS_DOMAIN . '/?bbp_user=' . $this->keymaster_id . '&#038;bbp_subs=subscriptions';
     446
     447        // Output.
     448        $this->expectOutputString( $subscriptions_url );
     449        bbp_subscriptions_permalink( $this->keymaster_id );
     450    }
     451
     452    /**
     453     * @covers ::bbp_get_subscriptions_permalink
     454     */
     455    public function test_bbp_get_subscriptions_permalink() {
     456
     457        // Pretty permalinks
     458        $this->set_permalink_structure();
     459        $subscriptions_url = 'http://' . WP_TESTS_DOMAIN . '/forums/user/' . $this->keymaster_userdata->user_nicename . '/subscriptions/';
     460
     461        // String.
     462        $this->assertSame( $subscriptions_url, bbp_get_subscriptions_permalink( $this->keymaster_id ) );
     463
     464        // Ugly permalinks
     465        $this->set_permalink_structure( '' );
     466        $subscriptions_url = 'http://' . WP_TESTS_DOMAIN . '/?bbp_user=' . $this->keymaster_id . '&bbp_subs=subscriptions';
     467
     468        // String.
     469        $this->assertSame( $subscriptions_url, bbp_get_subscriptions_permalink( $this->keymaster_id ) );
     470    }
    328471
    329472    /**
     
    420563     */
    421564    public function test_bbp_user_topics_created_url() {
    422         $topics_created_url = 'http://' . WP_TESTS_DOMAIN . '/?bbp_user=' . $this->keymaster_id . '&#038;bbp_tops=1';
     565
     566        // Pretty permalinks
     567        $this->set_permalink_structure();
     568        $topics_created_url = 'http://' . WP_TESTS_DOMAIN . '/forums/user/' . $this->keymaster_userdata->user_nicename . '/topics/';
    423569
    424570        // Output.
    425571        $this->expectOutputString( $topics_created_url );
    426572        bbp_user_topics_created_url( $this->keymaster_id );
     573
     574        ob_clean();
     575
     576        // Ugly permalinks
     577        $this->set_permalink_structure( '' );
     578        $topics_created_url = 'http://' . WP_TESTS_DOMAIN . '/?bbp_user=' . $this->keymaster_id . '&#038;bbp_tops=1';
     579
     580        // Output.
     581        $this->expectOutputString( $topics_created_url );
     582        bbp_user_topics_created_url( $this->keymaster_id );
    427583    }
    428584
     
    431587     */
    432588    public function test_bbp_get_user_topics_created_url() {
     589
     590        // Pretty permalinks
     591        $this->set_permalink_structure();
     592        $topics_created_url = 'http://' . WP_TESTS_DOMAIN . '/forums/user/' . $this->keymaster_userdata->user_nicename . '/topics/';
     593
     594        // String.
     595        $this->assertSame( $topics_created_url, bbp_get_user_topics_created_url( $this->keymaster_id ) );
     596
     597        // Ugly permalinks
     598        $this->set_permalink_structure( '' );
    433599        $topics_created_url = 'http://' . WP_TESTS_DOMAIN . '/?bbp_user=' . $this->keymaster_id . '&bbp_tops=1';
    434600
     
    441607     */
    442608    public function test_bbp_user_replies_created_url() {
    443         $replies_created_url = 'http://' . WP_TESTS_DOMAIN . '/?bbp_user='. $this->keymaster_id . '&#038;bbp_reps=1';
     609
     610        // Pretty permalinks
     611        $this->set_permalink_structure();
     612        $replies_created_url = 'http://' . WP_TESTS_DOMAIN . '/forums/user/' . $this->keymaster_userdata->user_nicename . '/replies/';
    444613
    445614        // Output.
    446615        $this->expectOutputString( $replies_created_url );
    447616        bbp_user_replies_created_url( $this->keymaster_id );
     617
     618        ob_clean();
     619
     620        // Ugly permalinks
     621        $this->set_permalink_structure( '' );
     622        $replies_created_url = 'http://' . WP_TESTS_DOMAIN . '/?bbp_user='. $this->keymaster_id . '&#038;bbp_reps=1';
     623
     624        // Output.
     625        $this->expectOutputString( $replies_created_url );
     626        bbp_user_replies_created_url( $this->keymaster_id );
    448627    }
    449628
     
    452631     */
    453632    public function test_bbp_get_user_replies_created_url() {
     633
     634        // Pretty permalinks
     635        $this->set_permalink_structure();
     636        $replies_created_url = 'http://' . WP_TESTS_DOMAIN . '/forums/user/' . $this->keymaster_userdata->user_nicename . '/replies/';
     637
     638        // String.
     639        $this->assertSame( $replies_created_url, bbp_get_user_replies_created_url( $this->keymaster_id ) );
     640
     641        // Ugly permalinks
     642        $this->set_permalink_structure( '' );
    454643        $replies_created_url = 'http://' . WP_TESTS_DOMAIN . '/?bbp_user='. $this->keymaster_id . '&bbp_reps=1';
    455644
     
    521710
    522711        $display_name = $this->keymaster_userdata->display_name;
    523         $current_user = wp_get_current_user();
     712        $current_user = get_current_user_id();
    524713        $size = 80;
    525714        $wp_avatar = get_avatar( $current_user, $size );
    526715
     716        // Pretty permalinks
     717        $this->set_permalink_structure();
     718        $author_link = '<a href="http://' . WP_TESTS_DOMAIN . '/forums/user/' . $this->keymaster_userdata->user_nicename . '/" title="View ' . $display_name .
     719            '&#039;s profile" class="bbp-author-avatar" rel="nofollow">' . $wp_avatar .
     720            '</a>&nbsp;<a href="http://' . WP_TESTS_DOMAIN . '/forums/user/' . $this->keymaster_userdata->user_nicename . '/" title="View ' . $display_name .
     721            '&#039;s profile" class="bbp-author-name" rel="nofollow">' . $display_name . '</a>';
     722
     723        // String.
     724        $this->assertSame( $author_link, bbp_get_author_link( $t ) );
     725
     726        // Output.
     727        $this->expectOutputString( $author_link );
     728        bbp_author_link( $t );
     729
     730        ob_clean();
     731
     732        // Ugly permalinks
     733        $this->set_permalink_structure( '' );
    527734        $author_link = '<a href="http://' . WP_TESTS_DOMAIN . '/?bbp_user=' . $this->keymaster_id . '" title="View ' . $display_name .
    528735            '&#039;s profile" class="bbp-author-avatar" rel="nofollow">' . $wp_avatar .
Note: See TracChangeset for help on using the changeset viewer.