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

Fix failing tests and compatibility with 5.9. #36368

Merged
merged 6 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .wp-env.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"core": "WordPress/WordPress#5.8.1",
"core": "WordPress/WordPress",
"plugins": [ "." ],
"themes": [ "WordPress/theme-experiments/tt1-blocks#[email protected]" ],
"env": {
Expand Down
2 changes: 1 addition & 1 deletion lib/class-wp-rest-menu-items-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class WP_REST_Menu_Items_Controller extends WP_REST_Posts_Controller {
*/
public function __construct( $post_type ) {
parent::__construct( $post_type );
$this->namespace = '__experimental';
$this->namespace = 'wp/v2';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/class-wp-rest-menu-locations-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class WP_REST_Menu_Locations_Controller extends WP_REST_Controller {
* Constructor.
*/
public function __construct() {
$this->namespace = '__experimental';
$this->namespace = 'wp/v2';
$this->rest_base = 'menu-locations';
}

Expand Down
2 changes: 1 addition & 1 deletion lib/class-wp-rest-menus-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class WP_REST_Menus_Controller extends WP_REST_Terms_Controller {
*/
public function __construct( $taxonomy ) {
parent::__construct( $taxonomy );
$this->namespace = '__experimental';
$this->namespace = 'wp/v2';
}

/**
Expand Down
10 changes: 5 additions & 5 deletions lib/navigation-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ class="edit-navigation"
}

/**
* This function returns an url for the /__experimental/menus endpoint
* This function returns an url for the /wp/v2/menus endpoint
*
* @since 11.8.0
*
* @param int $results_per_page Results per page.
* @return string
*/
function gutenberg_navigation_get_menus_endpoint( $results_per_page = 100 ) {
return '/__experimental/menus?' . build_query(
return '/wp/v2/menus?' . build_query(
array(
'per_page' => $results_per_page,
'context' => 'edit',
Expand All @@ -39,7 +39,7 @@ function gutenberg_navigation_get_menus_endpoint( $results_per_page = 100 ) {
}

/**
* This function returns an url for the /__experimental/menu-items endpoint
* This function returns an url for the /wp/v2/menu-items endpoint
*
* @since 11.8.0
*
Expand All @@ -48,7 +48,7 @@ function gutenberg_navigation_get_menus_endpoint( $results_per_page = 100 ) {
* @return string
*/
function gutenberg_navigation_get_menu_items_endpoint( $menu_id, $results_per_page = 100 ) {
return '/__experimental/menu-items?' . build_query(
return '/wp/v2/menu-items?' . build_query(
array(
'context' => 'edit',
'menus' => $menu_id,
Expand Down Expand Up @@ -88,7 +88,7 @@ function gutenberg_navigation_init( $hook ) {
$first_menu_id = ! empty( $menus ) ? $menus[0]->term_id : null;

$preload_paths = array(
'/__experimental/menu-locations',
'/wp/v2/menu-locations',
array( '/wp/v2/pages', 'OPTIONS' ),
array( '/wp/v2/posts', 'OPTIONS' ),
gutenberg_navigation_get_types_endpoint(),
Expand Down
6 changes: 3 additions & 3 deletions packages/core-data/src/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ export const defaultEntities = [
{
name: 'menu',
kind: 'root',
baseURL: '/__experimental/menus',
baseURL: '/wp/v2/menus',
baseURLParams: { context: 'edit' },
plural: 'menus',
label: __( 'Menu' ),
},
{
name: 'menuItem',
kind: 'root',
baseURL: '/__experimental/menu-items',
baseURL: '/wp/v2/menu-items',
baseURLParams: { context: 'edit' },
plural: 'menuItems',
label: __( 'Menu Item' ),
Expand All @@ -121,7 +121,7 @@ export const defaultEntities = [
{
name: 'menuLocation',
kind: 'root',
baseURL: '/__experimental/menu-locations',
baseURL: '/wp/v2/menu-locations',
baseURLParams: { context: 'edit' },
plural: 'menuLocations',
label: __( 'Menu Location' ),
Expand Down
4 changes: 2 additions & 2 deletions packages/e2e-test-utils/src/menus.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*/
import { rest, batch } from './rest-api';

const menusEndpoint = '/__experimental/menus';
const menuItemsEndpoint = '/__experimental/menu-items';
const menusEndpoint = '/wp/v2/menus';
const menuItemsEndpoint = '/wp/v2/menu-items';

const menuItemObjectRequests = {
post: ( menuItem ) => ( {
Expand Down
5 changes: 3 additions & 2 deletions packages/e2e-tests/specs/editor/blocks/classic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ describe( 'Classic', () => {
await page.click( '.media-menu-item#menu-item-gallery' );

// Wait for media modal to appear and upload image.
await page.waitForSelector( '.media-modal input[type=file]' );
const inputElement = await page.$( '.media-modal input[type=file]' );
const inputElement = await page.waitForSelector(
'.media-modal .moxie-shim input[type=file]'
);
const testImagePath = path.join(
__dirname,
'..',
Expand Down
16 changes: 4 additions & 12 deletions packages/e2e-tests/specs/editor/plugins/image-size.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { v4 as uuid } from 'uuid';
import {
activatePlugin,
createNewPost,
clickButton,
deactivatePlugin,
insertBlock,
openDocumentSettingsSidebar,
Expand All @@ -30,11 +29,9 @@ describe( 'changing image size', () => {

it( 'should insert and change my image size', async () => {
await insertBlock( 'Image' );
await clickButton( 'Media Library' );

// Wait for media modal to appear and upload image.
await page.waitForSelector( '.media-modal input[type=file]' );
const inputElement = await page.$( '.media-modal input[type=file]' );
const inputElement = await page.waitForSelector(
Copy link
Contributor Author

@talldan talldan Nov 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't tell why this test was failing. The image upload just wasn't happening, but it works when testing manually. I've modified it to upload the image in a different way, using the image block placeholder's Upload button. This is actually more succinct, though reduces test coverage for the media modal.

It could be related to this core bug or other changes to the media modal - https://core.trac.wordpress.org/ticket/54411

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though it might actually be better to have test coverage for the placeholder upload button, given there are other tests for using the media modal. I think it's worth keeping this change.

'figure[aria-label="Block: Image"] input[type=file]'
);
const testImagePath = path.join(
__dirname,
'..',
Expand All @@ -49,12 +46,7 @@ describe( 'changing image size', () => {
await inputElement.uploadFile( tmpFileName );

// Wait for upload to finish.
await page.waitForSelector(
`.media-modal li[aria-label="${ filename }"]`
);

// Insert the uploaded image.
await page.click( '.media-modal button.media-button-select' );
await page.waitForXPath( `//img[contains(@src, "${ filename }")]` );

// Select the new size updated with the plugin.
await openDocumentSettingsSidebar();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ describe( 'adding inline tokens', () => {
await clickButton( 'Inline image' );

// Wait for media modal to appear and upload image.
await page.waitForSelector( '.media-modal input[type=file]' );
const inputElement = await page.$( '.media-modal input[type=file]' );
// Wait for media modal to appear and upload image.
const inputElement = await page.waitForSelector(
'.media-modal .moxie-shim input[type=file]'
);
const testImagePath = path.join(
__dirname,
'..',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ const menusFixture = [
// Matching against variations of the same URL encoded and non-encoded
// produces the most reliable mocking.
const REST_MENUS_ROUTES = [
'/__experimental/menus',
`rest_route=${ encodeURIComponent( '/__experimental/menus' ) }`,
'/wp/v2/menus',
`rest_route=${ encodeURIComponent( '/wp/v2/menus' ) }`,
];
const REST_MENU_ITEMS_ROUTES = [
'/__experimental/menu-items',
`rest_route=${ encodeURIComponent( '/__experimental/menu-items' ) }`,
'/wp/v2/menu-items',
`rest_route=${ encodeURIComponent( '/wp/v2/menu-items' ) }`,
];

const REST_PAGES_ROUTES = [
Expand Down
2 changes: 1 addition & 1 deletion packages/edit-navigation/src/hooks/use-menu-locations.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default function useMenuLocations() {
const fetchMenuLocationsByName = async () => {
const newMenuLocationsByName = await apiFetch( {
method: 'GET',
path: '/__experimental/menu-locations',
path: '/wp/v2/menu-locations',
} );

if ( isMounted ) {
Expand Down
2 changes: 1 addition & 1 deletion packages/edit-navigation/src/store/test/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ describe( 'getNavigationPostForMenu', () => {
jest.useRealTimers();

apiFetch.mockImplementation( async ( { path, method = 'GET' } ) => {
if ( ! path.startsWith( '/__experimental/menu-items?' ) ) {
if ( ! path.startsWith( '/wp/v2/menu-items?' ) ) {
throw new Error( `unexpected API endpoint: ${ path }` );
}

Expand Down
4 changes: 0 additions & 4 deletions phpunit/class-block-fixture-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ class Block_Fixture_Test extends WP_UnitTestCase {
* @dataProvider data_block_fixtures
*/
function test_kses_doesnt_change_fixtures( $block, $filename ) {
// Skip this test while Gutenberg is pinned to WordPress 5.8.1.
// Once WordPress 5.9 is released, this test can be re-enabled.
// See: https://github.com/WordPress/gutenberg/pull/35611.
$this->markTestSkipped( 'This test requires WordPress 5.9. See: https://core.trac.wordpress.org/ticket/54261' );

// KSES doesn't allow data: URLs, so we need to replace any of them in fixtures.
$block = preg_replace( "/src=['\"]data:[^'\"]+['\"]/", 'src="https://wordpress.org/foo.jpg"', $block );
Expand Down
Loading