Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate Navigation fallbacks logic between Editor and Front of Site via REST API #48698

Merged
merged 110 commits into from
Apr 21, 2023
Merged
Changes from 1 commit
Commits
Show all changes
110 commits
Select commit Hold shift + click to select a range
f8a66b8
Add Navigation REST class with fallback endpoint
getdave Mar 2, 2023
c7aa87f
Scaffold out tests
getdave Mar 22, 2023
1115c7b
Add fallback creation method and tests
getdave Mar 22, 2023
84a1af9
Add tests for returning existing Navigation posts
getdave Mar 22, 2023
c7d168f
Use Gutenberg versions of block functions
getdave Mar 22, 2023
5ea9a22
Add classic meny and concurrent request assertions
getdave Mar 22, 2023
24cfd94
Test does not create from classic if Navigation menu exists
getdave Mar 22, 2023
13d33df
Test for page list being unavailable
getdave Mar 22, 2023
13bb243
Extract common Nav fallback code into dedicated class
getdave Mar 22, 2023
b3d51a6
Remove changes to load
getdave Mar 22, 2023
0ecd828
Move get recent navigation into common class
getdave Mar 22, 2023
80ff0d9
Migrate functions to class and deprecate originals
getdave Mar 22, 2023
c1dd6f5
Refactor method to get fallback to exit early style
getdave Mar 22, 2023
e9f021d
Use new class in render_callback
getdave Mar 23, 2023
e85b9c8
Add example of dedicated class tests over REST endpoint tests
getdave Mar 23, 2023
9befce9
Add example of refactoring editor code to use new API endpoint
getdave Mar 23, 2023
38f3712
Update docblock
getdave Mar 23, 2023
0576ade
Add permissions check and test
getdave Mar 23, 2023
47ea683
Improve comments
getdave Mar 23, 2023
b0f19ce
Adjust test user
getdave Mar 23, 2023
0686177
Revert removal of deprecated function bodies
getdave Mar 23, 2023
7c39ed8
Reinstate deprecations
getdave Mar 23, 2023
1a8cc32
Update editor notice
getdave Mar 23, 2023
aaada54
Update endpoint to singular form (fallback)
getdave Mar 23, 2023
4649e99
Rename class to be specifically related to fallbacks and non generic
getdave Mar 23, 2023
8668dec
Also update file names
getdave Mar 23, 2023
d10cdd0
Avoid returning unecessary WP_Error
getdave Mar 23, 2023
6132be9
Avoid get_post and use performance internal method
getdave Mar 23, 2023
4c152e4
Normalize functions to standardise signatures
getdave Mar 23, 2023
457d390
Extract Menu parsing logic into separate class
getdave Mar 24, 2023
4734199
Refactor classic menu fallback logic
getdave Mar 24, 2023
1b750d5
Add test for Classic Menu in Primary Location
getdave Mar 24, 2023
e1cbab0
Add test for classic menu fallback to “primary” slug
getdave Mar 24, 2023
ad48992
Add further tests for classic menu fallback mechanic
getdave Mar 24, 2023
fd79656
Tidy
getdave Mar 24, 2023
f433cf2
Controller docblocks
getdave Mar 24, 2023
d5b54c4
Docblocks for WP_Navigation_Fallbacks_Gutenberg
getdave Mar 24, 2023
8aa039f
Simplfy fallbacks sequence
getdave Mar 24, 2023
4cf43ab
Tweak error slug
getdave Mar 24, 2023
7037a38
Use array() syntax
getdave Mar 24, 2023
2669c52
Improve function naming for clarity
getdave Mar 24, 2023
4b3c1c9
Try to fix PHPCS errors and warnings
getdave Mar 24, 2023
be54021
Rename class
getdave Mar 30, 2023
5f5341a
Correct return type
getdave Mar 30, 2023
11d1b1b
Update naming for consistency
getdave Mar 30, 2023
f4ee89d
Extract function for default registered blocks
getdave Mar 30, 2023
29a20c9
Corrects spelling in comment
getdave Mar 30, 2023
321db0a
Use more appropriate assertion
getdave Mar 30, 2023
2a9ffcf
Remove code references that no longer apply
getdave Mar 30, 2023
6001581
Remove PHP based ordering.
getdave Mar 31, 2023
1bba273
Rename class to match file
getdave Mar 31, 2023
cc075a9
Move to standalone block editor REST endpoint
getdave Apr 17, 2023
9603ce8
Migrate all tests to the Domain class and remove from REST endpoint t…
getdave Apr 17, 2023
7143798
Add smoke test to REST endpoint
getdave Apr 17, 2023
f8ef276
Augment smoke test to check for number of menus created
getdave Apr 17, 2023
eba41ce
Add schema and associated test
getdave Apr 18, 2023
f6082f9
Add useful comment
getdave Apr 18, 2023
577b32d
Update editor logic to expect an ID from the REST endpoint
getdave Apr 18, 2023
3479818
Correct return type
getdave Apr 18, 2023
953a515
Add default domain to i18n
getdave Apr 18, 2023
c1657dc
Try to get the file docblock comment correct
getdave Apr 18, 2023
449e2ee
Another file comment update
getdave Apr 18, 2023
38a3a50
Update lib/experimental/class-wp-rest-navigation-fallbacks-controller…
scruffian Apr 18, 2023
59c69c2
Update REST method naming to use `get_item`
getdave Apr 18, 2023
00b83e4
Move method inline with main permissions check
getdave Apr 18, 2023
e8a6356
Ensure rest response for endpoint
getdave Apr 18, 2023
0d29d95
Simplify perrmissions checks
getdave Apr 18, 2023
b1660fa
Add and translate error messages
getdave Apr 18, 2023
5a53b92
Remove erroneous comment
getdave Apr 18, 2023
1b18d69
Use static function
getdave Apr 18, 2023
12ecaba
Add @covers notation
getdave Apr 18, 2023
b631518
Add messages to assertions
getdave Apr 18, 2023
b00ac6b
Add messages to all assertions
getdave Apr 18, 2023
6037f45
Remove unused method
getdave Apr 18, 2023
de35df2
Update correct return type
getdave Apr 18, 2023
2590732
Implement prepare_item_for_response
getdave Apr 18, 2023
1f201d6
Revert to returning object in REST response
getdave Apr 18, 2023
2d09c18
Adjust tests to assert on new return type
getdave Apr 18, 2023
b69b3f1
Add response context filtering
getdave Apr 18, 2023
6ad35cc
Revert to `array` accidentally introduced in refactor
getdave Apr 18, 2023
6277397
add an extra comment to keep the linter happy, maybe
scruffian Apr 18, 2023
6f85821
Check fields before included them in response
getdave Apr 19, 2023
fa1b395
Improve test name
getdave Apr 19, 2023
f228b7e
Update e2e test to expect Page List fallback Menu to be auto-created
getdave Apr 19, 2023
8b718cc
Revert fallbacks invocation to simplified method
getdave Apr 19, 2023
c9f3c05
Correct privacy on members of WP_Navigation_Fallbacks_Gutenberg
getdave Apr 19, 2023
2c6bb93
Rename test and remove associated @doesNotPerformAssertions
getdave Apr 19, 2023
d5d6833
Remove unnecessary test for WP_Error
getdave Apr 19, 2023
b919057
Update comment
getdave Apr 19, 2023
734d3e4
Minor comment rewording.
getdave Apr 19, 2023
8a61e15
Remove unnecessary comments
getdave Apr 19, 2023
eed97ff
Reword comment to align with block terminology
getdave Apr 19, 2023
ccd235b
Improve comment wording.
getdave Apr 19, 2023
2164b79
Remove some comments
getdave Apr 19, 2023
1f715df
Rename classes with singular “fallback”
getdave Apr 19, 2023
7794109
Extract conditional to var for clarity
getdave Apr 19, 2023
9f213d5
Rename converter class
getdave Apr 19, 2023
638f7e2
Fix comments in JS
getdave Apr 19, 2023
a2a8e3c
Add comments to improve clarity around fallbacks logic
getdave Apr 19, 2023
308571f
Shorten method name to reduce verbosity
getdave Apr 19, 2023
eaceebe
Remove unnecessary comments from self documenting code
getdave Apr 19, 2023
d3b85da
Rename variables for clarity
getdave Apr 19, 2023
a3bf3be
Fix PHPCS
getdave Apr 20, 2023
3238826
Make converter class static
getdave Apr 20, 2023
191dd14
Improve var naming
getdave Apr 20, 2023
09e1681
Ensure all assertions have messages
getdave Apr 20, 2023
780bc12
Add @covers annotation
getdave Apr 20, 2023
56f181b
Add links to the response
getdave Apr 21, 2023
da4cdb9
Add test for inclusion of links in Response
getdave Apr 21, 2023
db39cdb
Fix PHPCS
getdave Apr 21, 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 classic meny and concurrent request assertions
getdave committed Apr 17, 2023

Verified

This commit was signed with the committer’s verified signature.
richardlau Richard Lau
commit 5ea9a2294649bc753eef288a25afb87ab579a964
70 changes: 68 additions & 2 deletions phpunit/class-wp-rest-navigation-controller-test.php
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ public function test_register_routes() {
$this->assertArrayHasKey( '/wp/v2/navigation/fallbacks', $routes );
}

public function test_it_should_create_and_return_a_default_fallback_navigation_menu_in_absence_of_other_fallbacks() {
public function test_should_return_a_default_fallback_navigation_menu_in_absence_of_other_fallbacks() {
$request = new WP_REST_Request( 'GET', '/wp/v2/navigation/fallbacks' );
$response = rest_get_server()->dispatch( $request );
$data = $response->get_data();
@@ -44,7 +44,32 @@ public function test_it_should_create_and_return_a_default_fallback_navigation_m
$this->assertCount( 1, $navs_in_db, 'The fallback Navigation post should be the only one in the database.' );
}

public function test_it_should_return_the_most_recently_created_navigation_menu_if_one_exists() {
public function test_should_manage_concurrent_requests() {
$request_one = new WP_REST_Request( 'GET', '/wp/v2/navigation/fallbacks' );
$request_two = new WP_REST_Request( 'GET', '/wp/v2/navigation/fallbacks' );
$request_three = new WP_REST_Request( 'GET', '/wp/v2/navigation/fallbacks' );

// Fire off multiple requests.
rest_get_server()->dispatch( $request_one );
rest_get_server()->dispatch( $request_two );

// Assert on the final request.
$response = rest_get_server()->dispatch( $request_three );

$data = $response->get_data();

$this->assertEquals( 200, $response->get_status() );

$this->assertInstanceOf( 'WP_Post', $data );

$this->assertEquals( 'Navigation', $data->post_title, 'Post title should be the default title' );

$navs_in_db = $this->get_navigations_in_database();

$this->assertCount( 1, $navs_in_db, 'The fallback Navigation post should be the only one in the database.' );
}

public function test_should_return_the_most_recently_created_navigation_menu_if_one_exists() {

// Pre-add a Navigation Menu to simulate when a user already has a menu.
self::factory()->post->create_and_get(
@@ -82,6 +107,47 @@ public function test_it_should_return_the_most_recently_created_navigation_menu_
$this->assertCount( 2, $navs_in_db, 'Only the existing Navigation menus should be present in the database.' );
}

public function test_should_return_fallback_navigation_from_existing_classic_menu() {
$menu_id = wp_create_nav_menu( 'Existing Classic Menu' );

wp_update_nav_menu_item(
$menu_id,
0,
array(
'menu-item-title' => 'Classic Menu Item 1',
'menu-item-url' => '/classic-menu-item-1',
'menu-item-status' => 'publish',
)
);

$request = new WP_REST_Request( 'GET', '/wp/v2/navigation/fallbacks' );
$response = rest_get_server()->dispatch( $request );
$data = $response->get_data();

$this->assertEquals( 200, $response->get_status() );

$this->assertInstanceOf( 'WP_Post', $data );

$this->assertEquals( 'Existing Classic Menu', $data->post_title, 'Post title should be the same as the classic menu.' );

// Assert that the fallback contains a navigation-link block.
$this->assertStringContainsString( '<!-- wp:navigation-link', $data->post_content, 'The fallback Navigation Menu should contain a `core/navigation-link` block.' );

// Assert that fallback post_content contains the expected menu item title.
$this->assertStringContainsString( '"label":"Classic Menu Item 1"', $data->post_content, 'The fallback Navigation Menu should contain menu item with a label matching the title of the menu item from the Classic Menu.' );

// Assert that fallback post_content contains the expected menu item url.
$this->assertStringContainsString( '"url":"/classic-menu-item-1"', $data->post_content, 'The fallback Navigation Menu should contain menu item with a url matching the slug of the menu item from the Classic Menu.' );

// Check that only a single Navigation fallback was created.
$navs_in_db = $this->get_navigations_in_database();
$this->assertCount( 1, $navs_in_db, 'A single Navigation menu should be present in the database.' );

}