Make WordPress Core


Ignore:
Timestamp:
10/30/2025 04:01:56 PM (6 weeks ago)
Author:
SergeyBiryukov
Message:

Editor: Correct error message in WP_Block_Templates_Registry::unregister().

When attempting to unregister a non-existent block template, the error message will now include the template name.

Follow-up to [59073].

Props mukesh27, shailu25.
Fixes #64072.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/block-template.php

    r60729 r61090  
    480480
    481481    /**
     482     * Tests that unregister_block_template() returns a WP_Error when trying to unregister
     483     * a non-registered template, and that the error message includes the template name.
     484     *
     485     * @ticket 64072
     486     *
     487     * @covers ::unregister_block_template
     488     */
     489    public function test_unregister_block_template_error_message_includes_template_name() {
     490        $template_name = 'test-plugin//unregistered-template';
     491
     492        // Ensure template is not registered.
     493        unregister_block_template( $template_name );
     494
     495        // Expect _doing_it_wrong() notice.
     496        $this->setExpectedIncorrectUsage( 'WP_Block_Templates_Registry::unregister' );
     497
     498        // Try to unregister again, should return WP_Error.
     499        $error = unregister_block_template( $template_name );
     500
     501        $this->assertInstanceOf( 'WP_Error', $error );
     502        $this->assertStringContainsString(
     503            $template_name,
     504            $error->get_error_message(),
     505            'Error message should include the template name.'
     506        );
     507    }
     508
     509    /**
    482510     * Registers a test block to log `in_the_loop()` results.
    483511     *
Note: See TracChangeset for help on using the changeset viewer.