-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Navigation link: prime caches for all posts in menu items (#40752)
* Prime posts in navigation menus. * Improve logic again. * Change variable name and function names. * Feedback and tweaks. * Add a unit test. * Fix lints. * Apply suggestions from code review Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com> * Move functions * Improve comment. * Add another unit test. Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com>
- Loading branch information
1 parent
033a06f
commit 722d640
Showing
2 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
/** | ||
* Navigation block rendering tests. | ||
* | ||
* @package WordPress | ||
* @subpackage Blocks | ||
*/ | ||
|
||
/** | ||
* Tests for the Navigation block. | ||
* | ||
* @group blocks | ||
*/ | ||
class Render_Block_Navigation_Test extends WP_UnitTestCase { | ||
/** | ||
* @covers ::gutenberg_block_core_navigation_from_block_get_post_ids | ||
*/ | ||
public function test_block_core_navigation_get_post_ids_from_block() { | ||
$parsed_blocks = parse_blocks( | ||
'<!-- wp:navigation-link {"label":"Sample Page","type":"page","kind":"post-type","id":755,"url":"http://localhost:8888/?page_id=755"} /-->' | ||
); | ||
$parsed_block = $parsed_blocks[0]; | ||
$context = array(); | ||
$block = new WP_Block( $parsed_block, $context, $this->registry ); | ||
|
||
$post_ids = gutenberg_block_core_navigation_from_block_get_post_ids( $block ); | ||
$this->assertSameSets( array( 755 ), $post_ids ); | ||
} | ||
|
||
/** | ||
* @covers ::gutenberg_block_core_navigation_from_block_get_post_ids | ||
*/ | ||
public function test_block_core_navigation_get_post_ids_from_block_nested() { | ||
$parsed_blocks = parse_blocks( | ||
'<!-- wp:group --> | ||
<!-- wp:navigation-link {"label":"Sample Page","type":"page","id":20,"url":"http://localhost:8888/?page_id=20","kind":"post-type","isTopLevelLink":true} /--> | ||
<!-- wp:navigation-link {"label":"Hello world!","type":"post","id":10,"url":"http://localhost:8888/?p=10","kind":"post-type","isTopLevelLink":true} /--> | ||
<!-- wp:navigation-submenu {"label":"Uncategorized","type":"category","id":1,"url":"http://localhost:8888/?cat=1","kind":"taxonomy","isTopLevelItem":true} --> | ||
<!-- wp:navigation-link {"label":"Sample Page","type":"page","id":30,"url":"http://localhost:8888/?page_id=30","kind":"post-type","isTopLevelLink":false} /--> | ||
<!-- wp:navigation-submenu {"label":"Hello world!","type":"post","id":40,"url":"http://localhost:8888/?p=40","kind":"post-type","isTopLevelItem":false} --> | ||
<!-- wp:navigation-link {"label":"Uncategorized","type":"category","id":5,"url":"http://localhost:8888/?cat=5","kind":"taxonomy","isTopLevelLink":false} /--> | ||
<!-- wp:navigation-link {"label":"Hello world!","type":"post","id":60,"url":"http://localhost:8888/?p=60","kind":"post-type","isTopLevelLink":false} /--> | ||
<!-- /wp:navigation-submenu --> | ||
<!-- /wp:navigation-submenu --> | ||
<!-- /wp:group -->' | ||
); | ||
$parsed_block = $parsed_blocks[0]; | ||
$context = array(); | ||
$block = new WP_Block( $parsed_block, $context, $this->registry ); | ||
|
||
$post_ids = gutenberg_block_core_navigation_from_block_get_post_ids( $block ); | ||
$this->assertSameSets( array( 40, 60, 10, 20, 30 ), $post_ids ); | ||
} | ||
|
||
/** | ||
* @covers ::gutenberg_block_core_navigation_from_block_get_post_ids | ||
*/ | ||
public function test_block_core_navigation_get_post_ids_from_block_with_submenu() { | ||
$parsed_blocks = parse_blocks( '<!-- wp:navigation-submenu {"label":"Test","type":"post","id":789,"url":"http://localhost/blog/test-3","kind":"post-type","isTopLevelItem":true} -->\n<!-- wp:navigation-link {"label":"(no title)","type":"post","id":755,"url":"http://localhost/blog/755","kind":"post-type","isTopLevelLink":false} /-->\n<!-- /wp:navigation-submenu -->' ); | ||
$parsed_block = $parsed_blocks[0]; | ||
$context = array(); | ||
$block = new WP_Block( $parsed_block, $context, $this->registry ); | ||
|
||
$post_ids = gutenberg_block_core_navigation_from_block_get_post_ids( $block ); | ||
$this->assertSameSetsWithIndex( array( 755, 789 ), $post_ids ); | ||
} | ||
|
||
|
||
} |