Make WordPress Core


Ignore:
Timestamp:
01/28/2026 09:28:06 PM (6 months ago)
Author:
jorbin
Message:

Script Loader: Emit notices when enqueueing a script, style, or script module with missing dependencies.

First Developed in https://github.com/WordPress/wordpress-develop/pull/10545. Backport developed in https://github.com/WordPress/wordpress-develop/pull/10789.

Follow-up to [60999].

Reviewed by jorbin, wildworks.
Merges [61323], [61357], and [61542].

Props deepakprajapati, westonruter, mukeshpanchal27, jorbin, wildworks.
See #63486.
Fixes #64229.

Location:
branches/6.9
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/6.9

  • branches/6.9/tests/phpunit/tests/dependencies/styles.php

    r61536 r61550  
    816816                $this->assertEqualHTML( $expected, $printed );
    817817        }
     818
     819        /**
     820         * Tests that WP_Styles emits a _doing_it_wrong() notice for missing dependencies.
     821         *
     822         * @ticket 64229
     823         * @covers WP_Dependencies::all_deps
     824         */
     825        public function test_wp_style_doing_it_wrong_for_missing_dependencies() {
     826                $expected_incorrect_usage = 'WP_Styles::add';
     827                $this->setExpectedIncorrectUsage( $expected_incorrect_usage );
     828
     829                wp_enqueue_style(
     830                        'main-style',
     831                        '/main-style.css',
     832                        array( 'missing-style-dep' )
     833                );
     834
     835                $markup = get_echo( 'wp_print_styles' );
     836                $this->assertStringNotContainsString( 'main-style.css', $markup, 'Expected style to be absent.' );
     837
     838                $this->assertArrayHasKey(
     839                        $expected_incorrect_usage,
     840                        $this->caught_doing_it_wrong,
     841                        "Expected $expected_incorrect_usage to trigger a _doing_it_wrong() notice for missing dependency."
     842                );
     843
     844                $this->assertStringContainsString(
     845                        'The style with the handle "main-style" was enqueued with dependencies that are not registered: missing-style-dep',
     846                        $this->caught_doing_it_wrong[ $expected_incorrect_usage ],
     847                        'Expected _doing_it_wrong() notice to indicate missing dependencies for enqueued styles.'
     848                );
     849        }
    818850}
Note: See TracChangeset for help on using the changeset viewer.