Skip to content

Commit

Permalink
Fix: Regression: Template lock option is not taken into consideration…
Browse files Browse the repository at this point in the history
…; Add: end to end tests; (#14390)
  • Loading branch information
jorgefilipecosta authored and youknowriad committed Mar 20, 2019
1 parent 1ad22de commit 462e9fa
Show file tree
Hide file tree
Showing 4 changed files with 220 additions and 7 deletions.
56 changes: 56 additions & 0 deletions packages/e2e-tests/plugins/cpt-locking.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* Plugin Name: Gutenberg Test Plugin, CPT Locking
* Plugin URI: https://github.com/WordPress/gutenberg
* Author: Gutenberg Team
*
* @package gutenberg-test-cpt-locking
*/

/**
* Registers CPT's with 3 diffferent types of locking.
*/
function gutenberg_test_cpt_locking() {
$template = array(
array( 'core/image' ),
array(
'core/paragraph',
array(
'placeholder' => 'Add a description',
),
),
array( 'core/quote' ),
);
register_post_type(
'locked-all-post',
array(
'public' => true,
'label' => 'Locked All Post',
'show_in_rest' => true,
'template' => $template,
'template_lock' => 'all',
)
);
register_post_type(
'locked-insert-post',
array(
'public' => true,
'label' => 'Locked Insert Post',
'show_in_rest' => true,
'template' => $template,
'template_lock' => 'insert',
)
);
register_post_type(
'not-locked-post',
array(
'public' => true,
'label' => 'Not Locked Post',
'show_in_rest' => true,
'template' => $template,
'template_lock' => false,
)
);
}

add_action( 'init', 'gutenberg_test_cpt_locking' );
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`cpt locking template_lock false should allow blocks to be inserted 1`] = `
"<!-- wp:image -->
<figure class=\\"wp-block-image\\"><img alt=\\"\\"/></figure>
<!-- /wp:image -->
<!-- wp:paragraph {\\"placeholder\\":\\"Add a description\\"} -->
<p></p>
<!-- /wp:paragraph -->
<!-- wp:quote -->
<blockquote class=\\"wp-block-quote\\"><p></p></blockquote>
<!-- /wp:quote -->
<!-- wp:list -->
<ul><li>List content</li></ul>
<!-- /wp:list -->"
`;
exports[`cpt locking template_lock false should allow blocks to be moved 1`] = `
"<!-- wp:paragraph {\\"placeholder\\":\\"Add a description\\"} -->
<p>p1</p>
<!-- /wp:paragraph -->
<!-- wp:image -->
<figure class=\\"wp-block-image\\"><img alt=\\"\\"/></figure>
<!-- /wp:image -->
<!-- wp:quote -->
<blockquote class=\\"wp-block-quote\\"><p></p></blockquote>
<!-- /wp:quote -->"
`;
exports[`cpt locking template_lock false should allow blocks to be removed 1`] = `
"<!-- wp:image -->
<figure class=\\"wp-block-image\\"><img alt=\\"\\"/></figure>
<!-- /wp:image -->
<!-- wp:quote -->
<blockquote class=\\"wp-block-quote\\"><p></p></blockquote>
<!-- /wp:quote -->"
`;
exports[`cpt locking template_lock insert should allow blocks to be moved 1`] = `
"<!-- wp:paragraph {\\"placeholder\\":\\"Add a description\\"} -->
<p>p1</p>
<!-- /wp:paragraph -->
<!-- wp:image -->
<figure class=\\"wp-block-image\\"><img alt=\\"\\"/></figure>
<!-- /wp:image -->
<!-- wp:quote -->
<blockquote class=\\"wp-block-quote\\"><p></p></blockquote>
<!-- /wp:quote -->"
`;
99 changes: 99 additions & 0 deletions packages/e2e-tests/specs/plugins/cpt-locking.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/**
* WordPress dependencies
*/
import {
activatePlugin,
clickBlockToolbarButton,
createNewPost,
deactivatePlugin,
getEditedPostContent,
insertBlock,
} from '@wordpress/e2e-test-utils';

describe( 'cpt locking', () => {
beforeAll( async () => {
await activatePlugin( 'gutenberg-test-plugin-cpt-locking' );
} );

afterAll( async () => {
await deactivatePlugin( 'gutenberg-test-plugin-cpt-locking' );
} );

const shouldRemoveTheInserter = async () => {
expect(
await page.$( '.edit-post-header [aria-label="Add block"]' )
).toBeNull();
};

const shouldNotAllowBlocksToBeRemoved = async () => {
await page.type( '.editor-rich-text__editable.wp-block-paragraph', 'p1' );
await clickBlockToolbarButton( 'More options' );
expect(
await page.$x( '//button[contains(text(), "Remove Block")]' )
).toHaveLength( 0 );
};

const shouldAllowBlocksToBeMoved = async () => {
await page.click( '.editor-rich-text__editable.wp-block-paragraph' );
expect(
await page.$( 'button[aria-label="Move up"]' )
).not.toBeNull();
await page.click( 'button[aria-label="Move up"]' );
await page.type( '.editor-rich-text__editable.wp-block-paragraph', 'p1' );
expect( await getEditedPostContent() ).toMatchSnapshot();
};

describe( 'template_lock all', () => {
beforeEach( async () => {
await createNewPost( { postType: 'locked-all-post' } );
} );

it( 'should remove the inserter', shouldRemoveTheInserter );

it( 'should not allow blocks to be removed', shouldNotAllowBlocksToBeRemoved );

it( 'should not allow blocks to be moved', async () => {
await page.click( '.editor-rich-text__editable.wp-block-paragraph' );
expect(
await page.$( 'button[aria-label="Move up"]' )
).toBeNull();
} );
} );

describe( 'template_lock insert', () => {
beforeEach( async () => {
await createNewPost( { postType: 'locked-insert-post' } );
} );

it( 'should remove the inserter', shouldRemoveTheInserter );

it( 'should not allow blocks to be removed', shouldNotAllowBlocksToBeRemoved );

it( 'should allow blocks to be moved', shouldAllowBlocksToBeMoved );
} );

describe( 'template_lock false', () => {
beforeEach( async () => {
await createNewPost( { postType: 'not-locked-post' } );
} );

it( 'should allow blocks to be inserted', async () => {
expect(
await page.$( '.edit-post-header [aria-label="Add block"]' )
).not.toBeNull();
await insertBlock( 'List' );
await page.keyboard.type( 'List content' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'should allow blocks to be removed', async () => {
await page.type( '.editor-rich-text__editable.wp-block-paragraph', 'p1' );
await clickBlockToolbarButton( 'More options' );
const [ removeBlock ] = await page.$x( '//button[contains(text(), "Remove Block")]' );
await removeBlock.click();
expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'should allow blocks to be moved', shouldAllowBlocksToBeMoved );
} );
} );
15 changes: 8 additions & 7 deletions packages/editor/src/components/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,21 @@ class EditorProvider extends Component {
return {
...pick( settings, [
'alignWide',
'allowedBlockTypes',
'availableLegacyWidgets',
'bodyPlaceholder',
'colors',
'disableCustomColors',
'fontSizes',
'disableCustomFontSizes',
'imageSizes',
'maxWidth',
'allowedBlockTypes',
'focusMode',
'fontSizes',
'hasFixedToolbar',
'hasPermissionsToManageWidgets',
'focusMode',
'styles',
'imageSizes',
'isRTL',
'bodyPlaceholder',
'maxWidth',
'styles',
'templateLock',
'titlePlaceholder',
] ),
__experimentalMetaSource: {
Expand Down

0 comments on commit 462e9fa

Please sign in to comment.