Skip to content
Open
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
10 changes: 10 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
"comment unspam",
"comment untrash",
"comment update",
"block",
"block get",
"block list",
"menu",
"menu create",
"menu delete",
Expand Down Expand Up @@ -96,13 +99,18 @@
"option update",
"option set-autoload",
"option get-autoload",
"pattern",
"pattern get",
"pattern list",
"post",
"post create",
"post delete",
"post edit",
"post exists",
"post generate",
"post get",
"post has-block",
"post has-blocks",
"post list",
"post meta",
"post meta add",
Expand All @@ -113,6 +121,8 @@
"post meta patch",
"post meta pluck",
"post meta update",
"post parse-blocks",
"post render-blocks",
"post term",
"post term add",
"post term list",
Expand Down
25 changes: 25 additions & 0 deletions entity-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,28 @@
},
)
);

// Block and pattern commands require WordPress 5.0+.
WP_CLI::add_command(
'block',
'Block_Command',
array(
'before_invoke' => function () {
if ( Utils\wp_version_compare( '5.0', '<' ) ) {
WP_CLI::error( 'Requires WordPress 5.0 or greater.' );
}
},
)
);

WP_CLI::add_command(
'pattern',
'Pattern_Command',
array(
'before_invoke' => function () {
if ( Utils\wp_version_compare( '5.5', '<' ) ) {
WP_CLI::error( 'Requires WordPress 5.5 or greater.' );
}
},
)
);
71 changes: 71 additions & 0 deletions features/block.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
Feature: Manage WordPress block types

Background:
Given a WP install

@require-wp-5.0
Scenario: Listing block types
When I run `wp block list --format=csv`
Then STDOUT should contain:
"""
name,title
"""
And STDOUT should contain:
"""
core/paragraph
"""

@require-wp-5.0
Scenario: Listing block types with specific fields
When I run `wp block list --fields=name,title,category`
Then STDOUT should be a table containing rows:
| name | title | category |
| core/paragraph | Paragraph | text |

@require-wp-5.0
Scenario: Getting a specific block type
When I run `wp block get core/paragraph --fields=name,title,category`
Then STDOUT should be a table containing rows:
| Field | Value |
| name | core/paragraph |
| title | Paragraph |
| category | text |

@require-wp-5.0
Scenario: Getting a non-existent block type
When I try `wp block get core/nonexistent-block`
Then STDERR should contain:
"""
Error: Block type 'core/nonexistent-block' is not registered.
"""
And the return code should be 1

@require-wp-5.0
Scenario: Getting a specific field from a block type
When I run `wp block get core/paragraph --field=title`
Then STDOUT should be:
"""
Paragraph
"""

@require-wp-5.0
Scenario: Listing block types in JSON format
When I run `wp block list --format=json`
Then STDOUT should contain:
"""
{"name":"core\/paragraph","title":"Paragraph","description":"Start with the basic building block of all narrative.","category":"text"}
"""

@require-wp-5.0
Scenario: Count block types
When I run `wp block list --format=count`
Then STDOUT should match /^\d+$/

@less-than-wp-5.0
Scenario: Block commands require WordPress 5.0+
When I try `wp block list`
Then STDERR should contain:
"""
Error: Requires WordPress 5.0 or greater.
"""
And the return code should be 1
57 changes: 57 additions & 0 deletions features/pattern.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
Feature: Manage WordPress block patterns

Background:
Given a WP install

@require-wp-5.5
Scenario: Listing block patterns
When I run `wp pattern list --format=csv`
Then STDOUT should contain:
"""
name,title
"""

When I run `wp pattern list --format=json`
Then STDOUT should be JSON containing:
"""
[{"name":"core\/query-standard-posts","title":"Standard"}]
"""

@require-wp-5.5
Scenario: Filtering block patterns by category
When I run `wp pattern list --category=buttons --format=count`
Then STDOUT should match /^\d+$/

@require-wp-5.5
Scenario: Getting a specific block pattern
When I run `wp pattern list --format=csv --fields=name`
Then STDOUT should contain:
"""
name
"""

When I run `wp pattern list --format=count`
Then STDOUT should match /^\d+$/

@require-wp-5.5
Scenario: Getting a non-existent block pattern
When I try `wp pattern get nonexistent/pattern`
Then STDERR should contain:
"""
Error: Block pattern 'nonexistent/pattern' is not registered.
"""
And the return code should be 1

@require-wp-5.5
Scenario: Count block patterns
When I run `wp pattern list --format=count`
Then STDOUT should match /^\d+$/

@less-than-wp-5.0
Scenario: Pattern commands require WordPress 5.5+
When I try `wp pattern list`
Then STDERR should contain:
"""
Error: Requires WordPress 5.5 or greater.
"""
And the return code should be 1
106 changes: 106 additions & 0 deletions features/post-blocks.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
Feature: Manage WordPress post blocks

Background:
Given a WP install

@require-wp-5.0
Scenario: Check if a post has blocks
When I run `wp post create --post_title='Block post' --post_content='<!-- wp:paragraph --><p>Hello World</p><!-- /wp:paragraph -->' --porcelain`
Then STDOUT should be a number
And save STDOUT as {POST_ID}

When I run `wp post has-blocks {POST_ID}`
Then STDOUT should contain:
"""
Success: Post {POST_ID} has blocks.
"""
And the return code should be 0

@require-wp-5.0
Scenario: Check if a post does not have blocks
When I run `wp post create --post_title='Regular post' --post_content='<p>Hello World</p>' --porcelain`
Then STDOUT should be a number
And save STDOUT as {POST_ID}

When I try `wp post has-blocks {POST_ID}`
Then STDERR should be empty
And the return code should be 1

@require-wp-5.0
Scenario: Check if a post contains a specific block type
When I run `wp post create --post_title='Block post' --post_content='<!-- wp:paragraph --><p>Hello World</p><!-- /wp:paragraph -->' --porcelain`
Then STDOUT should be a number
And save STDOUT as {POST_ID}

When I run `wp post has-block {POST_ID} core/paragraph`
Then STDOUT should contain:
"""
Success: Post {POST_ID} contains the block 'core/paragraph'.
"""
And the return code should be 0

When I try `wp post has-block {POST_ID} core/image`
Then STDERR should be empty
And the return code should be 1

@require-wp-5.0
Scenario: Parse blocks from a post
When I run `wp post create --post_title='Block post' --post_content='<!-- wp:paragraph --><p>Hello World</p><!-- /wp:paragraph -->' --porcelain`
Then STDOUT should be a number
And save STDOUT as {POST_ID}

When I run `wp post parse-blocks {POST_ID}`
Then STDOUT should be JSON containing:
"""
[
{
"blockName": "core/paragraph",
"attrs": [],
"innerBlocks": [],
"innerHTML": "<p>Hello World</p>",
"innerContent": [
"<p>Hello World</p>"
]
}
]
"""

When I run `wp post parse-blocks {POST_ID} --format=yaml`
Then STDOUT should contain:
"""
blockName:
"""
And STDOUT should contain:
"""
core/paragraph
"""

@require-wp-5.0
Scenario: Render blocks from a post
When I run `wp post create --post_title='Block post' --post_content='<!-- wp:paragraph --><p>Hello World</p><!-- /wp:paragraph -->' --porcelain`
Then STDOUT should be a number
And save STDOUT as {POST_ID}

When I run `wp post render-blocks {POST_ID}`
Then STDOUT should contain:
"""
<p>Hello World</p>
"""

@require-wp-5.0
Scenario: Post get command includes block_version field
When I run `wp post create --post_title='Block post' --post_content='<!-- wp:paragraph --><p>Hello World</p><!-- /wp:paragraph -->' --porcelain`
Then STDOUT should be a number
And save STDOUT as {POST_ID}

When I run `wp post get {POST_ID} --field=block_version`
Then STDOUT should match /^\d+$/

@less-than-wp-5.0
Scenario: Post block commands require WordPress 5.0+
When I try `wp post has-blocks 1`
Then STDERR should contain:
"""
Error: This command requires WordPress 5.0 or greater.
"""
And the return code should be 1
2 changes: 2 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
<exclude-pattern>*/src/Site(_Meta|_Option)?_Command\.php$</exclude-pattern>
<exclude-pattern>*/src/Term(_Meta)?_Command\.php$</exclude-pattern>
<exclude-pattern>*/src/User(_Application_Password|_Meta|_Session|_Term)?_Command\.php$</exclude-pattern>
<exclude-pattern>*/src/Block_Command\.php$</exclude-pattern>
<exclude-pattern>*/src/Pattern_Command\.php$</exclude-pattern>
</rule>

<!-- Whitelisting to provide backward compatibility to classes possibly extending this class. -->
Expand Down
Loading
Loading