Make WordPress Core

Ticket #30210: 30210.unit-tests.patch

File 30210.unit-tests.patch, 2.1 KB (added by stevenkword, 7 years ago)
  • tests/phpunit/tests/feed/rss2.php

     
    209209
    210210                remove_filter( 'comments_open', '__return_false' );
    211211        }
     212
     213        /*
     214         * Check to make sure we are not rendering feed templates for invalid feed endpoints.
     215         * e.g.) https://example.com/wp-content/feed/
     216         *
     217         * @ticket 30210
     218         */
     219        function test_invalid_feed_endpoints() {
     220                global $wp_rewrite;
     221
     222                $wp_rewrite->init();
     223                $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
     224
     225                // An example of an invalid feed endpoint
     226                $this->go_to( content_url( 'feed/' ) );
     227
     228                // This must be globalized after calling `WP_UnitTestCase::go_to` which references $GLOBALS['wp_query'] and not $wp_query.
     229                global $wp_query;
     230
     231                // Queries performed on invalid feed endpoints should never contain posts.
     232                $this->assertFalse( $wp_query->have_posts() );
     233
     234                // This is the assertion.  Once the exception is thrown in do_feed, execution stops, preventing futher assertions.
     235                $this->setExpectedException( 'WPDieException', 'ERROR: This is not a valid feed.' );
     236                do_feed();
     237        }
     238
     239        /*
     240         * Make sure the requested feed is registered before rendering the requested template.
     241         *
     242         * @ticket 30210
     243         */
     244        function test_nonexistent_feeds() {
     245                global $wp_rewrite;
     246                $feedname = 'badfeed';
     247
     248                // Unregister the feed if it exists
     249                if ( in_array( $feedname, $wp_rewrite->feeds ) ) {
     250                        unset( $wp_rewrite->feeds->feedname );
     251                        $hook = 'do_feed_' . $feedname;
     252                        // Remove default function hook
     253                        remove_action( $hook, $hook );
     254                }
     255
     256                $this->go_to( '/?feed=' . $feedname );
     257
     258                // This must be globalized after calling `WP_UnitTestCase::go_to` which references $GLOBALS['wp_query'] and not $wp_query.
     259                global $wp_query;
     260
     261                // This is the assertion.  Once the exception is thrown in do_feed, execution stops, preventing futher assertions.
     262                $this->setExpectedException( 'WPDieException', 'ERROR: This is not a valid feed template.' );
     263                do_feed();
     264        }
    212265}