Add BlockInterface::remove()
This commit is contained in:
parent
0b83163d9c
commit
514f96cbfe
|
@ -70,6 +70,11 @@ interface BlockInterface {
|
|||
*/
|
||||
public function &get_root_template(): BlockTemplateInterface;
|
||||
|
||||
/**
|
||||
* Remove the block from its parent.
|
||||
*/
|
||||
public function remove();
|
||||
|
||||
/**
|
||||
* Check if the block is detached from its parent or root template.
|
||||
*
|
||||
|
|
|
@ -173,6 +173,13 @@ class AbstractBlock implements BlockInterface {
|
|||
return $this->parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the block from its parent.
|
||||
*/
|
||||
public function remove() {
|
||||
$this->parent->remove_block( $this->id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the block is detached from its parent block container or the template it belongs to.
|
||||
*
|
||||
|
|
|
@ -232,6 +232,27 @@ class BlockTest extends WC_Unit_Test_Case {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that removing a block by calling remove on it detaches it.
|
||||
*/
|
||||
public function test_remove_block_self() {
|
||||
$template = new BlockTemplate();
|
||||
|
||||
$block = $template->add_block(
|
||||
[
|
||||
'id' => 'test-block-id',
|
||||
'blockName' => 'test-block-name',
|
||||
]
|
||||
);
|
||||
|
||||
$block->remove();
|
||||
|
||||
$this->assertTrue(
|
||||
$block->is_detached(),
|
||||
'Failed asserting that the block is detached from its parent and root template.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that adding nested blocks sets the parent and root template correctly.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue