Files
wordpress-develop/tests/phpunit/tests/block-supports/spacing.php
T
Robert Anderson f034bc832e Add Site Editor and PHP changes from Gutenberg 10.1 - 11.9
- First pass at adding the site editor from the Gutenberg plugin to
  wp-admin/site-editor.php.
- Adds miscellaneous PHP changes from Gutenberg 10.1 - 11.9.

Follows [52042].
See #54337.
Props youknowriad, aristath, hellofromtonya, gziolo.


git-svn-id: https://develop.svn.wordpress.org/trunk@52069 602fd350-edb4-49c9-b593-d223f7449a82
2021-11-09 02:15:23 +00:00

139 lines
4.0 KiB
PHP

<?php
/**
* @group block-supports
*/
class WP_Block_Supports_Spacing_Test extends WP_UnitTestCase {
private $sample_block_content = '<div class="wp-block-test-block">Test</div>';
private $test_gap_block_value = array();
private $test_gap_block_args = array();
function set_up() {
parent::set_up();
$this->test_gap_block_value = array(
'blockName' => 'test/test-block',
'attrs' => array(
'style' => array(
'spacing' => array(
'blockGap' => '3em',
),
),
),
);
$this->test_gap_block_args = array(
'api_version' => 2,
'supports' => array(
'spacing' => array(
'blockGap' => true,
),
),
);
}
function tear_down() {
unregister_block_type( 'test/test-block' );
parent::tear_down();
}
function test_spacing_gap_block_support_renders_block_inline_style() {
register_block_type( 'test/test-block', $this->test_gap_block_args );
$render_output = wp_render_spacing_gap_support(
$this->sample_block_content,
$this->test_gap_block_value
);
$this->assertSame(
'<div style="--wp--style--block-gap: 3em" class="wp-block-test-block">Test</div>',
$render_output
);
}
function test_spacing_gap_block_support_renders_block_inline_style_with_inner_tag() {
register_block_type( 'test/test-block', $this->test_gap_block_args );
$render_output = wp_render_spacing_gap_support(
'<div class="wp-test-block"><p style="color: red;">Test</p></div>',
$this->test_gap_block_value
);
$this->assertSame(
'<div style="--wp--style--block-gap: 3em" class="wp-test-block"><p style="color: red;">Test</p></div>',
$render_output
);
}
function test_spacing_gap_block_support_renders_block_inline_style_with_no_other_attributes() {
register_block_type( 'test/test-block', $this->test_gap_block_args );
$render_output = wp_render_spacing_gap_support(
'<div><p>Test</p></div>',
$this->test_gap_block_value
);
$this->assertSame(
'<div style="--wp--style--block-gap: 3em"><p>Test</p></div>',
$render_output
);
}
function test_spacing_gap_block_support_renders_appended_block_inline_style() {
register_block_type( 'test/test-block', $this->test_gap_block_args );
$render_output = wp_render_spacing_gap_support(
'<div class="wp-test-block" style="background: green;"><p style="color: red;">Test</p></div>',
$this->test_gap_block_value
);
$this->assertSame(
'<div class="wp-test-block" style="--wp--style--block-gap: 3em; background: green;"><p style="color: red;">Test</p></div>',
$render_output
);
}
function test_spacing_gap_block_support_does_not_render_style_when_support_is_false() {
$this->test_gap_block_args['supports']['spacing']['blockGap'] = false;
register_block_type( 'test/test-block', $this->test_gap_block_args );
$render_output = wp_render_spacing_gap_support(
$this->sample_block_content,
$this->test_gap_block_value
);
$this->assertEquals(
$this->sample_block_content,
$render_output
);
}
function test_spacing_gap_block_support_does_not_render_style_when_gap_is_null() {
$this->test_gap_block_value['attrs']['style']['spacing']['blockGap'] = null;
$this->test_gap_block_args['supports']['spacing']['blockGap'] = true;
register_block_type( 'test/test-block', $this->test_gap_block_args );
$render_output = wp_render_spacing_gap_support(
$this->sample_block_content,
$this->test_gap_block_value
);
$this->assertEquals(
$this->sample_block_content,
$render_output
);
}
function test_spacing_gap_block_support_does_not_render_style_when_gap_is_illegal_value() {
$this->test_gap_block_value['attrs']['style']['spacing']['blockGap'] = '" javascript="alert("hello");';
$this->test_gap_block_args['supports']['spacing']['blockGap'] = true;
register_block_type( 'test/test-block', $this->test_gap_block_args );
$render_output = wp_render_spacing_gap_support(
$this->sample_block_content,
$this->test_gap_block_value
);
$this->assertEquals(
$this->sample_block_content,
$render_output
);
}
}