Make WordPress Core

Changeset 58420


Ignore:
Timestamp:
06/16/2024 10:15:33 AM (4 months ago)
Author:
SergeyBiryukov
Message:

Tests: Use more specific assertions in WP_Script_Modules tests.

Follow-up to [57269], [57327], [57593].

See #60705.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/script-modules/wpScriptModules.php

    r57987 r58420  
    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
     
    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
     
    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
     
    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.
     
    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
     
    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
     
    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
     
    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
     
    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
     
    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
     
    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
     
    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
     
    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
     
    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(
     
    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(
     
    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(
     
    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.
     
    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
     
    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
     
    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
     
    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.
     
    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'] );
     
    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
     
    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}
Note: See TracChangeset for help on using the changeset viewer.