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
162 changes: 162 additions & 0 deletions features/comment-notes.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
Feature: Manage WordPress notes

Background:
Given a WP install

@require-wp-6.9
Scenario: Create and list notes
When I run `wp comment create --comment_post_ID=1 --comment_content='This is a note about the block' --comment_author='Editor' --comment_type='note' --porcelain`
Then STDOUT should be a number
And save STDOUT as {NOTE_ID}

When I run `wp comment get {NOTE_ID} --field=comment_type`
Then STDOUT should be:
"""
note
"""

When I run `wp comment list --type=note --post_id=1 --format=ids`
Then STDOUT should be:
"""
{NOTE_ID}
"""

When I run `wp comment list --type=note --post_id=1 --fields=comment_ID,comment_type,comment_content`
Then STDOUT should be a table containing rows:
| comment_ID | comment_type | comment_content |
| {NOTE_ID} | note | This is a note about the block |

@require-wp-6.9
Scenario: Notes are not shown by default in comment list
When I run `wp comment create --comment_post_ID=1 --comment_content='Regular comment' --comment_author='User' --porcelain`
Then save STDOUT as {COMMENT_ID}

When I run `wp comment create --comment_post_ID=1 --comment_content='This is a note' --comment_author='Editor' --comment_type='note' --porcelain`
Then save STDOUT as {NOTE_ID}

When I run `wp comment list --post_id=1 --format=ids`
Then STDOUT should contain:
"""
{COMMENT_ID}
"""
And STDOUT should not contain:
"""
{NOTE_ID}
"""

When I run `wp comment list --type=note --post_id=1 --format=ids`
Then STDOUT should be:
"""
{NOTE_ID}
"""

@require-wp-6.9
Scenario: Reply to a note
When I run `wp comment create --comment_post_ID=1 --comment_content='Initial note' --comment_author='Editor1' --comment_type='note' --porcelain`
Then save STDOUT as {PARENT_NOTE_ID}

When I run `wp comment create --comment_post_ID=1 --comment_content='Reply to note' --comment_author='Editor2' --comment_type='note' --comment_parent={PARENT_NOTE_ID} --porcelain`
Then save STDOUT as {REPLY_NOTE_ID}

When I run `wp comment get {REPLY_NOTE_ID} --field=comment_parent`
Then STDOUT should be:
"""
{PARENT_NOTE_ID}
"""

When I run `wp comment list --type=note --post_id=1 --format=count`
Then STDOUT should be:
"""
2
"""

@require-wp-6.9
Scenario: Resolve a note
When I run `wp comment create --comment_post_ID=1 --comment_content='Note to be resolved' --comment_author='Editor' --comment_type='note' --porcelain`
Then save STDOUT as {NOTE_ID}

When I run `wp comment create --comment_post_ID=1 --comment_content='Resolving' --comment_author='Editor' --comment_type='note' --comment_parent={NOTE_ID} --porcelain`
Then save STDOUT as {RESOLVE_NOTE_ID}

When I run `wp comment meta add {RESOLVE_NOTE_ID} _wp_note_status resolved`
Then STDOUT should contain:
"""
Success: Added custom field.
"""

When I run `wp comment meta get {RESOLVE_NOTE_ID} _wp_note_status`
Then STDOUT should be:
"""
resolved
"""

@require-wp-6.9
Scenario: Reopen a resolved note
When I run `wp comment create --comment_post_ID=1 --comment_content='Note to resolve and reopen' --comment_author='Editor' --comment_type='note' --porcelain`
Then save STDOUT as {NOTE_ID}

When I run `wp comment create --comment_post_ID=1 --comment_content='Resolving' --comment_author='Editor' --comment_type='note' --comment_parent={NOTE_ID} --porcelain`
Then save STDOUT as {RESOLVE_NOTE_ID}

When I run `wp comment meta add {RESOLVE_NOTE_ID} _wp_note_status resolved`
Then STDOUT should contain:
"""
Success: Added custom field.
"""

When I run `wp comment create --comment_post_ID=1 --comment_content='Reopening' --comment_author='Editor' --comment_type='note' --comment_parent={NOTE_ID} --porcelain`
Then save STDOUT as {REOPEN_NOTE_ID}

When I run `wp comment meta add {REOPEN_NOTE_ID} _wp_note_status reopen`
Then STDOUT should contain:
"""
Success: Added custom field.
"""

When I run `wp comment meta get {REOPEN_NOTE_ID} _wp_note_status`
Then STDOUT should be:
"""
reopen
"""

@require-wp-6.9
Scenario: List notes with comment meta
When I run `wp comment create --comment_post_ID=1 --comment_content='First note' --comment_author='Editor' --comment_type='note' --porcelain`
Then save STDOUT as {NOTE1_ID}

When I run `wp comment create --comment_post_ID=1 --comment_content='Resolved note' --comment_author='Editor' --comment_type='note' --comment_parent={NOTE1_ID} --porcelain`
Then save STDOUT as {NOTE2_ID}

When I run `wp comment meta add {NOTE2_ID} _wp_note_status resolved`
Then STDOUT should contain:
"""
Success: Added custom field.
"""

When I run `wp comment meta list {NOTE2_ID} --keys=_wp_note_status`
Then STDOUT should be a table containing rows:
| comment_id | meta_key | meta_value |
| {NOTE2_ID} | _wp_note_status | resolved |

@require-wp-6.9
Scenario: Get notes for multiple posts
When I run `wp post create --post_title='Post 2' --porcelain`
Then save STDOUT as {POST2_ID}

When I run `wp comment create --comment_post_ID=1 --comment_content='Note on post 1' --comment_author='Editor' --comment_type='note' --porcelain`
Then save STDOUT as {NOTE1_ID}

When I run `wp comment create --comment_post_ID={POST2_ID} --comment_content='Note on post 2' --comment_author='Editor' --comment_type='note' --porcelain`
Then save STDOUT as {NOTE2_ID}

When I run `wp comment list --type=note --post_id=1 --format=ids`
Then STDOUT should be:
"""
{NOTE1_ID}
"""

When I run `wp comment list --type=note --post_id={POST2_ID} --format=ids`
Then STDOUT should be:
"""
{NOTE2_ID}
"""
41 changes: 41 additions & 0 deletions src/Comment_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,34 @@
* Success: Trashed comment 264.
* Success: Trashed comment 262.
*
* # Create a note for a block (WordPress 6.9+).
* $ wp comment create --comment_post_ID=15 --comment_content="This block needs revision" --comment_author="editor" --comment_type="note"
* Success: Created comment 945.
*
* # List notes for a specific post (WordPress 6.9+).
* $ wp comment list --type=note --post_id=15
* +------------+---------------------+----------------------------------+
* | comment_ID | comment_date | comment_content |
* +------------+---------------------+----------------------------------+
* | 945 | 2024-11-10 14:30:00 | This block needs revision |
* +------------+---------------------+----------------------------------+
*
* # Reply to a note (WordPress 6.9+).
* $ wp comment create --comment_post_ID=15 --comment_content="Updated per feedback" --comment_author="editor" --comment_type="note" --comment_parent=945
* Success: Created comment 946.
*
* # Resolve a note by adding a comment with status meta (WordPress 6.9+).
* $ wp comment create --comment_post_ID=15 --comment_content="Resolving" --comment_author="editor" --comment_type="note" --comment_parent=945 --porcelain
* 947
* $ wp comment meta add 947 _wp_note_status resolved
* Success: Added custom field.
*
* # Reopen a resolved note (WordPress 6.9+).
* $ wp comment create --comment_post_ID=15 --comment_content="Reopening for further review" --comment_author="editor" --comment_type="note" --comment_parent=945 --porcelain
* 948
* $ wp comment meta add 948 _wp_note_status reopen
* Success: Added custom field.
*
* @package wp-cli
*/
class Comment_Command extends CommandWithDBObject {
Expand Down Expand Up @@ -63,12 +91,16 @@
* # Create comment.
* $ wp comment create --comment_post_ID=15 --comment_content="hello blog" --comment_author="wp-cli"
* Success: Created comment 932.
*
* # Create a note (WordPress 6.9+).
* $ wp comment create --comment_post_ID=15 --comment_content="This block needs revision" --comment_author="editor" --comment_type="note"
* Success: Created comment 933.
*/
public function create( $args, $assoc_args ) {
$assoc_args = wp_slash( $assoc_args );
parent::_create(
$args,
$assoc_args,

Check failure on line 103 in src/Comment_Command.php

View workflow job for this annotation

GitHub Actions / code-quality / PHPStan

Parameter #2 $assoc_args of method WP_CLI\CommandWithDBObject::_create() expects array, array|string given.

Check failure on line 103 in src/Comment_Command.php

View workflow job for this annotation

GitHub Actions / code-quality / PHPStan

Parameter #2 $assoc_args of method WP_CLI\CommandWithDBObject::_create() expects array, array|string given.
function ( $params ) {
if ( isset( $params['comment_post_ID'] ) ) {
$post_id = $params['comment_post_ID'];
Expand Down Expand Up @@ -115,7 +147,7 @@
$assoc_args = wp_slash( $assoc_args );
parent::_update(
$args,
$assoc_args,

Check failure on line 150 in src/Comment_Command.php

View workflow job for this annotation

GitHub Actions / code-quality / PHPStan

Parameter #2 $assoc_args of method WP_CLI\CommandWithDBObject::_update() expects array, array|string given.

Check failure on line 150 in src/Comment_Command.php

View workflow job for this annotation

GitHub Actions / code-quality / PHPStan

Parameter #2 $assoc_args of method WP_CLI\CommandWithDBObject::_update() expects array, array|string given.
function ( $params ) {
if ( ! wp_update_comment( $params ) ) {
return new WP_Error( 'db_error', 'Could not update comment.' );
Expand Down Expand Up @@ -362,6 +394,15 @@
* | 3 | 2023-11-10 11:22:31 | John Doe |
* +------------+---------------------+----------------+
*
* # List notes for a specific post (WordPress 6.9+).
* $ wp comment list --type=note --post_id=15 --fields=ID,comment_date,comment_content
* +------------+---------------------+----------------------------------+
* | comment_ID | comment_date | comment_content |
* +------------+---------------------+----------------------------------+
* | 10 | 2024-11-10 14:30:00 | This block needs revision |
* | 11 | 2024-11-10 15:45:00 | Updated per feedback |
* +------------+---------------------+----------------------------------+
*
* @subcommand list
*/
public function list_( $args, $assoc_args ) {
Expand Down
Loading