Skip to content

Commit fa7902c

Browse files
Tests: Use more specific assertions in WP_Script_Modules tests.
Follow-up to [57269], [57327], [57593]. See #60705. git-svn-id: https://develop.svn.wordpress.org/trunk@58420 602fd350-edb4-49c9-b593-d223f7449a82
1 parent dc6c8c8 commit fa7902c

1 file changed

Lines changed: 36 additions & 36 deletions

File tree

tests/phpunit/tests/script-modules/wpScriptModules.php

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ public function test_wp_dequeue_script_module() {
122122
$enqueued_script_modules = $this->get_enqueued_script_modules();
123123

124124
$this->assertCount( 1, $enqueued_script_modules );
125-
$this->assertFalse( isset( $enqueued_script_modules['foo'] ) );
126-
$this->assertTrue( isset( $enqueued_script_modules['bar'] ) );
125+
$this->assertArrayNotHasKey( 'foo', $enqueued_script_modules );
126+
$this->assertArrayHasKey( 'bar', $enqueued_script_modules );
127127
}
128128

129129

@@ -149,8 +149,8 @@ public function test_wp_deregister_script_module() {
149149
$enqueued_script_modules = $this->get_enqueued_script_modules();
150150

151151
$this->assertCount( 1, $enqueued_script_modules );
152-
$this->assertFalse( isset( $enqueued_script_modules['foo'] ) );
153-
$this->assertTrue( isset( $enqueued_script_modules['bar'] ) );
152+
$this->assertArrayNotHasKey( 'foo', $enqueued_script_modules );
153+
$this->assertArrayHasKey( 'bar', $enqueued_script_modules );
154154
}
155155

156156
/**
@@ -168,7 +168,7 @@ public function test_wp_deregister_unexistent_script_module() {
168168
$enqueued_script_modules = $this->get_enqueued_script_modules();
169169

170170
$this->assertCount( 0, $enqueued_script_modules );
171-
$this->assertFalse( isset( $enqueued_script_modules['unexistent'] ) );
171+
$this->assertArrayNotHasKey( 'unexistent', $enqueued_script_modules );
172172
}
173173

174174
/**
@@ -190,13 +190,13 @@ public function test_wp_deregister_already_deregistered_script_module() {
190190
$enqueued_script_modules = $this->get_enqueued_script_modules();
191191

192192
$this->assertCount( 0, $enqueued_script_modules );
193-
$this->assertFalse( isset( $enqueued_script_modules['foo'] ) );
193+
$this->assertArrayNotHasKey( 'foo', $enqueued_script_modules );
194194

195195
$this->script_modules->deregister( 'foo' ); // Dequeued.
196196
$enqueued_script_modules = $this->get_enqueued_script_modules();
197197

198198
$this->assertCount( 0, $enqueued_script_modules );
199-
$this->assertFalse( isset( $enqueued_script_modules['foo'] ) );
199+
$this->assertArrayNotHasKey( 'foo', $enqueued_script_modules );
200200
}
201201

202202
/**
@@ -218,7 +218,7 @@ public function test_wp_enqueue_script_module_works_before_register() {
218218

219219
$this->assertCount( 1, $enqueued_script_modules );
220220
$this->assertStringStartsWith( '/foo.js', $enqueued_script_modules['foo'] );
221-
$this->assertFalse( isset( $enqueued_script_modules['bar'] ) );
221+
$this->assertArrayNotHasKey( 'bar', $enqueued_script_modules );
222222
}
223223

224224
/**
@@ -242,8 +242,8 @@ public function test_wp_dequeue_script_module_works_before_register() {
242242
$enqueued_script_modules = $this->get_enqueued_script_modules();
243243

244244
$this->assertCount( 1, $enqueued_script_modules );
245-
$this->assertFalse( isset( $enqueued_script_modules['foo'] ) );
246-
$this->assertTrue( isset( $enqueued_script_modules['bar'] ) );
245+
$this->assertArrayNotHasKey( 'foo', $enqueued_script_modules );
246+
$this->assertArrayHasKey( 'bar', $enqueued_script_modules );
247247
}
248248

249249
/**
@@ -266,7 +266,7 @@ public function test_wp_import_map_dependencies() {
266266

267267
$this->assertCount( 1, $import_map );
268268
$this->assertStringStartsWith( '/dep.js', $import_map['dep'] );
269-
$this->assertFalse( isset( $import_map['no-dep'] ) );
269+
$this->assertArrayNotHasKey( 'no-dep', $import_map );
270270
}
271271

272272
/**
@@ -340,7 +340,7 @@ public function test_wp_import_map_recursive_dependencies() {
340340
$this->assertStringStartsWith( '/dynamic-dep.js', $import_map['dynamic-dep'] );
341341
$this->assertStringStartsWith( '/nested-static-dep.js', $import_map['nested-static-dep'] );
342342
$this->assertStringStartsWith( '/nested-dynamic-dep.js', $import_map['nested-dynamic-dep'] );
343-
$this->assertFalse( isset( $import_map['no-dep'] ) );
343+
$this->assertArrayNotHasKey( 'no-dep', $import_map );
344344
}
345345

346346
/**
@@ -409,9 +409,9 @@ public function test_wp_enqueue_preloaded_static_dependencies() {
409409
$this->assertCount( 2, $preloaded_script_modules );
410410
$this->assertStringStartsWith( '/static-dep.js', $preloaded_script_modules['static-dep'] );
411411
$this->assertStringStartsWith( '/nested-static-dep.js', $preloaded_script_modules['nested-static-dep'] );
412-
$this->assertFalse( isset( $preloaded_script_modules['no-dep'] ) );
413-
$this->assertFalse( isset( $preloaded_script_modules['dynamic-dep'] ) );
414-
$this->assertFalse( isset( $preloaded_script_modules['nested-dynamic-dep'] ) );
412+
$this->assertArrayNotHasKey( 'dynamic-dep', $preloaded_script_modules );
413+
$this->assertArrayNotHasKey( 'nested-dynamic-dep', $preloaded_script_modules );
414+
$this->assertArrayNotHasKey( 'no-dep', $preloaded_script_modules );
415415
}
416416

417417
/**
@@ -445,9 +445,9 @@ public function test_wp_dont_preload_static_dependencies_of_dynamic_dependencies
445445

446446
$this->assertCount( 1, $preloaded_script_modules );
447447
$this->assertStringStartsWith( '/static-dep.js', $preloaded_script_modules['static-dep'] );
448-
$this->assertFalse( isset( $preloaded_script_modules['dynamic-dep'] ) );
449-
$this->assertFalse( isset( $preloaded_script_modules['nested-static-dep'] ) );
450-
$this->assertFalse( isset( $preloaded_script_modules['no-dep'] ) );
448+
$this->assertArrayNotHasKey( 'dynamic-dep', $preloaded_script_modules );
449+
$this->assertArrayNotHasKey( 'nested-dynamic-dep', $preloaded_script_modules );
450+
$this->assertArrayNotHasKey( 'no-dep', $preloaded_script_modules );
451451
}
452452

453453
/**
@@ -476,8 +476,8 @@ public function test_wp_preloaded_dependencies_filter_enqueued_script_modules()
476476
$preloaded_script_modules = $this->get_preloaded_script_modules();
477477

478478
$this->assertCount( 1, $preloaded_script_modules );
479-
$this->assertTrue( isset( $preloaded_script_modules['dep'] ) );
480-
$this->assertFalse( isset( $preloaded_script_modules['enqueued-dep'] ) );
479+
$this->assertArrayHasKey( 'dep', $preloaded_script_modules );
480+
$this->assertArrayNotHasKey( 'enqueued-dep', $preloaded_script_modules );
481481
}
482482

483483
/**
@@ -507,8 +507,8 @@ public function test_wp_enqueued_script_modules_with_dependants_add_import_map()
507507
$import_map = $this->get_import_map();
508508

509509
$this->assertCount( 2, $import_map );
510-
$this->assertTrue( isset( $import_map['dep'] ) );
511-
$this->assertTrue( isset( $import_map['enqueued-dep'] ) );
510+
$this->assertArrayHasKey( 'dep', $import_map );
511+
$this->assertArrayHasKey( 'enqueued-dep', $import_map );
512512
}
513513

514514
/**
@@ -531,7 +531,7 @@ public function test_get_src() {
531531
);
532532

533533
$result = $get_src->invoke( $this->script_modules, 'module_with_version' );
534-
$this->assertEquals( 'http://example.com/module.js?ver=1.0', $result );
534+
$this->assertSame( 'http://example.com/module.js?ver=1.0', $result );
535535

536536
$this->script_modules->register(
537537
'module_without_version',
@@ -541,7 +541,7 @@ public function test_get_src() {
541541
);
542542

543543
$result = $get_src->invoke( $this->script_modules, 'module_without_version' );
544-
$this->assertEquals( 'http://example.com/module.js', $result );
544+
$this->assertSame( 'http://example.com/module.js', $result );
545545

546546
$this->script_modules->register(
547547
'module_with_wp_version',
@@ -551,7 +551,7 @@ public function test_get_src() {
551551
);
552552

553553
$result = $get_src->invoke( $this->script_modules, 'module_with_wp_version' );
554-
$this->assertEquals( 'http://example.com/module.js?ver=' . get_bloginfo( 'version' ), $result );
554+
$this->assertSame( 'http://example.com/module.js?ver=' . get_bloginfo( 'version' ), $result );
555555

556556
$this->script_modules->register(
557557
'module_with_existing_query_string',
@@ -561,7 +561,7 @@ public function test_get_src() {
561561
);
562562

563563
$result = $get_src->invoke( $this->script_modules, 'module_with_existing_query_string' );
564-
$this->assertEquals( 'http://example.com/module.js?foo=bar&ver=1.0', $result );
564+
$this->assertSame( 'http://example.com/module.js?foo=bar&ver=1.0', $result );
565565

566566
// Filter the version to include the ID in the final URL, to test the filter, this should affect the tests below.
567567
add_filter(
@@ -574,10 +574,10 @@ function ( $src, $id ) {
574574
);
575575

576576
$result = $get_src->invoke( $this->script_modules, 'module_without_version' );
577-
$this->assertEquals( 'http://example.com/module.js?script_module_id=module_without_version', $result );
577+
$this->assertSame( 'http://example.com/module.js?script_module_id=module_without_version', $result );
578578

579579
$result = $get_src->invoke( $this->script_modules, 'module_with_existing_query_string' );
580-
$this->assertEquals( 'http://example.com/module.js?foo=bar&ver=1.0&script_module_id=module_with_existing_query_string', $result );
580+
$this->assertSame( 'http://example.com/module.js?foo=bar&ver=1.0&script_module_id=module_with_existing_query_string', $result );
581581
}
582582

583583
/**
@@ -606,13 +606,13 @@ public function test_version_is_propagated_correctly() {
606606
$this->script_modules->enqueue( 'foo' );
607607

608608
$enqueued_script_modules = $this->get_enqueued_script_modules();
609-
$this->assertEquals( '/foo.js?ver=1.0', $enqueued_script_modules['foo'] );
609+
$this->assertSame( '/foo.js?ver=1.0', $enqueued_script_modules['foo'] );
610610

611611
$import_map = $this->get_import_map();
612-
$this->assertEquals( '/dep.js?ver=2.0', $import_map['dep'] );
612+
$this->assertSame( '/dep.js?ver=2.0', $import_map['dep'] );
613613

614614
$preloaded_script_modules = $this->get_preloaded_script_modules();
615-
$this->assertEquals( '/dep.js?ver=2.0', $preloaded_script_modules['dep'] );
615+
$this->assertSame( '/dep.js?ver=2.0', $preloaded_script_modules['dep'] );
616616
}
617617

618618
/**
@@ -630,7 +630,7 @@ public function test_wp_enqueue_script_module_doesnt_register_without_a_valid_sr
630630
$enqueued_script_modules = $this->get_enqueued_script_modules();
631631

632632
$this->assertCount( 0, $enqueued_script_modules );
633-
$this->assertFalse( isset( $enqueued_script_modules['foo'] ) );
633+
$this->assertArrayNotHasKey( 'foo', $enqueued_script_modules );
634634
}
635635

636636
/**
@@ -666,7 +666,7 @@ public function test_wp_enqueue_script_module_registers_with_valid_src_the_secon
666666
$enqueued_script_modules = $this->get_enqueued_script_modules();
667667

668668
$this->assertCount( 0, $enqueued_script_modules );
669-
$this->assertFalse( isset( $enqueued_script_modules['foo'] ) );
669+
$this->assertArrayNotHasKey( 'foo', $enqueued_script_modules );
670670

671671
$this->script_modules->enqueue( 'foo', '/foo.js' ); // Valid src.
672672

@@ -695,7 +695,7 @@ public function test_wp_enqueue_script_module_registers_all_params() {
695695
$import_map = $this->get_import_map();
696696

697697
$this->assertCount( 1, $enqueued_script_modules );
698-
$this->assertEquals( '/foo.js?ver=1.0', $enqueued_script_modules['foo'] );
698+
$this->assertSame( '/foo.js?ver=1.0', $enqueued_script_modules['foo'] );
699699
$this->assertCount( 1, $import_map );
700700
$this->assertStringStartsWith( '/dep.js', $import_map['dep'] );
701701
}
@@ -708,7 +708,7 @@ public function test_wp_enqueue_script_module_registers_all_params() {
708708
public function test_wp_print_import_map_has_no_polyfill_when_no_modules_registered() {
709709
$import_map_polyfill = get_echo( array( $this->script_modules, 'print_import_map' ) );
710710

711-
$this->assertEquals( '', $import_map_polyfill );
711+
$this->assertSame( '', $import_map_polyfill );
712712
}
713713

714714
/**
@@ -730,6 +730,6 @@ public function test_wp_print_import_map_has_polyfill_when_modules_registered()
730730
$p->next_tag( array( 'tag' => 'SCRIPT' ) );
731731
$id = $p->get_attribute( 'id' );
732732

733-
$this->assertEquals( 'wp-load-polyfill-importmap', $id );
733+
$this->assertSame( 'wp-load-polyfill-importmap', $id );
734734
}
735735
}

0 commit comments

Comments
 (0)