Make WordPress Core

Ticket #51839: 51839.2.diff

File 51839.2.diff, 2.6 KB (added by peterwilsoncc, 4 years ago)
  • src/wp-includes/link-template.php

    diff --git a/src/wp-includes/link-template.php b/src/wp-includes/link-template.php
    index 4f4fbe6cb8..5ab02a1c3b 100644
    a b function get_feed_link( $feed = '' ) { 
    690690
    691691        $permalink = $wp_rewrite->get_feed_permastruct();
    692692
    693         if ( '' !== $permalink ) {
     693        if ( $permalink ) {
    694694                if ( false !== strpos( $feed, 'comments_' ) ) {
    695695                        $feed      = str_replace( 'comments_', '', $feed );
    696696                        $permalink = $wp_rewrite->get_comment_feed_permastruct();
  • new file tests/phpunit/tests/link/getFeedLink.php

    diff --git a/tests/phpunit/tests/link/getFeedLink.php b/tests/phpunit/tests/link/getFeedLink.php
    new file mode 100644
    index 0000000000..41d6d922d2
    - +  
     1<?php
     2
     3/**
     4 * @group link
     5 * @covers ::get_feed_link
     6 */
     7class Tests_Link_GetFeedLink extends WP_UnitTestCase {
     8
     9        /**
     10         * @ticket 51839
     11         * @dataProvider data_plain_permastruct
     12         *
     13         * @param string $expected Expected suffix to home_url().
     14         * @param string $type     Feed type to request.
     15         */
     16        public function tests_plain_permastruct( $expected, $type ) {
     17                $this->set_permalink_structure( '' );
     18
     19                $this->assertSame( home_url( $expected ), get_feed_link( $type ) );
     20        }
     21
     22        public function data_plain_permastruct() {
     23                return array(
     24                        array( '?feed=rss2', '' ),
     25                        array( '?feed=atom', 'atom' ),
     26                        array( '?feed=get-feed-link', 'get-feed-link' ),
     27                        array( '?feed=comments-rss2', 'comments_rss2' ),
     28                        array( '?feed=comments-atom', 'comments_atom' ),
     29                );
     30        }
     31
     32        /**
     33         * @ticket 51839
     34         * @dataProvider data_pretty_permastruct
     35         *
     36         * @param string $expected Expected suffix to home_url().
     37         * @param string $type     Feed type to request.
     38         */
     39        public function tests_pretty_permastruct( $expected, $type ) {
     40                $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
     41
     42                $this->assertSame( home_url( $expected ), get_feed_link( $type ) );
     43        }
     44
     45        /**
     46         * @ticket 51839
     47         * @dataProvider data_pretty_permastruct
     48         *
     49         * @param string $expected Expected suffix to home_url().
     50         * @param string $type     Feed type to request.
     51         */
     52        public function tests_pretty_permastruct_with_prefix( $expected, $type ) {
     53                $this->set_permalink_structure( '/archives/%post_id%/%postname%/' );
     54
     55                $this->assertSame( home_url( $expected ), get_feed_link( $type ) );
     56        }
     57
     58        public function data_pretty_permastruct() {
     59                return array(
     60                        array( '/feed/', '' ),
     61                        array( '/feed/atom/', 'atom' ),
     62                        array( '/feed/get-feed-link/', 'get-feed-link' ),
     63                        array( '/comments/feed/', 'comments_rss2' ),
     64                        array( '/comments/feed/atom/', 'comments_atom' ),
     65                );
     66        }
     67}