WordPress.org

Make WordPress Core

Ticket #30210: 30210.unit-test.patch

File 30210.unit-test.patch, 953 bytes (added by lyubomir_popov, 5 years ago)

Unit test for the JRGould's patch

  • tests/phpunit/tests/feed/rss2.php

    diff --git tests/phpunit/tests/feed/rss2.php tests/phpunit/tests/feed/rss2.php
    index 7ae6e78..1bc21e8 100644
    class Tests_Feed_RSS2 extends WP_UnitTestCase { 
    178178                        $this->assertEquals( html_entity_decode( get_post_comments_feed_link( $post->ID) ), $comment_rss[0]['content'] );
    179179                }
    180180        }
     181
     182        function test_no_posts_rss() {
     183                global $wp_query;
     184
     185                //backups the original $wp_query
     186                $wp_query_orig = wp_clone( $wp_query );
     187
     188                //sets an empty query
     189                $wp_query = new WP_Query();
     190
     191                $exceptionMessage = '';
     192               
     193                try {
     194                        do_feed();
     195                } catch ( WPDieException $e ) {
     196                        $exceptionMessage = $e->getMessage();
     197                }
     198
     199                $this->assertEquals( 'ERROR: This is not a valid feed.', $exceptionMessage, 'Expecting a 404 error to be thrown when there are no posts' );
     200
     201                //restores the original $wp_query
     202                $wp_query = $wp_query_orig;
     203        }
     204
    181205}