Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
1e5412a
Navigation: Always create a fallback navigation menu on every page load
scruffian Mar 1, 2023
78ae0b1
Add basic unit tests
getdave Mar 1, 2023
83d1ac3
Fix Classic Meny fallback to use Menu title not slug
getdave Mar 1, 2023
d68c93a
Add tests for Classic Menu
getdave Mar 1, 2023
a139d85
Refactor assertions to expected actual format
getdave Mar 1, 2023
5e254c1
Cleanup test file
getdave Mar 1, 2023
238d956
Add checks for total Navigation Posts created
getdave Mar 1, 2023
ef16a4c
Add test to cover prefering existing Nav Menu over Classic Menu
getdave Mar 1, 2023
4c8f78d
Rename and improve function comment
getdave Mar 1, 2023
fc8991d
Add tests for retrieving fallback blocks
getdave Mar 1, 2023
ff12582
Ensure different post_content for different menus
getdave Mar 1, 2023
c20ec7b
Test filtering empty blocks
getdave Mar 1, 2023
1138e30
Fix parse error in unit tests
getdave Mar 1, 2023
1a82aaf
Fix PHP CS warnings
getdave Mar 1, 2023
a31eec4
Fix more PHPCS warnings
getdave Mar 1, 2023
ec6d2ad
fix linting issues'
scruffian Mar 2, 2023
5665b74
change the hooks we create the fallback on
scruffian Mar 2, 2023
e13b4f3
Move hooks to run on one time operations and ensure only run for bloc…
getdave Mar 3, 2023
da7f46d
Fix tests
getdave Mar 3, 2023
a5a3651
Add tests for theme switch hook auto-creation
getdave Mar 3, 2023
84bd746
Check that there are no menus before Theme switch test
getdave Mar 3, 2023
f6dab81
Add test for wp_install
getdave Mar 6, 2023
641a0ed
Update comment to indicate page list is not an ideal scenario
getdave Mar 6, 2023
02c1353
Add test to validate menus not created when switching to a block Theme
getdave Mar 6, 2023
11ab9db
Revert whitespace changes
getdave Mar 6, 2023
3a64b4d
Apply PHPUnit annotations from review
getdave Mar 6, 2023
d59cde3
Remove unnecessary return and annotation function
getdave Mar 6, 2023
a9c7248
Try adding messages to all assertions
getdave Mar 6, 2023
e0d8d7c
Add @covers annotation
getdave Mar 6, 2023
dff1682
Apply correct annotations to test class
getdave Mar 6, 2023
8604f51
Rename test file and add group annotation
getdave Mar 6, 2023
249fd74
Fix PHPCS unused variable
getdave Mar 6, 2023
2b2795e
Normalise assertion
getdave Mar 6, 2023
61f9a8e
Fix tests
getdave Mar 6, 2023
0c8bbe2
Refactor to avoid requiring a return value from the hooked creation f…
getdave Mar 6, 2023
3f164c7
Refactor creation functions to SRP.
getdave Mar 6, 2023
7722010
Improve doc blocks
getdave Mar 6, 2023
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
Prev Previous commit
Next Next commit
Add basic unit tests
  • Loading branch information
getdave committed Mar 6, 2023
commit 78ae0b1f9ac6a704d39898239255896aa9d847b0
2 changes: 2 additions & 0 deletions packages/block-library/src/navigation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,8 @@ function block_core_navigation_create_fallback() {
if ( ! $navigation_post ) {
$navigation_post = block_core_navigation_get_default_pages_fallback();
}

return $navigation_post;
}


Expand Down
42 changes: 42 additions & 0 deletions phpunit/navigation-block-fallback-test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* Tests Fallback Behavior for Navigation block
*
* @package WordPress
*/

class Tests_Block_Navigation_Fallbacks extends WP_UnitTestCase {
public function set_up() {
parent::set_up();
switch_theme( 'emptytheme' );
}

public static function wpSetUpBeforeClass() {

}

public static function wpTearDownAfterClass() {

}

public function test_creates_fallback_with_page_list_by_default() {
$fallback = gutenberg_block_core_navigation_create_fallback();

$this->assertEquals( $fallback->post_type, 'wp_navigation' );
$this->assertEquals( $fallback->post_title, 'Navigation' );
$this->assertEquals( $fallback->post_content, '<!-- wp:page-list /-->' );
$this->assertEquals( $fallback->post_status, 'publish' );
}

public function test_skip_if_filter_returns_truthy() {
add_filter( 'block_core_navigation_skip_fallback', '__return_true' );

$actual = gutenberg_block_core_navigation_create_fallback();

$this->assertEquals( $actual, null );

remove_filter( 'block_core_navigation_skip_fallback', '__return_true' );
}
}