-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Plugin: Preserve inline scripts in Gutenberg override
- Loading branch information
Showing
2 changed files
with
114 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
/** | ||
* Test `gutenberg_override_script`. | ||
* | ||
* @package Gutenberg | ||
*/ | ||
|
||
class Override_Script_Test extends WP_UnitTestCase { | ||
function setUp() { | ||
parent::setUp(); | ||
|
||
wp_register_script( | ||
'gutenberg-dummy-script', | ||
'https://example.com/original', | ||
array( 'original-dependency' ), | ||
'original-version', | ||
false | ||
); | ||
} | ||
|
||
function tearDown() { | ||
parent::tearDown(); | ||
|
||
wp_deregister_script( 'gutenberg-dummy-script' ); | ||
} | ||
|
||
/** | ||
* Tests that script properties are overridden. | ||
*/ | ||
function test_replaces_registered_properties() { | ||
gutenberg_override_script( | ||
'gutenberg-dummy-script', | ||
'https://example.com/updated', | ||
array( 'updated-dependency' ), | ||
'updated-version', | ||
true | ||
); | ||
|
||
global $wp_scripts; | ||
$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->assertEquals( 1, $script->extra['group'] ); | ||
} | ||
|
||
/** | ||
* Tests that new script registers normally if no handle by the name. | ||
*/ | ||
function test_registers_new_script() { | ||
gutenberg_override_script( | ||
'gutenberg-second-dummy-script', | ||
'https://example.com/', | ||
array( 'dependency' ), | ||
'version', | ||
true | ||
); | ||
|
||
global $wp_scripts; | ||
$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->assertEquals( 1, $script->extra['group'] ); | ||
} | ||
} |