From 9c76c73b5e4cdceddbd1d7d955e910132a9bfaad Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Mon, 11 Nov 2024 12:52:05 +0100 Subject: [PATCH] Add tests --- .../interactivity-api/wpInteractivityAPI.php | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/phpunit/tests/interactivity-api/wpInteractivityAPI.php b/tests/phpunit/tests/interactivity-api/wpInteractivityAPI.php index d6d7c28fdb77c..c63c64c6888e6 100644 --- a/tests/phpunit/tests/interactivity-api/wpInteractivityAPI.php +++ b/tests/phpunit/tests/interactivity-api/wpInteractivityAPI.php @@ -1079,6 +1079,38 @@ public function test_evaluate_value_negation() { $this->assertFalse( $result ); } + /** + * Tests that the `evaluate` method operates correctly when used with the + * negation operator (!) with non-existent paths. + * + * @ticket 62374 + * + * @covers ::evaluate + */ + public function test_evaluate_value_negation_non_existent_path() { + $this->interactivity->state( 'myPlugin', array() ); + $this->interactivity->state( 'otherPlugin', array() ); + $this->set_internal_context_stack( + array( + 'myPlugin' => array(), + 'otherPlugin' => array(), + ) + ); + $this->set_internal_namespace_stack( 'myPlugin' ); + + $result = $this->evaluate( '!state.missing' ); + $this->assertTrue( $result ); + + $result = $this->evaluate( '!context.missing' ); + $this->assertTrue( $result ); + + $result = $this->evaluate( 'otherPlugin::!state.deeply.nested.missing' ); + $this->assertTrue( $result ); + + $result = $this->evaluate( 'otherPlugin::!context.deeply.nested.missing' ); + $this->assertTrue( $result ); + } + /** * Tests the `evaluate` method with non-existent paths. *