WordPress.org

Make WordPress Core

Ticket #28026: unittest.28026.diff

File unittest.28026.diff, 1.5 KB (added by lektro, 5 years ago)

Unit Test

  • tests/phpunit/tests/link.php

    diff --git tests/phpunit/tests/link.php tests/phpunit/tests/link.php
    index 1de3f68..229d64f 100644
    class Tests_Link extends WP_UnitTestCase { 
    286286                $relative_link = wp_make_link_relative( $link );
    287287                $this->assertEquals( '/this-is-a-test/?redirect=https://example.org/a-different-test-post/', $relative_link );
    288288        }
     289
     290        /**
     291         * @ticket 28026
     292         */
     293        function test_same_date_posts_sort_by_id() {
     294                // Need some sample posts to test adjacency
     295                $post_one = $this->factory->post->create_and_get( array(
     296                        'post_title' => 'First',
     297                        'post_date' => '2012-01-01 12:00:00'
     298                ) );
     299
     300                $post_two = $this->factory->post->create_and_get( array(
     301                        'post_title' => 'Second',
     302                        'post_date' => '2012-02-01 12:00:00'
     303                ) );
     304
     305                $post_three = $this->factory->post->create_and_get( array(
     306                        'post_title' => 'Third',
     307                        'post_date' => '2012-02-01 12:00:00'
     308                ) );
     309
     310                // Assign some terms
     311                wp_set_object_terms( $post_one->ID, 'wordpress', 'category', false );
     312                wp_set_object_terms( $post_two->ID, 'wordpress', 'category', false );
     313                wp_set_object_terms( $post_three->ID, 'wordpress', 'category', false );
     314
     315                // Test equal date post adjacency
     316                $this->go_to( get_permalink( $post_two->ID ) );
     317
     318                $this->assertEquals( $post_one, get_adjacent_post( false, '', true ) );
     319
     320                $this->go_to( get_permalink( $post_three->ID ) );
     321
     322                $this->assertEquals( $post_two, get_adjacent_post( false, '', true ) );
     323
     324        }
    289325}