Skip to content

Commit 4df55dd

Browse files
committed
Tests: Use strict assertions for REST responses and theme previews.
Compare REST response status codes and theme-preview hook priorities with integer expectations. Check ability pagination headers against string expectations without casting the returned values. Developed in: WordPress#11707 Props shreyasikhar26. See #64895. git-svn-id: https://develop.svn.wordpress.org/trunk@63935 602fd350-edb4-49c9-b593-d223f7449a82
1 parent b33eb5e commit 4df55dd

6 files changed

Lines changed: 56 additions & 56 deletions

‎tests/phpunit/tests/rest-api/rest-attachments-controller.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3676,7 +3676,7 @@ public function test_edit_image_updates_attachment_fields() {
36763676
$response = rest_do_request( $request );
36773677

36783678
// The edit endpoint creates a new attachment, so we expect a 201 status.
3679-
$this->assertEquals( 201, $response->get_status() );
3679+
$this->assertSame( 201, $response->get_status() );
36803680

36813681
$data = $response->get_data();
36823682
$new_attachment_id = $data['id'];

‎tests/phpunit/tests/rest-api/rest-global-styles-controller.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ public function test_global_styles_route_accepts_integer_id() {
807807
$request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' . self::$global_styles_id );
808808
$response = rest_get_server()->dispatch( $request );
809809

810-
$this->assertEquals( 200, $response->get_status() );
810+
$this->assertSame( 200, $response->get_status() );
811811

812812
$data = $response->get_data();
813813
$this->assertIsInt( $data['id'] );

‎tests/phpunit/tests/rest-api/wpRestAbilitiesV1CategoriesController.php‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public function test_get_items(): void {
145145
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories' );
146146
$response = $this->server->dispatch( $request );
147147

148-
$this->assertEquals( 200, $response->get_status() );
148+
$this->assertSame( 200, $response->get_status() );
149149

150150
$data = $response->get_data();
151151
$this->assertIsArray( $data );
@@ -168,7 +168,7 @@ public function test_get_item(): void {
168168
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories/test-data-retrieval' );
169169
$response = $this->server->dispatch( $request );
170170

171-
$this->assertEquals( 200, $response->get_status() );
171+
$this->assertSame( 200, $response->get_status() );
172172

173173
$data = $response->get_data();
174174
$this->assertSame( 'test-data-retrieval', $data['slug'] );
@@ -186,7 +186,7 @@ public function test_get_item_with_meta(): void {
186186
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories/test-communication' );
187187
$response = $this->server->dispatch( $request );
188188

189-
$this->assertEquals( 200, $response->get_status() );
189+
$this->assertSame( 200, $response->get_status() );
190190

191191
$data = $response->get_data();
192192
$this->assertSame( 'test-communication', $data['slug'] );
@@ -207,7 +207,7 @@ public function test_get_item_with_selected_fields(): void {
207207
add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 );
208208
$response = apply_filters( 'rest_post_dispatch', $response, $this->server, $request );
209209

210-
$this->assertEquals( 200, $response->get_status() );
210+
$this->assertSame( 200, $response->get_status() );
211211

212212
$data = $response->get_data();
213213
$this->assertCount( 2, $data, 'Response should only contain the requested fields.' );
@@ -224,7 +224,7 @@ public function test_get_item_not_found(): void {
224224
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories/non-existent' );
225225
$response = $this->server->dispatch( $request );
226226

227-
$this->assertEquals( 404, $response->get_status() );
227+
$this->assertSame( 404, $response->get_status() );
228228

229229
$data = $response->get_data();
230230
$this->assertSame( 'rest_ability_category_not_found', $data['code'] );
@@ -241,7 +241,7 @@ public function test_get_items_permission_denied(): void {
241241
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories' );
242242
$response = $this->server->dispatch( $request );
243243

244-
$this->assertEquals( 401, $response->get_status() );
244+
$this->assertSame( 401, $response->get_status() );
245245
}
246246

247247
/**
@@ -255,7 +255,7 @@ public function test_get_item_permission_denied(): void {
255255
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories/test-data-retrieval' );
256256
$response = $this->server->dispatch( $request );
257257

258-
$this->assertEquals( 401, $response->get_status() );
258+
$this->assertSame( 401, $response->get_status() );
259259
}
260260

261261
/**
@@ -268,15 +268,15 @@ public function test_pagination_headers(): void {
268268
$request->set_param( 'per_page', 10 );
269269
$response = $this->server->dispatch( $request );
270270

271-
$this->assertEquals( 200, $response->get_status() );
271+
$this->assertSame( 200, $response->get_status() );
272272

273273
$headers = $response->get_headers();
274274
$this->assertArrayHasKey( 'X-WP-Total', $headers );
275275
$this->assertArrayHasKey( 'X-WP-TotalPages', $headers );
276276

277277
$total_categories = count( wp_get_ability_categories() );
278-
$this->assertSame( $total_categories, (int) $headers['X-WP-Total'] );
279-
$this->assertEquals( ceil( $total_categories / 10 ), (int) $headers['X-WP-TotalPages'] );
278+
$this->assertSame( (string) $total_categories, $headers['X-WP-Total'] );
279+
$this->assertSame( (string) ceil( $total_categories / 10 ), $headers['X-WP-TotalPages'] );
280280
}
281281

282282
/**
@@ -349,7 +349,7 @@ public function test_collection_params(): void {
349349
$request->set_param( 'page', 2 );
350350
$response = $this->server->dispatch( $request );
351351

352-
$this->assertEquals( 200, $response->get_status() );
352+
$this->assertSame( 200, $response->get_status() );
353353
$data = $response->get_data();
354354
$this->assertCount( 5, $data );
355355

@@ -447,7 +447,7 @@ public function test_get_schema(): void {
447447
public function test_ability_category_slug_with_valid_format(): void {
448448
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/categories/test-data-retrieval' );
449449
$response = $this->server->dispatch( $request );
450-
$this->assertEquals( 200, $response->get_status() );
450+
$this->assertSame( 200, $response->get_status() );
451451
}
452452

453453
/**

‎tests/phpunit/tests/rest-api/wpRestAbilitiesV1ListController.php‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ public function test_get_items(): void {
304304
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities' );
305305
$response = $this->server->dispatch( $request );
306306

307-
$this->assertEquals( 200, $response->get_status() );
307+
$this->assertSame( 200, $response->get_status() );
308308

309309
$data = $response->get_data();
310310
$this->assertIsArray( $data );
@@ -327,7 +327,7 @@ public function test_get_item(): void {
327327
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities/test/calculator' );
328328
$response = $this->server->dispatch( $request );
329329

330-
$this->assertEquals( 200, $response->get_status() );
330+
$this->assertSame( 200, $response->get_status() );
331331

332332
$data = $response->get_data();
333333
$this->assertCount( 7, $data, 'Response should contain all fields.' );
@@ -353,7 +353,7 @@ public function test_get_item_with_selected_fields(): void {
353353
add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 );
354354
$response = apply_filters( 'rest_post_dispatch', $response, $this->server, $request );
355355

356-
$this->assertEquals( 200, $response->get_status() );
356+
$this->assertSame( 200, $response->get_status() );
357357

358358
$data = $response->get_data();
359359
$this->assertCount( 2, $data, 'Response should only contain the requested fields.' );
@@ -373,7 +373,7 @@ public function test_get_item_with_embed_context(): void {
373373
add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 );
374374
$response = apply_filters( 'rest_post_dispatch', $response, $this->server, $request );
375375

376-
$this->assertEquals( 200, $response->get_status() );
376+
$this->assertSame( 200, $response->get_status() );
377377

378378
$data = $response->get_data();
379379
$this->assertCount( 3, $data, 'Response should only contain the fields for embed context.' );
@@ -391,7 +391,7 @@ public function test_get_item_not_found(): void {
391391
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities/non/existent' );
392392
$response = $this->server->dispatch( $request );
393393

394-
$this->assertEquals( 404, $response->get_status() );
394+
$this->assertSame( 404, $response->get_status() );
395395

396396
$data = $response->get_data();
397397
$this->assertSame( 'rest_ability_not_found', $data['code'] );
@@ -406,7 +406,7 @@ public function test_get_item_not_show_in_rest(): void {
406406
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities/test/not-show-in-rest' );
407407
$response = $this->server->dispatch( $request );
408408

409-
$this->assertEquals( 404, $response->get_status() );
409+
$this->assertSame( 404, $response->get_status() );
410410

411411
$data = $response->get_data();
412412
$this->assertSame( 'rest_ability_not_found', $data['code'] );
@@ -484,7 +484,7 @@ public function test_get_items_permission_denied(): void {
484484
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities' );
485485
$response = $this->server->dispatch( $request );
486486

487-
$this->assertEquals( 401, $response->get_status() );
487+
$this->assertSame( 401, $response->get_status() );
488488
}
489489

490490
/**
@@ -497,15 +497,15 @@ public function test_pagination_headers(): void {
497497
$request->set_param( 'per_page', 10 );
498498
$response = $this->server->dispatch( $request );
499499

500-
$this->assertEquals( 200, $response->get_status() );
500+
$this->assertSame( 200, $response->get_status() );
501501

502502
$headers = $response->get_headers();
503503
$this->assertArrayHasKey( 'X-WP-Total', $headers );
504504
$this->assertArrayHasKey( 'X-WP-TotalPages', $headers );
505505

506506
$total_abilities = count( wp_get_abilities() ) - 1; // Exclude the one that doesn't show in REST.
507-
$this->assertSame( $total_abilities, (int) $headers['X-WP-Total'] );
508-
$this->assertEquals( ceil( $total_abilities / 10 ), (int) $headers['X-WP-TotalPages'] );
507+
$this->assertSame( (string) $total_abilities, $headers['X-WP-Total'] );
508+
$this->assertSame( (string) ceil( $total_abilities / 10 ), $headers['X-WP-TotalPages'] );
509509
}
510510

511511
/**
@@ -587,7 +587,7 @@ public function test_collection_params(): void {
587587
$request->set_param( 'page', 2 );
588588
$response = $this->server->dispatch( $request );
589589

590-
$this->assertEquals( 200, $response->get_status() );
590+
$this->assertSame( 200, $response->get_status() );
591591
$data = $response->get_data();
592592
$this->assertCount( 5, $data );
593593

@@ -725,7 +725,7 @@ public function test_ability_name_with_valid_special_characters(): void {
725725

726726
wp_unregister_ability( 'test-hyphen/ability' );
727727

728-
$this->assertEquals( 200, $response->get_status() );
728+
$this->assertSame( 200, $response->get_status() );
729729
}
730730

731731
/**
@@ -759,7 +759,7 @@ public function test_ability_name_with_invalid_special_characters( string $name
759759
$request = new WP_REST_Request( 'GET', '/wp-abilities/v1/abilities/' . $name );
760760
$response = $this->server->dispatch( $request );
761761
// Should return 404 as the regex pattern won't match
762-
$this->assertEquals( 404, $response->get_status() );
762+
$this->assertSame( 404, $response->get_status() );
763763
}
764764

765765
/**
@@ -776,7 +776,7 @@ public function test_extremely_long_ability_names(): void {
776776
$response = $this->server->dispatch( $request );
777777

778778
// Should return 404 as ability doesn't exist
779-
$this->assertEquals( 404, $response->get_status() );
779+
$this->assertSame( 404, $response->get_status() );
780780
}
781781

782782
/**
@@ -833,7 +833,7 @@ public function test_filter_by_category(): void {
833833
$request->set_param( 'category', 'math' );
834834
$response = $this->server->dispatch( $request );
835835

836-
$this->assertEquals( 200, $response->get_status() );
836+
$this->assertSame( 200, $response->get_status() );
837837

838838
$data = $response->get_data();
839839
$this->assertIsArray( $data );
@@ -865,7 +865,7 @@ public function test_filter_by_nonexistent_category(): void {
865865
$request->set_param( 'category', 'nonexistent' );
866866
$response = $this->server->dispatch( $request );
867867

868-
$this->assertEquals( 200, $response->get_status() );
868+
$this->assertSame( 200, $response->get_status() );
869869

870870
$data = $response->get_data();
871871
$this->assertIsArray( $data );

0 commit comments

Comments
 (0)