Skip to content

Commit

Permalink
Refactor to use Tag Processor
Browse files Browse the repository at this point in the history
  • Loading branch information
cbravobernal committed Nov 6, 2023
1 parent efb9df5 commit ab2d4f5
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions phpunit/blocks/render-query-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@ public function test_enhanced_query_markup_rendering_at_bottom_on_custom_html_el
<!-- wp:post-template {"align":"wide"} -->
<!-- wp:test/plugin-block /-->
<!-- /wp:post-template -->
<span>Helper to get last HTML Tag</span>
</aside>
<!-- /wp:query -->
HTML;

// Set main query to single post.
Expand All @@ -160,13 +162,16 @@ public function test_enhanced_query_markup_rendering_at_bottom_on_custom_html_el

$output = do_blocks( $content );

$aside_closing_tag = '</aside>';
$pos = strrpos( $output, $aside_closing_tag );
$last_closing_tag_pos = strrpos( $output, '>', -( strlen( $output ) - $pos ) );
$last_opening_tag_pos = strrpos( $output, '<', -( strlen( $output ) - $last_closing_tag_pos ) );
$previous_tag = substr( $output, $last_opening_tag_pos, $last_closing_tag_pos - $last_opening_tag_pos + 1 );
$p = new WP_HTML_Tag_Processor( $output );

$p->next_tag( 'span' );

$this->assertSame( '</div>', $previous_tag );
// Test that there is a div added just after the last tag inside the aside.
$this->assertSame( $p->next_tag(), true );
// Test that that div is the accesibility one.
$this->assertSame( 'screen-reader-text', $p->get_attribute( 'class' ) );
$this->assertSame( 'context.core.query.message', $p->get_attribute( 'data-wp-text' ) );
$this->assertSame( 'polite', $p->get_attribute( 'aria-live' ) );
}

/**
Expand Down

0 comments on commit ab2d4f5

Please sign in to comment.