Fix up CustomBlockTest (it was creating detached blocks by mistake)

This commit is contained in:
Matt Sherman 2023-09-11 20:41:59 -04:00
parent 1179a5339a
commit 2be3dbe47c
2 changed files with 8 additions and 24 deletions

View File

@ -42,7 +42,7 @@ class CustomBlockTemplate extends AbstractBlockTemplate {
*
* @param array $block_config The block data.
*/
public function add_custom_block( array $block_config ): BlockInterface {
public function add_custom_block( array $block_config ): CustomBlockInterface {
$block = new CustomBlock( $block_config, $this->get_root_template(), $this );
return $this->add_inner_block( $block );
}

View File

@ -7,7 +7,7 @@ use Automattic\WooCommerce\Admin\BlockTemplates\BlockTemplateInterface;
use Automattic\WooCommerce\Internal\Admin\BlockTemplates\Block;
use Automattic\WooCommerce\Internal\Admin\BlockTemplates\BlockTemplate;
use Customers;
use WC_Unit_Test_Case;
/**
@ -18,13 +18,8 @@ class CustomBlockTest extends WC_Unit_Test_Case {
* Test that the add_block method does not exist by default on blocks.
*/
public function test_add_block_does_not_exist() {
$template = new BlockTemplate();
$block = new CustomBlock(
[
'blockName' => 'test-block-name',
],
$template
);
$template = new CustomBlockTemplate();
$block = $template->add_custom_block( [ 'blockName' => 'test-block-name' ] );
$this->assertFalse( method_exists( $block, 'add_block' ) );
}
@ -33,13 +28,8 @@ class CustomBlockTest extends WC_Unit_Test_Case {
* Test that a custom block inserter method inserts as expected.
*/
public function test_add_custom_inner_block() {
$template = new BlockTemplate();
$block = new CustomBlock(
[
'blockName' => 'test-block-name',
],
$template
);
$template = new CustomBlockTemplate();
$block = $template->add_custom_block( [ 'blockName' => 'test-block-name' ] );
$block->add_custom_inner_block( 'a' );
$block->add_custom_inner_block( 'b' );
@ -72,14 +62,8 @@ class CustomBlockTest extends WC_Unit_Test_Case {
* Test that a custom block is removed as expected.
*/
public function test_remove_custom_inner_block() {
$template = new BlockTemplate();
$block = new CustomBlock(
[
'blockName' => 'test-block-name',
],
$template
);
$template = new CustomBlockTemplate();
$block = $template->add_custom_block( [ 'blockName' => 'test-block-name' ] );
$block->add_custom_inner_block( 'a' );
$block->add_custom_inner_block( 'b' );