mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add post type support to get_calendar() function #8251
Open
Sukhendu2002
wants to merge
7
commits into
WordPress:trunk
Choose a base branch
from
Sukhendu2002:feature/34093-add-post-type-support-to-calendar
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7893c77
Add post type support to get_calendar() function and related tests
Sukhendu2002 775e6da
Add related unit tests
Sukhendu2002 04fecae
Update func_get_args() usage in get_calendar()
Sukhendu2002 6860b8b
Update spacing
Sukhendu2002 714b79e
Remove redundant teardown
Sukhendu2002 faa0c7c
Fix PHPCS Errors
Sukhendu2002 bfc4bf7
Use get_echo() utility in get_calendar test
Sukhendu2002 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
/** | ||
* Tests for the get_calendar() function. | ||
* | ||
* @since 6.8.0 | ||
* | ||
* @group functions | ||
* @group calendar | ||
* | ||
* @covers ::get_calendar | ||
*/ | ||
class Tests_Get_Calendar extends WP_UnitTestCase { | ||
|
||
/** | ||
* Array of post IDs. | ||
* | ||
* @var int[] | ||
*/ | ||
protected static $post_ids = array(); | ||
|
||
/** | ||
* Set up before class. | ||
* | ||
* @param WP_UnitTest_Factory $factory Test factory. | ||
*/ | ||
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { | ||
self::$post_ids = $factory->post->create_many( | ||
3, | ||
array( | ||
'post_date' => '2025-02-01 12:00:00', | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Test that get_calendar() displays output when display is true. | ||
* | ||
* @ticket 34093 | ||
*/ | ||
public function test_get_calendar_display() { | ||
$expected = '<table id="wp-calendar"'; | ||
$actual = get_echo( 'get_calendar', array( array( 'display' => true ) ) ); | ||
$this->assertStringContainsString( $expected, $actual ); | ||
} | ||
|
||
/** | ||
* Test that get_calendar() respects the get_calendar_args filter. | ||
* | ||
* @ticket 34093 | ||
*/ | ||
public function test_get_calendar_args_filter() { | ||
$page_id = self::factory()->post->create( | ||
array( | ||
'post_type' => 'page', | ||
'post_date' => '2025-02-03 12:00:00', | ||
) | ||
); | ||
|
||
add_filter( | ||
'get_calendar_args', | ||
function ( $args ) { | ||
$args['post_type'] = 'page'; | ||
return $args; | ||
} | ||
); | ||
|
||
$calendar_html = get_echo( 'get_calendar' ); | ||
|
||
remove_all_filters( 'get_calendar_args' ); | ||
|
||
$this->assertStringContainsString( '<table id="wp-calendar"', $calendar_html ); | ||
$this->assertStringContainsString( 'Posts published on February 3, 2025', $calendar_html ); | ||
$this->assertStringContainsString( 'February 2025', $calendar_html ); | ||
} | ||
|
||
/** | ||
* Test that get_calendar() maintains backwards compatibility with old parameter format. | ||
* | ||
* @ticket 34093 | ||
*/ | ||
public function test_get_calendar_backwards_compatibility() { | ||
$first_calendar_html = get_echo( 'get_calendar', array( false ) ); | ||
|
||
wp_cache_delete( 'get_calendar', 'calendar' ); | ||
|
||
$second_calendar_html = get_calendar( false, false ); | ||
|
||
$this->assertStringContainsString( '<th scope="col" aria-label="Monday">Mon</th>', $first_calendar_html ); | ||
$this->assertStringContainsString( 'February 2025', $first_calendar_html ); | ||
$this->assertStringContainsString( '<table id="wp-calendar"', $second_calendar_html ); | ||
$this->assertStringContainsString( '<th scope="col" aria-label="Monday">Mon</th>', $second_calendar_html ); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about Backward compatibility. Previously it was two args not one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function handles backward compatibility through func_get_args().
This allows both old code
get_calendar(true, false)
and new codeget_calendar(['initial' => true])
to work without breaking existing implementations.