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
This commit is contained in:
Sergey Biryukov 2024-06-16 10:15:33 +00:00
parent dc6c8c8ea0
commit fa7902c8c8

View File

@ -122,8 +122,8 @@ class Tests_Script_Modules_WpScriptModules extends WP_UnitTestCase {
$enqueued_script_modules = $this->get_enqueued_script_modules();
$this->assertCount( 1, $enqueued_script_modules );
$this->assertFalse( isset( $enqueued_script_modules['foo'] ) );
$this->assertTrue( isset( $enqueued_script_modules['bar'] ) );
$this->assertArrayNotHasKey( 'foo', $enqueued_script_modules );
$this->assertArrayHasKey( 'bar', $enqueued_script_modules );
}
@ -149,8 +149,8 @@ class Tests_Script_Modules_WpScriptModules extends WP_UnitTestCase {
$enqueued_script_modules = $this->get_enqueued_script_modules();
$this->assertCount( 1, $enqueued_script_modules );
$this->assertFalse( isset( $enqueued_script_modules['foo'] ) );
$this->assertTrue( isset( $enqueued_script_modules['bar'] ) );
$this->assertArrayNotHasKey( 'foo', $enqueued_script_modules );
$this->assertArrayHasKey( 'bar', $enqueued_script_modules );
}
/**
@ -168,7 +168,7 @@ class Tests_Script_Modules_WpScriptModules extends WP_UnitTestCase {
$enqueued_script_modules = $this->get_enqueued_script_modules();
$this->assertCount( 0, $enqueued_script_modules );
$this->assertFalse( isset( $enqueued_script_modules['unexistent'] ) );
$this->assertArrayNotHasKey( 'unexistent', $enqueued_script_modules );
}
/**
@ -190,13 +190,13 @@ class Tests_Script_Modules_WpScriptModules extends WP_UnitTestCase {
$enqueued_script_modules = $this->get_enqueued_script_modules();
$this->assertCount( 0, $enqueued_script_modules );
$this->assertFalse( isset( $enqueued_script_modules['foo'] ) );
$this->assertArrayNotHasKey( 'foo', $enqueued_script_modules );
$this->script_modules->deregister( 'foo' ); // Dequeued.
$enqueued_script_modules = $this->get_enqueued_script_modules();
$this->assertCount( 0, $enqueued_script_modules );
$this->assertFalse( isset( $enqueued_script_modules['foo'] ) );
$this->assertArrayNotHasKey( 'foo', $enqueued_script_modules );
}
/**
@ -218,7 +218,7 @@ class Tests_Script_Modules_WpScriptModules extends WP_UnitTestCase {
$this->assertCount( 1, $enqueued_script_modules );
$this->assertStringStartsWith( '/foo.js', $enqueued_script_modules['foo'] );
$this->assertFalse( isset( $enqueued_script_modules['bar'] ) );
$this->assertArrayNotHasKey( 'bar', $enqueued_script_modules );
}
/**
@ -242,8 +242,8 @@ class Tests_Script_Modules_WpScriptModules extends WP_UnitTestCase {
$enqueued_script_modules = $this->get_enqueued_script_modules();
$this->assertCount( 1, $enqueued_script_modules );
$this->assertFalse( isset( $enqueued_script_modules['foo'] ) );
$this->assertTrue( isset( $enqueued_script_modules['bar'] ) );
$this->assertArrayNotHasKey( 'foo', $enqueued_script_modules );
$this->assertArrayHasKey( 'bar', $enqueued_script_modules );
}
/**
@ -266,7 +266,7 @@ class Tests_Script_Modules_WpScriptModules extends WP_UnitTestCase {
$this->assertCount( 1, $import_map );
$this->assertStringStartsWith( '/dep.js', $import_map['dep'] );
$this->assertFalse( isset( $import_map['no-dep'] ) );
$this->assertArrayNotHasKey( 'no-dep', $import_map );
}
/**
@ -340,7 +340,7 @@ class Tests_Script_Modules_WpScriptModules extends WP_UnitTestCase {
$this->assertStringStartsWith( '/dynamic-dep.js', $import_map['dynamic-dep'] );
$this->assertStringStartsWith( '/nested-static-dep.js', $import_map['nested-static-dep'] );
$this->assertStringStartsWith( '/nested-dynamic-dep.js', $import_map['nested-dynamic-dep'] );
$this->assertFalse( isset( $import_map['no-dep'] ) );
$this->assertArrayNotHasKey( 'no-dep', $import_map );
}
/**
@ -409,9 +409,9 @@ class Tests_Script_Modules_WpScriptModules extends WP_UnitTestCase {
$this->assertCount( 2, $preloaded_script_modules );
$this->assertStringStartsWith( '/static-dep.js', $preloaded_script_modules['static-dep'] );
$this->assertStringStartsWith( '/nested-static-dep.js', $preloaded_script_modules['nested-static-dep'] );
$this->assertFalse( isset( $preloaded_script_modules['no-dep'] ) );
$this->assertFalse( isset( $preloaded_script_modules['dynamic-dep'] ) );
$this->assertFalse( isset( $preloaded_script_modules['nested-dynamic-dep'] ) );
$this->assertArrayNotHasKey( 'dynamic-dep', $preloaded_script_modules );
$this->assertArrayNotHasKey( 'nested-dynamic-dep', $preloaded_script_modules );
$this->assertArrayNotHasKey( 'no-dep', $preloaded_script_modules );
}
/**
@ -445,9 +445,9 @@ class Tests_Script_Modules_WpScriptModules extends WP_UnitTestCase {
$this->assertCount( 1, $preloaded_script_modules );
$this->assertStringStartsWith( '/static-dep.js', $preloaded_script_modules['static-dep'] );
$this->assertFalse( isset( $preloaded_script_modules['dynamic-dep'] ) );
$this->assertFalse( isset( $preloaded_script_modules['nested-static-dep'] ) );
$this->assertFalse( isset( $preloaded_script_modules['no-dep'] ) );
$this->assertArrayNotHasKey( 'dynamic-dep', $preloaded_script_modules );
$this->assertArrayNotHasKey( 'nested-dynamic-dep', $preloaded_script_modules );
$this->assertArrayNotHasKey( 'no-dep', $preloaded_script_modules );
}
/**
@ -476,8 +476,8 @@ class Tests_Script_Modules_WpScriptModules extends WP_UnitTestCase {
$preloaded_script_modules = $this->get_preloaded_script_modules();
$this->assertCount( 1, $preloaded_script_modules );
$this->assertTrue( isset( $preloaded_script_modules['dep'] ) );
$this->assertFalse( isset( $preloaded_script_modules['enqueued-dep'] ) );
$this->assertArrayHasKey( 'dep', $preloaded_script_modules );
$this->assertArrayNotHasKey( 'enqueued-dep', $preloaded_script_modules );
}
/**
@ -507,8 +507,8 @@ class Tests_Script_Modules_WpScriptModules extends WP_UnitTestCase {
$import_map = $this->get_import_map();
$this->assertCount( 2, $import_map );
$this->assertTrue( isset( $import_map['dep'] ) );
$this->assertTrue( isset( $import_map['enqueued-dep'] ) );
$this->assertArrayHasKey( 'dep', $import_map );
$this->assertArrayHasKey( 'enqueued-dep', $import_map );
}
/**
@ -531,7 +531,7 @@ class Tests_Script_Modules_WpScriptModules extends WP_UnitTestCase {
);
$result = $get_src->invoke( $this->script_modules, 'module_with_version' );
$this->assertEquals( 'http://example.com/module.js?ver=1.0', $result );
$this->assertSame( 'http://example.com/module.js?ver=1.0', $result );
$this->script_modules->register(
'module_without_version',
@ -541,7 +541,7 @@ class Tests_Script_Modules_WpScriptModules extends WP_UnitTestCase {
);
$result = $get_src->invoke( $this->script_modules, 'module_without_version' );
$this->assertEquals( 'http://example.com/module.js', $result );
$this->assertSame( 'http://example.com/module.js', $result );
$this->script_modules->register(
'module_with_wp_version',
@ -551,7 +551,7 @@ class Tests_Script_Modules_WpScriptModules extends WP_UnitTestCase {
);
$result = $get_src->invoke( $this->script_modules, 'module_with_wp_version' );
$this->assertEquals( 'http://example.com/module.js?ver=' . get_bloginfo( 'version' ), $result );
$this->assertSame( 'http://example.com/module.js?ver=' . get_bloginfo( 'version' ), $result );
$this->script_modules->register(
'module_with_existing_query_string',
@ -561,7 +561,7 @@ class Tests_Script_Modules_WpScriptModules extends WP_UnitTestCase {
);
$result = $get_src->invoke( $this->script_modules, 'module_with_existing_query_string' );
$this->assertEquals( 'http://example.com/module.js?foo=bar&ver=1.0', $result );
$this->assertSame( 'http://example.com/module.js?foo=bar&ver=1.0', $result );
// Filter the version to include the ID in the final URL, to test the filter, this should affect the tests below.
add_filter(
@ -574,10 +574,10 @@ class Tests_Script_Modules_WpScriptModules extends WP_UnitTestCase {
);
$result = $get_src->invoke( $this->script_modules, 'module_without_version' );
$this->assertEquals( 'http://example.com/module.js?script_module_id=module_without_version', $result );
$this->assertSame( 'http://example.com/module.js?script_module_id=module_without_version', $result );
$result = $get_src->invoke( $this->script_modules, 'module_with_existing_query_string' );
$this->assertEquals( 'http://example.com/module.js?foo=bar&ver=1.0&script_module_id=module_with_existing_query_string', $result );
$this->assertSame( 'http://example.com/module.js?foo=bar&ver=1.0&script_module_id=module_with_existing_query_string', $result );
}
/**
@ -606,13 +606,13 @@ class Tests_Script_Modules_WpScriptModules extends WP_UnitTestCase {
$this->script_modules->enqueue( 'foo' );
$enqueued_script_modules = $this->get_enqueued_script_modules();
$this->assertEquals( '/foo.js?ver=1.0', $enqueued_script_modules['foo'] );
$this->assertSame( '/foo.js?ver=1.0', $enqueued_script_modules['foo'] );
$import_map = $this->get_import_map();
$this->assertEquals( '/dep.js?ver=2.0', $import_map['dep'] );
$this->assertSame( '/dep.js?ver=2.0', $import_map['dep'] );
$preloaded_script_modules = $this->get_preloaded_script_modules();
$this->assertEquals( '/dep.js?ver=2.0', $preloaded_script_modules['dep'] );
$this->assertSame( '/dep.js?ver=2.0', $preloaded_script_modules['dep'] );
}
/**
@ -630,7 +630,7 @@ class Tests_Script_Modules_WpScriptModules extends WP_UnitTestCase {
$enqueued_script_modules = $this->get_enqueued_script_modules();
$this->assertCount( 0, $enqueued_script_modules );
$this->assertFalse( isset( $enqueued_script_modules['foo'] ) );
$this->assertArrayNotHasKey( 'foo', $enqueued_script_modules );
}
/**
@ -666,7 +666,7 @@ class Tests_Script_Modules_WpScriptModules extends WP_UnitTestCase {
$enqueued_script_modules = $this->get_enqueued_script_modules();
$this->assertCount( 0, $enqueued_script_modules );
$this->assertFalse( isset( $enqueued_script_modules['foo'] ) );
$this->assertArrayNotHasKey( 'foo', $enqueued_script_modules );
$this->script_modules->enqueue( 'foo', '/foo.js' ); // Valid src.
@ -695,7 +695,7 @@ class Tests_Script_Modules_WpScriptModules extends WP_UnitTestCase {
$import_map = $this->get_import_map();
$this->assertCount( 1, $enqueued_script_modules );
$this->assertEquals( '/foo.js?ver=1.0', $enqueued_script_modules['foo'] );
$this->assertSame( '/foo.js?ver=1.0', $enqueued_script_modules['foo'] );
$this->assertCount( 1, $import_map );
$this->assertStringStartsWith( '/dep.js', $import_map['dep'] );
}
@ -708,7 +708,7 @@ class Tests_Script_Modules_WpScriptModules extends WP_UnitTestCase {
public function test_wp_print_import_map_has_no_polyfill_when_no_modules_registered() {
$import_map_polyfill = get_echo( array( $this->script_modules, 'print_import_map' ) );
$this->assertEquals( '', $import_map_polyfill );
$this->assertSame( '', $import_map_polyfill );
}
/**
@ -730,6 +730,6 @@ class Tests_Script_Modules_WpScriptModules extends WP_UnitTestCase {
$p->next_tag( array( 'tag' => 'SCRIPT' ) );
$id = $p->get_attribute( 'id' );
$this->assertEquals( 'wp-load-polyfill-importmap', $id );
$this->assertSame( 'wp-load-polyfill-importmap', $id );
}
}