Skip to content
Merged
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
104 changes: 104 additions & 0 deletions features/post-generate.feature
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,107 @@ Feature: Generate new WordPress posts
howdy-3
"""
And STDERR should be empty

Scenario: Generating posts with post_date argument without time
When I run `wp post generate --count=1 --post_date="2018-07-01"`
And I run `wp post list --field=post_date`
Then STDOUT should contain:
"""
2018-07-01 00:00:00
"""
And I run `wp post list --field=post_date_gmt`
Then STDOUT should contain:
"""
2018-07-01 00:00:00
"""

Scenario: Generating posts with post_date argument with time
When I run `wp post generate --count=1 --post_date="2018-07-02 02:21:05"`
And I run `wp post list --field=post_date`
Then STDOUT should contain:
"""
2018-07-02 02:21:05
"""
And I run `wp post list --field=post_date_gmt`
Then STDOUT should contain:
"""
2018-07-02 02:21:05
"""

Scenario: Generating posts with post_date_gmt argument without time
When I run `wp post generate --count=1 --post_date_gmt="2018-07-03"`
And I run `wp post list --field=post_date`
Then STDOUT should contain:
"""
2018-07-03 00:00:00
"""
And I run `wp post list --field=post_date_gmt`
Then STDOUT should contain:
"""
2018-07-03 00:00:00
"""

Scenario: Generating posts with post_date_gmt argument with time
When I run `wp post generate --count=1 --post_date_gmt="2018-07-04 12:34:56"`
And I run `wp post list --field=post_date`
Then STDOUT should contain:
"""
2018-07-04 12:34:56
"""
And I run `wp post list --field=post_date_gmt`
Then STDOUT should contain:
"""
2018-07-04 12:34:56
"""

Scenario: Generating posts with post_date argument with hyphenated time
When I run `wp post generate --count=1 --post_date="2018-07-05-17:17:17"`
And I run `wp post list --field=post_date`
Then STDOUT should contain:
"""
2018-07-05 17:17:17
"""
And I run `wp post list --field=post_date_gmt`
Then STDOUT should contain:
"""
2018-07-05 17:17:17
"""

Scenario: Generating posts with post_date_gmt argument with hyphenated time
When I run `wp post generate --count=1 --post_date_gmt="2018-07-06-12:12:12"`
And I run `wp post list --field=post_date`
Then STDOUT should contain:
"""
2018-07-06 12:12:12
"""
And I run `wp post list --field=post_date_gmt`
Then STDOUT should contain:
"""
2018-07-06 12:12:12
"""

Scenario: Generating posts with different post_date & post_date_gmt argument without time
When I run `wp post generate --count=1 --post_date="1999-12-31" --post_date_gmt="2000-01-01"`
And I run `wp post list --field=post_date`
Then STDOUT should contain:
"""
1999-12-31 00:00:00
"""
And I run `wp post list --field=post_date_gmt`
Then STDOUT should contain:
"""
2000-01-01 00:00:00
"""

Scenario: Generating posts with different post_date & post_date_gmt argument with time
When I run `wp post generate --count=1 --post_date="1999-12-31 11:11:00" --post_date_gmt="2000-01-01 02:11:00"`
And I run `wp post list --field=post_date`
Then STDOUT should contain:
"""
1999-12-31 11:11:00
"""
And I run `wp post list --field=post_date_gmt`
Then STDOUT should contain:
"""
2000-01-01 02:11:00
"""
17 changes: 16 additions & 1 deletion src/Post_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,9 @@ public function list_( $_, $assoc_args ) {
* [--post_date=<yyyy-mm-dd-hh-ii-ss>]
* : The date of the generated posts. Default: current date
*
* [--post_date_gmt=<yyyy-mm-dd-hh-ii-ss>]
* : The GMT date of the generated posts. Default: value of post_date (or current date if it's not set)
*
* [--post_content]
* : If set, the command reads the post_content from STDIN.
*
Expand Down Expand Up @@ -680,12 +683,23 @@ public function generate( $args, $assoc_args ) {
'post_type' => 'post',
'post_status' => 'publish',
'post_author' => false,
'post_date' => current_time( 'mysql' ),
'post_date' => false,
'post_date_gmt' => false,
'post_content' => '',
'post_title' => '',
);
extract( array_merge( $defaults, $assoc_args ), EXTR_SKIP );

$call_time = current_time( 'mysql' );

if ( $post_date_gmt === false ) {
$post_date_gmt = $post_date ? $post_date : $call_time;
}

if ( $post_date === false ) {
$post_date = $post_date_gmt ? $post_date_gmt : $call_time;
}

// @codingStandardsIgnoreStart
if ( !post_type_exists( $post_type ) ) {
WP_CLI::error( sprintf( "'%s' is not a registered post type.", $post_type ) );
Expand Down Expand Up @@ -745,6 +759,7 @@ public function generate( $args, $assoc_args ) {
'post_parent' => $current_parent,
'post_name' => ! empty( $post_title ) ? sanitize_title( $post_title . ( $i === $total ) ? '' : '-$i' ) : "post-$i",
'post_date' => $post_date,
'post_date_gmt' => $post_date_gmt,
'post_content' => $post_content,
);

Expand Down