Skip to content

Commit 1ca14da

Browse files
committed
Refactor test_note_type_exclusion to use expected_types
1 parent 1223d6a commit 1ca14da

File tree

1 file changed

+28
-27
lines changed

1 file changed

+28
-27
lines changed

tests/phpunit/tests/comment/query.php

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5405,64 +5405,65 @@ protected function create_note_type_test_comments(): array {
54055405
* @covers WP_Comment_Query::get_comment_ids
54065406
* @dataProvider data_note_type_exclusion
54075407
*
5408-
* @param array<string, string|array> $query_args Query arguments for WP_Comment_Query.
5409-
* @param int[] $expected_indices Indices of expected comments in the $comments array.
5408+
* @param array<string, string|array> $query_args Query arguments for WP_Comment_Query.
5409+
* @param string[] $expected_types Expected comment types.
54105410
*/
5411-
public function test_note_type_exclusion( array $query_args, array $expected_indices ) {
5412-
$comments = $this->create_note_type_test_comments();
5411+
public function test_note_type_exclusion( array $query_args, array $expected_types ) {
5412+
$this->create_note_type_test_comments();
54135413

54145414
$query = new WP_Comment_Query();
54155415
$found = $query->query( array_merge( $query_args, array( 'fields' => 'ids' ) ) );
54165416

5417-
$expected = array();
5418-
foreach ( $expected_indices as $index ) {
5419-
$keys = array_keys( $comments );
5420-
$expected[] = $comments[ $keys[ $index ] ];
5421-
}
5417+
$actual_types = array_map(
5418+
static function ( int $comment_id ): string {
5419+
return get_comment( $comment_id )->comment_type;
5420+
},
5421+
$found
5422+
);
54225423

5423-
$this->assertSameSets( $expected, $found );
5424+
$this->assertSameSets( $expected_types, $actual_types, 'Expected comment query to return comments of the these types.' );
54245425
}
54255426

54265427
/**
54275428
* Data provider for note type exclusion tests.
54285429
*
54295430
* @since 6.9.0
54305431
*
5431-
* @return array<string, array{ query_args: array<string, string|array>, expected_indices: int[] }>
5432+
* @return array<string, array{ query_args: array<string, string|array>, expected_types: string[] }>
54325433
*/
54335434
public function data_note_type_exclusion(): array {
54345435
return array(
54355436
'default query excludes note' => array(
5436-
'query_args' => array(),
5437-
'expected_indices' => array( 0, 1 ), // comment and pingback.
5437+
'query_args' => array(),
5438+
'expected_types' => array( 'comment', 'pingback' ),
54385439
),
54395440
'empty type parameter excludes note' => array(
5440-
'query_args' => array( 'type' => '' ),
5441-
'expected_indices' => array( 0, 1 ), // comment and pingback.
5441+
'query_args' => array( 'type' => '' ),
5442+
'expected_types' => array( 'comment', 'pingback' ),
54425443
),
54435444
'type all includes note' => array(
5444-
'query_args' => array( 'type' => 'all' ),
5445-
'expected_indices' => array( 0, 1, 2 ), // comment, pingback, and note.
5445+
'query_args' => array( 'type' => 'all' ),
5446+
'expected_types' => array( 'comment', 'pingback', 'note' ),
54465447
),
54475448
'explicit note type' => array(
5448-
'query_args' => array( 'type' => 'note' ),
5449-
'expected_indices' => array( 2 ), // only note.
5449+
'query_args' => array( 'type' => 'note' ),
5450+
'expected_types' => array( 'note' ),
54505451
),
54515452
'type__in with note' => array(
5452-
'query_args' => array( 'type__in' => array( 'note' ) ),
5453-
'expected_indices' => array( 2 ), // only note.
5453+
'query_args' => array( 'type__in' => array( 'note' ) ),
5454+
'expected_types' => array( 'note' ),
54545455
),
54555456
'type__in with note and pingback' => array(
5456-
'query_args' => array( 'type__in' => array( 'note', 'pingback' ) ),
5457-
'expected_indices' => array( 1, 2 ), // pingback and note.
5457+
'query_args' => array( 'type__in' => array( 'note', 'pingback' ) ),
5458+
'expected_types' => array( 'note', 'pingback' ),
54585459
),
54595460
'type pings excludes note' => array(
5460-
'query_args' => array( 'type' => 'pings' ),
5461-
'expected_indices' => array( 1 ), // only pingback.
5461+
'query_args' => array( 'type' => 'pings' ),
5462+
'expected_types' => array( 'pingback' ),
54625463
),
54635464
'type__not_in with note' => array(
5464-
'query_args' => array( 'type__not_in' => array( 'note' ) ),
5465-
'expected_indices' => array( 0, 1 ), // comment and pingback.
5465+
'query_args' => array( 'type__not_in' => array( 'note' ) ),
5466+
'expected_types' => array( 'comment', 'pingback' ),
54665467
),
54675468
);
54685469
}

0 commit comments

Comments
 (0)