-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Block editor: iframe: add
enqueue_block_assets
(#49655)
- Loading branch information
Showing
5 changed files
with
145 additions
and
1 deletion.
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
21 changes: 21 additions & 0 deletions
21
packages/e2e-tests/plugins/iframed-enqueue-block-assets.php
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,21 @@ | ||
<?php | ||
/** | ||
* Plugin Name: Gutenberg Test Iframed enqueue_block_assets | ||
* Plugin URI: https://github.com/WordPress/gutenberg | ||
* Author: Gutenberg Team | ||
* | ||
* @package gutenberg-test-iframed-iframed-enqueue-block-assets | ||
*/ | ||
|
||
add_action( | ||
'enqueue_block_assets', | ||
function() { | ||
wp_enqueue_style( | ||
'iframed-enqueue-block-assets', | ||
plugin_dir_url( __FILE__ ) . 'iframed-enqueue-block-assets/style.css', | ||
array(), | ||
filemtime( plugin_dir_path( __FILE__ ) . 'iframed-enqueue-block-assets/style.css' ) | ||
); | ||
wp_add_inline_style( 'iframed-enqueue-block-assets', 'body{padding:20px!important}' ); | ||
} | ||
); |
9 changes: 9 additions & 0 deletions
9
packages/e2e-tests/plugins/iframed-enqueue-block-assets/style.css
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,9 @@ | ||
/** | ||
* The following styles get applied both on the front of your site and in the | ||
* editor. | ||
*/ | ||
body { | ||
background-color: rgb(33, 117, 155) !important; | ||
color: #fff !important; | ||
padding: 2px !important; | ||
} |
44 changes: 44 additions & 0 deletions
44
packages/e2e-tests/specs/editor/plugins/iframed-equeue-block-assets.test.js
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,44 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
activatePlugin, | ||
createNewPost, | ||
deactivatePlugin, | ||
canvas, | ||
activateTheme, | ||
} from '@wordpress/e2e-test-utils'; | ||
|
||
async function getComputedStyle( context, selector, property ) { | ||
return await context.evaluate( | ||
( sel, prop ) => | ||
window.getComputedStyle( document.querySelector( sel ) )[ prop ], | ||
selector, | ||
property | ||
); | ||
} | ||
|
||
describe( 'iframed inline styles', () => { | ||
beforeEach( async () => { | ||
// Activate the empty theme (block based theme), which is iframed. | ||
await activateTheme( 'emptytheme' ); | ||
await activatePlugin( 'gutenberg-test-iframed-enqueue_block_assets' ); | ||
await createNewPost(); | ||
} ); | ||
|
||
afterEach( async () => { | ||
await deactivatePlugin( 'gutenberg-test-iframed-enqueue_block_assets' ); | ||
await activateTheme( 'twentytwentyone' ); | ||
} ); | ||
|
||
it( 'should load styles added through enqueue_block_assets', async () => { | ||
// Check stylesheet. | ||
expect( | ||
await getComputedStyle( canvas(), 'body', 'background-color' ) | ||
).toBe( 'rgb(33, 117, 155)' ); | ||
// Check inline style. | ||
expect( await getComputedStyle( canvas(), 'body', 'padding' ) ).toBe( | ||
'20px' | ||
); | ||
} ); | ||
} ); |