Skip to content

Commit

Permalink
Add more get_attribute_names tests()
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham committed Jan 2, 2023
1 parent 8c51859 commit ca06c64
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions phpunit/html/wp-html-tag-processor-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,55 @@ public function test_set_attribute_is_case_insensitive() {
}

/**
* @covers WP_HTML_Tag_Processor::get_attribute_names
* @ticket 56299
*
* @covers get_attribute_names
*/
public function test_get_attribute_names_returns_null_before_finding_tags() {
$p = new WP_HTML_Tag_Processor( '<div class="test">Test</div>' );
$this->assertNull( $p->get_attribute_names() );
}

/**
* @ticket 56299
*
* @covers get_attribute
*/
public function test_get_attribute_names_returns_null_when_not_in_open_tag() {
$p = new WP_HTML_Tag_Processor( '<div class="test">Test</div>' );
$p->next_tag( 'p' );
$this->assertNull( $p->get_attribute_names(), 'Accessing attributes of a non-existing tag did not return null' );
}

/**
* @ticket 56299
*
* @covers get_attribute_names
*/
public function test_get_attribute_names_returns_null_when_in_closing_tag() {
$p = new WP_HTML_Tag_Processor( '<div class="test">Test</div>' );
$p->next_tag( 'div' );
$p->next_tag( array( 'tag_closers' => 'visit' ) );
$this->assertNull( $p->get_attribute_names(), 'Accessing attributes of a closing tag did not return null' );
}

/**
* @ticket 56299
*
* @covers get_attribute_names
*/
public function test_get_attribute_names_returns_empty_array_when_no_attributes_present() {
$p = new WP_HTML_Tag_Processor( '<div>Test</div>' );
$p->next_tag( 'div' );
$this->assertSame( array(), $p->get_attribute_names(), 'Accessing the attributes on a tag without any did not return an empty array' );
}

/**
* @ticket 56299
*
* @covers get_attribute_names
*/
public function test_get_attribute_names() {
public function test_get_attribute_names_returns_attribute_names() {
$p = new WP_HTML_Tag_Processor( '<div enabled class="test" data-test-id="14">Test</div>' );
$p->next_tag();
$this->assertSame(
Expand Down

0 comments on commit ca06c64

Please sign in to comment.