WordPress.org

Make WordPress Core

Ticket #4575: 4575_tests.diff

File 4575_tests.diff, 2.1 KB (added by mauteri, 4 years ago)

Unit Test for get_last_build_date

  • tests/feed/rss2.php

     
    3232                ) );
    3333
    3434                // Set a predictable time for testing date archives.
    35                 self::$post_date = '2003-05-27 10:07:53';
     35                self::$post_date = strtotime( '2003-05-27 10:07:53' );
    3636
    3737                $count = get_option( 'posts_per_rss' ) + 1;
     38                $i = 0;
    3839
    3940                // Create a few posts
    40                 self::$posts = $factory->post->create_many( $count, array(
    41                         'post_author'  => self::$user_id,
    42                         'post_date'    => self::$post_date,
    43                         'post_content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec velit massa, ultrices eu est suscipit, mattis posuere est. Donec vitae purus lacus. Cras vitae odio odio.',
    44                         'post_excerpt' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
    45                 ) );
     41                self::$posts = array();
     42                while ( $count-- ) {
     43                        self::$posts[] = $factory->post->create( array(
     44                                'post_author'  => self::$user_id,
     45                                'post_date'    => gmdate( 'Y-m-d H:i:s', self::$post_date + ( 5 * ++$i ) ), // separate post dates 5 seconds apart.
     46                                'post_content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec velit massa, ultrices eu est suscipit, mattis posuere est. Donec vitae purus lacus. Cras vitae odio odio.',
     47                                'post_excerpt' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
     48                        ) );
     49                }
    4650
    4751                // Assign a category to those posts
    4852                foreach ( self::$posts as $post ) {
     
    8387        }
    8488
    8589        /**
     90         * Test <rss> element has correct last build date.
     91         */
     92        function test_get_last_build_date() {
     93                $this->go_to( '/?feed=rss2' );
     94                $feed = $this->do_rss2();
     95                $xml = xml_to_array( $feed );
     96
     97                // Get the <rss> child element of <xml>.
     98                $rss = xml_find( $xml, 'rss' );
     99                $last_build_date = $rss[0]['child'][0]['child'][4]['content'];
     100                $this->assertEquals( strtotime( get_last_build_date() ), strtotime( $last_build_date ) );
     101        }
     102
     103        /**
    86104         * Test the <rss> element to make sure its present and populated
    87105         * with the expected child elements and attributes.
    88106         */