Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 151 additions & 0 deletions tests/phpunit/tests/link/postCommentsFeedLink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<?php

/**
* @group link
*
* @covers ::post_comments_feed_link
*/
class Tests_Link_PostCommentsFeedLink extends WP_UnitTestCase {

/**
* Test post ID.
*
* @var int
*/
protected static $post_id;

/**
* Set up before class.
*
* @param WP_UnitTest_Factory $factory Test factory.
*/
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
self::$post_id = $factory->post->create(
array(
'post_title' => 'Sample Post for Feed',
)
);
}

/**
* Tests post_comments_feed_link() with default link text on plain permalinks.
*
* @ticket 65819
*/
public function test_post_comments_feed_link_default_text() {
$this->set_permalink_structure( '' );

$expected_url = get_post_comments_feed_link( self::$post_id );
$expected = '<a href="' . esc_url( $expected_url ) . '">Comments Feed</a>';

ob_start();
post_comments_feed_link( '', self::$post_id );
$output = ob_get_clean();

$this->assertSame( $expected, $output );
}

/**
* Tests post_comments_feed_link() with custom link text.
*
* @ticket 65819
*/
public function test_post_comments_feed_link_custom_text() {
$this->set_permalink_structure( '' );

$expected_url = get_post_comments_feed_link( self::$post_id );
$expected = '<a href="' . esc_url( $expected_url ) . '">Subscribe via RSS</a>';

ob_start();
post_comments_feed_link( 'Subscribe via RSS', self::$post_id );
$output = ob_get_clean();

$this->assertSame( $expected, $output );
}

/**
* Tests post_comments_feed_link() with pretty permalink structure.
*
* @ticket 65819
*/
public function test_post_comments_feed_link_pretty_permastruct() {
$this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );

$expected_url = get_post_comments_feed_link( self::$post_id );
$expected = '<a href="' . esc_url( $expected_url ) . '">Comments Feed</a>';

ob_start();
post_comments_feed_link( '', self::$post_id );
$output = ob_get_clean();

$this->assertSame( $expected, $output );
}

/**
* Tests post_comments_feed_link() defaulting to global $post when post_id is 0.
*
* @ticket 65819
*/
public function test_post_comments_feed_link_defaults_to_global_post() {
global $post;

$this->set_permalink_structure( '' );

$original_post = $post;
$post = get_post( self::$post_id );

$expected_url = get_post_comments_feed_link( self::$post_id );
$expected = '<a href="' . esc_url( $expected_url ) . '">Comments Feed</a>';

ob_start();
post_comments_feed_link();
$output = ob_get_clean();

$post = $original_post;

$this->assertSame( $expected, $output );
}

/**
* Tests post_comments_feed_link() with a custom feed type.
*
* @ticket 65819
*/
public function test_post_comments_feed_link_custom_feed_type() {
$this->set_permalink_structure( '' );

$expected_url = get_post_comments_feed_link( self::$post_id, 'atom' );
$expected = '<a href="' . esc_url( $expected_url ) . '">Atom Comments</a>';

ob_start();
post_comments_feed_link( 'Atom Comments', self::$post_id, 'atom' );
$output = ob_get_clean();

$this->assertSame( $expected, $output );
}

/**
* Tests the 'post_comments_feed_link_html' filter hook.
*
* @ticket 65819
*/
public function test_post_comments_feed_link_html_filter() {
$this->set_permalink_structure( '' );

add_filter(
'post_comments_feed_link_html',
static function ( $link, $post_id, $feed ) {
return '<span class="post-feed" data-post="' . (int) $post_id . '" data-feed="' . esc_attr( $feed ) . '">' . $link . '</span>';
},
10,
3
);

ob_start();
post_comments_feed_link( 'Comments', self::$post_id, 'atom' );
$output = ob_get_clean();

$this->assertStringStartsWith( '<span class="post-feed" data-post="' . self::$post_id . '" data-feed="atom"><a', $output );
$this->assertStringEndsWith( 'Comments</a></span>', $output );
}
}
106 changes: 106 additions & 0 deletions tests/phpunit/tests/link/theFeedLink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php

/**
* @group link
*
* @covers ::the_feed_link
*/
class Tests_Link_TheFeedLink extends WP_UnitTestCase {

/**
* Tests the_feed_link() with plain permalink structure and default feed.
*
* @ticket 65819
*/
public function test_the_feed_link_plain_permastruct_default_feed() {
$this->set_permalink_structure( '' );

$expected_url = home_url( '?feed=' . get_default_feed() );
$expected = '<a href="' . esc_url( $expected_url ) . '">Entries RSS</a>';

ob_start();
the_feed_link( 'Entries RSS' );
$output = ob_get_clean();

$this->assertSame( $expected, $output );
}

/**
* Tests the_feed_link() with pretty permalink structure and default feed.
*
* @ticket 65819
*/
public function test_the_feed_link_pretty_permastruct_default_feed() {
$this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );

$expected_url = home_url( '/feed/' );
$expected = '<a href="' . esc_url( $expected_url ) . '">Entries Feed</a>';

ob_start();
the_feed_link( 'Entries Feed' );
$output = ob_get_clean();

$this->assertSame( $expected, $output );
}

/**
* Tests the_feed_link() with custom feed type.
*
* @ticket 65819
*/
public function test_the_feed_link_custom_feed_type() {
$this->set_permalink_structure( '' );

$expected_url = home_url( '?feed=atom' );
$expected = '<a href="' . esc_url( $expected_url ) . '">Atom Feed</a>';

ob_start();
the_feed_link( 'Atom Feed', 'atom' );
$output = ob_get_clean();

$this->assertSame( $expected, $output );
}

/**
* Tests the_feed_link() with pretty permalinks and custom feed type.
*
* @ticket 65819
*/
public function test_the_feed_link_pretty_permastruct_custom_feed_type() {
$this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );

$expected_url = home_url( '/feed/atom/' );
$expected = '<a href="' . esc_url( $expected_url ) . '">Atom Feed</a>';

ob_start();
the_feed_link( 'Atom Feed', 'atom' );
$output = ob_get_clean();

$this->assertSame( $expected, $output );
}

/**
* Tests the 'the_feed_link' filter hook.
*
* @ticket 65819
*/
public function test_the_feed_link_filter() {
$this->set_permalink_structure( '' );

add_filter(
'the_feed_link',
static function ( $link, $feed ) {
return '<div class="feed-wrapper" data-feed="' . esc_attr( $feed ) . '">' . $link . '</div>';
},
10,
2
);

ob_start();
the_feed_link( 'Custom Filtered Feed', 'atom' );
$output = ob_get_clean();

$this->assertStringStartsWith( '<div class="feed-wrapper" data-feed="atom"><a', $output );
$this->assertStringEndsWith( 'Custom Filtered Feed</a></div>', $output );
}
}
Loading