-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
class-polyfill-test.php
54 lines (42 loc) · 1.31 KB
/
class-polyfill-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
<?php
/**
* Test gutenberg_get_script_polyfill()
*
* @package Gutenberg
*/
class Polyfill_Test extends WP_UnitTestCase {
var $old_wp_scripts;
function setUp() {
parent::setUp();
$this->old_wp_scripts = isset( $GLOBALS['wp_scripts'] ) ? $GLOBALS['wp_scripts'] : null;
remove_action( 'wp_default_scripts', 'wp_default_scripts' );
$GLOBALS['wp_scripts'] = new WP_Scripts();
$GLOBALS['wp_scripts']->default_version = get_bloginfo( 'version' );
gutenberg_register_scripts_and_styles();
}
public function tearDown() {
$GLOBALS['wp_scripts'] = $this->old_wp_scripts;
add_action( 'wp_default_scripts', 'wp_default_scripts' );
parent::tearDown();
}
function test_gutenberg_get_script_polyfill_ignores_missing_handle() {
$polyfill = gutenberg_get_script_polyfill(
array(
'\'Promise\' in window' => 'promise',
)
);
$this->assertEquals( '', $polyfill );
}
function test_gutenberg_get_script_polyfill_returns_inline_script() {
wp_register_script( 'promise', 'https://unpkg.com/promise-polyfill/promise.js' );
$polyfill = gutenberg_get_script_polyfill(
array(
'\'Promise\' in window' => 'promise',
)
);
$this->assertEquals(
'( \'Promise\' in window ) || document.write( \'<script src="https://unpkg.com/promise-polyfill/promise.js"></scr\' + \'ipt>\' );',
$polyfill
);
}
}