Skip to content

Commit f812fc5

Browse files
committed
Update tests
1 parent 087ee6b commit f812fc5

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

features/post-revision.feature

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Feature: Manage WordPress post revisions
6464
Success: Updated post {POST_ID}.
6565
"""
6666

67-
When I run `wp post update {POST_ID} --post_content='Third version'`
67+
When I run `wp post update {POST_ID} --post_title='New Title' --post_content='Third version'`
6868
Then STDOUT should contain:
6969
"""
7070
Success: Updated post {POST_ID}.
@@ -81,7 +81,19 @@ Feature: Manage WordPress post revisions
8181
Then save STDOUT as {REVISION_ID_2}
8282

8383
When I run `wp post revision diff {REVISION_ID_1} {REVISION_ID_2}`
84-
Then the return code should be 0
84+
Then STDOUT should contain:
85+
"""
86+
- Second version
87+
+ Third version
88+
"""
89+
And STDOUT should contain:
90+
"""
91+
--- Test Post
92+
"""
93+
And STDOUT should contain:
94+
"""
95+
+++ New Title
96+
"""
8597

8698
Scenario: Show diff between revision and current post
8799
When I run `wp post create --post_title='Diff Test' --post_content='Original text' --porcelain`
@@ -99,7 +111,10 @@ Feature: Manage WordPress post revisions
99111
And save STDOUT as {REVISION_ID}
100112

101113
When I run `wp post revision diff {REVISION_ID}`
102-
Then the return code should be 0
114+
Then STDOUT should contain:
115+
"""
116+
Success: No difference found.
117+
"""
103118

104119
Scenario: Diff with invalid revision should fail
105120
When I try `wp post revision diff 99999`

src/Post_Revision_Command.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ public function diff( $args, $assoc_args ) {
161161
$left_lines = explode( "\n", $left_string );
162162
$right_lines = explode( "\n", $right_string );
163163

164+
if ( ! class_exists( 'Text_Diff', false ) ) {
165+
// @phpstan-ignore constant.notFound
166+
require ABSPATH . WPINC . '/wp-diff.php';
167+
}
168+
164169
// Create Text_Diff object
165170
$text_diff = new \Text_Diff( 'auto', [ $left_lines, $right_lines ] );
166171

0 commit comments

Comments
 (0)