Skip to content

Commit 26034db

Browse files
committed
Add some test scenarios & make them actually pass ;)
1 parent 3dc0674 commit 26034db

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed

features/post-generate.feature

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,55 @@ Feature: Generate new WordPress posts
6060
howdy-3
6161
"""
6262
And STDERR should be empty
63+
64+
Scenario: Generating posts with post_date argument without time
65+
When I run `wp post generate --count=1 --post_date="2018-07-01"`
66+
And I run `wp post list --field=post_date`
67+
Then STDOUT should contain:
68+
"""
69+
2018-07-01 00:00:00
70+
"""
71+
And I run `wp post list --field=post_date_gmt`
72+
Then STDOUT should contain:
73+
"""
74+
2018-07-01 00:00:00
75+
"""
76+
77+
Scenario: Generating posts with post_date argument with time
78+
When I run `wp post generate --count=1 --post_date="2018-07-02 00:00:00"`
79+
And I run `wp post list --field=post_date`
80+
Then STDOUT should contain:
81+
"""
82+
2018-07-02 00:00:00
83+
"""
84+
And I run `wp post list --field=post_date_gmt`
85+
Then STDOUT should contain:
86+
"""
87+
2018-07-02 00:00:00
88+
"""
89+
90+
Scenario: Generating posts with post_date_gmt argument without time
91+
When I run `wp post generate --count=1 --post_date_gmt="2018-07-03"`
92+
And I run `wp post list --field=post_date`
93+
Then STDOUT should contain:
94+
"""
95+
2018-07-03 00:00:00
96+
"""
97+
And I run `wp post list --field=post_date_gmt`
98+
Then STDOUT should contain:
99+
"""
100+
2018-07-03 00:00:00
101+
"""
102+
103+
Scenario: Generating posts with post_date_gmt argument with time
104+
When I run `wp post generate --count=1 --post_date_gmt="2018-07-04 00:00:00"`
105+
And I run `wp post list --field=post_date`
106+
Then STDOUT should contain:
107+
"""
108+
2018-07-04 00:00:00
109+
"""
110+
And I run `wp post list --field=post_date_gmt`
111+
Then STDOUT should contain:
112+
"""
113+
2018-07-04 00:00:00
114+
"""

src/Post_Command.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,15 +683,21 @@ public function generate( $args, $assoc_args ) {
683683
'post_type' => 'post',
684684
'post_status' => 'publish',
685685
'post_author' => false,
686-
'post_date' => current_time( 'mysql' ),
686+
'post_date' => false,
687687
'post_date_gmt' => false,
688688
'post_content' => '',
689689
'post_title' => '',
690690
);
691691
extract( array_merge( $defaults, $assoc_args ), EXTR_SKIP );
692692

693+
$call_time = current_time( 'mysql' );
694+
693695
if ( $post_date_gmt === false ) {
694-
$post_date_gmt = $post_date;
696+
$post_date_gmt = $post_date ? $post_date : $call_time;
697+
}
698+
699+
if ( $post_date === false ) {
700+
$post_date = $post_date_gmt ? $post_date_gmt : $call_time;
695701
}
696702

697703
// @codingStandardsIgnoreStart

0 commit comments

Comments
 (0)