Skip to content

Commit

Permalink
Use self::HTML_SIMPLE to signal unchanged HTML in the unit tests. Typ…
Browse files Browse the repository at this point in the history
…e-cast the Walker instead of concatenating it with an empty string.

Co-authored by: Grzegorz Ziółkowski <grzegorz.ziolkowski@automattic.com>
  • Loading branch information
adamziel committed Jul 27, 2022
1 parent cf8bfbe commit 5bf0c28
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions lib/experimental/class-wp-html-walker-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class WP_HTML_Walker_Tests extends TestCase {
*/
public function test_to_string_with_no_updates_returns_the_original_html() {
$w = new WP_HTML_Walker( self::HTML_SIMPLE );
$this->assertSame( self::HTML_SIMPLE, $w . '' );
$this->assertSame( self::HTML_SIMPLE, (string) $w );
}

/**
Expand All @@ -40,7 +40,7 @@ public function test_finding_non_existing_tag_returns_false() {
public function test_set_new_attribute() {
$w = new WP_HTML_Walker( self::HTML_SIMPLE );
$w->next_tag()->set_attribute( 'test-attribute', 'test-value' );
$this->assertSame( '<div test-attribute="test-value" id="first"><span id="second">Text</span></div>', $w . '' );
$this->assertSame( '<div test-attribute="test-value" id="first"><span id="second">Text</span></div>', (string) $w );
}

/**
Expand All @@ -49,7 +49,7 @@ public function test_set_new_attribute() {
public function test_set_existing_attribute() {
$w = new WP_HTML_Walker( self::HTML_SIMPLE );
$w->next_tag()->set_attribute( 'id', 'new-id' );
$this->assertSame( '<div id="new-id"><span id="second">Text</span></div>', $w . '' );
$this->assertSame( '<div id="new-id"><span id="second">Text</span></div>', (string) $w );
}

/**
Expand All @@ -58,7 +58,7 @@ public function test_set_existing_attribute() {
public function test_remove_existing_attribute() {
$w = new WP_HTML_Walker( self::HTML_SIMPLE );
$w->next_tag()->remove_attribute( 'id' );
$this->assertSame( '<div ><span id="second">Text</span></div>', $w . '' );
$this->assertSame( '<div ><span id="second">Text</span></div>', (string) $w );
}

/**
Expand All @@ -67,7 +67,7 @@ public function test_remove_existing_attribute() {
public function test_remove_non_existing_attribute() {
$w = new WP_HTML_Walker( self::HTML_SIMPLE );
$w->next_tag()->remove_attribute( 'no-such-attribute' );
$this->assertSame( '<div id="first"><span id="second">Text</span></div>', $w . '' );
$this->assertSame( self::HTML_SIMPLE, (string) $w );
}

/**
Expand All @@ -76,7 +76,7 @@ public function test_remove_non_existing_attribute() {
public function test_add_class_when_there_is_no_class_attribute() {
$w = new WP_HTML_Walker( self::HTML_SIMPLE );
$w->next_tag()->add_class( 'foo-class' );
$this->assertSame( '<div class="foo-class" id="first"><span id="second">Text</span></div>', $w . '' );
$this->assertSame( '<div class="foo-class" id="first"><span id="second">Text</span></div>', (string) $w );
}

/**
Expand All @@ -85,7 +85,7 @@ public function test_add_class_when_there_is_no_class_attribute() {
public function test_add_two_classes_when_there_is_no_class_attribute() {
$w = new WP_HTML_Walker( self::HTML_SIMPLE );
$w->next_tag()->add_class( 'foo-class' )->add_class( 'bar-class' );
$this->assertSame( '<div class="foo-class bar-class" id="first"><span id="second">Text</span></div>', $w . '' );
$this->assertSame( '<div class="foo-class bar-class" id="first"><span id="second">Text</span></div>', (string) $w );
}

/**
Expand All @@ -94,7 +94,7 @@ public function test_add_two_classes_when_there_is_no_class_attribute() {
public function test_remove_class_when_there_is_no_class_attribute() {
$w = new WP_HTML_Walker( self::HTML_SIMPLE );
$w->next_tag()->remove_class( 'foo-class' );
$this->assertSame( '<div id="first"><span id="second">Text</span></div>', $w . '' );
$this->assertSame( self::HTML_SIMPLE, (string) $w );
}

/**
Expand All @@ -105,7 +105,7 @@ public function test_add_class_when_there_is_a_class_attribute() {
$w->next_tag()->add_class( 'foo-class' )->add_class( 'bar-class' );
$this->assertSame(
'<div class="main with-border foo-class bar-class" id="first"><span class="not-main bold with-border" id="second">Text</span></div>',
$w . ''
(string) $w
);
}

Expand All @@ -114,10 +114,10 @@ public function test_add_class_when_there_is_a_class_attribute() {
*/
public function test_remove_class_when_there_is_a_class_attribute() {
$w = new WP_HTML_Walker( self::HTML_WITH_CLASSES );
$w->next_tag()->add_class( 'foo-class' )->add_class( 'bar-class' );
$w->next_tag()->remove( 'main' );
$this->assertSame(
'<div class="main with-border foo-class bar-class" id="first"><span class="not-main bold with-border" id="second">Text</span></div>',
$w . ''
'<div class="with-border foo-class bar-class" id="first"><span class="not-main bold with-border" id="second">Text</span></div>',
(string) $w
);
}

Expand All @@ -129,7 +129,7 @@ public function test_removing_all_classes_removes_the_class_attribute() {
$w->next_tag()->remove_class( 'main' )->remove_class( 'with-border' );
$this->assertSame(
'<div id="first"><span class="not-main bold with-border" id="second">Text</span></div>',
$w . ''
(string) $w
);
}

Expand All @@ -141,7 +141,7 @@ public function test_does_not_add_duplicate_class_names() {
$w->next_tag()->add_class( 'with-border' );
$this->assertSame(
'<div class="main with-border" id="first"><span class="not-main bold with-border" id="second">Text</span></div>',
$w . ''
(string) $w
);
}

Expand All @@ -153,7 +153,7 @@ public function test_preserves_class_name_order_when_a_duplicate_class_name_is_a
$w->next_tag()->add_class( 'main' );
$this->assertSame(
'<div class="main with-border" id="first"><span class="not-main bold with-border" id="second">Text</span></div>',
$w . ''
(string) $w
);
}

Expand All @@ -165,14 +165,14 @@ public function test_set_attribute_takes_priority_over_add_class() {
$w->next_tag()->add_class( 'add_class' )->set_attribute( 'class', 'set_attribute' );
$this->assertSame(
'<div class="set_attribute" id="first"><span class="not-main bold with-border" id="second">Text</span></div>',
$w . ''
(string) $w
);

$w = new WP_HTML_Walker( self::HTML_WITH_CLASSES );
$w->next_tag()->set_attribute( 'class', 'set_attribute' )->add_class( 'add_class' );
$this->assertSame(
'<div class="set_attribute" id="first"><span class="not-main bold with-border" id="second">Text</span></div>',
$w . ''
(string) $w
);
}

Expand Down Expand Up @@ -282,6 +282,6 @@ public function test_advanced_use_case() {
)
)
->remove_attribute( 'class' );
$this->assertSame( $expected_output, $w . '' );
$this->assertSame( $expected_output, (string) $w );
}
}

0 comments on commit 5bf0c28

Please sign in to comment.