Skip to content

Commit

Permalink
Add a test for an empty directive
Browse files Browse the repository at this point in the history
  • Loading branch information
luisherranz committed Oct 19, 2023
1 parent ff6542b commit 114f097
Showing 1 changed file with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function test_directive_keeps_working_after_malformed_context_objects() {
);
}

public function test_directive_keeps_working_with_an_empty_directive() {
public function test_directive_keeps_working_with_a_directive_without_value() {
$context = new WP_Directive_Context();

$markup = '
Expand Down Expand Up @@ -175,4 +175,55 @@ public function test_directive_keeps_working_with_an_empty_directive() {
$context->get_context()
);
}

public function test_directive_keeps_working_with_an_empty_directive() {
$context = new WP_Directive_Context();

$markup = '
<div data-wp-context=\'{ "my-key": "some-value" }\'>
<div data-wp-context="">
</div>
</div>
';
$tags = new WP_HTML_Tag_Processor( $markup );

// Parent div.
$tags->next_tag( array( 'tag_closers' => 'visit' ) );
gutenberg_interactivity_process_wp_context( $tags, $context );

$this->assertSame(
array( 'my-key' => 'some-value' ),
$context->get_context()
);

// Children div.
$tags->next_tag( array( 'tag_closers' => 'visit' ) );
gutenberg_interactivity_process_wp_context( $tags, $context );

// Still the same context.
$this->assertSame(
array( 'my-key' => 'some-value' ),
$context->get_context()
);

// Closing children div.
$tags->next_tag( array( 'tag_closers' => 'visit' ) );
gutenberg_interactivity_process_wp_context( $tags, $context );

// Still the same context.
$this->assertSame(
array( 'my-key' => 'some-value' ),
$context->get_context()
);

// Closing parent div.
$tags->next_tag( array( 'tag_closers' => 'visit' ) );
gutenberg_interactivity_process_wp_context( $tags, $context );

// Now the context is empty.
$this->assertSame(
array(),
$context->get_context()
);
}
}

0 comments on commit 114f097

Please sign in to comment.