|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Tests for the wp_make_theme_file_tree() function. |
| 4 | + * |
| 5 | + * @group admin |
| 6 | + * @group admin-includes |
| 7 | + * @covers ::wp_make_theme_file_tree |
| 8 | + */ |
| 9 | +class Tests_wp_make_theme_file_tree extends WP_UnitTestCase { |
| 10 | + |
| 11 | + /** |
| 12 | + * Tests wp_make_theme_file_tree() with various file structures. |
| 13 | + * |
| 14 | + * @ticket 65175 |
| 15 | + * @dataProvider data_wp_make_theme_file_tree |
| 16 | + * |
| 17 | + * @param array $allowed_files The list of theme files. |
| 18 | + * @param array $expected The expected tree structure. |
| 19 | + */ |
| 20 | + public function test_wp_make_theme_file_tree( $allowed_files, $expected ) { |
| 21 | + $this->assertSame( $expected, wp_make_theme_file_tree( $allowed_files ) ); |
| 22 | + } |
| 23 | + |
| 24 | + /** |
| 25 | + * Data provider for test_wp_make_theme_file_tree. |
| 26 | + * |
| 27 | + * @return array<string, array{ |
| 28 | + * allowed_files: array<string, string>, |
| 29 | + * expected: array<string, string|array>, |
| 30 | + * }> |
| 31 | + */ |
| 32 | + public function data_wp_make_theme_file_tree(): array { |
| 33 | + return array( |
| 34 | + 'empty_list' => array( |
| 35 | + 'allowed_files' => array(), |
| 36 | + 'expected' => array(), |
| 37 | + ), |
| 38 | + 'flat_list' => array( |
| 39 | + 'allowed_files' => array( |
| 40 | + 'style.css' => '/path/to/theme/style.css', |
| 41 | + 'index.php' => '/path/to/theme/index.php', |
| 42 | + ), |
| 43 | + 'expected' => array( |
| 44 | + 'style.css' => 'style.css', |
| 45 | + 'index.php' => 'index.php', |
| 46 | + ), |
| 47 | + ), |
| 48 | + 'nested_list' => array( |
| 49 | + 'allowed_files' => array( |
| 50 | + 'style.css' => '/path/to/theme/style.css', |
| 51 | + 'inc/header.php' => '/path/to/theme/inc/header.php', |
| 52 | + 'inc/footer.php' => '/path/to/theme/inc/footer.php', |
| 53 | + 'templates/a.php' => '/path/to/theme/templates/a.php', |
| 54 | + ), |
| 55 | + 'expected' => array( |
| 56 | + 'style.css' => 'style.css', |
| 57 | + 'inc' => array( |
| 58 | + 'header.php' => 'inc/header.php', |
| 59 | + 'footer.php' => 'inc/footer.php', |
| 60 | + ), |
| 61 | + 'templates' => array( |
| 62 | + 'a.php' => 'templates/a.php', |
| 63 | + ), |
| 64 | + ), |
| 65 | + ), |
| 66 | + 'deeply_nested_list' => array( |
| 67 | + 'allowed_files' => array( |
| 68 | + 'a/b/c/d.php' => '/path/to/theme/a/b/c/d.php', |
| 69 | + ), |
| 70 | + 'expected' => array( |
| 71 | + 'a' => array( |
| 72 | + 'b' => array( |
| 73 | + 'c' => array( |
| 74 | + 'd.php' => 'a/b/c/d.php', |
| 75 | + ), |
| 76 | + ), |
| 77 | + ), |
| 78 | + ), |
| 79 | + ), |
| 80 | + 'mixed_nesting' => array( |
| 81 | + 'allowed_files' => array( |
| 82 | + 'index.php' => '/path/to/theme/index.php', |
| 83 | + 'inc/header.php' => '/path/to/theme/inc/header.php', |
| 84 | + 'inc/utils/a.php' => '/path/to/theme/inc/utils/a.php', |
| 85 | + ), |
| 86 | + 'expected' => array( |
| 87 | + 'index.php' => 'index.php', |
| 88 | + 'inc' => array( |
| 89 | + 'header.php' => 'inc/header.php', |
| 90 | + 'utils' => array( |
| 91 | + 'a.php' => 'inc/utils/a.php', |
| 92 | + ), |
| 93 | + ), |
| 94 | + ), |
| 95 | + ), |
| 96 | + ); |
| 97 | + } |
| 98 | +} |
0 commit comments