-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
class-override-script-test.php
89 lines (76 loc) · 2.06 KB
/
class-override-script-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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/**
* Test `gutenberg_override_script`.
*
* @package Gutenberg
*/
class Override_Script_Test extends WP_UnitTestCase {
public function set_up() {
parent::set_up();
wp_register_script(
'gutenberg-dummy-script',
'https://example.com/original',
array( 'original-dependency' ),
'original-version',
false
);
}
public function tear_down() {
parent::tear_down();
wp_deregister_script( 'gutenberg-dummy-script' );
}
/**
* Tests that script is localized.
*/
public function test_localizes_script() {
global $wp_scripts;
gutenberg_override_script(
$wp_scripts,
'gutenberg-dummy-script',
'https://example.com/',
array( 'dependency' ),
'version',
false
);
$script = $wp_scripts->query( 'gutenberg-dummy-script', 'registered' );
$this->assertEquals( array( 'dependency' ), $script->deps );
}
/**
* Tests that script properties are overridden.
*/
public function test_replaces_registered_properties() {
global $wp_scripts;
gutenberg_override_script(
$wp_scripts,
'gutenberg-dummy-script',
'https://example.com/updated',
array( 'updated-dependency' ),
'updated-version',
true
);
$script = $wp_scripts->query( 'gutenberg-dummy-script', 'registered' );
$this->assertEquals( 'https://example.com/updated', $script->src );
$this->assertEquals( array( 'updated-dependency' ), $script->deps );
$this->assertEquals( 'updated-version', $script->ver );
$this->assertSame( 1, $script->args );
}
/**
* Tests that new script registers normally if no handle by the name.
*/
public function test_registers_new_script() {
global $wp_scripts;
gutenberg_override_script(
$wp_scripts,
'gutenberg-second-dummy-script',
'https://example.com/',
array( 'dependency' ),
'version',
true
);
$script = $wp_scripts->query( 'gutenberg-second-dummy-script', 'registered' );
$this->assertEquals( 'https://example.com/', $script->src );
$this->assertEquals( array( 'dependency' ), $script->deps );
$this->assertEquals( 'version', $script->ver );
$this->assertSame( 1, $script->args );
}
}