Skip to content

Commit 0d0c832

Browse files
Tests: Add unit tests for wp_make_theme_file_tree().
Follow-up to [41851]. Props pbearne. Fixes #65175. git-svn-id: https://develop.svn.wordpress.org/trunk@62388 602fd350-edb4-49c9-b593-d223f7449a82
1 parent b0b4861 commit 0d0c832

1 file changed

Lines changed: 97 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)