Tests: Use assertSame() in WP_Interactivity_API tests.

This ensures that not only the return values match the expected results, but also that their type is the same.

Going forward, stricter type checking by using `assertSame()` should generally be preferred to `assertEquals()` where appropriate, to make the tests more reliable.

Follow-up to [57563], [57649], [57822], [57826], [57835], [58159], [58327].

See #61530.

git-svn-id: https://develop.svn.wordpress.org/trunk@58594 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2024-06-28 15:45:08 +00:00
parent 5effffccd0
commit 80bd30e4c1
10 changed files with 275 additions and 275 deletions

View File

@ -58,7 +58,7 @@ class Tests_WP_Interactivity_API_WP_Class extends WP_UnitTestCase {
public function test_wp_class_sets_class_name() {
$html = '<div data-wp-class--some-class="myPlugin::state.true">Text</div>';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'some-class', $p->get_attribute( 'class' ) );
$this->assertSame( 'some-class', $p->get_attribute( 'class' ) );
}
/**
@ -76,7 +76,7 @@ class Tests_WP_Interactivity_API_WP_Class extends WP_UnitTestCase {
data-wp-class--other-class="myPlugin::state.true"
>Text</div>';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'some-class other-class', $p->get_attribute( 'class' ) );
$this->assertSame( 'some-class other-class', $p->get_attribute( 'class' ) );
}
/**
@ -94,7 +94,7 @@ class Tests_WP_Interactivity_API_WP_Class extends WP_UnitTestCase {
data-wp-class--other-class="myPlugin::state.false"
>Text</div>';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'some-class', $p->get_attribute( 'class' ) );
$this->assertSame( 'some-class', $p->get_attribute( 'class' ) );
$html = '
<div
@ -103,7 +103,7 @@ class Tests_WP_Interactivity_API_WP_Class extends WP_UnitTestCase {
data-wp-class--other-class="myPlugin::state.false"
>Text</div>';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'some-class', $p->get_attribute( 'class' ) );
$this->assertSame( 'some-class', $p->get_attribute( 'class' ) );
}
/**
@ -116,7 +116,7 @@ class Tests_WP_Interactivity_API_WP_Class extends WP_UnitTestCase {
public function test_wp_class_sets_class_name_when_class_attribute_exists() {
$html = '<div class="other-class" data-wp-class--some-class="myPlugin::state.true">Text</div>';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'other-class some-class', $p->get_attribute( 'class' ) );
$this->assertSame( 'other-class some-class', $p->get_attribute( 'class' ) );
}
/**
@ -143,7 +143,7 @@ class Tests_WP_Interactivity_API_WP_Class extends WP_UnitTestCase {
public function test_wp_class_doesnt_add_class_name_on_false() {
$html = '<div class="other-class" data-wp-class--some-class="myPlugin::state.false">Text</div>';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'other-class', $p->get_attribute( 'class' ) );
$this->assertSame( 'other-class', $p->get_attribute( 'class' ) );
}
/**
@ -157,7 +157,7 @@ class Tests_WP_Interactivity_API_WP_Class extends WP_UnitTestCase {
public function test_wp_class_keeps_class_name_when_class_name_exists() {
$html = '<div class="some-class" data-wp-class--some-class="myPlugin::state.true">Text</div>';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'some-class', $p->get_attribute( 'class' ) );
$this->assertSame( 'some-class', $p->get_attribute( 'class' ) );
}
/**
@ -171,7 +171,7 @@ class Tests_WP_Interactivity_API_WP_Class extends WP_UnitTestCase {
public function test_wp_class_keeps_class_name_when_class_name_exists_and_is_not_the_only_one() {
$html = '<div class="other-class some-class" data-wp-class--some-class="myPlugin::state.true">Text</div>';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'other-class some-class', $p->get_attribute( 'class' ) );
$this->assertSame( 'other-class some-class', $p->get_attribute( 'class' ) );
}
/**
@ -199,7 +199,7 @@ class Tests_WP_Interactivity_API_WP_Class extends WP_UnitTestCase {
public function test_wp_class_removes_class_name_when_class_name_exists_and_is_not_the_only_one() {
$html = '<div class="other-class some-class" data-wp-class--some-class="myPlugin::state.false">Text</div>';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'other-class', $p->get_attribute( 'class' ) );
$this->assertSame( 'other-class', $p->get_attribute( 'class' ) );
}
/**
@ -227,7 +227,7 @@ class Tests_WP_Interactivity_API_WP_Class extends WP_UnitTestCase {
public function test_wp_class_doesnt_change_class_attribute_with_empty_directive_suffix() {
$html = '<div class="other-class" data-wp-class="myPlugin::state.true">Text</div>';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'other-class', $p->get_attribute( 'class' ) );
$this->assertSame( 'other-class', $p->get_attribute( 'class' ) );
}
/**
@ -242,7 +242,7 @@ class Tests_WP_Interactivity_API_WP_Class extends WP_UnitTestCase {
public function test_wp_class_doesnt_change_class_attribute_with_empty_value() {
$html = '<div class="other-class" data-wp-class--some-class="">Text</div>';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'other-class', $p->get_attribute( 'class' ) );
$this->assertSame( 'other-class', $p->get_attribute( 'class' ) );
}
/**
@ -257,7 +257,7 @@ class Tests_WP_Interactivity_API_WP_Class extends WP_UnitTestCase {
public function test_wp_class_doesnt_change_class_attribute_without_value() {
$html = '<div class="other-class" data-wp-class--some-class>Text</div>';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'other-class', $p->get_attribute( 'class' ) );
$this->assertSame( 'other-class', $p->get_attribute( 'class' ) );
}
/**
@ -271,7 +271,7 @@ class Tests_WP_Interactivity_API_WP_Class extends WP_UnitTestCase {
public function test_wp_class_works_with_multiple_directives() {
$html = '<div data-wp-class--some-class="myPlugin::state.true" data-wp-class--some-class="myPlugin::state.true">Text</div>';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'some-class', $p->get_attribute( 'class' ) );
$this->assertSame( 'some-class', $p->get_attribute( 'class' ) );
}
/**
@ -286,17 +286,17 @@ class Tests_WP_Interactivity_API_WP_Class extends WP_UnitTestCase {
$this->interactivity->state( 'myPlugin', array( 'text' => 'some text' ) );
$html = '<div data-wp-class--some-class="myPlugin::state.text">Text</div>';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'some-class', $p->get_attribute( 'class' ) );
$this->assertSame( 'some-class', $p->get_attribute( 'class' ) );
$this->interactivity->state( 'myPlugin', array( 'array' => array( 1, 2 ) ) );
$html = '<div data-wp-class--some-class="myPlugin::state.array">Text</div>';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'some-class', $p->get_attribute( 'class' ) );
$this->assertSame( 'some-class', $p->get_attribute( 'class' ) );
$this->interactivity->state( 'myPlugin', array( 'number' => 1 ) );
$html = '<div data-wp-class--some-class="myPlugin::state.number">Text</div>';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'some-class', $p->get_attribute( 'class' ) );
$this->assertSame( 'some-class', $p->get_attribute( 'class' ) );
}
/**

View File

@ -56,7 +56,7 @@ class Tests_WP_Interactivity_API_WP_Context extends WP_UnitTestCase {
</div>
';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'some-id', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id', $p->get_attribute( 'id' ) );
}
/**
@ -78,7 +78,7 @@ class Tests_WP_Interactivity_API_WP_Context extends WP_UnitTestCase {
</div>
';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'some-id', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id', $p->get_attribute( 'id' ) );
}
/**
@ -99,9 +99,9 @@ class Tests_WP_Interactivity_API_WP_Context extends WP_UnitTestCase {
</div>
';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'some-id-1', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id-1', $p->get_attribute( 'id' ) );
$p->next_tag( array( 'class_name' => 'test' ) );
$this->assertEquals( 'some-id-2', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id-2', $p->get_attribute( 'id' ) );
}
/**
@ -121,7 +121,7 @@ class Tests_WP_Interactivity_API_WP_Context extends WP_UnitTestCase {
</div>
';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'some-id-2', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id-2', $p->get_attribute( 'id' ) );
}
/**
@ -142,9 +142,9 @@ class Tests_WP_Interactivity_API_WP_Context extends WP_UnitTestCase {
</div>
';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'some-id-2', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id-2', $p->get_attribute( 'id' ) );
$p->next_tag( array( 'class_name' => 'test' ) );
$this->assertEquals( 'some-id-1', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id-1', $p->get_attribute( 'id' ) );
}
/**
@ -165,9 +165,9 @@ class Tests_WP_Interactivity_API_WP_Context extends WP_UnitTestCase {
</div>
';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'some-id-1', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id-1', $p->get_attribute( 'id' ) );
$p->next_tag( array( 'class_name' => 'test' ) );
$this->assertEquals( 'some-id-2', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id-2', $p->get_attribute( 'id' ) );
}
/**
@ -206,9 +206,9 @@ class Tests_WP_Interactivity_API_WP_Context extends WP_UnitTestCase {
</div>
';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'some-id-1', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id-1', $p->get_attribute( 'id' ) );
$p->next_tag( array( 'class_name' => 'test' ) );
$this->assertEquals( 'some-id-1', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id-1', $p->get_attribute( 'id' ) );
}
/**
@ -247,9 +247,9 @@ class Tests_WP_Interactivity_API_WP_Context extends WP_UnitTestCase {
</div>
';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'some-id-1', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id-1', $p->get_attribute( 'id' ) );
$p->next_tag( array( 'class_name' => 'test' ) );
$this->assertEquals( 'some-id-1', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id-1', $p->get_attribute( 'id' ) );
}
/**
@ -288,9 +288,9 @@ class Tests_WP_Interactivity_API_WP_Context extends WP_UnitTestCase {
</div>
';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'some-id-1', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id-1', $p->get_attribute( 'id' ) );
$p->next_tag( array( 'class_name' => 'test' ) );
$this->assertEquals( 'some-id-1', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id-1', $p->get_attribute( 'id' ) );
}
/**
@ -307,7 +307,7 @@ class Tests_WP_Interactivity_API_WP_Context extends WP_UnitTestCase {
</div>
';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'some-id', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id', $p->get_attribute( 'id' ) );
}
/**
@ -346,7 +346,7 @@ class Tests_WP_Interactivity_API_WP_Context extends WP_UnitTestCase {
</div>
';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'some-id', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id', $p->get_attribute( 'id' ) );
}
/**
@ -368,7 +368,7 @@ class Tests_WP_Interactivity_API_WP_Context extends WP_UnitTestCase {
</div>
';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'some-id', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id', $p->get_attribute( 'id' ) );
}
/**
@ -389,7 +389,7 @@ class Tests_WP_Interactivity_API_WP_Context extends WP_UnitTestCase {
</div>
';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'some-id', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id', $p->get_attribute( 'id' ) );
}
/**
@ -416,11 +416,11 @@ class Tests_WP_Interactivity_API_WP_Context extends WP_UnitTestCase {
</div>
';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'other-id', $p->get_attribute( 'id' ) );
$this->assertSame( 'other-id', $p->get_attribute( 'id' ) );
$p->next_tag( array( 'class_name' => 'test' ) );
$this->assertEquals( 'some-id', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id', $p->get_attribute( 'id' ) );
$p->next_tag( array( 'class_name' => 'test' ) );
$this->assertEquals( 'some-id', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id', $p->get_attribute( 'id' ) );
$p->next_tag( array( 'class_name' => 'test' ) );
$this->assertNull( $p->get_attribute( 'id' ) );
}
@ -445,7 +445,7 @@ class Tests_WP_Interactivity_API_WP_Context extends WP_UnitTestCase {
</div>
';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'some-id', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id', $p->get_attribute( 'id' ) );
}
/**
@ -469,9 +469,9 @@ class Tests_WP_Interactivity_API_WP_Context extends WP_UnitTestCase {
</div>
';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'some-id-1', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id-1', $p->get_attribute( 'id' ) );
$p->next_tag( array( 'class_name' => 'test' ) );
$this->assertEquals( 'some-id-2', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id-2', $p->get_attribute( 'id' ) );
}
/**
@ -494,7 +494,7 @@ class Tests_WP_Interactivity_API_WP_Context extends WP_UnitTestCase {
</div>
';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'some-id-2', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id-2', $p->get_attribute( 'id' ) );
}
/**
@ -518,8 +518,8 @@ class Tests_WP_Interactivity_API_WP_Context extends WP_UnitTestCase {
</div>
';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'some-id-2', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id-2', $p->get_attribute( 'id' ) );
$p->next_tag( array( 'class_name' => 'test' ) );
$this->assertEquals( 'some-id-1', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id-1', $p->get_attribute( 'id' ) );
}
}

View File

@ -42,7 +42,7 @@ class Tests_WP_Interactivity_API_WP_Each extends WP_UnitTestCase {
<span data-wp-text="myPlugin::context.item"></span>
</div>';
$new = $this->interactivity->process_directives( $original );
$this->assertEquals( $original, $new );
$this->assertSame( $original, $new );
}
/**
@ -68,7 +68,7 @@ class Tests_WP_Interactivity_API_WP_Each extends WP_UnitTestCase {
<span data-wp-text="myPlugin::context.item"></span>
</template>';
$new = $this->interactivity->process_directives( $original );
$this->assertEquals( $original, $new );
$this->assertSame( $original, $new );
}
/**
@ -92,7 +92,7 @@ class Tests_WP_Interactivity_API_WP_Each extends WP_UnitTestCase {
'<span data-wp-each-child data-wp-text="myPlugin::context.item">2</span>' .
'<div id="after-wp-each" data-wp-bind--id="myPlugin::state.after">Text</div>';
$new = $this->interactivity->process_directives( $original );
$this->assertEquals( $expected, $new );
$this->assertSame( $expected, $new );
}
/**
@ -116,7 +116,7 @@ class Tests_WP_Interactivity_API_WP_Each extends WP_UnitTestCase {
'</template>' .
'<div id="after-wp-each" data-wp-bind--id="myPlugin::state.after">Text</div>';
$new = $this->interactivity->process_directives( $original );
$this->assertEquals( $expected, $new );
$this->assertSame( $expected, $new );
}
/**
@ -145,7 +145,7 @@ class Tests_WP_Interactivity_API_WP_Each extends WP_UnitTestCase {
'<div id="after-wp-each" data-wp-bind--id="myPlugin::context.after" data-wp-text="myPlugin::context.item">New text</div>' .
'</div>';
$new = $this->interactivity->process_directives( $original );
$this->assertEquals( $expected, $new );
$this->assertSame( $expected, $new );
}
/**
@ -173,7 +173,7 @@ class Tests_WP_Interactivity_API_WP_Each extends WP_UnitTestCase {
'<div id="after-wp-each" data-wp-bind--id="myPlugin::state.after">Text</div>' .
'</div>';
$new = $this->interactivity->process_directives( $original );
$this->assertEquals( $expected, $new );
$this->assertSame( $expected, $new );
}
/**
@ -201,7 +201,7 @@ class Tests_WP_Interactivity_API_WP_Each extends WP_UnitTestCase {
'<div id="after-wp-each" data-wp-bind--id="state.after">Text</div>' .
'</div>';
$new = $this->interactivity->process_directives( $original );
$this->assertEquals( $expected, $new );
$this->assertSame( $expected, $new );
}
/**
@ -229,7 +229,7 @@ class Tests_WP_Interactivity_API_WP_Each extends WP_UnitTestCase {
'<span data-wp-each-child data-wp-text="myPlugin::context.item">2</span>' .
'<div id="after-wp-each" data-wp-bind--id="myPlugin::state.after">Text</div>';
$new = $this->interactivity->process_directives( $original );
$this->assertEquals( $expected, $new );
$this->assertSame( $expected, $new );
}
/**
@ -257,7 +257,7 @@ class Tests_WP_Interactivity_API_WP_Each extends WP_UnitTestCase {
'<img data-wp-each-child id="2" data-wp-bind--id="myPlugin::context.item">' .
'<div id="after-wp-each" data-wp-bind--id="myPlugin::state.after">Text</div>';
$new = $this->interactivity->process_directives( $original );
$this->assertEquals( $expected, $new );
$this->assertSame( $expected, $new );
}
/**
@ -286,7 +286,7 @@ class Tests_WP_Interactivity_API_WP_Each extends WP_UnitTestCase {
'<span data-wp-each-child data-wp-text="myPlugin::context.item">2</span>' .
'<div id="after-wp-each" data-wp-bind--id="myPlugin::state.after">Text</div>';
$new = $this->interactivity->process_directives( $original );
$this->assertEquals( $expected, $new );
$this->assertSame( $expected, $new );
}
/**
@ -318,7 +318,7 @@ class Tests_WP_Interactivity_API_WP_Each extends WP_UnitTestCase {
'</div>' .
'<div id="after-wp-each" data-wp-bind--id="myPlugin::state.after">Text</div>';
$new = $this->interactivity->process_directives( $original );
$this->assertEquals( $expected, $new );
$this->assertSame( $expected, $new );
}
/**
@ -361,7 +361,7 @@ class Tests_WP_Interactivity_API_WP_Each extends WP_UnitTestCase {
'<span data-wp-each-child data-wp-text="myPlugin::context.item.name">two</span>' .
'<div id="after-wp-each" data-wp-bind--id="myPlugin::state.after">Text</div>';
$new = $this->interactivity->process_directives( $original );
$this->assertEquals( $expected, $new );
$this->assertSame( $expected, $new );
}
/**
@ -385,7 +385,7 @@ class Tests_WP_Interactivity_API_WP_Each extends WP_UnitTestCase {
'<span data-wp-each-child data-wp-text="myPlugin::context.myitem">2</span>' .
'<div id="after-wp-each" data-wp-bind--id="myPlugin::state.after">Text</div>';
$new = $this->interactivity->process_directives( $original );
$this->assertEquals( $expected, $new );
$this->assertSame( $expected, $new );
}
/**
@ -410,7 +410,7 @@ class Tests_WP_Interactivity_API_WP_Each extends WP_UnitTestCase {
'<span data-wp-each-child data-wp-text="myPlugin::context.myItem">2</span>' .
'<div id="after-wp-each" data-wp-bind--id="myPlugin::state.after">Text</div>';
$new = $this->interactivity->process_directives( $original );
$this->assertEquals( $expected, $new );
$this->assertSame( $expected, $new );
}
/**
@ -426,14 +426,14 @@ class Tests_WP_Interactivity_API_WP_Each extends WP_UnitTestCase {
'id: <span data-wp-text="myPlugin::context.item"></span>' .
'</template>';
$new = $this->interactivity->process_directives( $original );
$this->assertEquals( $original, $new );
$this->assertSame( $original, $new );
$original = '' .
'<template data-wp-each="myPlugin::state.list">' .
'<span data-wp-text="myPlugin::context.item"></span>!' .
'</template>';
$new = $this->interactivity->process_directives( $original );
$this->assertEquals( $original, $new );
$this->assertSame( $original, $new );
// But it should work fine with spaces and linebreaks.
$original = '
@ -444,9 +444,9 @@ class Tests_WP_Interactivity_API_WP_Each extends WP_UnitTestCase {
$p = new WP_HTML_Tag_Processor( $new );
$p->next_tag( array( 'class_name' => 'test' ) );
$p->next_tag( array( 'class_name' => 'test' ) );
$this->assertEquals( '1', $p->get_attribute( 'id' ) );
$this->assertSame( '1', $p->get_attribute( 'id' ) );
$p->next_tag( array( 'class_name' => 'test' ) );
$this->assertEquals( '2', $p->get_attribute( 'id' ) );
$this->assertSame( '2', $p->get_attribute( 'id' ) );
}
/**
@ -487,7 +487,7 @@ class Tests_WP_Interactivity_API_WP_Each extends WP_UnitTestCase {
'<span data-wp-each-child data-wp-text="myPlugin::context.item2">4</span>' .
'<div id="after-wp-each" data-wp-bind--id="myPlugin::state.after">Text</div>';
$new = $this->interactivity->process_directives( $original );
$this->assertEquals( $expected, $new );
$this->assertSame( $expected, $new );
}
/**
@ -533,7 +533,7 @@ class Tests_WP_Interactivity_API_WP_Each extends WP_UnitTestCase {
'<span data-wp-each-child data-wp-text="myPlugin::context.item2">4</span>' .
'<div id="after-wp-each" data-wp-bind--id="myPlugin::state.after">Text</div>';
$new = $this->interactivity->process_directives( $original );
$this->assertEquals( $expected, $new );
$this->assertSame( $expected, $new );
}
/**
@ -571,7 +571,7 @@ class Tests_WP_Interactivity_API_WP_Each extends WP_UnitTestCase {
'<span data-wp-each-child data-wp-text="myPlugin::context.number">4</span>' .
'<div id="after-wp-each" data-wp-bind--id="myPlugin::state.after">Text</div>';
$new = $this->interactivity->process_directives( $original );
$this->assertEquals( $expected, $new );
$this->assertSame( $expected, $new );
}
/**
@ -590,7 +590,7 @@ class Tests_WP_Interactivity_API_WP_Each extends WP_UnitTestCase {
'</template>' .
'<div data-wp-bind--id="myPlugin::state.after">Text</div>';
$new = $this->interactivity->process_directives( $original );
$this->assertEquals( $original, $new );
$this->assertSame( $original, $new );
}
/**
@ -614,7 +614,7 @@ class Tests_WP_Interactivity_API_WP_Each extends WP_UnitTestCase {
'</template>' .
'<div data-wp-bind--id="myPlugin::state.after">Text</div>';
$new = $this->interactivity->process_directives( $original );
$this->assertEquals( $original, $new );
$this->assertSame( $original, $new );
}
/**
@ -639,23 +639,23 @@ class Tests_WP_Interactivity_API_WP_Each extends WP_UnitTestCase {
$this->interactivity->state( 'myPlugin', array( 'list' => null ) );
$new = $this->interactivity->process_directives( $original );
$this->assertEquals( $expected, $new );
$this->assertSame( $expected, $new );
$this->interactivity->state( 'myPlugin', array( 'list' => 'Text' ) );
$new = $this->interactivity->process_directives( $original );
$this->assertEquals( $expected, $new );
$this->assertSame( $expected, $new );
$this->interactivity->state( 'myPlugin', array( 'list' => 100 ) );
$new = $this->interactivity->process_directives( $original );
$this->assertEquals( $expected, $new );
$this->assertSame( $expected, $new );
$this->interactivity->state( 'myPlugin', array( 'list' => false ) );
$new = $this->interactivity->process_directives( $original );
$this->assertEquals( $expected, $new );
$this->assertSame( $expected, $new );
$this->interactivity->state( 'myPlugin', array( 'list' => true ) );
$new = $this->interactivity->process_directives( $original );
$this->assertEquals( $expected, $new );
$this->assertSame( $expected, $new );
}
/**
@ -682,6 +682,6 @@ class Tests_WP_Interactivity_API_WP_Each extends WP_UnitTestCase {
'<span data-wp-each-child data-wp-text="myPlugin::context.item">2</span>' .
'<div id="after-wp-each" data-wp-bind--id="myPlugin::state.after">Text</div>';
$new = $this->interactivity->process_directives( $original );
$this->assertEquals( $expected, $new );
$this->assertSame( $expected, $new );
}
}

View File

@ -58,7 +58,7 @@ class Tests_WP_Interactivity_API_WP_Interactive extends WP_UnitTestCase {
</div>
';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'some-id', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id', $p->get_attribute( 'id' ) );
}
/**
@ -76,7 +76,7 @@ class Tests_WP_Interactivity_API_WP_Interactive extends WP_UnitTestCase {
</div>
';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'some-id', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id', $p->get_attribute( 'id' ) );
}
/**
@ -97,9 +97,9 @@ class Tests_WP_Interactivity_API_WP_Interactive extends WP_UnitTestCase {
</div>
';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'some-id', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id', $p->get_attribute( 'id' ) );
$p->next_tag( array( 'class_name' => 'test' ) );
$this->assertEquals( 'other-id', $p->get_attribute( 'id' ) );
$this->assertSame( 'other-id', $p->get_attribute( 'id' ) );
}
/**
@ -121,9 +121,9 @@ class Tests_WP_Interactivity_API_WP_Interactive extends WP_UnitTestCase {
</div>
';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'some-id', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id', $p->get_attribute( 'id' ) );
$p->next_tag( array( 'class_name' => 'test' ) );
$this->assertEquals( 'some-id', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id', $p->get_attribute( 'id' ) );
}
/**
@ -144,9 +144,9 @@ class Tests_WP_Interactivity_API_WP_Interactive extends WP_UnitTestCase {
</div>
';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'some-id', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id', $p->get_attribute( 'id' ) );
$p->next_tag( array( 'class_name' => 'test' ) );
$this->assertEquals( 'some-id', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id', $p->get_attribute( 'id' ) );
}
/**
@ -167,9 +167,9 @@ class Tests_WP_Interactivity_API_WP_Interactive extends WP_UnitTestCase {
</div>
';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'some-id', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id', $p->get_attribute( 'id' ) );
$p->next_tag( array( 'class_name' => 'test' ) );
$this->assertEquals( 'some-id', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id', $p->get_attribute( 'id' ) );
}
/**
@ -190,9 +190,9 @@ class Tests_WP_Interactivity_API_WP_Interactive extends WP_UnitTestCase {
</div>
';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'some-id', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id', $p->get_attribute( 'id' ) );
$p->next_tag( array( 'class_name' => 'test' ) );
$this->assertEquals( 'some-id', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id', $p->get_attribute( 'id' ) );
}
/**
@ -209,7 +209,7 @@ class Tests_WP_Interactivity_API_WP_Interactive extends WP_UnitTestCase {
</div>
';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'some-id', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id', $p->get_attribute( 'id' ) );
}
/**
@ -227,7 +227,7 @@ class Tests_WP_Interactivity_API_WP_Interactive extends WP_UnitTestCase {
</div>
';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'other-id', $p->get_attribute( 'id' ) );
$this->assertSame( 'other-id', $p->get_attribute( 'id' ) );
}
/**
@ -248,9 +248,9 @@ class Tests_WP_Interactivity_API_WP_Interactive extends WP_UnitTestCase {
</div>
';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'some-id', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id', $p->get_attribute( 'id' ) );
$p->next_tag( array( 'class_name' => 'test' ) );
$this->assertEquals( 'other-id', $p->get_attribute( 'id' ) );
$this->assertSame( 'other-id', $p->get_attribute( 'id' ) );
$html = '
<div data-wp-interactive=\'{ "namespace": "myPlugin" }\'>
@ -261,8 +261,8 @@ class Tests_WP_Interactivity_API_WP_Interactive extends WP_UnitTestCase {
</div>
';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'other-id', $p->get_attribute( 'id' ) );
$this->assertSame( 'other-id', $p->get_attribute( 'id' ) );
$p->next_tag( array( 'class_name' => 'test' ) );
$this->assertEquals( 'some-id', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id', $p->get_attribute( 'id' ) );
}
}

View File

@ -88,9 +88,9 @@ class Tests_WP_Interactivity_API_WP_Router_Region extends WP_UnitTestCase {
$html = '<div>Nothing here</div>';
$new_html = $this->interactivity->process_directives( $html );
$footer = $this->render_wp_footer();
$this->assertEquals( $html, $new_html );
$this->assertEquals( '', $footer );
$this->assertEquals( '', get_echo( 'wp_print_styles' ) );
$this->assertSame( $html, $new_html );
$this->assertSame( '', $footer );
$this->assertSame( '', get_echo( 'wp_print_styles' ) );
}
/**
@ -108,14 +108,14 @@ class Tests_WP_Interactivity_API_WP_Router_Region extends WP_UnitTestCase {
<div data-wp-router-region="region B">Another interactive region</div>
';
$new_html = $this->interactivity->process_directives( $html );
$this->assertEquals( $html, $new_html );
$this->assertSame( $html, $new_html );
// Check that the style is loaded, but only once.
$styles = get_echo( 'wp_print_styles' );
$query = array( 'tag_name' => 'style' );
$p = new WP_HTML_Tag_Processor( $styles );
$this->assertTrue( $p->next_tag( $query ) );
$this->assertEquals( 'wp-interactivity-router-animations-inline-css', $p->get_attribute( 'id' ) );
$this->assertSame( 'wp-interactivity-router-animations-inline-css', $p->get_attribute( 'id' ) );
$this->assertStringContainsString( '.wp-interactivity-router-loading-bar', $styles );
$this->assertFalse( $p->next_tag( $query ) );

View File

@ -61,47 +61,47 @@ class Tests_WP_Interactivity_API_WP_Style extends WP_UnitTestCase {
public function test_merge_style_property_sets_properties() {
// Adds property on empty style attribute.
$result = $this->merge_style_property( '', 'color', 'green' );
$this->assertEquals( 'color:green;', $result );
$this->assertSame( 'color:green;', $result );
// Changes style property when there is an existing property.
$result = $this->merge_style_property( 'color:red;', 'color', 'green' );
$this->assertEquals( 'color:green;', $result );
$this->assertSame( 'color:green;', $result );
// Adds a new property when the existing one does not match.
$result = $this->merge_style_property( 'color:red;', 'background', 'blue' );
$this->assertEquals( 'color:red;background:blue;', $result );
$this->assertSame( 'color:red;background:blue;', $result );
// Handles multiple existing properties.
$result = $this->merge_style_property( 'color:red;margin:5px;', 'color', 'green' );
$this->assertEquals( 'margin:5px;color:green;', $result );
$this->assertSame( 'margin:5px;color:green;', $result );
// Adds a new property when multiple existing properties do not match.
$result = $this->merge_style_property( 'color:red;margin:5px;', 'padding', '10px' );
$this->assertEquals( 'color:red;margin:5px;padding:10px;', $result );
$this->assertSame( 'color:red;margin:5px;padding:10px;', $result );
// Removes whitespaces in all properties.
$result = $this->merge_style_property( ' color : red; margin : 5px; ', 'padding', ' 10px ' );
$this->assertEquals( 'color:red;margin:5px;padding:10px;', $result );
$this->assertSame( 'color:red;margin:5px;padding:10px;', $result );
// Updates a property when it's not the first one in the value.
$result = $this->merge_style_property( 'color:red;margin:5px;', 'margin', '15px' );
$this->assertEquals( 'color:red;margin:15px;', $result );
$this->assertSame( 'color:red;margin:15px;', $result );
// Adds missing trailing semicolon.
$result = $this->merge_style_property( 'color:red;margin:5px', 'padding', '10px' );
$this->assertEquals( 'color:red;margin:5px;padding:10px;', $result );
$this->assertSame( 'color:red;margin:5px;padding:10px;', $result );
// Doesn't add double semicolons.
$result = $this->merge_style_property( 'color:red;margin:5px;', 'padding', '10px;' );
$this->assertEquals( 'color:red;margin:5px;padding:10px;', $result );
$this->assertSame( 'color:red;margin:5px;padding:10px;', $result );
// Handles empty properties in the input.
$result = $this->merge_style_property( 'color:red;;margin:5px;;', 'padding', '10px' );
$this->assertEquals( 'color:red;margin:5px;padding:10px;', $result );
$this->assertSame( 'color:red;margin:5px;padding:10px;', $result );
// Moves the modified property to the end.
$result = $this->merge_style_property( 'border-style: dashed; border: 3px solid red;', 'border-style', 'inset' );
$this->assertEquals( 'border:3px solid red;border-style:inset;', $result );
$this->assertSame( 'border:3px solid red;border-style:inset;', $result );
}
/**
@ -115,35 +115,35 @@ class Tests_WP_Interactivity_API_WP_Style extends WP_UnitTestCase {
public function test_merge_style_property_with_falsy_values() {
// Removes a property with an empty string.
$result = $this->merge_style_property( 'color:red;margin:5px;', 'color', '' );
$this->assertEquals( 'margin:5px;', $result );
$this->assertSame( 'margin:5px;', $result );
// Removes a property with null.
$result = $this->merge_style_property( 'color:red;margin:5px;', 'color', null );
$this->assertEquals( 'margin:5px;', $result );
$this->assertSame( 'margin:5px;', $result );
// Removes a property with false.
$result = $this->merge_style_property( 'color:red;margin:5px;', 'color', false );
$this->assertEquals( 'margin:5px;', $result );
$this->assertSame( 'margin:5px;', $result );
// Removes a property with 0.
$result = $this->merge_style_property( 'color:red;margin:5px;', 'color', 0 );
$this->assertEquals( 'margin:5px;', $result );
$this->assertSame( 'margin:5px;', $result );
// It doesn't add a new property with an empty string.
$result = $this->merge_style_property( 'color:red;', 'padding', '' );
$this->assertEquals( 'color:red;', $result );
$this->assertSame( 'color:red;', $result );
// It doesn't add a new property with null.
$result = $this->merge_style_property( 'color:red;', 'padding', null );
$this->assertEquals( 'color:red;', $result );
$this->assertSame( 'color:red;', $result );
// It doesn't add a new property with false.
$result = $this->merge_style_property( 'color:red;', 'padding', false );
$this->assertEquals( 'color:red;', $result );
$this->assertSame( 'color:red;', $result );
// It doesn't add a new property with 0.
$result = $this->merge_style_property( 'color:red;', 'padding', 0 );
$this->assertEquals( 'color:red;', $result );
$this->assertSame( 'color:red;', $result );
}
/**
@ -170,7 +170,7 @@ class Tests_WP_Interactivity_API_WP_Style extends WP_UnitTestCase {
public function test_wp_style_sets_style_attribute() {
$html = '<div data-wp-style--color="myPlugin::state.green">Text</div>';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'color:green;', $p->get_attribute( 'style' ) );
$this->assertSame( 'color:green;', $p->get_attribute( 'style' ) );
}
/**
@ -188,7 +188,7 @@ class Tests_WP_Interactivity_API_WP_Style extends WP_UnitTestCase {
data-wp-style--background="myPlugin::state.green"
>Text</div>';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'color:green;background:green;', $p->get_attribute( 'style' ) );
$this->assertSame( 'color:green;background:green;', $p->get_attribute( 'style' ) );
}
/**
@ -206,7 +206,7 @@ class Tests_WP_Interactivity_API_WP_Style extends WP_UnitTestCase {
data-wp-style--background="myPlugin::state.false"
>Text</div>';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'color:green;', $p->get_attribute( 'style' ) );
$this->assertSame( 'color:green;', $p->get_attribute( 'style' ) );
$html = '
<div
@ -215,7 +215,7 @@ class Tests_WP_Interactivity_API_WP_Style extends WP_UnitTestCase {
data-wp-style--background="myPlugin::state.false"
>Text</div>';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'color:green;', $p->get_attribute( 'style' ) );
$this->assertSame( 'color:green;', $p->get_attribute( 'style' ) );
}
/**
@ -229,7 +229,7 @@ class Tests_WP_Interactivity_API_WP_Style extends WP_UnitTestCase {
public function test_wp_style_sets_style_property_when_style_attribute_exists() {
$html = '<div style="padding:10px;" data-wp-style--color="myPlugin::state.green">Text</div>';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'padding:10px;color:green;', $p->get_attribute( 'style' ) );
$this->assertSame( 'padding:10px;color:green;', $p->get_attribute( 'style' ) );
}
/**
@ -243,7 +243,7 @@ class Tests_WP_Interactivity_API_WP_Style extends WP_UnitTestCase {
public function test_wp_style_overwrites_style_property_when_style_property_exists() {
$html = '<div style="color:red;" data-wp-style--color="myPlugin::state.green">Text</div>';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'color:green;', $p->get_attribute( 'style' ) );
$this->assertSame( 'color:green;', $p->get_attribute( 'style' ) );
}
/**
@ -271,7 +271,7 @@ class Tests_WP_Interactivity_API_WP_Style extends WP_UnitTestCase {
public function test_wp_style_doesnt_add_style_property_on_false() {
$html = '<div style="padding:10px;" data-wp-style--color="myPlugin::state.false">Text</div>';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'padding:10px;', $p->get_attribute( 'style' ) );
$this->assertSame( 'padding:10px;', $p->get_attribute( 'style' ) );
}
/**
@ -285,7 +285,7 @@ class Tests_WP_Interactivity_API_WP_Style extends WP_UnitTestCase {
public function test_wp_style_keeps_style_property_when_style_property_exists() {
$html = '<div style="color:green;" data-wp-style--color="myPlugin::state.green">Text</div>';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'color:green;', $p->get_attribute( 'style' ) );
$this->assertSame( 'color:green;', $p->get_attribute( 'style' ) );
}
/**
@ -299,7 +299,7 @@ class Tests_WP_Interactivity_API_WP_Style extends WP_UnitTestCase {
public function test_wp_style_keeps_style_property_when_style_property_exists_and_is_not_the_only_one() {
$html = '<div style="padding:10px;color:green;" data-wp-style--color="myPlugin::state.green">Text</div>';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'padding:10px;color:green;', $p->get_attribute( 'style' ) );
$this->assertSame( 'padding:10px;color:green;', $p->get_attribute( 'style' ) );
}
/**
@ -327,7 +327,7 @@ class Tests_WP_Interactivity_API_WP_Style extends WP_UnitTestCase {
public function test_wp_style_removes_style_property_when_style_property_exists_and_is_not_the_only_one() {
$html = '<div style="padding:10px;color:green;" data-wp-style--color="myPlugin::state.false">Text</div>';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'padding:10px;', $p->get_attribute( 'style' ) );
$this->assertSame( 'padding:10px;', $p->get_attribute( 'style' ) );
}
/**
@ -355,7 +355,7 @@ class Tests_WP_Interactivity_API_WP_Style extends WP_UnitTestCase {
public function test_wp_style_doesnt_change_style_attribute_with_empty_directive_suffix() {
$html = '<div style="padding:10px;" data-wp-style="myPlugin::state.green">Text</div>';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'padding:10px;', $p->get_attribute( 'style' ) );
$this->assertSame( 'padding:10px;', $p->get_attribute( 'style' ) );
}
/**
@ -370,7 +370,7 @@ class Tests_WP_Interactivity_API_WP_Style extends WP_UnitTestCase {
public function test_wp_style_doesnt_change_style_attribute_with_empty_value() {
$html = '<div style="padding:10px" data-wp-style--color="">Text</div>';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'padding:10px;', $p->get_attribute( 'style' ) );
$this->assertSame( 'padding:10px;', $p->get_attribute( 'style' ) );
}
/**
@ -385,7 +385,7 @@ class Tests_WP_Interactivity_API_WP_Style extends WP_UnitTestCase {
public function test_wp_style_doesnt_change_style_attribute_without_value() {
$html = '<div style="padding: 10px;" data-wp-style--color>Text</div>';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'padding:10px;', $p->get_attribute( 'style' ) );
$this->assertSame( 'padding:10px;', $p->get_attribute( 'style' ) );
}
/**
@ -399,7 +399,7 @@ class Tests_WP_Interactivity_API_WP_Style extends WP_UnitTestCase {
public function test_wp_style_works_with_multiple_directives() {
$html = '<div data-wp-style--color="myPlugin::state.green" data-wp-style--color="myPlugin::state.green">Text</div>';
list($p) = $this->process_directives( $html );
$this->assertEquals( 'color:green;', $p->get_attribute( 'style' ) );
$this->assertSame( 'color:green;', $p->get_attribute( 'style' ) );
}
/**

View File

@ -39,7 +39,7 @@ class Tests_Interactivity_API_WpInteractivityAPIWPText extends WP_UnitTestCase {
public function test_wp_text_sets_inner_content() {
$html = '<div data-wp-text="myPlugin::state.text">Text</div>';
$new_html = $this->interactivity->process_directives( $html );
$this->assertEquals( '<div data-wp-text="myPlugin::state.text">Updated</div>', $new_html );
$this->assertSame( '<div data-wp-text="myPlugin::state.text">Updated</div>', $new_html );
}
/**
@ -53,7 +53,7 @@ class Tests_Interactivity_API_WpInteractivityAPIWPText extends WP_UnitTestCase {
$this->interactivity->state( 'myPlugin', array( 'number' => 100 ) );
$html = '<div data-wp-text="myPlugin::state.number">Text</div>';
$new_html = $this->interactivity->process_directives( $html );
$this->assertEquals( '<div data-wp-text="myPlugin::state.number">100</div>', $new_html );
$this->assertSame( '<div data-wp-text="myPlugin::state.number">100</div>', $new_html );
}
/**
@ -77,23 +77,23 @@ class Tests_Interactivity_API_WpInteractivityAPIWPText extends WP_UnitTestCase {
);
$html = '<div data-wp-text="myPlugin::state.true">Text</div>';
$new_html = $this->interactivity->process_directives( $html );
$this->assertEquals( '<div data-wp-text="myPlugin::state.true"></div>', $new_html );
$this->assertSame( '<div data-wp-text="myPlugin::state.true"></div>', $new_html );
$html = '<div data-wp-text="myPlugin::state.false">Text</div>';
$new_html = $this->interactivity->process_directives( $html );
$this->assertEquals( '<div data-wp-text="myPlugin::state.false"></div>', $new_html );
$this->assertSame( '<div data-wp-text="myPlugin::state.false"></div>', $new_html );
$html = '<div data-wp-text="myPlugin::state.null">Text</div>';
$new_html = $this->interactivity->process_directives( $html );
$this->assertEquals( '<div data-wp-text="myPlugin::state.null"></div>', $new_html );
$this->assertSame( '<div data-wp-text="myPlugin::state.null"></div>', $new_html );
$html = '<div data-wp-text="myPlugin::state.array">Text</div>';
$new_html = $this->interactivity->process_directives( $html );
$this->assertEquals( '<div data-wp-text="myPlugin::state.array"></div>', $new_html );
$this->assertSame( '<div data-wp-text="myPlugin::state.array"></div>', $new_html );
$html = '<div data-wp-text="myPlugin::state.func">Text</div>';
$new_html = $this->interactivity->process_directives( $html );
$this->assertEquals( '<div data-wp-text="myPlugin::state.func"></div>', $new_html );
$this->assertSame( '<div data-wp-text="myPlugin::state.func"></div>', $new_html );
}
/**
@ -107,7 +107,7 @@ class Tests_Interactivity_API_WpInteractivityAPIWPText extends WP_UnitTestCase {
public function test_wp_text_sets_inner_content_with_nested_tags() {
$html = '<div data-wp-text="myPlugin::state.text"><div><div>Text</div><div>Another text</div></div></div>';
$new_html = $this->interactivity->process_directives( $html );
$this->assertEquals( '<div data-wp-text="myPlugin::state.text">Updated</div>', $new_html );
$this->assertSame( '<div data-wp-text="myPlugin::state.text">Updated</div>', $new_html );
}
/**
@ -121,7 +121,7 @@ class Tests_Interactivity_API_WpInteractivityAPIWPText extends WP_UnitTestCase {
public function test_wp_text_sets_inner_content_even_with_unbalanced_but_different_tags_inside_content() {
$html = '<div data-wp-text="myPlugin::state.text"><span>Text</div>';
$new_html = $this->interactivity->process_directives( $html );
$this->assertEquals( '<div data-wp-text="myPlugin::state.text">Updated</div>', $new_html );
$this->assertSame( '<div data-wp-text="myPlugin::state.text">Updated</div>', $new_html );
}
/**
@ -137,7 +137,7 @@ class Tests_Interactivity_API_WpInteractivityAPIWPText extends WP_UnitTestCase {
public function test_wp_text_fails_with_unbalanced_and_same_tags_inside_content() {
$html = '<div data-wp-text="myPlugin::state.text">Text<div></div>';
$new_html = $this->interactivity->process_directives( $html );
$this->assertEquals( '<div data-wp-text="myPlugin::state.text">Text<div></div>', $new_html );
$this->assertSame( '<div data-wp-text="myPlugin::state.text">Text<div></div>', $new_html );
}
/**
@ -152,6 +152,6 @@ class Tests_Interactivity_API_WpInteractivityAPIWPText extends WP_UnitTestCase {
$this->interactivity->state( 'myPlugin', array( 'text' => '<span>Updated</span>' ) );
$html = '<div data-wp-text="myPlugin::state.text">Text</div>';
$new_html = $this->interactivity->process_directives( $html );
$this->assertEquals( '<div data-wp-text="myPlugin::state.text">&lt;span&gt;Updated&lt;/span&gt;</div>', $new_html );
$this->assertSame( '<div data-wp-text="myPlugin::state.text">&lt;span&gt;Updated&lt;/span&gt;</div>', $new_html );
}
}

View File

@ -69,8 +69,8 @@ class Tests_Interactivity_API_WpInteractivityAPI extends WP_UnitTestCase {
* @covers ::config
*/
public function test_state_and_config_should_be_empty() {
$this->assertEquals( array(), $this->interactivity->state( 'myPlugin' ) );
$this->assertEquals( array(), $this->interactivity->config( 'myPlugin' ) );
$this->assertSame( array(), $this->interactivity->state( 'myPlugin' ) );
$this->assertSame( array(), $this->interactivity->config( 'myPlugin' ) );
}
/**
@ -89,9 +89,9 @@ class Tests_Interactivity_API_WpInteractivityAPI extends WP_UnitTestCase {
'nested' => array( 'c' => 3 ),
);
$result = $this->interactivity->state( 'myPlugin', $state );
$this->assertEquals( $state, $result );
$this->assertSame( $state, $result );
$result = $this->interactivity->config( 'myPlugin', $state );
$this->assertEquals( $state, $result );
$this->assertSame( $state, $result );
}
/**
@ -106,14 +106,14 @@ class Tests_Interactivity_API_WpInteractivityAPI extends WP_UnitTestCase {
$this->interactivity->state( 'myPlugin', array( 'a' => 1 ) );
$this->interactivity->state( 'myPlugin', array( 'b' => 2 ) );
$this->interactivity->state( 'otherPlugin', array( 'c' => 3 ) );
$this->assertEquals(
$this->assertSame(
array(
'a' => 1,
'b' => 2,
),
$this->interactivity->state( 'myPlugin' )
);
$this->assertEquals(
$this->assertSame(
array( 'c' => 3 ),
$this->interactivity->state( 'otherPlugin' )
);
@ -121,14 +121,14 @@ class Tests_Interactivity_API_WpInteractivityAPI extends WP_UnitTestCase {
$this->interactivity->config( 'myPlugin', array( 'a' => 1 ) );
$this->interactivity->config( 'myPlugin', array( 'b' => 2 ) );
$this->interactivity->config( 'otherPlugin', array( 'c' => 3 ) );
$this->assertEquals(
$this->assertSame(
array(
'a' => 1,
'b' => 2,
),
$this->interactivity->config( 'myPlugin' )
);
$this->assertEquals(
$this->assertSame(
array( 'c' => 3 ),
$this->interactivity->config( 'otherPlugin' )
); }
@ -145,14 +145,14 @@ class Tests_Interactivity_API_WpInteractivityAPI extends WP_UnitTestCase {
public function test_state_and_config_existing_props_can_be_overwritten() {
$this->interactivity->state( 'myPlugin', array( 'a' => 1 ) );
$this->interactivity->state( 'myPlugin', array( 'a' => 2 ) );
$this->assertEquals(
$this->assertSame(
array( 'a' => 2 ),
$this->interactivity->state( 'myPlugin' )
);
$this->interactivity->config( 'myPlugin', array( 'a' => 1 ) );
$this->interactivity->config( 'myPlugin', array( 'a' => 2 ) );
$this->assertEquals(
$this->assertSame(
array( 'a' => 2 ),
$this->interactivity->config( 'myPlugin' )
);
@ -170,14 +170,14 @@ class Tests_Interactivity_API_WpInteractivityAPI extends WP_UnitTestCase {
public function test_state_and_config_existing_indexed_arrays_are_replaced() {
$this->interactivity->state( 'myPlugin', array( 'a' => array( 1, 2 ) ) );
$this->interactivity->state( 'myPlugin', array( 'a' => array( 3, 4 ) ) );
$this->assertEquals(
$this->assertSame(
array( 'a' => array( 3, 4 ) ),
$this->interactivity->state( 'myPlugin' )
);
$this->interactivity->config( 'myPlugin', array( 'a' => array( 1, 2 ) ) );
$this->interactivity->config( 'myPlugin', array( 'a' => array( 3, 4 ) ) );
$this->assertEquals(
$this->assertSame(
array( 'a' => array( 3, 4 ) ),
$this->interactivity->config( 'myPlugin' )
);
@ -218,10 +218,10 @@ class Tests_Interactivity_API_WpInteractivityAPI extends WP_UnitTestCase {
'otherPlugin' => array( 'b' => 2 ),
);
$this->assertEquals(
$this->assertSame(
array(
'state' => $data,
'config' => $data,
'state' => $data,
),
$result
);
@ -251,7 +251,7 @@ class Tests_Interactivity_API_WpInteractivityAPI extends WP_UnitTestCase {
public function test_config_not_printed_when_empty() {
$this->interactivity->state( 'myPlugin', array( 'a' => 1 ) );
$result = $this->print_client_interactivity_data();
$this->assertEquals( array( 'state' => array( 'myPlugin' => array( 'a' => 1 ) ) ), $result );
$this->assertSame( array( 'state' => array( 'myPlugin' => array( 'a' => 1 ) ) ), $result );
}
/**
@ -265,7 +265,7 @@ class Tests_Interactivity_API_WpInteractivityAPI extends WP_UnitTestCase {
public function test_state_not_printed_when_empty() {
$this->interactivity->config( 'myPlugin', array( 'a' => 1 ) );
$result = $this->print_client_interactivity_data();
$this->assertEquals( array( 'config' => array( 'myPlugin' => array( 'a' => 1 ) ) ), $result );
$this->assertSame( array( 'config' => array( 'myPlugin' => array( 'a' => 1 ) ) ), $result );
}
/**
@ -286,7 +286,7 @@ class Tests_Interactivity_API_WpInteractivityAPI extends WP_UnitTestCase {
SCRIPT_TAG;
$this->assertSame( $expected, $printed_script );
$this->assertSameIgnoreEOL( $expected, $printed_script );
}
/**
@ -319,7 +319,7 @@ SCRIPT_TAG;
SCRIPT_TAG;
$this->assertSame( $expected, $printed_script );
$this->assertSameIgnoreEOL( $expected, $printed_script );
}
/**
@ -340,7 +340,7 @@ SCRIPT_TAG;
SCRIPT_TAG;
$this->assertSame( $expected, $printed_script );
$this->assertSameIgnoreEOL( $expected, $printed_script );
}
/**
@ -373,7 +373,7 @@ SCRIPT_TAG;
SCRIPT_TAG;
$this->assertSame( $expected, $printed_script );
$this->assertSameIgnoreEOL( $expected, $printed_script );
}
/**
@ -410,7 +410,7 @@ SCRIPT_TAG;
$expected = <<<"JSON"
{"config":{"myPlugin":{"chars":"&\\u003C\\u003E/"}},"state":{"myPlugin":{"ampersand":"&","less-than sign":"\\u003C","greater-than sign":"\\u003E","solidus":"/","line separator":"\u{2028}","paragraph separator":"\u{2029}","flag of england":"\u{1F3F4}\u{E0067}\u{E0062}\u{E0065}\u{E006E}\u{E0067}\u{E007F}","malicious script closer":"\\u003C/script\\u003E","entity-encoded malicious script closer":"&lt;/script&gt;"}}}
JSON;
$this->assertEquals( $expected, $interactivity_data_string[1] );
$this->assertSame( $expected, $interactivity_data_string[1] );
}
/**
@ -450,7 +450,7 @@ JSON;
$expected = <<<"JSON"
{"config":{"myPlugin":{"chars":"&\\u003C\\u003E/"}},"state":{"myPlugin":{"ampersand":"&","less-than sign":"\\u003C","greater-than sign":"\\u003E","solidus":"/","line separator":"\\u2028","paragraph separator":"\\u2029","flag of england":"\\ud83c\\udff4\\udb40\\udc67\\udb40\\udc62\\udb40\\udc65\\udb40\\udc6e\\udb40\\udc67\\udb40\\udc7f","malicious script closer":"\\u003C/script\\u003E","entity-encoded malicious script closer":"&lt;/script&gt;"}}}
JSON;
$this->assertEquals( $expected, $interactivity_data_string[1] );
$this->assertSame( $expected, $interactivity_data_string[1] );
}
/**
@ -467,7 +467,7 @@ JSON;
$this->interactivity->state( 'myPlugin', array( 'a' => 1 ) );
$this->interactivity->state( 'otherPlugin', array( 'b' => 2 ) );
$this->assertEquals(
$this->assertSame(
array( 'a' => 1 ),
$this->interactivity->state()
);
@ -488,7 +488,7 @@ JSON;
$this->interactivity->state( 'myPlugin', array( 'a' => 1 ) );
$this->interactivity->state( 'otherPlugin', array( 'b' => 2 ) );
$this->assertEquals(
$this->assertSame(
array(),
$this->interactivity->state( null, array( 'newProp' => 'value' ) )
);
@ -508,7 +508,7 @@ JSON;
$this->interactivity->state( 'myPlugin', array( 'a' => 1 ) );
$this->interactivity->state( 'otherPlugin', array( 'b' => 2 ) );
$this->assertEquals(
$this->assertSame(
array(),
$this->interactivity->state( '' )
);
@ -524,7 +524,7 @@ JSON;
* @expectedIncorrectUsage WP_Interactivity_API::state
*/
public function test_state_without_namespace_outside_directive_processing() {
$this->assertEquals(
$this->assertSame(
array(),
$this->interactivity->state()
);
@ -550,11 +550,11 @@ JSON;
)
);
$this->assertEquals(
$this->assertSame(
array( 'a' => 1 ),
$this->interactivity->get_context( 'myPlugin' )
);
$this->assertEquals(
$this->assertSame(
array( 'b' => 2 ),
$this->interactivity->get_context( 'otherPlugin' )
);
@ -580,7 +580,7 @@ JSON;
)
);
$this->assertEquals(
$this->assertSame(
array( 'a' => 1 ),
$this->interactivity->get_context()
);
@ -598,7 +598,7 @@ JSON;
$this->set_internal_namespace_stack( 'myPlugin' );
$this->set_internal_context_stack();
$this->assertEquals(
$this->assertSame(
array(),
$this->interactivity->get_context( 'myPlugin' )
);
@ -623,7 +623,7 @@ JSON;
)
);
$this->assertEquals(
$this->assertSame(
array(),
$this->interactivity->get_context( 'otherPlugin' )
);
@ -648,7 +648,7 @@ JSON;
)
);
$this->assertEquals(
$this->assertSame(
array(),
$this->interactivity->get_context( '' )
);
@ -666,7 +666,7 @@ JSON;
*/
public function test_get_context_outside_of_directive_processing() {
$context = $this->interactivity->get_context();
$this->assertEquals( array(), $context );
$this->assertSame( array(), $context );
}
/**
@ -681,55 +681,55 @@ JSON;
$extract_directive_value->setAccessible( true );
$result = $extract_directive_value->invoke( $this->interactivity, 'state.foo', 'myPlugin' );
$this->assertEquals( array( 'myPlugin', 'state.foo' ), $result );
$this->assertSame( array( 'myPlugin', 'state.foo' ), $result );
$result = $extract_directive_value->invoke( $this->interactivity, 'otherPlugin::state.foo', 'myPlugin' );
$this->assertEquals( array( 'otherPlugin', 'state.foo' ), $result );
$this->assertSame( array( 'otherPlugin', 'state.foo' ), $result );
$result = $extract_directive_value->invoke( $this->interactivity, '{ "isOpen": false }', 'myPlugin' );
$this->assertEquals( array( 'myPlugin', array( 'isOpen' => false ) ), $result );
$this->assertSame( array( 'myPlugin', array( 'isOpen' => false ) ), $result );
$result = $extract_directive_value->invoke( $this->interactivity, 'otherPlugin::{ "isOpen": false }', 'myPlugin' );
$this->assertEquals( array( 'otherPlugin', array( 'isOpen' => false ) ), $result );
$this->assertSame( array( 'otherPlugin', array( 'isOpen' => false ) ), $result );
$result = $extract_directive_value->invoke( $this->interactivity, 'true', 'myPlugin' );
$this->assertEquals( array( 'myPlugin', true ), $result );
$this->assertSame( array( 'myPlugin', true ), $result );
$result = $extract_directive_value->invoke( $this->interactivity, 'false', 'myPlugin' );
$this->assertEquals( array( 'myPlugin', false ), $result );
$this->assertSame( array( 'myPlugin', false ), $result );
$result = $extract_directive_value->invoke( $this->interactivity, 'null', 'myPlugin' );
$this->assertEquals( array( 'myPlugin', null ), $result );
$this->assertSame( array( 'myPlugin', null ), $result );
$result = $extract_directive_value->invoke( $this->interactivity, '100', 'myPlugin' );
$this->assertEquals( array( 'myPlugin', 100 ), $result );
$this->assertSame( array( 'myPlugin', 100 ), $result );
$result = $extract_directive_value->invoke( $this->interactivity, '1.2', 'myPlugin' );
$this->assertEquals( array( 'myPlugin', 1.2 ), $result );
$this->assertSame( array( 'myPlugin', 1.2 ), $result );
$result = $extract_directive_value->invoke( $this->interactivity, '1.2.3', 'myPlugin' );
$this->assertEquals( array( 'myPlugin', '1.2.3' ), $result );
$this->assertSame( array( 'myPlugin', '1.2.3' ), $result );
$result = $extract_directive_value->invoke( $this->interactivity, 'otherPlugin::true', 'myPlugin' );
$this->assertEquals( array( 'otherPlugin', true ), $result );
$this->assertSame( array( 'otherPlugin', true ), $result );
$result = $extract_directive_value->invoke( $this->interactivity, 'otherPlugin::false', 'myPlugin' );
$this->assertEquals( array( 'otherPlugin', false ), $result );
$this->assertSame( array( 'otherPlugin', false ), $result );
$result = $extract_directive_value->invoke( $this->interactivity, 'otherPlugin::null', 'myPlugin' );
$this->assertEquals( array( 'otherPlugin', null ), $result );
$this->assertSame( array( 'otherPlugin', null ), $result );
$result = $extract_directive_value->invoke( $this->interactivity, 'otherPlugin::100', 'myPlugin' );
$this->assertEquals( array( 'otherPlugin', 100 ), $result );
$this->assertSame( array( 'otherPlugin', 100 ), $result );
$result = $extract_directive_value->invoke( $this->interactivity, 'otherPlugin::1.2', 'myPlugin' );
$this->assertEquals( array( 'otherPlugin', 1.2 ), $result );
$this->assertSame( array( 'otherPlugin', 1.2 ), $result );
$result = $extract_directive_value->invoke( $this->interactivity, 'otherPlugin::1.2.3', 'myPlugin' );
$this->assertEquals( array( 'otherPlugin', '1.2.3' ), $result );
$this->assertSame( array( 'otherPlugin', '1.2.3' ), $result );
$result = $extract_directive_value->invoke( $this->interactivity, 'otherPlugin::[{"o":4}, null, 3e6]', 'myPlugin' );
$this->assertEquals( array( 'otherPlugin', array( array( 'o' => 4 ), null, 3000000.0 ) ), $result );
$this->assertSame( array( 'otherPlugin', array( array( 'o' => 4 ), null, 3000000.0 ) ), $result );
}
/**
@ -744,26 +744,26 @@ JSON;
$extract_directive_value->setAccessible( true );
$result = $extract_directive_value->invoke( $this->interactivity, '', 'myPlugin' );
$this->assertEquals( array( 'myPlugin', null ), $result );
$this->assertSame( array( 'myPlugin', null ), $result );
// This is a boolean attribute.
$result = $extract_directive_value->invoke( $this->interactivity, true, 'myPlugin' );
$this->assertEquals( array( 'myPlugin', null ), $result );
$this->assertSame( array( 'myPlugin', null ), $result );
$result = $extract_directive_value->invoke( $this->interactivity, false, 'myPlugin' );
$this->assertEquals( array( 'myPlugin', null ), $result );
$this->assertSame( array( 'myPlugin', null ), $result );
$result = $extract_directive_value->invoke( $this->interactivity, null, 'myPlugin' );
$this->assertEquals( array( 'myPlugin', null ), $result );
$this->assertSame( array( 'myPlugin', null ), $result );
// A string ending in `::` without any extra characters is not considered a
// namespace.
$result = $extract_directive_value->invoke( $this->interactivity, 'myPlugin::', 'myPlugin' );
$this->assertEquals( array( 'myPlugin', 'myPlugin::' ), $result );
$this->assertSame( array( 'myPlugin', 'myPlugin::' ), $result );
// A namespace with invalid characters is not considered a valid namespace.
$result = $extract_directive_value->invoke( $this->interactivity, '$myPlugin::state.foo', 'myPlugin' );
$this->assertEquals( array( 'myPlugin', '$myPlugin::state.foo' ), $result );
$this->assertSame( array( 'myPlugin', '$myPlugin::state.foo' ), $result );
}
/**
@ -779,11 +779,11 @@ JSON;
// Invalid JSON due to missing quotes. Returns the original value.
$result = $extract_directive_value->invoke( $this->interactivity, '{ isOpen: false }', 'myPlugin' );
$this->assertEquals( array( 'myPlugin', '{ isOpen: false }' ), $result );
$this->assertSame( array( 'myPlugin', '{ isOpen: false }' ), $result );
// Null string. Returns null.
$result = $extract_directive_value->invoke( $this->interactivity, 'null', 'myPlugin' );
$this->assertEquals( array( 'myPlugin', null ), $result );
$this->assertSame( array( 'myPlugin', null ), $result );
}
/**
@ -799,13 +799,13 @@ JSON;
$extract_prefix_and_suffix->setAccessible( true );
$result = $extract_prefix_and_suffix->invoke( $this->interactivity, 'data-wp-interactive' );
$this->assertEquals( array( 'data-wp-interactive' ), $result );
$this->assertSame( array( 'data-wp-interactive' ), $result );
$result = $extract_prefix_and_suffix->invoke( $this->interactivity, 'data-wp-bind--src' );
$this->assertEquals( array( 'data-wp-bind', 'src' ), $result );
$this->assertSame( array( 'data-wp-bind', 'src' ), $result );
$result = $extract_prefix_and_suffix->invoke( $this->interactivity, 'data-wp-foo--and--bar' );
$this->assertEquals( array( 'data-wp-foo', 'and--bar' ), $result );
$this->assertSame( array( 'data-wp-foo', 'and--bar' ), $result );
}
/**
@ -819,11 +819,11 @@ JSON;
public function test_process_directives_do_nothing_without_directives() {
$html = '<div>Inner content here</div>';
$processed_html = $this->interactivity->process_directives( $html );
$this->assertEquals( $html, $processed_html );
$this->assertSame( $html, $processed_html );
$html = '<div><span>Content</span><strong>More Content</strong></div>';
$processed_html = $this->interactivity->process_directives( $html );
$this->assertEquals( $html, $processed_html );
$this->assertSame( $html, $processed_html );
}
/**
@ -840,7 +840,7 @@ JSON;
$processed_html = $this->interactivity->process_directives( $html );
$p = new WP_HTML_Tag_Processor( $processed_html );
$p->next_tag();
$this->assertEquals( 'some-id', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id', $p->get_attribute( 'id' ) );
}
/**
@ -853,7 +853,7 @@ JSON;
public function test_process_directives_doesnt_fail_with_unknown_directives() {
$html = '<div data-wp-unknown="">Text</div>';
$processed_html = $this->interactivity->process_directives( $html );
$this->assertEquals( $html, $processed_html );
$this->assertSame( $html, $processed_html );
}
/**
@ -876,9 +876,9 @@ JSON;
$processed_html = $this->interactivity->process_directives( $html );
$p = new WP_HTML_Tag_Processor( $processed_html );
$p->next_tag();
$this->assertEquals( 'some-id', $p->get_attribute( 'id' ) );
$this->assertEquals( 'some-class', $p->get_attribute( 'class' ) );
$this->assertEquals( 'display:none;', $p->get_attribute( 'style' ) );
$this->assertSame( 'some-id', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-class', $p->get_attribute( 'class' ) );
$this->assertSame( 'display:none;', $p->get_attribute( 'style' ) );
$this->assertStringContainsString( 'Updated', $p->get_updated_html() );
$this->assertStringNotContainsString( 'Text', $p->get_updated_html() );
}
@ -952,7 +952,7 @@ JSON;
$processed_html = $this->interactivity->process_directives( $html );
$p = new WP_HTML_Tag_Processor( $processed_html );
$p->next_tag( 'div' );
$this->assertEquals( 'some-id', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id', $p->get_attribute( 'id' ) );
}
/**
@ -1017,7 +1017,7 @@ JSON;
$p->next_tag( 'math' );
$this->assertNull( $p->get_attribute( 'id' ) );
$p->next_tag( 'div' );
$this->assertEquals( 'some-id', $p->get_attribute( 'id' ) );
$this->assertSame( 'some-id', $p->get_attribute( 'id' ) );
}
/**
@ -1121,16 +1121,16 @@ JSON;
$this->set_internal_namespace_stack( 'myPlugin' );
$result = $this->evaluate( 'state.key' );
$this->assertEquals( 'myPlugin-state', $result );
$this->assertSame( 'myPlugin-state', $result );
$result = $this->evaluate( 'context.key' );
$this->assertEquals( 'myPlugin-context', $result );
$this->assertSame( 'myPlugin-context', $result );
$result = $this->evaluate( 'otherPlugin::state.key' );
$this->assertEquals( 'otherPlugin-state', $result );
$this->assertSame( 'otherPlugin-state', $result );
$result = $this->evaluate( 'otherPlugin::context.key' );
$this->assertEquals( 'otherPlugin-context', $result );
$this->assertSame( 'otherPlugin-context', $result );
$result = $this->evaluate( 'state.obj.prop' );
$this->assertSame( 'object property', $result );
@ -1241,16 +1241,16 @@ JSON;
$this->set_internal_namespace_stack( 'myPlugin' );
$result = $this->evaluate( 'state.nested.key' );
$this->assertEquals( 'myPlugin-state-nested', $result );
$this->assertSame( 'myPlugin-state-nested', $result );
$result = $this->evaluate( 'context.nested.key' );
$this->assertEquals( 'myPlugin-context-nested', $result );
$this->assertSame( 'myPlugin-context-nested', $result );
$result = $this->evaluate( 'otherPlugin::state.nested.key' );
$this->assertEquals( 'otherPlugin-state-nested', $result );
$this->assertSame( 'otherPlugin-state-nested', $result );
$result = $this->evaluate( 'otherPlugin::context.nested.key' );
$this->assertEquals( 'otherPlugin-context-nested', $result );
$this->assertSame( 'otherPlugin-context-nested', $result );
}
/**

View File

@ -24,14 +24,14 @@ class Tests_Interactivity_API_WpInteractivityAPIDirectivesProcessor extends WP_U
$content = '<template>Text</template>';
$p = new WP_Interactivity_API_Directives_Processor( $content );
$p->next_tag();
$this->assertEquals( 'Text', $p->get_content_between_balanced_template_tags() );
$this->assertSame( 'Text', $p->get_content_between_balanced_template_tags() );
$content = '<template>Text</template><template>More text</template>';
$p = new WP_Interactivity_API_Directives_Processor( $content );
$p->next_tag();
$this->assertEquals( 'Text', $p->get_content_between_balanced_template_tags() );
$this->assertSame( 'Text', $p->get_content_between_balanced_template_tags() );
$p->next_tag();
$this->assertEquals( 'More text', $p->get_content_between_balanced_template_tags() );
$this->assertSame( 'More text', $p->get_content_between_balanced_template_tags() );
}
/**
@ -46,7 +46,7 @@ class Tests_Interactivity_API_WpInteractivityAPIDirectivesProcessor extends WP_U
$content = '<template></template>';
$p = new WP_Interactivity_API_Directives_Processor( $content );
$p->next_tag();
$this->assertEquals( '', $p->get_content_between_balanced_template_tags() );
$this->assertSame( '', $p->get_content_between_balanced_template_tags() );
}
/**
@ -81,12 +81,12 @@ class Tests_Interactivity_API_WpInteractivityAPIDirectivesProcessor extends WP_U
$content = '<template><span>Content</span><strong>More Content</strong></template>';
$p = new WP_Interactivity_API_Directives_Processor( $content );
$p->next_tag();
$this->assertEquals( '<span>Content</span><strong>More Content</strong>', $p->get_content_between_balanced_template_tags() );
$this->assertSame( '<span>Content</span><strong>More Content</strong>', $p->get_content_between_balanced_template_tags() );
$content = '<template><template>Content</template><img src="example.jpg"></template>';
$p = new WP_Interactivity_API_Directives_Processor( $content );
$p->next_tag();
$this->assertEquals( '<template>Content</template><img src="example.jpg">', $p->get_content_between_balanced_template_tags() );
$this->assertSame( '<template>Content</template><img src="example.jpg">', $p->get_content_between_balanced_template_tags() );
}
/**
@ -131,7 +131,7 @@ class Tests_Interactivity_API_WpInteractivityAPIDirectivesProcessor extends WP_U
$content = '<template>Missing opening span</span></template>';
$p = new WP_Interactivity_API_Directives_Processor( $content );
$p->next_tag();
$this->assertEquals( 'Missing opening span</span>', $p->get_content_between_balanced_template_tags() );
$this->assertSame( 'Missing opening span</span>', $p->get_content_between_balanced_template_tags() );
}
/**
@ -163,10 +163,10 @@ class Tests_Interactivity_API_WpInteractivityAPIDirectivesProcessor extends WP_U
$p = new WP_Interactivity_API_Directives_Processor( $content );
$p->next_tag();
$p->get_content_between_balanced_template_tags();
$this->assertEquals( 'TEMPLATE', $p->get_tag() );
$this->assertSame( 'TEMPLATE', $p->get_tag() );
$this->assertTrue( $p->is_tag_closer() );
$p->next_tag();
$this->assertEquals( 'DIV', $p->get_tag() );
$this->assertSame( 'DIV', $p->get_tag() );
}
/**
@ -479,13 +479,13 @@ class Tests_Interactivity_API_WpInteractivityAPIDirectivesProcessor extends WP_U
$this->assertTrue( $result );
$this->assertEquals( $content_1 . $content_2, $p );
$p->next_tag( array( 'tag_closers' => 'visit' ) );
$this->assertEquals( 'content-2', $p->get_attribute( 'class' ) );
$this->assertSame( 'content-2', $p->get_attribute( 'class' ) );
$p->next_tag( array( 'tag_closers' => 'visit' ) );
$result = $p->append_content_after_template_tag_closer( $content_3 );
$this->assertTrue( $result );
$p->next_tag( array( 'tag_closers' => 'visit' ) );
$this->assertEquals( $content_1 . $content_2 . $content_3, $p );
$this->assertEquals( 'content-3', $p->get_attribute( 'class' ) );
$this->assertSame( 'content-3', $p->get_attribute( 'class' ) );
}
/**
@ -509,7 +509,7 @@ class Tests_Interactivity_API_WpInteractivityAPIDirectivesProcessor extends WP_U
$this->assertTrue( $result );
$this->assertEquals( $content_1 . $content_2 . $content_3, $p );
$p->next_tag( array( 'tag_closers' => 'visit' ) );
$this->assertEquals( 'content-3', $p->get_attribute( 'class' ) );
$this->assertSame( 'content-3', $p->get_attribute( 'class' ) );
$p = new WP_Interactivity_API_Directives_Processor( $content_1 . $content_3 );
$p->next_tag( array( 'tag_closers' => 'visit' ) );
@ -518,7 +518,7 @@ class Tests_Interactivity_API_WpInteractivityAPIDirectivesProcessor extends WP_U
$this->assertTrue( $result );
$this->assertEquals( $content_1 . $content_4 . $content_3, $p );
$p->next_tag( array( 'tag_closers' => 'visit' ) );
$this->assertEquals( 'content-4', $p->get_attribute( 'class' ) );
$this->assertSame( 'content-4', $p->get_attribute( 'class' ) );
}
/**
@ -558,16 +558,16 @@ class Tests_Interactivity_API_WpInteractivityAPIDirectivesProcessor extends WP_U
$this->assertTrue( $result );
$this->assertEquals( $content_1 . $content_2, $p );
$p->next_tag( array( 'tag_closers' => 'visit' ) );
$this->assertEquals( 'content-2', $p->get_attribute( 'class' ) );
$this->assertSame( 'content-2', $p->get_attribute( 'class' ) );
// Rewinds to the first template.
$p->seek( 'first template' );
$p->release_bookmark( 'first template' );
$this->assertEquals( 'content-1', $p->get_attribute( 'class' ) );
$this->assertSame( 'content-1', $p->get_attribute( 'class' ) );
$p->next_tag( array( 'tag_closers' => 'visit' ) );
$result = $p->append_content_after_template_tag_closer( $content_3 );
$this->assertEquals( $content_1 . $content_3 . $content_2, $p );
$p->next_tag( array( 'tag_closers' => 'visit' ) );
$this->assertEquals( 'content-3', $p->get_attribute( 'class' ) );
$this->assertSame( 'content-3', $p->get_attribute( 'class' ) );
}
/**
@ -615,9 +615,9 @@ class Tests_Interactivity_API_WpInteractivityAPIDirectivesProcessor extends WP_U
$this->assertTrue( $result );
$this->assertEquals( $content_1 . $content_2, $p );
$p->next_tag();
$this->assertEquals( 'content-2-template-1', $p->get_attribute( 'class' ) );
$this->assertSame( 'content-2-template-1', $p->get_attribute( 'class' ) );
$p->next_tag();
$this->assertEquals( 'content-2-template-2', $p->get_attribute( 'class' ) );
$this->assertSame( 'content-2-template-2', $p->get_attribute( 'class' ) );
$p->next_tag( array( 'tag_closers' => 'visit' ) );
$result = $p->append_content_after_template_tag_closer( $content_3 );
$this->assertTrue( $result );
@ -640,7 +640,7 @@ class Tests_Interactivity_API_WpInteractivityAPIDirectivesProcessor extends WP_U
$result = $p->append_content_after_template_tag_closer( '' );
$this->assertFalse( $result );
$this->assertEquals( $content, $p );
$this->assertEquals( 'TEMPLATE', $p->get_tag() ); // It didn't move.
$this->assertSame( 'TEMPLATE', $p->get_tag() ); // It didn't move.
$this->assertTrue( $p->is_tag_closer() ); // It didn't move.
}
@ -694,7 +694,7 @@ class Tests_Interactivity_API_WpInteractivityAPIDirectivesProcessor extends WP_U
$p = new WP_Interactivity_API_Directives_Processor( $content );
$p->next_tag();
$this->assertTrue( $p->next_balanced_tag_closer_tag() );
$this->assertEquals( 'DIV', $p->get_tag() );
$this->assertSame( 'DIV', $p->get_tag() );
$this->assertTrue( $p->is_tag_closer() );
}
@ -731,14 +731,14 @@ class Tests_Interactivity_API_WpInteractivityAPIDirectivesProcessor extends WP_U
$p = new WP_Interactivity_API_Directives_Processor( $content );
$p->next_tag();
$this->assertTrue( $p->next_balanced_tag_closer_tag() );
$this->assertEquals( 'DIV', $p->get_tag() );
$this->assertSame( 'DIV', $p->get_tag() );
$this->assertTrue( $p->is_tag_closer() );
$content = '<div><div>Nested content</div></div>';
$p = new WP_Interactivity_API_Directives_Processor( $content );
$p->next_tag();
$this->assertTrue( $p->next_balanced_tag_closer_tag() );
$this->assertEquals( 'DIV', $p->get_tag() );
$this->assertSame( 'DIV', $p->get_tag() );
$this->assertTrue( $p->is_tag_closer() );
$this->assertFalse( $p->next_tag() ); // No more content.
}
@ -793,7 +793,7 @@ class Tests_Interactivity_API_WpInteractivityAPIDirectivesProcessor extends WP_U
$p->next_tag();
$this->assertTrue( $p->skip_to_tag_closer() );
$this->assertTrue( $p->is_tag_closer() );
$this->assertEquals( 'DIV', $p->get_tag() );
$this->assertSame( 'DIV', $p->get_tag() );
}
/**

View File

@ -76,7 +76,7 @@ class Tests_Interactivity_API_wpInteractivityAPIFunctions extends WP_UnitTestCas
$rendered_blocks = do_blocks( $post_content );
$p = new WP_HTML_Tag_Processor( $rendered_blocks );
$p->next_tag( array( 'class_name' => 'interactive/block-1' ) );
$this->assertEquals( '1', $p->get_attribute( 'value' ) );
$this->assertSame( '1', $p->get_attribute( 'value' ) );
}
/**
@ -97,13 +97,13 @@ class Tests_Interactivity_API_wpInteractivityAPIFunctions extends WP_UnitTestCas
$rendered_blocks = do_blocks( $post_content );
$p = new WP_HTML_Tag_Processor( $rendered_blocks );
$p->next_tag( array( 'class_name' => 'interactive/block-1' ) );
$this->assertEquals( '1', $p->get_attribute( 'value' ) );
$this->assertSame( '1', $p->get_attribute( 'value' ) );
$p->next_tag( array( 'class_name' => 'interactive/block-2' ) );
$this->assertEquals( '2', $p->get_attribute( 'value' ) );
$this->assertSame( '2', $p->get_attribute( 'value' ) );
$p->next_tag( array( 'class_name' => 'non-interactive/block-3' ) );
$this->assertNull( $p->get_attribute( 'value' ) );
$p->next_tag( array( 'class_name' => 'interactive/block-4' ) );
$this->assertEquals( '4', $p->get_attribute( 'value' ) );
$this->assertSame( '4', $p->get_attribute( 'value' ) );
}
/**
@ -122,7 +122,7 @@ class Tests_Interactivity_API_wpInteractivityAPIFunctions extends WP_UnitTestCas
$rendered_blocks = do_blocks( $post_content );
$p = new WP_HTML_Tag_Processor( $rendered_blocks );
$p->next_tag( array( 'class_name' => 'interactive/block-2' ) );
$this->assertEquals( '2', $p->get_attribute( 'value' ) );
$this->assertSame( '2', $p->get_attribute( 'value' ) );
}
/**
@ -143,9 +143,9 @@ class Tests_Interactivity_API_wpInteractivityAPIFunctions extends WP_UnitTestCas
$rendered_blocks = do_blocks( $post_content );
$p = new WP_HTML_Tag_Processor( $rendered_blocks );
$p->next_tag( array( 'class_name' => 'interactive/block-2' ) );
$this->assertEquals( '2', $p->get_attribute( 'value' ) );
$this->assertSame( '2', $p->get_attribute( 'value' ) );
$p->next_tag( array( 'class_name' => 'interactive/block-3' ) );
$this->assertEquals( '3', $p->get_attribute( 'value' ) );
$this->assertSame( '3', $p->get_attribute( 'value' ) );
}
/**
@ -168,9 +168,9 @@ class Tests_Interactivity_API_wpInteractivityAPIFunctions extends WP_UnitTestCas
$rendered_blocks = do_blocks( $post_content );
$p = new WP_HTML_Tag_Processor( $rendered_blocks );
$p->next_tag( array( 'class_name' => 'interactive/block-2' ) );
$this->assertEquals( '2', $p->get_attribute( 'value' ) );
$this->assertSame( '2', $p->get_attribute( 'value' ) );
$p->next_tag( array( 'class_name' => 'interactive/block-4' ) );
$this->assertEquals( '4', $p->get_attribute( 'value' ) );
$this->assertSame( '4', $p->get_attribute( 'value' ) );
}
/**
@ -190,7 +190,7 @@ class Tests_Interactivity_API_wpInteractivityAPIFunctions extends WP_UnitTestCas
$rendered_blocks = do_blocks( $post_content );
$p = new WP_HTML_Tag_Processor( $rendered_blocks );
$p->next_tag( array( 'class_name' => 'interactive/block-1' ) );
$this->assertEquals( '1', $p->get_attribute( 'value' ) );
$this->assertSame( '1', $p->get_attribute( 'value' ) );
$p->next_tag( array( 'class_name' => 'non-interactive/block-2' ) );
$this->assertNull( $p->get_attribute( 'value' ) );
}
@ -212,9 +212,9 @@ class Tests_Interactivity_API_wpInteractivityAPIFunctions extends WP_UnitTestCas
$rendered_blocks = do_blocks( $post_content );
$p = new WP_HTML_Tag_Processor( $rendered_blocks );
$p->next_tag( array( 'class_name' => 'interactive/block-1' ) );
$this->assertEquals( '1', $p->get_attribute( 'value' ) );
$this->assertSame( '1', $p->get_attribute( 'value' ) );
$p->next_tag( array( 'class_name' => 'non-interactive/block-2' ) );
$this->assertEquals( '1', $p->get_attribute( 'value' ) );
$this->assertSame( '1', $p->get_attribute( 'value' ) );
}
/**
@ -238,13 +238,13 @@ class Tests_Interactivity_API_wpInteractivityAPIFunctions extends WP_UnitTestCas
$rendered_blocks = do_blocks( $post_content );
$p = new WP_HTML_Tag_Processor( $rendered_blocks );
$p->next_tag( array( 'class_name' => 'interactive/block-1' ) );
$this->assertEquals( '1', $p->get_attribute( 'value' ) );
$this->assertSame( '1', $p->get_attribute( 'value' ) );
$p->next_tag( array( 'class_name' => 'interactive/block-2' ) );
$this->assertEquals( '2', $p->get_attribute( 'value' ) );
$this->assertSame( '2', $p->get_attribute( 'value' ) );
$p->next_tag( array( 'class_name' => 'non-interactive/block-3' ) );
$this->assertEquals( '2', $p->get_attribute( 'value' ) );
$this->assertSame( '2', $p->get_attribute( 'value' ) );
$p->next_tag( array( 'class_name' => 'non-interactive/block-4' ) );
$this->assertEquals( '1', $p->get_attribute( 'value' ) );
$this->assertSame( '1', $p->get_attribute( 'value' ) );
}
/**
@ -288,7 +288,7 @@ class Tests_Interactivity_API_wpInteractivityAPIFunctions extends WP_UnitTestCas
$html = '<div data-wp-test></div>';
$this->data_wp_test_processor_count = 0;
wp_interactivity_process_directives( $html );
$this->assertEquals( 1, $this->data_wp_test_processor_count );
$this->assertSame( 1, $this->data_wp_test_processor_count );
register_block_type(
'test/custom-directive-block',
@ -309,7 +309,7 @@ class Tests_Interactivity_API_wpInteractivityAPIFunctions extends WP_UnitTestCas
$this->data_wp_test_processor_count = 0;
do_blocks( $post_content );
unregister_block_type( 'test/custom-directive-block' );
$this->assertEquals( 2, $this->data_wp_test_processor_count );
$this->assertSame( 2, $this->data_wp_test_processor_count );
$directive_processors->setValue( null, $old_directive_processors );
}
@ -343,7 +343,7 @@ class Tests_Interactivity_API_wpInteractivityAPIFunctions extends WP_UnitTestCas
$processor->next_tag( array( 'data-wp-interactive' => 'nameSpace' ) );
remove_filter( 'render_block_data', 'test_render_block_data' );
unregister_block_type( 'test/custom-directive-block' );
$this->assertEquals( 'test', $processor->get_attribute( 'value' ) );
$this->assertSame( 'test', $processor->get_attribute( 'value' ) );
}
/**
@ -355,8 +355,8 @@ class Tests_Interactivity_API_wpInteractivityAPIFunctions extends WP_UnitTestCas
* @covers wp_interactivity_data_wp_context
*/
public function test_wp_interactivity_data_wp_context_with_different_arrays() {
$this->assertEquals( 'data-wp-context=\'{}\'', wp_interactivity_data_wp_context( array() ) );
$this->assertEquals(
$this->assertSame( 'data-wp-context=\'{}\'', wp_interactivity_data_wp_context( array() ) );
$this->assertSame(
'data-wp-context=\'{"a":1,"b":"2","c":true}\'',
wp_interactivity_data_wp_context(
array(
@ -366,11 +366,11 @@ class Tests_Interactivity_API_wpInteractivityAPIFunctions extends WP_UnitTestCas
)
)
);
$this->assertEquals(
$this->assertSame(
'data-wp-context=\'{"a":[1,2]}\'',
wp_interactivity_data_wp_context( array( 'a' => array( 1, 2 ) ) )
);
$this->assertEquals(
$this->assertSame(
'data-wp-context=\'[1,2]\'',
wp_interactivity_data_wp_context( array( 1, 2 ) )
);
@ -385,8 +385,8 @@ class Tests_Interactivity_API_wpInteractivityAPIFunctions extends WP_UnitTestCas
* @covers wp_interactivity_data_wp_context
*/
public function test_wp_interactivity_data_wp_context_with_different_arrays_and_a_namespace() {
$this->assertEquals( 'data-wp-context=\'myPlugin::{}\'', wp_interactivity_data_wp_context( array(), 'myPlugin' ) );
$this->assertEquals(
$this->assertSame( 'data-wp-context=\'myPlugin::{}\'', wp_interactivity_data_wp_context( array(), 'myPlugin' ) );
$this->assertSame(
'data-wp-context=\'myPlugin::{"a":1,"b":"2","c":true}\'',
wp_interactivity_data_wp_context(
array(
@ -397,11 +397,11 @@ class Tests_Interactivity_API_wpInteractivityAPIFunctions extends WP_UnitTestCas
'myPlugin'
)
);
$this->assertEquals(
$this->assertSame(
'data-wp-context=\'myPlugin::{"a":[1,2]}\'',
wp_interactivity_data_wp_context( array( 'a' => array( 1, 2 ) ), 'myPlugin' )
);
$this->assertEquals(
$this->assertSame(
'data-wp-context=\'myPlugin::[1,2]\'',
wp_interactivity_data_wp_context( array( 1, 2 ), 'myPlugin' )
);
@ -418,10 +418,10 @@ class Tests_Interactivity_API_wpInteractivityAPIFunctions extends WP_UnitTestCas
* @covers wp_interactivity_data_wp_context
*/
public function test_wp_interactivity_data_wp_context_with_json_flags() {
$this->assertEquals( 'data-wp-context=\'{"tag":"\u003Cfoo\u003E"}\'', wp_interactivity_data_wp_context( array( 'tag' => '<foo>' ) ) );
$this->assertEquals( 'data-wp-context=\'{"apos":"\u0027bar\u0027"}\'', wp_interactivity_data_wp_context( array( 'apos' => "'bar'" ) ) );
$this->assertEquals( 'data-wp-context=\'{"quot":"\u0022baz\u0022"}\'', wp_interactivity_data_wp_context( array( 'quot' => '"baz"' ) ) );
$this->assertEquals( 'data-wp-context=\'{"amp":"T\u0026T"}\'', wp_interactivity_data_wp_context( array( 'amp' => 'T&T' ) ) );
$this->assertSame( 'data-wp-context=\'{"tag":"\u003Cfoo\u003E"}\'', wp_interactivity_data_wp_context( array( 'tag' => '<foo>' ) ) );
$this->assertSame( 'data-wp-context=\'{"apos":"\u0027bar\u0027"}\'', wp_interactivity_data_wp_context( array( 'apos' => "'bar'" ) ) );
$this->assertSame( 'data-wp-context=\'{"quot":"\u0022baz\u0022"}\'', wp_interactivity_data_wp_context( array( 'quot' => '"baz"' ) ) );
$this->assertSame( 'data-wp-context=\'{"amp":"T\u0026T"}\'', wp_interactivity_data_wp_context( array( 'amp' => 'T&T' ) ) );
}
/**
@ -448,7 +448,7 @@ class Tests_Interactivity_API_wpInteractivityAPIFunctions extends WP_UnitTestCas
$processor = new WP_HTML_Tag_Processor( $processed_content );
$processor->next_tag( array( 'class_name' => 'test' ) );
unregister_block_type( 'test/custom-directive-block' );
$this->assertEquals( '1', $processor->get_attribute( 'src' ) );
$this->assertSame( '1', $processor->get_attribute( 'src' ) );
}
/**
@ -488,8 +488,8 @@ class Tests_Interactivity_API_wpInteractivityAPIFunctions extends WP_UnitTestCas
);
$second_input_value = $processor->get_attribute( 'value' );
unregister_block_type( 'test/custom-directive-block' );
$this->assertEquals( 'inner', $first_input_value );
$this->assertEquals( 'outer', $second_input_value );
$this->assertSame( 'inner', $first_input_value );
$this->assertSame( 'outer', $second_input_value );
}
/**