|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Test cases for the `get_file_data()` function. |
| 4 | + * |
| 5 | + * @group functions |
| 6 | + * @group file |
| 7 | + * @group plugins |
| 8 | + * @group themes |
| 9 | + * |
| 10 | + * @covers ::get_file_data |
| 11 | + */ |
| 12 | +class Tests_Functions_GetFileData extends WP_UnitTestCase { |
| 13 | + |
| 14 | + |
| 15 | + /** |
| 16 | + * Tests get_file_data(). |
| 17 | + * |
| 18 | + * @ticket 19854 |
| 19 | + * @ticket 42517 |
| 20 | + * @ticket 47186 |
| 21 | + * |
| 22 | + * @dataProvider data_test_get_data_file |
| 23 | + * |
| 24 | + * @param string $file File path, relative to the test data directory. |
| 25 | + * @param array<string, string> $headers Default headers. |
| 26 | + * @param string $context Context. |
| 27 | + * @param array<string, string> $expected Expected headers. |
| 28 | + */ |
| 29 | + public function test_get_file_data( $file, $headers, $context, $expected ) { |
| 30 | + $actual = get_file_data( DIR_TESTDATA . $file, $headers, $context ); |
| 31 | + |
| 32 | + $this->assertNotEmpty( $actual ); |
| 33 | + |
| 34 | + foreach ( $actual as $header => $value ) { |
| 35 | + $this->assertSame( $expected[ $header ], $value, $header ); |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + /* |
| 40 | + * Data provider for test_get_file_data(). |
| 41 | + * |
| 42 | + * @return array<string, array{ |
| 43 | + * file: string, |
| 44 | + * headers: array<string, string>, |
| 45 | + * context: string, |
| 46 | + * expected: array<string, string>, |
| 47 | + * }> |
| 48 | + */ |
| 49 | + public function data_test_get_data_file() { |
| 50 | + return array( |
| 51 | + 'theme headers' => array( |
| 52 | + 'file' => '/themedir1/default/style.css', |
| 53 | + 'headers' => array( |
| 54 | + 'Name' => 'Theme Name', |
| 55 | + 'ThemeURI' => 'Theme URI', |
| 56 | + 'Description' => 'Description', |
| 57 | + 'Version' => 'Version', |
| 58 | + 'Author' => 'Author', |
| 59 | + 'AuthorURI' => 'Author URI', |
| 60 | + ), |
| 61 | + 'context' => '', |
| 62 | + 'expected' => array( |
| 63 | + 'Name' => 'WordPress Default', |
| 64 | + 'ThemeURI' => 'http://wordpress.org/', |
| 65 | + 'Description' => 'The default WordPress theme based on the famous <a href="http://binarybonsai.com/kubrick/">Kubrick</a>.', |
| 66 | + 'Version' => '1.6', |
| 67 | + 'Author' => 'Michael Heilemann', |
| 68 | + 'AuthorURI' => 'http://binarybonsai.com/', |
| 69 | + ), |
| 70 | + ), |
| 71 | + 'cr line endings' => array( |
| 72 | + 'file' => '/formatting/file-header-cr-line-endings.php', |
| 73 | + 'headers' => array( |
| 74 | + 'SomeHeader' => 'Some Header', |
| 75 | + 'Description' => 'Description', |
| 76 | + 'Author' => 'Author', |
| 77 | + ), |
| 78 | + 'context' => '', |
| 79 | + 'expected' => array( |
| 80 | + 'SomeHeader' => 'Some header value!', |
| 81 | + 'Description' => 'This file is using CR line endings for a testcase.', |
| 82 | + 'Author' => 'A Very Old Mac', |
| 83 | + ), |
| 84 | + ), |
| 85 | + 'php open tag prefix' => array( |
| 86 | + 'file' => '/formatting/file-header-php-open-tag-prefix.php', |
| 87 | + 'headers' => array( |
| 88 | + 'TemplateName' => 'Template Name', |
| 89 | + ), |
| 90 | + 'context' => '', |
| 91 | + 'expected' => array( |
| 92 | + 'TemplateName' => 'Something', |
| 93 | + ), |
| 94 | + ), |
| 95 | + 'php short open tag prefix' => array( |
| 96 | + 'file' => '/formatting/file-header-php-short-open-tag-prefix.php', |
| 97 | + 'headers' => array( |
| 98 | + 'TemplateName' => 'Template Name', |
| 99 | + ), |
| 100 | + 'context' => '', |
| 101 | + 'expected' => array( |
| 102 | + 'TemplateName' => 'Something', |
| 103 | + ), |
| 104 | + ), |
| 105 | + ); |
| 106 | + } |
| 107 | +} |
0 commit comments