Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,8 @@ private function block_attribute_updates_to_modifiable_text_updates() {
' ' .
$this->block_name .
' ' .
$encoded_attributes
$encoded_attributes .
( $this->is_self_closing_block() ? '/' : '' )
);

return true;
Expand Down
18 changes: 18 additions & 0 deletions components/DataLiberation/Tests/BlockMarkupProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,24 @@ public function test_set_block_attribute_value_updates_a_list_value() {
);
}

public function test_set_block_attribute_value_updates_a_list_value_with_a_self_closing_block() {
$p = new BlockMarkupProcessor(
'<!-- wp:image {"sources": ["small.png", "large.png"] } /-->'
);
$this->assertTrue( $p->next_token(), 'Failed to find the block opener' );
$this->assertTrue( $p->next_block_attribute(), 'Failed to find the first block attribute' );
Copy link
Collaborator Author

@adamziel adamziel Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only really have a single block attribute, I'll rename this method to something more sensible such as next_array_entry_in_current_block_attribute() or so in a follow-up PR.

$this->assertTrue( $p->next_block_attribute(), 'Failed to find the second block attribute' );
$this->assertTrue( $p->next_block_attribute(), 'Failed to find the third block attribute' );

$p->set_block_attribute_value( 'medium.png' );
$this->assertEquals( 'medium.png', $p->get_block_attribute_value(), 'Failed to find the block attribute value' );
$this->assertEquals(
'<!-- wp:image {"sources":["small.png","medium.png"]} /-->',
$p->get_updated_html(),
'Failed to update the block attribute value'
);
}

public function test_set_block_attribute_can_be_called_multiple_times() {
$p = new BlockMarkupProcessor(
'<!-- wp:image {"sources": { "lowres": "small.png", "hires": "large.png" } } -->'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ public static function provider_test_set_url_examples() {
'https://w.org',
'<!-- wp:image {"src":"https:\/\/w.org"} -->',
),
'In the "url" block attribute of a navigation-link block' => array(
'<!-- wp:navigation-link {"url": "https://w.org"} /-->',
'https://w.org',
'<!-- wp:navigation-link {"url":"https:\/\/w.org"} /-->',
),
'In a text node' => array(
'Have you seen https://wordpress.org yet?',
'https://w.org',
Expand Down