-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Regression: Template lock option is not taken into consideration…
…; Add: end to end tests; (#14390)
- Loading branch information
1 parent
1ad22de
commit 462e9fa
Showing
4 changed files
with
220 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' ); |
57 changes: 57 additions & 0 deletions
57
packages/e2e-tests/specs/plugins/__snapshots__/cpt-locking.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 -->" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters