Skip to content

Commit ef50673

Browse files
authored
Merge branch 'WordPress:trunk' into trunk
2 parents d9686ce + d792cbd commit ef50673

4 files changed

Lines changed: 109 additions & 81 deletions

File tree

src/wp-includes/functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7051,7 +7051,7 @@ function get_file_data( $file, $default_headers, $context = '' ) {
70517051
}
70527052

70537053
foreach ( $all_headers as $field => $regex ) {
7054-
if ( preg_match( '/^(?:[ \t]*<\?php)?[ \t\/*#@]*' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, $match ) && $match[1] ) {
7054+
if ( preg_match( '/^(?:[ \t]*<\?(?:php)?)?[ \t\/*#@]*' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, $match ) && $match[1] ) {
70557055
$all_headers[ $field ] = _cleanup_header_comment( $match[1] );
70567056
} else {
70577057
$all_headers[ $field ] = '';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<? # Template Name: Something ?>

tests/phpunit/tests/file.php

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -15,86 +15,6 @@ public function set_up() {
1515
$this->dir = untrailingslashit( get_temp_dir() );
1616
}
1717

18-
/**
19-
* @group plugins
20-
* @group themes
21-
*/
22-
public function test_get_file_data() {
23-
$theme_headers = array(
24-
'Name' => 'Theme Name',
25-
'ThemeURI' => 'Theme URI',
26-
'Description' => 'Description',
27-
'Version' => 'Version',
28-
'Author' => 'Author',
29-
'AuthorURI' => 'Author URI',
30-
);
31-
32-
$actual = get_file_data( DIR_TESTDATA . '/themedir1/default/style.css', $theme_headers );
33-
34-
$expected = array(
35-
'Name' => 'WordPress Default',
36-
'ThemeURI' => 'http://wordpress.org/',
37-
'Description' => 'The default WordPress theme based on the famous <a href="http://binarybonsai.com/kubrick/">Kubrick</a>.',
38-
'Version' => '1.6',
39-
'Author' => 'Michael Heilemann',
40-
'AuthorURI' => 'http://binarybonsai.com/',
41-
);
42-
43-
$this->assertNotEmpty( $actual );
44-
45-
foreach ( $actual as $header => $value ) {
46-
$this->assertSame( $expected[ $header ], $value, $header );
47-
}
48-
}
49-
50-
/**
51-
* @ticket 19854
52-
* @group plugins
53-
* @group themes
54-
*/
55-
public function test_get_file_data_with_cr_line_endings() {
56-
$headers = array(
57-
'SomeHeader' => 'Some Header',
58-
'Description' => 'Description',
59-
'Author' => 'Author',
60-
);
61-
62-
$actual = get_file_data( DIR_TESTDATA . '/formatting/file-header-cr-line-endings.php', $headers );
63-
$expected = array(
64-
'SomeHeader' => 'Some header value!',
65-
'Description' => 'This file is using CR line endings for a testcase.',
66-
'Author' => 'A Very Old Mac',
67-
);
68-
69-
$this->assertNotEmpty( $actual );
70-
71-
foreach ( $actual as $header => $value ) {
72-
$this->assertSame( $expected[ $header ], $value, $header );
73-
}
74-
}
75-
76-
/**
77-
* @ticket 47186
78-
* @group plugins
79-
* @group themes
80-
*/
81-
public function test_get_file_data_with_php_open_tag_prefix() {
82-
$headers = array(
83-
'TemplateName' => 'Template Name',
84-
);
85-
86-
$actual = get_file_data( DIR_TESTDATA . '/formatting/file-header-php-open-tag-prefix.php', $headers );
87-
$expected = array(
88-
'TemplateName' => 'Something',
89-
);
90-
91-
$this->assertNotEmpty( $actual );
92-
93-
foreach ( $actual as $header => $value ) {
94-
$this->assertSame( $expected[ $header ], $value, $header );
95-
}
96-
}
97-
9818
private function is_unique_writable_file( $path, $filename ) {
9919
$fullpath = $path . DIRECTORY_SEPARATOR . $filename;
10020

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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

Comments
 (0)