Make WordPress Core


Ignore:
Timestamp:
11/30/2025 12:54:26 AM (8 weeks ago)
Author:
westonruter
Message:

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

Developed in https://github.com/WordPress/wordpress-develop/pull/10545

Follow-up to [60999].

Props deepakprajapati, westonruter.
See #63486.
Fixes #64229.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/dependencies/styles.php

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