Skip to content

Commit 8e52876

Browse files
authored
Merge pull request #471 from ProgressPlanner/filip/v14/increase-min-posts
Correction for min post count when updating term descriptions
2 parents 0e7d7ac + 464e82b commit 8e52876

2 files changed

Lines changed: 56 additions & 20 deletions

File tree

classes/suggested-tasks/data-collector/class-terms-without-description.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Terms_Without_Description extends Base_Data_Collector {
2626
*
2727
* @var int
2828
*/
29-
protected const MIN_POSTS = 1;
29+
protected const MIN_POSTS = 2;
3030

3131
/**
3232
* Initialize the data collector.

tests/phpunit/test-class-terms-without-description-data-collector.php

Lines changed: 55 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,28 @@ public function test_collect_returns_terms_without_description() {
7070
$this->assertNotWPError( $term_result );
7171
$term_id = $term_result['term_id'];
7272

73-
// Create a post and assign the term to it.
74-
$post_id = wp_insert_post(
73+
// Create two posts and assign the term to them.
74+
$post_id1 = wp_insert_post(
75+
[
76+
'post_title' => 'Test Post 1',
77+
'post_content' => 'Test content 1',
78+
'post_status' => 'publish',
79+
'post_type' => 'post',
80+
]
81+
);
82+
$this->assertNotWPError( $post_id1 );
83+
wp_set_object_terms( $post_id1, $term_id, 'category' );
84+
85+
$post_id2 = wp_insert_post(
7586
[
76-
'post_title' => 'Test Post',
77-
'post_content' => 'Test content',
87+
'post_title' => 'Test Post 2',
88+
'post_content' => 'Test content 2',
7889
'post_status' => 'publish',
7990
'post_type' => 'post',
8091
]
8192
);
82-
$this->assertNotWPError( $post_id );
83-
wp_set_object_terms( $post_id, $term_id, 'category' );
93+
$this->assertNotWPError( $post_id2 );
94+
wp_set_object_terms( $post_id2, $term_id, 'category' );
8495

8596
// Get the data.
8697
$this->data_collector->update_cache();
@@ -93,7 +104,8 @@ public function test_collect_returns_terms_without_description() {
93104
$this->assertEquals( 'category', $result['taxonomy'] );
94105

95106
// Clean up.
96-
wp_delete_post( $post_id );
107+
wp_delete_post( $post_id1 );
108+
wp_delete_post( $post_id2 );
97109
}
98110

99111
/**
@@ -147,16 +159,27 @@ public function test_cache_is_updated_when_term_is_edited() {
147159
$term_id = $term_result['term_id'];
148160

149161
// Create a post and assign the term to it.
150-
$post_id = wp_insert_post(
162+
$post_id1 = wp_insert_post(
151163
[
152-
'post_title' => 'Test Post',
153-
'post_content' => 'Test content',
164+
'post_title' => 'Test Post 1',
165+
'post_content' => 'Test content 1',
154166
'post_status' => 'publish',
155167
'post_type' => 'post',
156168
]
157169
);
158-
$this->assertNotWPError( $post_id );
159-
wp_set_object_terms( $post_id, $term_id, 'category' );
170+
$this->assertNotWPError( $post_id1 );
171+
wp_set_object_terms( $post_id1, $term_id, 'category' );
172+
173+
$post_id2 = wp_insert_post(
174+
[
175+
'post_title' => 'Test Post 2',
176+
'post_content' => 'Test content 2',
177+
'post_status' => 'publish',
178+
'post_type' => 'post',
179+
]
180+
);
181+
$this->assertNotWPError( $post_id2 );
182+
wp_set_object_terms( $post_id2, $term_id, 'category' );
160183

161184
// Get initial data.
162185
$this->data_collector->update_cache();
@@ -180,7 +203,8 @@ public function test_cache_is_updated_when_term_is_edited() {
180203
$this->assertNull( $updated_result );
181204

182205
// Clean up.
183-
wp_delete_post( $post_id );
206+
wp_delete_post( $post_id1 );
207+
wp_delete_post( $post_id2 );
184208
}
185209

186210
/**
@@ -193,16 +217,27 @@ public function test_cache_is_updated_when_term_is_deleted() {
193217
$term_id = $term_result['term_id'];
194218

195219
// Create a post and assign the term to it.
196-
$post_id = wp_insert_post(
220+
$post_id1 = wp_insert_post(
221+
[
222+
'post_title' => 'Test Post 1',
223+
'post_content' => 'Test content 1',
224+
'post_status' => 'publish',
225+
'post_type' => 'post',
226+
]
227+
);
228+
$this->assertNotWPError( $post_id1 );
229+
wp_set_object_terms( $post_id1, $term_id, 'category' );
230+
231+
$post_id2 = wp_insert_post(
197232
[
198-
'post_title' => 'Test Post',
199-
'post_content' => 'Test content',
233+
'post_title' => 'Test Post 2',
234+
'post_content' => 'Test content 2',
200235
'post_status' => 'publish',
201236
'post_type' => 'post',
202237
]
203238
);
204-
$this->assertNotWPError( $post_id );
205-
wp_set_object_terms( $post_id, $term_id, 'category' );
239+
$this->assertNotWPError( $post_id2 );
240+
wp_set_object_terms( $post_id2, $term_id, 'category' );
206241

207242
// Get initial data.
208243
$this->data_collector->update_cache();
@@ -220,7 +255,8 @@ public function test_cache_is_updated_when_term_is_deleted() {
220255
$this->assertNull( $updated_result );
221256

222257
// Clean up.
223-
wp_delete_post( $post_id );
258+
wp_delete_post( $post_id1 );
259+
wp_delete_post( $post_id2 );
224260
}
225261

226262
/**

0 commit comments

Comments
 (0)