Skip to content

Commit

Permalink
Add a test case for missing link property
Browse files Browse the repository at this point in the history
Co-authored-by: Marin Atanasov <[email protected]>
  • Loading branch information
Mamaduka and tyxla committed Sep 12, 2023
1 parent a3350d8 commit c79c8c3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/block-library/src/table-of-contents/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function block_core_table_of_contents_build_list( $tree, $args ) {
$pagelink = ! empty( $heading['page'] ) ? add_query_arg( 'page', $heading['page'], $permalink ) : $permalink;
$content = '<a class="wp-block-table-of-contents__entry" href="' . esc_url( $pagelink . $heading['link'] ) . '">' . esc_html( $heading['content'] ) . '</a>';
} else {
$content = '<span class=wp-block-table-of-contents__entry>' . esc_html( $heading['content'] ) . '</span>';
$content = '<span class="wp-block-table-of-contents__entry">' . esc_html( $heading['content'] ) . '</span>';
}

$list .= '<li>' . $content . $children . '</li>';
Expand Down
7 changes: 6 additions & 1 deletion phpunit/blocks/render-block-table-of-contents-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static function wpSetUpBeforeClass() {
add_post_meta(
self::$page->ID,
'core_table_of_contents',
'[{"content":"Heading text","level":2,"link":"#heading-text"},{"content":"A sub-heading","level":3,"link":"#a-sub-heading"}]',
'[{"content":"Heading text","level":2,"link":"#heading-text","page":null},{"content":"A sub-heading","level":3,"link":"#a-sub-heading","page":null},{"content":"Missing anchor","level":2,"link":null,"page":null}]',
true
);
}
Expand Down Expand Up @@ -111,5 +111,10 @@ public function test_render_table_of_contents_from_meta() {
$new_content,
'Failed to render a sub-heading element from meta'
);
$this->assertStringContainsString(
'<span class="wp-block-table-of-contents__entry">Missing anchor</span>',
$new_content,
'Failed to render a heading element with a missing anchor'
);
}
}

0 comments on commit c79c8c3

Please sign in to comment.