Make WordPress Core

Ticket #40587: 40587.3.diff

File 40587.3.diff, 3.3 KB (added by stevenkword, 8 years ago)

Adding unit tests for confidence

  • src/wp-includes/link-template.php

     
    560560 * @param string $feed   Optional. Feed type. Default empty.
    561561 */
    562562function the_feed_link( $anchor, $feed = '' ) {
    563         $link = '<a href="' . esc_url( get_feed_link( $feed ) ) . '">' . $anchor . '</a>';
     563        $link = '<a rel="alternate" type="' . esc_attr( feed_content_type( $feed ) ) . '" href="' . esc_url( get_feed_link( $feed ) ) . '">' . esc_html( $anchor ) . '</a>';
    564564
    565565        /**
    566566         * Filters the feed link anchor tag.
     
    699699                $link_text = __('Comments Feed');
    700700        }
    701701
    702         $link = '<a href="' . esc_url( $url ) . '">' . $link_text . '</a>';
     702        $link = '<a rel="alternate" type="' . esc_attr( feed_content_type( $feed ) ) . '" href="' . esc_url( $url ) . '">' . esc_html( $link_text ) . '</a>';
    703703        /**
    704704         * Filters the post comment feed link anchor tag.
    705705         *
  • tests/phpunit/tests/feed/template.php

     
     1<?php
     2/**
     3 * Tests for the Feeds template components
     4 *
     5 * @group feed
     6 */
     7class Tests_Feeds_Template extends WP_UnitTestCase {
     8        static $post_id;
     9
     10        /**
     11         * Setup a new user and attribute some posts.
     12         */
     13        public static function wpSetUpBeforeClass( $factory ) {
     14                self::$post_id = $factory->post->create();
     15        }
     16
     17        /**
     18         * Setup.
     19         */
     20        public function setUp() {
     21                parent::setUp();
     22                $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
     23        }
     24
     25        /**
     26         * Tests the RSS feed link
     27         */
     28        function test_the_feed_link_rss() {
     29                $expected = '<a rel="alternate" type="application/rss+xml" href="' . get_feed_link( 'rss' ) . '">feed</a>';
     30                ob_start();
     31                the_feed_link( 'feed', 'rss' );
     32                $actual = ob_get_clean();
     33                $this->assertEquals( $expected, $actual );
     34        }
     35
     36        /**
     37         * Tests Atom feed link
     38         */
     39        function test_the_feed_link_atom() {
     40                $expected = '<a rel="alternate" type="application/atom+xml" href="' . get_feed_link( 'atom' ) . '">feed</a>';
     41                ob_start();
     42                the_feed_link( 'feed', 'atom' );
     43                $actual = ob_get_clean();
     44                $this->assertEquals( $expected, $actual );
     45        }
     46
     47        /**
     48         * Tests RSS comments feed link
     49         */
     50        function test_post_comments_feed_link_rss() {
     51                $expected = '<a rel="alternate" type="application/rss+xml" href="' . get_post_comments_feed_link( self::$post_id, 'rss' ) . '">comments</a>';
     52                ob_start();
     53                post_comments_feed_link( 'comments', self::$post_id, 'rss' );
     54                $actual = ob_get_clean();
     55                $this->assertEquals( $expected, $actual );
     56        }
     57
     58        /**
     59         * Tests Atom comments feed link
     60         */
     61        function test_post_comments_feed_link_atom() {
     62                $expected = '<a rel="alternate" type="application/atom+xml" href="' . get_post_comments_feed_link( self::$post_id, 'atom' ) . '">comments</a>';
     63                ob_start();
     64                post_comments_feed_link( 'comments', self::$post_id, 'atom' );
     65                $actual = ob_get_clean();
     66                $this->assertEquals( $expected, $actual );
     67        }
     68}