diff --git a/tests/phpunit/tests/link/postCommentsFeedLink.php b/tests/phpunit/tests/link/postCommentsFeedLink.php new file mode 100644 index 0000000000000..7673471c78737 --- /dev/null +++ b/tests/phpunit/tests/link/postCommentsFeedLink.php @@ -0,0 +1,151 @@ +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 = 'Comments Feed'; + + 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 = 'Subscribe via RSS'; + + 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 = 'Comments Feed'; + + 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 = 'Comments Feed'; + + 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 = 'Atom Comments'; + + 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 '' . $link . ''; + }, + 10, + 3 + ); + + ob_start(); + post_comments_feed_link( 'Comments', self::$post_id, 'atom' ); + $output = ob_get_clean(); + + $this->assertStringStartsWith( 'assertStringEndsWith( 'Comments', $output ); + } +} diff --git a/tests/phpunit/tests/link/theFeedLink.php b/tests/phpunit/tests/link/theFeedLink.php new file mode 100644 index 0000000000000..01d43bea79b44 --- /dev/null +++ b/tests/phpunit/tests/link/theFeedLink.php @@ -0,0 +1,106 @@ +set_permalink_structure( '' ); + + $expected_url = home_url( '?feed=' . get_default_feed() ); + $expected = 'Entries RSS'; + + 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 = 'Entries Feed'; + + 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 = 'Atom Feed'; + + 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 = 'Atom Feed'; + + 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 '