Make WordPress Core


Ignore:
Timestamp:
10/27/2013 09:39:51 PM (11 years ago)
Author:
nacin
Message:

Add a $taxonomy argument to each of the adjacent post functions.

Each took an array of category (IDs) when to search. Those can now be term IDs and each function now has $taxonomy = 'category' as an optional argument.

Functions affected: get_previous_post(), get_next_post(), get_adjacent_post(), get_adjacent_post_rel_link(), adjacent_posts_rel_link(), next_post_rel_link(), prev_post_rel_link(), get_boundary_post(), get_previous_post_link(), previous_post_link(), get_next_post_link(), next_post_link(), get_adjacent_post_link(), adjacent_post_link().

props ethitter.
finally fixes #17807.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/link.php

    r25404 r25959  
    9797    }
    9898
     99    /**
     100     * @ticket 17807
     101     */
     102    function test_get_adjacent_post() {
     103        // Need some sample posts to test adjacency
     104        $post_one = $this->factory->post->create_and_get( array(
     105            'post_title' => 'First',
     106            'post_date' => '2012-01-01 12:00:00'
     107        ) );
     108
     109        $post_two = $this->factory->post->create_and_get( array(
     110            'post_title' => 'Second',
     111            'post_date' => '2012-02-01 12:00:00'
     112        ) );
     113
     114        $post_three = $this->factory->post->create_and_get( array(
     115            'post_title' => 'Third',
     116            'post_date' => '2012-03-01 12:00:00'
     117        ) );
     118
     119        $post_four = $this->factory->post->create_and_get( array(
     120            'post_title' => 'Fourth',
     121            'post_date' => '2012-04-01 12:00:00'
     122        ) );
     123
     124        // Assign some terms
     125        wp_set_object_terms( $post_one->ID, 'wordpress', 'category', false );
     126        wp_set_object_terms( $post_three->ID, 'wordpress', 'category', false );
     127
     128        wp_set_object_terms( $post_two->ID, 'plugins', 'post_tag', false );
     129        wp_set_object_terms( $post_four->ID, 'plugins', 'post_tag', false );
     130
     131        // Test normal post adjacency
     132        $this->go_to( get_permalink( $post_two->ID ) );
     133
     134        $this->assertEquals( $post_one, get_adjacent_post( false, '', true ) );
     135        $this->assertEquals( $post_three, get_adjacent_post( false, '', false ) );
     136
     137        $this->assertNotEquals( $post_two, get_adjacent_post( false, '', true ) );
     138        $this->assertNotEquals( $post_two, get_adjacent_post( false, '', false ) );
     139
     140        // Test category adjacency
     141        $this->go_to( get_permalink( $post_one->ID ) );
     142
     143        $this->assertEquals( '', get_adjacent_post( true, '', true, 'category' ) );
     144        $this->assertEquals( $post_three, get_adjacent_post( true, '', false, 'category' ) );
     145
     146        // Test tag adjacency
     147        $this->go_to( get_permalink( $post_two->ID ) );
     148
     149        $this->assertEquals( '', get_adjacent_post( true, '', true, 'post_tag' ) );
     150        $this->assertEquals( $post_four, get_adjacent_post( true, '', false, 'post_tag' ) );
     151
     152        // Test normal boundary post
     153        $this->go_to( get_permalink( $post_two->ID ) );
     154
     155        $this->assertEquals( array( $post_one ), get_boundary_post( false, '', true ) );
     156        $this->assertEquals( array( $post_four ), get_boundary_post( false, '', false ) );
     157
     158        // Test category boundary post
     159        $this->go_to( get_permalink( $post_one->ID ) );
     160
     161        $this->assertEquals( array( $post_one ), get_boundary_post( true, '', true, 'category' ) );
     162        $this->assertEquals( array( $post_three ), get_boundary_post( true, '', false, 'category' ) );
     163
     164        // Test tag boundary post
     165        $this->go_to( get_permalink( $post_two->ID ) );
     166
     167        $this->assertEquals( array( $post_two ), get_boundary_post( true, '', true, 'post_tag' ) );
     168        $this->assertEquals( array( $post_four ), get_boundary_post( true, '', false, 'post_tag' ) );
     169    }
    99170}
Note: See TracChangeset for help on using the changeset viewer.