Skip to content

Commit

Permalink
Tests: Correct test class name for rss_enclosure() as per the namin…
Browse files Browse the repository at this point in the history
…g conventions.

Includes:
* Moving `@covers` tags to the class-level DocBlock, since this is the only function tested in the class.
* Adjusting the assertion messages for clarity, as `rss_enclosure()` does not return anything directly.
* Using a static closure for improved performance.

Follow-up to [59241].

See #61530.

git-svn-id: https://develop.svn.wordpress.org/trunk@59243 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Oct 16, 2024
1 parent 11b435c commit 787e52f
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions tests/phpunit/tests/feed/rssEnclosure.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<?php

/**
* Test the feed.
* Tests for the rss_enclosure() function.
*
* @group feed
*
* @covers ::rss_enclosure
*/
class Tests_rssEnclosure extends WP_UnitTestCase {
class Tests_Feed_RssEnclosure extends WP_UnitTestCase {

/**
* @ticket 58798
*
* @covers ::rss_enclosure
*/
public function test_rss_enclosure_filter() {
$post_id = self::factory()->post->create();
Expand All @@ -21,7 +22,7 @@ public function test_rss_enclosure_filter() {

add_filter(
'rss_enclosure',
function () {
static function () {
return 'filtered_html_link_tag';
}
);
Expand All @@ -31,30 +32,25 @@ function () {

/**
* @ticket 58798
*
* @covers ::rss_enclosure
*/
public function test_rss_enclosure_when_global_post_is_empty() {
$this->assertEmpty( get_echo( 'rss_enclosure' ), 'It should return empty when the global post is not set.' );
$this->assertEmpty( get_echo( 'rss_enclosure' ), 'The output should be empty when the global post is not set.' );
}

/**
* @ticket 58798
*
* @covers ::rss_enclosure
*/
public function test_rss_enclosure_when_enclosure_meta_field_is_empty() {
$post_id = self::factory()->post->create();
$GLOBALS['post'] = $post_id;

$this->assertEmpty( get_echo( 'rss_enclosure' ), 'The global post does not have the `enclosure` meta field and should return empty. ' );
$this->assertEmpty( get_echo( 'rss_enclosure' ), 'The output should be empty when the global post does not have the `enclosure` meta field.' );
}

/**
* @ticket 58798
*
* @dataProvider data_rss_enclosure_with_multiline_enclosure_string
* @covers ::rss_enclosure
*/
public function test_rss_enclosure_with_multiline_enclosure_string( $enclosure_data, $enclosure_string ) {
$post_id = self::factory()->post->create();
Expand All @@ -64,13 +60,13 @@ public function test_rss_enclosure_with_multiline_enclosure_string( $enclosure_d

$expected = '<enclosure url="' . $enclosure_data['url'] . '" length="' . $enclosure_data['length'] . '" type="' . $enclosure_data['type'] . '" />' . "\n";

$this->assertSame( $expected, get_echo( 'rss_enclosure' ), 'It should return a valid enclosure tag. ' );
$this->assertSame( $expected, get_echo( 'rss_enclosure' ), 'The output should be a valid enclosure tag.' );
}

/**
* Data provider for valid enclosure string.
*
* @return array[].
* @return array[]
*/
public function data_rss_enclosure_with_multiline_enclosure_string() {
return array(
Expand Down Expand Up @@ -113,21 +109,20 @@ public function data_rss_enclosure_with_multiline_enclosure_string() {
* @ticket 58798
*
* @dataProvider data_rss_enclosure_with_non_valid_enclosure_string
* @covers ::rss_enclosure
*/
public function test_rss_enclosure_with_non_valid_enclosure_string( $enclosure_string ) {
$post_id = self::factory()->post->create();
$GLOBALS['post'] = $post_id;

update_post_meta( $post_id, 'enclosure', $enclosure_string );

$this->assertEmpty( get_echo( 'rss_enclosure' ), 'It should return empty when the `enclosure` meta field is not saved in a multiline string.' );
$this->assertEmpty( get_echo( 'rss_enclosure' ), 'The output should be empty when the `enclosure` meta field is not saved in a multiline string.' );
}

/**
* Data provider for non-valid enclosure string.
*
* @return array[].
* @return array[]
*/
public function data_rss_enclosure_with_non_valid_enclosure_string() {
return array(
Expand Down

0 comments on commit 787e52f

Please sign in to comment.