Repository navigation
Tests: Add unit tests for get_header_video_settings(). #16189
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
Closed
rejaulalomkhan
wants to merge
2
commits into
WordPress:trunk
from
rejaulalomkhan:tests/theme-get-header-video-settings
Closed
Changes from all commits
Commits
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 hidden or 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,56 @@ | ||
| <?php | ||
| /** | ||
| * Test get_header_video_settings(). | ||
| * | ||
| * @group themes | ||
| * | ||
| * @covers ::get_header_video_settings | ||
| */ | ||
| class Tests_Theme_GetHeaderVideoSettings extends WP_UnitTestCase { | ||
|
|
||
| /** | ||
| * Tests that get_header_video_settings() resolves the expected mimeType for video URLs. | ||
| * | ||
| * @ticket 38172 | ||
| * | ||
| * @dataProvider data_video_url_mime_types | ||
| * | ||
| * @param string $video_url Video URL. | ||
| * @param string $expected_mime Expected MIME type. | ||
| */ | ||
| public function test_get_header_video_settings_resolves_mime_type( $video_url, $expected_mime ) { | ||
| add_filter( | ||
| 'get_header_video_url', | ||
| static function () use ( $video_url ) { | ||
| return $video_url; | ||
| } | ||
| ); | ||
|
|
||
| $settings = get_header_video_settings(); | ||
|
|
||
| $this->assertSame( $expected_mime, $settings['mimeType'], 'MIME type does not match expected player type.' ); | ||
| if ( empty( $video_url ) ) { | ||
| $this->assertFalse( $settings['videoUrl'], 'Video URL should be false when no video URL is configured.' ); | ||
| } else { | ||
| $this->assertSame( set_url_scheme( $video_url ), $settings['videoUrl'], 'Video URL should match input URL with current scheme.' ); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Data provider for video URL to MIME type resolution. | ||
| * | ||
| * @return array<string, array{0: string, 1: string}> | ||
| */ | ||
| public static function data_video_url_mime_types() { | ||
| return array( | ||
| 'youtube watch URL' => array( 'https://www.youtube.com/watch?v=1234567890', 'video/x-youtube' ), | ||
| 'youtube watch URL without www' => array( 'https://youtube.com/watch?v=1234567890', 'video/x-youtube' ), | ||
| 'youtube short URL' => array( 'https://youtu.be/1234567890', 'video/x-youtube' ), | ||
| 'direct mp4 video file' => array( 'https://example.com/header-video.mp4', 'video/mp4' ), | ||
| 'direct webm video file' => array( 'https://example.com/header-video.webm', 'video/webm' ), | ||
| 'direct mov video file' => array( 'https://example.com/header-video.mov', 'video/quicktime' ), | ||
| 'unrecognized file extension' => array( 'https://example.com/header.xyz', '' ), | ||
| 'empty video URL' => array( '', '' ), | ||
| ); | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.