Skip to content

Commit 0e18cda

Browse files
committed
Tests: Tighten admin and update assertions.
Use `assertSame()` for attachment fields, color-scheme output, and the empty PHP update annotation. Document intentional metadata and object-value comparisons. Developed in: #15891 Props shailu25, desrosj. See #64895. git-svn-id: https://develop.svn.wordpress.org/trunk@65442 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 6872cd4 commit 0e18cda

6 files changed

Lines changed: 18 additions & 14 deletions

File tree

‎tests/phpunit/tests/admin/includes/ajax-actions/saveAttachmentOrder.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ public function test_save_attachment_order_success(): void {
9696

9797
$this->assertTrue( $response['success'], 'AJAX response should be successful' );
9898

99-
$this->assertEquals( 10, get_post( self::$attachment_ids[0] )->menu_order, 'First attachment menu_order should be 10' );
100-
$this->assertEquals( 20, get_post( self::$attachment_ids[1] )->menu_order, 'Second attachment menu_order should be 20' );
99+
$this->assertSame( 10, get_post( self::$attachment_ids[0] )->menu_order, 'First attachment menu_order should be 10' );
100+
$this->assertSame( 20, get_post( self::$attachment_ids[1] )->menu_order, 'Second attachment menu_order should be 20' );
101101
}
102102

103103
/**

‎tests/phpunit/tests/admin/includes/ajax-actions/sendAttachmentToEditor.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function test_send_attachment_to_editor_image_success(): void {
9393

9494
// Verify that the attachment was attached to the post.
9595
$attachment = get_post( self::$attachment_id );
96-
$this->assertEquals( self::$post_id, $attachment->post_parent, 'Attachment should be attached to the post' );
96+
$this->assertSame( self::$post_id, $attachment->post_parent, 'Attachment should be attached to the post' );
9797
}
9898

9999
/**

‎tests/phpunit/tests/admin/includes/misc/adminColorSchemePicker.php‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public function test_admin_color_scheme_picker_sorting() {
217217
}
218218

219219
$expected_order = array( 'modern', 'fresh', 'light', 'coffee', 'ocean' );
220-
$this->assertEquals( $expected_order, $found_colors, 'Color schemes should be ordered with modern, fresh, light first, followed by others alphabetically.' );
220+
$this->assertSame( $expected_order, $found_colors, 'Color schemes should be ordered with modern, fresh, light first, followed by others alphabetically.' );
221221
}
222222

223223
/**
@@ -250,29 +250,29 @@ public function test_admin_color_scheme_picker_html_structure() {
250250
$xpath = new DOMXPath( $dom );
251251

252252
// Check fieldset and legend.
253-
$this->assertEquals( 1, $xpath->query( '//fieldset[@id="color-picker"]' )->length );
254-
$this->assertEquals( 1, $xpath->query( '//legend' )->length );
253+
$this->assertSame( 1, $xpath->query( '//fieldset[@id="color-picker"]' )->length );
254+
$this->assertSame( 1, $xpath->query( '//legend' )->length );
255255

256256
// Check radio input.
257257
$radio = $xpath->query( '//input[@type="radio"][@value="modern"]' );
258-
$this->assertEquals( 1, $radio->length );
259-
$this->assertEquals( 'admin_color_modern', $radio->item( 0 )->getAttribute( 'id' ) );
258+
$this->assertSame( 1, $radio->length );
259+
$this->assertSame( 'admin_color_modern', $radio->item( 0 )->getAttribute( 'id' ) );
260260

261261
// Check hidden inputs.
262-
$this->assertEquals( 1, $xpath->query( '//input[@type="hidden"][@class="css_url"][@value="https://example.com/modern.css"]' )->length );
262+
$this->assertSame( 1, $xpath->query( '//input[@type="hidden"][@class="css_url"][@value="https://example.com/modern.css"]' )->length );
263263

264264
$icon_colors_input = $xpath->query( '//input[@type="hidden"][@class="icon_colors"]' );
265-
$this->assertEquals( 1, $icon_colors_input->length );
265+
$this->assertSame( 1, $icon_colors_input->length );
266266
$json_data = json_decode( $icon_colors_input->item( 0 )->getAttribute( 'value' ), true );
267-
$this->assertEquals( array( 'icons' => array( 'icons' => '#333' ) ), $json_data );
267+
$this->assertSame( array( 'icons' => array( 'icons' => '#333' ) ), $json_data );
268268

269269
// Check label.
270270
$label = $xpath->query( '//label[@for="admin_color_modern"]' );
271-
$this->assertEquals( 1, $label->length );
271+
$this->assertSame( 1, $label->length );
272272
$this->assertStringContainsString( 'Modern Display Name', $label->item( 0 )->nodeValue );
273273

274274
// Check color palette.
275-
$this->assertEquals( 2, $xpath->query( '//div[@class="color-palette-shade"]' )->length );
275+
$this->assertSame( 2, $xpath->query( '//div[@class="color-palette-shade"]' )->length );
276276
$this->assertStringContainsString( 'background-color: #111', $output );
277277
$this->assertStringContainsString( 'background-color: #222', $output );
278278
}

‎tests/phpunit/tests/admin/includes/misc/setScreenOptions.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public function test_set_screen_options( $option, $value, $expected ) {
6262
}
6363

6464
$meta = get_user_meta( $user_id, $option, true );
65+
// Keep assertEquals() because expected fixtures use integers while filter-passthrough options may store POST values as strings.
6566
$this->assertEquals( $expected, $meta );
6667
}
6768

@@ -149,6 +150,7 @@ public function test_set_screen_options_with_filters() {
149150
}
150151
}
151152

153+
// Keep assertEquals() because the filter returns the raw POST string while the assertion uses an integer.
152154
$this->assertEquals( 25, get_user_meta( $user_id, 'custom_per_page', true ) );
153155
}
154156

‎tests/phpunit/tests/admin/includesUpdate.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ public function test_wp_process_translation_update_selection_uses_current_packag
144144
$update->package = 'https://example.org/current.zip';
145145
set_site_transient( 'update_plugins', (object) array( 'translations' => array( (array) $update ) ) );
146146

147+
// Keep assertEquals() because the objects are intentionally compared by value.
147148
$this->assertEquals(
148149
array( $id => $update ),
149150
wp_process_translation_update_selection( array( $id ), array( $id ) )
@@ -496,6 +497,7 @@ static function ( $key ) use ( $updates ) {
496497
if ( false === $selected ) {
497498
$this->assertFalse( $actual );
498499
} else {
500+
// Keep assertEquals() because the objects are intentionally compared by value.
499501
$this->assertEquals( wp_get_translation_updates_by_id( $get_updates( $selected ) ), $actual );
500502
}
501503

‎tests/phpunit/tests/functions/wpGetUpdatePhpAnnotation.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Tests_functions_wpGetUpdatePhpAnnotation extends WP_UnitTestCase {
1414
* @ticket 59699
1515
*/
1616
public function test_wp_get_update_php_annotation() {
17-
$this->assertEquals( '', wp_get_update_php_annotation() );
17+
$this->assertSame( '', wp_get_update_php_annotation() );
1818
}
1919

2020
/**

0 commit comments

Comments
 (0)