Skip to content

Commit

Permalink
Update for other changes before rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal committed Jun 4, 2024
1 parent 7a0e70f commit 69aa352
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ private function _process_directives( string $html ) {
if ( 'SVG' === $tag_name || 'MATH' === $tag_name ) {
if ( $p->get_attribute_names_with_prefix( 'data-wp-' ) ) {
/* translators: 1: SVG or MATH HTML tag, 2: Namespace of the interactive block. */
$message = sprintf( __( 'Interactivity directives were detected on an incompatible %1$s tag when processing "%2$s". These directives will be ignored in the server side render.' ), $tag_name, end( $namespace_stack ) );
$message = sprintf( __( 'Interactivity directives were detected on an incompatible %1$s tag when processing "%2$s". These directives will be ignored in the server side render.' ), $tag_name, end( $this->namespace_stack ) );
_doing_it_wrong( __METHOD__, $message, '6.6.0' );
}
$p->skip_to_tag_closer();
Expand Down Expand Up @@ -506,7 +506,7 @@ private function _process_directives( string $html ) {
if ( $unbalanced || 0 < count( $tag_stack ) ) {
$tag_errored = 0 < count( $tag_stack ) ? end( $tag_stack )[0] : $tag_name;
/* translators: %1s: Namespace processed, %2s: The tag that caused the error; could be any HTML tag. */
$message = sprintf( __( 'Interactivity directives failed to process in "%1$s" due to a missing "%2$s" end tag.' ), end( $namespace_stack ), $tag_errored );
$message = sprintf( __( 'Interactivity directives failed to process in "%1$s" due to a missing "%2$s" end tag.' ), end( $this->namespace_stack ), $tag_errored );
_doing_it_wrong( __METHOD__, $message, '6.6.0' );
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ public function test_wp_each_nested_template_tags_using_previous_item_as_list()
*
* @covers ::process_directives
*
* @expectedIncorrectUsage WP_Interactivity_API::process_directives_args
* @expectedIncorrectUsage WP_Interactivity_API::_process_directives
*/
public function test_wp_each_unbalanced_tags() {
$original = '' .
Expand All @@ -601,7 +601,7 @@ public function test_wp_each_unbalanced_tags() {
*
* @covers ::process_directives
*
* @expectedIncorrectUsage WP_Interactivity_API::process_directives_args
* @expectedIncorrectUsage WP_Interactivity_API::_process_directives
*/
public function test_wp_each_unbalanced_tags_in_nested_template_tags() {
$this->interactivity->state( 'myPlugin', array( 'list2' => array( 3, 4 ) ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function test_wp_text_sets_inner_content_even_with_unbalanced_but_differe
*
* @covers ::process_directives
*
* @expectedIncorrectUsage WP_Interactivity_API::process_directives_args
* @expectedIncorrectUsage WP_Interactivity_API::_process_directives
*/
public function test_wp_text_fails_with_unbalanced_and_same_tags_inside_content() {
$html = '<div data-wp-text="myPlugin::state.text">Text<div></div>';
Expand Down
35 changes: 30 additions & 5 deletions tests/phpunit/tests/interactivity-api/wpInteractivityAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ public function test_process_directives_process_the_directives_in_the_correct_or
*
* @dataProvider data_html_with_unbalanced_tags
*
* @expectedIncorrectUsage WP_Interactivity_API::process_directives_args
* @expectedIncorrectUsage WP_Interactivity_API::_process_directives
*
* @param string $html HTML containing unbalanced tags and also a directive.
*/
Expand Down Expand Up @@ -992,7 +992,7 @@ public function test_process_directives_does_not_change_inner_html_in_svgs() {
* @ticket 60517
*
* @covers ::process_directives
* @expectedIncorrectUsage WP_Interactivity_API::process_directives_args
* @expectedIncorrectUsage WP_Interactivity_API::_process_directives
*/
public function test_process_directives_change_html_if_contains_math() {
$this->interactivity->state(
Expand Down Expand Up @@ -1027,7 +1027,7 @@ public function test_process_directives_change_html_if_contains_math() {
* @ticket 60517
*
* @covers ::process_directives
* @expectedIncorrectUsage WP_Interactivity_API::process_directives_args
* @expectedIncorrectUsage WP_Interactivity_API::_process_directives
* @expectedIncorrectUsage WP_Interactivity_API_Directives_Processor::skip_to_tag_closer
*/
public function test_process_directives_does_not_change_inner_html_in_math() {
Expand Down Expand Up @@ -1088,7 +1088,29 @@ private function evaluate( $directive_value ) {
* @covers ::evaluate
*/
public function test_evaluate_value() {
$this->interactivity->state( 'myPlugin', array( 'key' => 'myPlugin-state' ) );
$obj = new stdClass();
$obj->prop = 'object property';
$this->interactivity->state(
'myPlugin',
array(
'key' => 'myPlugin-state',
'obj' => $obj,
'arrAccess' => new class() implements ArrayAccess {
public function offsetExists( $offset ): bool {
return true;
}

#[\ReturnTypeWillChange]
public function offsetGet( $offset ) {
return $offset;
}

public function offsetSet( $offset, $value ): void {}

public function offsetUnset( $offset ): void {}
},
)
);
$this->interactivity->state( 'otherPlugin', array( 'key' => 'otherPlugin-state' ) );
$this->set_internal_context_stack(
array(
Expand All @@ -1111,7 +1133,7 @@ public function test_evaluate_value() {
$this->assertEquals( 'otherPlugin-context', $result );

$result = $this->evaluate( 'state.obj.prop' );
$this->assertSame( 'myPlugin-state', $result );
$this->assertSame( 'object property', $result );

$result = $this->evaluate( 'state.arrAccess.1' );
$this->assertSame( '1', $result );
Expand Down Expand Up @@ -1240,6 +1262,9 @@ public function test_evaluate_nested_value() {
* @expectedIncorrectUsage WP_Interactivity_API::evaluate
*/
public function test_evaluate_unvalid_namespaces() {
$this->set_internal_context_stack( array() );
$this->set_internal_namespace_stack();

$result = $this->evaluate( 'path', 'null' );
$this->assertNull( $result );

Expand Down

0 comments on commit 69aa352

Please sign in to comment.