diff --git a/src/wp-includes/class-wp-theme.php b/src/wp-includes/class-wp-theme.php
index 6952c59bda..d7cf008a59 100644
|
a
|
b
|
final class WP_Theme implements ArrayAccess {
|
| 1385 | 1385 | } |
| 1386 | 1386 | } |
| 1387 | 1387 | |
| | 1388 | /* |
| | 1389 | * Sort post templates by their translated, human-readable template name |
| | 1390 | * instead of by filename or slug. |
| | 1391 | */ |
| | 1392 | foreach ( array_keys( $post_templates ) as $type ) { |
| | 1393 | if ( ! is_array( $post_templates[ $type ] ) ) { |
| | 1394 | continue; |
| | 1395 | } |
| | 1396 | |
| | 1397 | uasort( $post_templates[ $type ], 'strnatcasecmp' ); |
| | 1398 | } |
| | 1399 | |
| 1388 | 1400 | return $post_templates; |
| 1389 | 1401 | } |
| 1390 | 1402 | |
diff --git a/tests/phpunit/data/themedir1/page-templates/template-a-zebra.php b/tests/phpunit/data/themedir1/page-templates/template-a-zebra.php
new file mode 100644
index 0000000000..a5824664c7
|
-
|
+
|
|
| | 1 | <?php |
| | 2 | /* |
| | 3 | Template Name: Zebra Template |
| | 4 | */ |
| | 5 | ?> |
diff --git a/tests/phpunit/data/themedir1/page-templates/template-z-alpha.php b/tests/phpunit/data/themedir1/page-templates/template-z-alpha.php
new file mode 100644
index 0000000000..40a1e24c4b
|
-
|
+
|
|
| | 1 | <?php |
| | 2 | /* |
| | 3 | Template Name: Alpha Template |
| | 4 | */ |
| | 5 | ?> |
diff --git a/tests/phpunit/tests/theme/wpTheme.php b/tests/phpunit/tests/theme/wpTheme.php
index a06fba32c5..6803696867 100644
|
a
|
b
|
class Tests_Theme_wpTheme extends WP_UnitTestCase {
|
| 348 | 348 | $this->assertCount( 2, $filter->get_events(), 'Should only be 4, as second run should not be cached' ); |
| 349 | 349 | } |
| 350 | 350 | |
| | 351 | /** |
| | 352 | * @ticket 49194 |
| | 353 | * |
| | 354 | * @covers WP_Theme::get_post_templates |
| | 355 | */ |
| | 356 | public function test_get_post_templates_should_sort_templates_by_template_name() { |
| | 357 | $theme = new WP_Theme( 'page-templates', $this->theme_root ); |
| | 358 | |
| | 359 | $post_templates = $theme->get_post_templates(); |
| | 360 | |
| | 361 | $this->assertArrayHasKey( 'page', $post_templates ); |
| | 362 | |
| | 363 | $actual = array_intersect_key( |
| | 364 | $post_templates['page'], |
| | 365 | array( |
| | 366 | 'template-z-alpha.php' => true, |
| | 367 | 'template-a-zebra.php' => true, |
| | 368 | ) |
| | 369 | ); |
| | 370 | |
| | 371 | $this->assertSame( |
| | 372 | array( |
| | 373 | 'template-z-alpha.php' => 'Alpha Template', |
| | 374 | 'template-a-zebra.php' => 'Zebra Template', |
| | 375 | ), |
| | 376 | $actual |
| | 377 | ); |
| | 378 | } |
| | 379 | |
| 351 | 380 | /** |
| 352 | 381 | * Test get_files for an existing theme. |
| 353 | 382 | * |