From db18b4a19b2d833a1be55c7eca0a9b8e2b2012f7 Mon Sep 17 00:00:00 2001 From: Mario Santos Date: Tue, 28 May 2024 11:01:24 +0200 Subject: [PATCH] Test protected fields are not editable --- .../editor/various/block-bindings.spec.js | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/test/e2e/specs/editor/various/block-bindings.spec.js b/test/e2e/specs/editor/various/block-bindings.spec.js index e99e73d8584502..658c11f3b709bb 100644 --- a/test/e2e/specs/editor/various/block-bindings.spec.js +++ b/test/e2e/specs/editor/various/block-bindings.spec.js @@ -1381,6 +1381,64 @@ test.describe( 'Block bindings', () => { previewPage.locator( '#paragraph-binding' ) ).toHaveText( 'new value' ); } ); + + test( 'should NOT be possible to edit the value of the custom field when it is protected', async ( { + editor, + } ) => { + await editor.insertBlock( { + name: 'core/paragraph', + attributes: { + anchor: 'protected-field-binding', + content: 'fallback value', + metadata: { + bindings: { + content: { + source: 'core/post-meta', + args: { key: '_protected_field' }, + }, + }, + }, + }, + } ); + + const protectedFieldBlock = editor.canvas.getByRole( + 'document', + { + name: 'Block: Paragraph', + } + ); + + await expect( protectedFieldBlock ).not.toBeEditable(); + } ); + + test( 'should NOT be possible to edit the value of the custom field when it is not shown in the REST API', async ( { + editor, + } ) => { + await editor.insertBlock( { + name: 'core/paragraph', + attributes: { + anchor: 'show-in-rest-false-binding', + content: 'fallback value', + metadata: { + bindings: { + content: { + source: 'core/post-meta', + args: { key: 'show_in_rest_false_field' }, + }, + }, + }, + }, + } ); + + const showInRestFalseBlock = editor.canvas.getByRole( + 'document', + { + name: 'Block: Paragraph', + } + ); + + await expect( showInRestFalseBlock ).not.toBeEditable(); + } ); } ); test.describe( 'Heading', () => {