From e26fa4eecab526d19c2197f8c15d1982f199d55c Mon Sep 17 00:00:00 2001 From: rejaulalomkhan Date: Tue, 24 Nov 2026 09:34:34 +0600 Subject: [PATCH 1/2] Tests: Add unit tests for get_header_video_settings(). Cover default settings structure, YouTube mimeType resolution, direct video filetype detection, and header_video_settings filter. See #38172. --- .../tests/theme/getHeaderVideoSettings.php | 124 ++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 tests/phpunit/tests/theme/getHeaderVideoSettings.php diff --git a/tests/phpunit/tests/theme/getHeaderVideoSettings.php b/tests/phpunit/tests/theme/getHeaderVideoSettings.php new file mode 100644 index 0000000000000..8c9b57ff4914b --- /dev/null +++ b/tests/phpunit/tests/theme/getHeaderVideoSettings.php @@ -0,0 +1,124 @@ +assertIsArray( $settings, 'Header video settings should return an array.' ); + $this->assertArrayHasKey( 'mimeType', $settings ); + $this->assertArrayHasKey( 'posterUrl', $settings ); + $this->assertArrayHasKey( 'videoUrl', $settings ); + $this->assertArrayHasKey( 'width', $settings ); + $this->assertArrayHasKey( 'height', $settings ); + $this->assertArrayHasKey( 'minWidth', $settings ); + $this->assertArrayHasKey( 'minHeight', $settings ); + $this->assertArrayHasKey( 'l10n', $settings ); + + $this->assertSame( 900, $settings['minWidth'], 'Default minWidth should be 900.' ); + $this->assertSame( 500, $settings['minHeight'], 'Default minHeight should be 500.' ); + $this->assertSame( '', $settings['mimeType'], 'Default mimeType should be empty when no video is set.' ); + $this->assertIsArray( $settings['l10n'], 'l10n setting should be an array.' ); + $this->assertArrayHasKey( 'pause', $settings['l10n'] ); + $this->assertArrayHasKey( 'play', $settings['l10n'] ); + $this->assertArrayHasKey( 'pauseSpeak', $settings['l10n'] ); + $this->assertArrayHasKey( 'playSpeak', $settings['l10n'] ); + } + + /** + * Tests that get_header_video_settings() sets youtube mimeType for YouTube video URLs. + * + * @ticket 38172 + * + * @dataProvider data_youtube_urls + * + * @param string $youtube_url YouTube URL. + */ + public function test_get_header_video_settings_with_youtube_url( $youtube_url ) { + add_filter( + 'get_header_video_url', + static function () use ( $youtube_url ) { + return $youtube_url; + } + ); + + $settings = get_header_video_settings(); + + $this->assertSame( 'video/x-youtube', $settings['mimeType'], 'Mime type for YouTube URL should be video/x-youtube.' ); + $this->assertSame( set_url_scheme( $youtube_url ), $settings['videoUrl'], 'Video URL should match YouTube URL with current scheme.' ); + } + + /** + * Data provider for YouTube URLs. + * + * @return array + */ + public static function data_youtube_urls() { + return array( + 'youtube watch URL' => array( 'https://www.youtube.com/watch?v=1234567890' ), + 'youtube watch URL no www' => array( 'https://youtube.com/watch?v=1234567890' ), + 'youtu.be short URL' => array( 'https://youtu.be/1234567890' ), + ); + } + + /** + * Tests that get_header_video_settings() correctly resolves filetype for direct video files. + * + * @ticket 38172 + */ + public function test_get_header_video_settings_with_direct_video_file() { + $video_url = 'https://example.com/sample-header-video.mp4'; + add_filter( + 'get_header_video_url', + static function () use ( $video_url ) { + return $video_url; + } + ); + + $settings = get_header_video_settings(); + + $this->assertSame( 'video/mp4', $settings['mimeType'], 'Mime type for .mp4 URL should be video/mp4.' ); + $this->assertSame( set_url_scheme( $video_url ), $settings['videoUrl'], 'Video URL should match the direct video URL with current scheme.' ); + } + + /** + * Tests that header_video_settings filter allows modifying the settings array. + * + * @ticket 38172 + */ + public function test_header_video_settings_filter() { + add_filter( + 'header_video_settings', + static function ( $settings ) { + $settings['minWidth'] = 1200; + $settings['custom'] = 'custom_value'; + return $settings; + } + ); + + $settings = get_header_video_settings(); + + $this->assertSame( 1200, $settings['minWidth'], 'minWidth should be modified by the filter.' ); + $this->assertSame( 'custom_value', $settings['custom'], 'Custom setting should be present from filter.' ); + } +} From 55f1320ac1eede6dc7d569e8a30b8694869b7c1b Mon Sep 17 00:00:00 2001 From: rejaulalomkhan Date: Wed, 25 Nov 2026 15:41:50 +0600 Subject: [PATCH 2/2] Tests: Refactor get_header_video_settings() tests per committer review. --- .../tests/theme/getHeaderVideoSettings.php | 116 ++++-------------- 1 file changed, 24 insertions(+), 92 deletions(-) diff --git a/tests/phpunit/tests/theme/getHeaderVideoSettings.php b/tests/phpunit/tests/theme/getHeaderVideoSettings.php index 8c9b57ff4914b..1a5653d69fa98 100644 --- a/tests/phpunit/tests/theme/getHeaderVideoSettings.php +++ b/tests/phpunit/tests/theme/getHeaderVideoSettings.php @@ -2,92 +2,23 @@ /** * Test get_header_video_settings(). * - * @group theme + * @group themes * * @covers ::get_header_video_settings */ class Tests_Theme_GetHeaderVideoSettings extends WP_UnitTestCase { /** - * Clean up after each test. - */ - public function tear_down() { - remove_all_filters( 'header_video_settings' ); - remove_all_filters( 'get_header_video_url' ); - parent::tear_down(); - } - - /** - * Tests that get_header_video_settings() returns default structure when no video is configured. - * - * @ticket 38172 - */ - public function test_get_header_video_settings_default_structure() { - $settings = get_header_video_settings(); - - $this->assertIsArray( $settings, 'Header video settings should return an array.' ); - $this->assertArrayHasKey( 'mimeType', $settings ); - $this->assertArrayHasKey( 'posterUrl', $settings ); - $this->assertArrayHasKey( 'videoUrl', $settings ); - $this->assertArrayHasKey( 'width', $settings ); - $this->assertArrayHasKey( 'height', $settings ); - $this->assertArrayHasKey( 'minWidth', $settings ); - $this->assertArrayHasKey( 'minHeight', $settings ); - $this->assertArrayHasKey( 'l10n', $settings ); - - $this->assertSame( 900, $settings['minWidth'], 'Default minWidth should be 900.' ); - $this->assertSame( 500, $settings['minHeight'], 'Default minHeight should be 500.' ); - $this->assertSame( '', $settings['mimeType'], 'Default mimeType should be empty when no video is set.' ); - $this->assertIsArray( $settings['l10n'], 'l10n setting should be an array.' ); - $this->assertArrayHasKey( 'pause', $settings['l10n'] ); - $this->assertArrayHasKey( 'play', $settings['l10n'] ); - $this->assertArrayHasKey( 'pauseSpeak', $settings['l10n'] ); - $this->assertArrayHasKey( 'playSpeak', $settings['l10n'] ); - } - - /** - * Tests that get_header_video_settings() sets youtube mimeType for YouTube video URLs. + * Tests that get_header_video_settings() resolves the expected mimeType for video URLs. * * @ticket 38172 * - * @dataProvider data_youtube_urls - * - * @param string $youtube_url YouTube URL. - */ - public function test_get_header_video_settings_with_youtube_url( $youtube_url ) { - add_filter( - 'get_header_video_url', - static function () use ( $youtube_url ) { - return $youtube_url; - } - ); - - $settings = get_header_video_settings(); - - $this->assertSame( 'video/x-youtube', $settings['mimeType'], 'Mime type for YouTube URL should be video/x-youtube.' ); - $this->assertSame( set_url_scheme( $youtube_url ), $settings['videoUrl'], 'Video URL should match YouTube URL with current scheme.' ); - } - - /** - * Data provider for YouTube URLs. - * - * @return array - */ - public static function data_youtube_urls() { - return array( - 'youtube watch URL' => array( 'https://www.youtube.com/watch?v=1234567890' ), - 'youtube watch URL no www' => array( 'https://youtube.com/watch?v=1234567890' ), - 'youtu.be short URL' => array( 'https://youtu.be/1234567890' ), - ); - } - - /** - * Tests that get_header_video_settings() correctly resolves filetype for direct video files. + * @dataProvider data_video_url_mime_types * - * @ticket 38172 + * @param string $video_url Video URL. + * @param string $expected_mime Expected MIME type. */ - public function test_get_header_video_settings_with_direct_video_file() { - $video_url = 'https://example.com/sample-header-video.mp4'; + 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 ) { @@ -97,28 +28,29 @@ static function () use ( $video_url ) { $settings = get_header_video_settings(); - $this->assertSame( 'video/mp4', $settings['mimeType'], 'Mime type for .mp4 URL should be video/mp4.' ); - $this->assertSame( set_url_scheme( $video_url ), $settings['videoUrl'], 'Video URL should match the direct video URL with current scheme.' ); + $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.' ); + } } /** - * Tests that header_video_settings filter allows modifying the settings array. + * Data provider for video URL to MIME type resolution. * - * @ticket 38172 + * @return array */ - public function test_header_video_settings_filter() { - add_filter( - 'header_video_settings', - static function ( $settings ) { - $settings['minWidth'] = 1200; - $settings['custom'] = 'custom_value'; - return $settings; - } + 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( '', '' ), ); - - $settings = get_header_video_settings(); - - $this->assertSame( 1200, $settings['minWidth'], 'minWidth should be modified by the filter.' ); - $this->assertSame( 'custom_value', $settings['custom'], 'Custom setting should be present from filter.' ); } }