Make WordPress Core

Changeset 59404 for branches/6.7


Ignore:
Timestamp:
11/14/2024 11:53:57 AM (22 months ago)
Author:
cbravobernal
Message:

Interactivity API: Allow missing state negation on server

Aligns on the behavior of the negation operator with directives to missing paths in client and in server.

With a directive like the following:

<div data-wp-bind--hidden="!state.missing.property">
	This should be hidden by the <code>hidden</code> attribute.
</div>

Both server and client will return with this fix:

<div data-wp-bind--hidden="!state.missing.property" hidden="">
	This should be hidden by the <code>hidden</code> attribute.
</div>

Reviewed by cbravobernal.
Merges [59398] to the 6.7 branch.

Props jonsurrell, luisherranz.
Fixes #62374.

Location:
branches/6.7
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/6.7

  • branches/6.7/src/wp-includes/interactivity-api/class-wp-interactivity-api.php

    r59153 r59404  
    585585                                $current = $current->$path_segment;
    586586                        } else {
    587                                 return null;
     587                                $current = null;
     588                                break;
    588589                        }
    589590
  • branches/6.7/tests/phpunit/tests/interactivity-api/wpInteractivityAPI.php

    r59131 r59404  
    10811081
    10821082        /**
     1083         * Tests that the `evaluate` method operates correctly when used with the
     1084         * negation operator (!) with non-existent paths.
     1085         *
     1086         * @ticket 62374
     1087         *
     1088         * @covers ::evaluate
     1089         */
     1090        public function test_evaluate_value_negation_non_existent_path() {
     1091                $this->interactivity->state( 'myPlugin', array() );
     1092                $this->interactivity->state( 'otherPlugin', array() );
     1093                $this->set_internal_context_stack(
     1094                        array(
     1095                                'myPlugin'    => array(),
     1096                                'otherPlugin' => array(),
     1097                        )
     1098                );
     1099                $this->set_internal_namespace_stack( 'myPlugin' );
     1100
     1101                $result = $this->evaluate( '!state.missing' );
     1102                $this->assertTrue( $result );
     1103
     1104                $result = $this->evaluate( '!context.missing' );
     1105                $this->assertTrue( $result );
     1106
     1107                $result = $this->evaluate( 'otherPlugin::!state.deeply.nested.missing' );
     1108                $this->assertTrue( $result );
     1109
     1110                $result = $this->evaluate( 'otherPlugin::!context.deeply.nested.missing' );
     1111                $this->assertTrue( $result );
     1112        }
     1113
     1114        /**
    10831115         * Tests the `evaluate` method with non-existent paths.
    10841116         *
Note: See TracChangeset for help on using the changeset viewer.