Skip to content

Commit c38a1b7

Browse files
Tests: Move get_file_data() tests to their own file.
This aims to make the tests more discoverable and easier to expand. Includes converting the tests to use a named data provider. Follow-up to [703/tests], [51182]. Props birgire, gschoppe, sukhendu2002, SergeyBiryukov. See #42517, #64894. git-svn-id: https://develop.svn.wordpress.org/trunk@62802 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 7a7652e commit c38a1b7

2 files changed

Lines changed: 96 additions & 80 deletions

File tree

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: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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 47186
20+
*
21+
* @dataProvider data_test_get_data_file
22+
*
23+
* @param string $file File path, relative to the test data directory.
24+
* @param array $headers Default headers.
25+
* @param string $context Context.
26+
* @param array $expected Expected headers.
27+
*/
28+
public function test_get_file_data( $file, $headers, $context, $expected ) {
29+
$actual = get_file_data( DIR_TESTDATA . $file, $headers, $context );
30+
31+
$this->assertNotEmpty( $actual );
32+
33+
foreach ( $actual as $header => $value ) {
34+
$this->assertSame( $expected[ $header ], $value, $header );
35+
}
36+
}
37+
38+
/*
39+
* Data provider for test_get_file_data().
40+
*
41+
* @return array<string, array{
42+
* file: string,
43+
* headers: array<string, string>,
44+
* context: string,
45+
* expected: array<string, string>,
46+
* }>
47+
*/
48+
public function data_test_get_data_file() {
49+
return array(
50+
'theme headers' => array(
51+
'file' => '/themedir1/default/style.css',
52+
'headers' => array(
53+
'Name' => 'Theme Name',
54+
'ThemeURI' => 'Theme URI',
55+
'Description' => 'Description',
56+
'Version' => 'Version',
57+
'Author' => 'Author',
58+
'AuthorURI' => 'Author URI',
59+
),
60+
'context' => '',
61+
'expected' => array(
62+
'Name' => 'WordPress Default',
63+
'ThemeURI' => 'http://wordpress.org/',
64+
'Description' => 'The default WordPress theme based on the famous <a href="http://binarybonsai.com/kubrick/">Kubrick</a>.',
65+
'Version' => '1.6',
66+
'Author' => 'Michael Heilemann',
67+
'AuthorURI' => 'http://binarybonsai.com/',
68+
),
69+
),
70+
'cr line endings' => array(
71+
'file' => '/formatting/file-header-cr-line-endings.php',
72+
'headers' => array(
73+
'SomeHeader' => 'Some Header',
74+
'Description' => 'Description',
75+
'Author' => 'Author',
76+
),
77+
'context' => '',
78+
'expected' => array(
79+
'SomeHeader' => 'Some header value!',
80+
'Description' => 'This file is using CR line endings for a testcase.',
81+
'Author' => 'A Very Old Mac',
82+
),
83+
),
84+
'php open tag prefix' => array(
85+
'file' => '/formatting/file-header-php-open-tag-prefix.php',
86+
'headers' => array(
87+
'TemplateName' => 'Template Name',
88+
),
89+
'context' => '',
90+
'expected' => array(
91+
'TemplateName' => 'Something',
92+
),
93+
),
94+
);
95+
}
96+
}

0 commit comments

Comments
 (0)