-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
class-vendor-script-filename-test.php
65 lines (63 loc) · 1.67 KB
/
class-vendor-script-filename-test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
* Test gutenberg_vendor_script_filename()
*
* @package Gutenberg
*/
class Vendor_Script_Filename_Test extends WP_UnitTestCase {
function vendor_script_filename_cases() {
return array(
// Development mode scripts.
array(
'react-handle',
'https://unpkg.com/[email protected]/umd/react.development.js',
'react-handle.HASH.js',
),
array(
'react-dom-handle',
'https://unpkg.com/[email protected]/umd/react-dom.development.js',
'react-dom-handle.HASH.js',
),
// Production mode scripts.
array(
'react-handle',
'https://unpkg.com/[email protected]/umd/react.production.min.js',
'react-handle.min.HASH.js',
),
array(
'react-dom-handle',
'https://unpkg.com/[email protected]/umd/react-dom.production.min.js',
'react-dom-handle.min.HASH.js',
),
// Other cases.
array(
'something-handle',
'https://localhost/something.js?querystring',
'something-handle.HASH.js',
),
array(
'something-handle',
'https://localhost/something.min.js?querystring',
'something-handle.min.HASH.js',
),
array(
'idkwhatthisis-handle',
'https://localhost/idkwhatthisis',
'idkwhatthisis-handle.HASH.js',
),
);
}
/**
* @dataProvider vendor_script_filename_cases
*/
function test_gutenberg_vendor_script_filename( $handle, $url, $expected_filename_pattern ) {
$hash = substr( md5( $url ), 0, 8 );
$actual_filename = gutenberg_vendor_script_filename( $handle, $url );
$actual_filename_pattern = str_replace( $hash, 'HASH', $actual_filename );
$this->assertEquals(
$expected_filename_pattern,
$actual_filename_pattern,
'Cacheable filename for ' . $url
);
}
}