WordPress.org

Make WordPress Core

Ticket #46227: 46227.8.diff

File 46227.8.diff, 3.4 KB (added by garrett-eclipse, 12 months ago)

Reintroduce Unit Tests from 46227.4.diff that got lost. Note: These probably shouldn't live in document-title.php though.

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

     
    45904590
    45914591        return $settings;
    45924592}
     4593
     4594/**
     4595 * Adds a link rel=feed element to the home page when a static front page is set in Settings > Reading.
     4596 *
     4597 * See {@see 'wp_head'}.
     4598 *
     4599 * @since 5.2.3
     4600 */
     4601function rel_feed_for_posts() {
     4602        $page_for_posts = get_option( 'page_for_posts' );
     4603
     4604        if ( is_front_page() && ! is_home() ) {
     4605                echo '<link rel="feed" type="text/html" href="' . get_the_permalink( $page_for_posts ) . '" title="' . the_title_attribute( array( 'echo' => false, 'post' => $page_for_posts ) ) . '" />';
     4606        }
     4607}
     4608
     4609/**
     4610 * Adds a link rel=feed element to the home page when a static front page is set in Settings > Reading.
     4611 *
     4612 * See {@see 'wp_head'}.
     4613 *
     4614 * @since 5.2.3
     4615 */
     4616function rel_feed_for_posts() {
     4617        $page_for_posts = get_option( 'page_for_posts' );
     4618
     4619        if ( is_front_page() && ! is_home() && $page_for_posts != 0 ) {
     4620                echo '<link rel="feed" type="text/html" href="' . get_the_permalink( $page_for_posts ) . '" title="' . the_title_attribute( array( 'echo' => false, 'post' => $page_for_posts ) ) . '" />';
     4621        }
     4622}
     4623
     4624/**
     4625 * Adds a link rel=feed element to the home page when a static front page is set in Settings > Reading.
     4626 *
     4627 * See {@see 'wp_head'}.
     4628 *
     4629 * @since 5.2.3
     4630 */
     4631function rel_feed_for_posts() {
     4632        $page_for_posts = get_option( 'page_for_posts' );
     4633
     4634        if ( is_front_page() && ! is_home() && $page_for_posts != 0 ) {
     4635                echo '<link rel="feed" type="text/html" href="' . get_the_permalink( $page_for_posts ) . '" title="' . the_title_attribute( array( 'echo' => false, 'post' => $page_for_posts ) ) . '" />';
     4636        }
     4637}
  • tests/phpunit/tests/general/document-title.php

     
    11<?php
    22
    33/**
    4  * A set of unit tests for functions in wp-includes/general-template.php
     4 * A set of unit tests for testing the Document Title functions in wp-includes/general-template.php
    55 *
     6 * @group general
    67 * @group template
    78 * @group document-title
     9 * @ticket 46227
    810 */
    911class Tests_General_DocumentTitle extends WP_UnitTestCase {
    1012
     
    275277        function _change_title_separator( $sep ) {
    276278                return '%%';
    277279        }
     280
     281        // Test adding custom feed link to the blog page in the header.
     282        function test_add_feed_link_to_header_front_page() {
     283                $test_title = 'Blog';
     284                // create a sample blog page.
     285                $blog_page_id = $this->factory->post->create(
     286                        array(
     287                                'post_title' => $test_title,
     288                                'post_type'  => 'page',
     289                        )
     290                );
     291
     292                update_option( 'page_for_posts', $blog_page_id );
     293                update_option( 'show_on_front', 'page' );
     294
     295                $this->go_to('/');
     296
     297                $doc = new DOMDocument();
     298                $doc->preserveWhiteSpace = false;
     299
     300                $test_link_str = '<link rel="feed" type="text/html" href="' . get_the_permalink( $blog_page_id ) . '" title="' . the_title_attribute( array( 'echo' => false, 'post' => $blog_page_id ) ) . '" />';
     301                $doc->loadHTML( $test_link_str );
     302
     303                $selector = new DOMXPath( $doc );
     304                $result = $selector->query( "/html/head/link[@rel= 'feed']" );
     305                $test_blog_title = $result->item(0)->getAttribute( 'title' );
     306
     307                $this->assertEquals( $test_blog_title, $test_title );
     308        }
    278309}