Make WordPress Core


Ignore:
Timestamp:
02/02/2024 08:22:11 PM (15 months ago)
Author:
gziolo
Message:

Editor: Refactor the way block bindings sources are handled

It fixes the coding style issues reported. It goes further and improves the code quality it other places where the logic for block bindings was added.

Follow-up for [57514].
Props: gziolo, mukesh27, youknowriad, santosguillamot.
See #60282.

File:
1 moved

Legend:

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

    r57525 r57526  
    11<?php
    22/**
    3  * Unit tests covering the Block Bindings public API.
     3 * Tests for Block Bindings integration with block rendering.
    44 *
    55 * @package WordPress
     
    99 * @group blocks
    1010 * @group block-bindings
    11  *
    12  * @covers register_block_bindings_source
    1311 */
    14 class WP_Block_Bindings_Test extends WP_UnitTestCase {
     12class WP_Block_Bindings_Render extends WP_UnitTestCase {
    1513
    1614    const SOURCE_NAME  = 'test/source';
     
    2018
    2119    /**
    22      * Set up before each test.
     20     * Tear down after each test.
    2321     *
    2422     * @since 6.5.0
    2523     */
    26     public function set_up() {
     24    public function tear_down() {
    2725        foreach ( get_all_registered_block_bindings_sources() as $source_name => $source_properties ) {
    2826            if ( str_starts_with( $source_name, 'test/' ) ) {
     
    3129        }
    3230
    33         parent::set_up();
     31        parent::tear_down();
    3432    }
    3533
     
    3937     * @ticket 60282
    4038     *
    41      * @covers register_block_bindings_source
     39     * @covers ::register_block_bindings_source
    4240     */
    4341    public function test_update_block_with_value_from_source() {
     
    6462        $result   = $block->render();
    6563
    66         // Check if the block content was updated correctly.
    6764        $this->assertEquals( $expected, $result, 'The block content should be updated with the value returned by the source.' );
    6865    }
     
    7370     * @ticket 60282
    7471     *
    75      * @covers register_block_bindings_source
     72     * @covers ::register_block_bindings_source
    7673     */
    7774    public function test_passing_arguments_to_source() {
     
    8986        );
    9087
    91         $key = 'test';
    92 
     88        $value         = 'test';
    9389        $block_content = <<<HTML
    94 <!-- wp:paragraph {"metadata":{"bindings":{"content":{"source":"test/source", "args": {"key": "$key"}}}}} --><p>This should not appear</p><!-- /wp:paragraph -->
     90<!-- wp:paragraph {"metadata":{"bindings":{"content":{"source":"test/source", "args": {"key": "$value"}}}}} --><p>This should not appear</p><!-- /wp:paragraph -->
    9591HTML;
    9692
     
    9894        $block         = new WP_Block( $parsed_blocks[0] );
    9995
    100         $expected = "<p>The attribute name is 'content' and its binding has argument 'key' with value 'test'.</p>";
     96        $expected = "<p>The attribute name is 'content' and its binding has argument 'key' with value '$value'.</p>";
    10197        $result   = $block->render();
    10298
    103         // Check if the block content was updated correctly.
    10499        $this->assertEquals( $expected, $result, 'The block content should be updated with the value returned by the source.' );
    105100    }
Note: See TracChangeset for help on using the changeset viewer.