Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Add tests to improve test coverage for HtmlString #51666

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions tests/Support/SupportHtmlStringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,31 @@

class SupportHtmlStringTest extends TestCase
{
public function testToHtml()
public function testToHtml(): void
{
// Check if HtmlString correctly converts a basic HTML string
$str = '<h1>foo</h1>';
$html = new HtmlString('<h1>foo</h1>');
$this->assertEquals($str, $html->toHtml());

// Check if HtmlString correctly preserves leading blank spaces in the HTML string
$startWithBlankSpaces = ' <h1> foo</h1>';
$html = new HtmlString(' <h1> foo</h1>');
$this->assertEquals($startWithBlankSpaces, $html->toHtml());

// Check if HtmlString correctly preserves trailing blank spaces in the HTML string
$endsWithBlankSpaces = '<h1>foo </h1> ';
$html = new HtmlString('<h1>foo </h1> ');
$this->assertEquals($endsWithBlankSpaces, $html->toHtml());

// Check if HtmlString correctly handles an empty string
$emptyHtml = new HtmlString('');
$this->assertEquals('', $emptyHtml->toHtml());

// Check if HtmlString correctly converts a plain text string
$str = 'foo bar';
$html = new HtmlString($str);
$this->assertEquals($str, $html->toHtml());
}

public function testToString()
Expand All @@ -21,9 +41,16 @@ public function testToString()
$this->assertEquals($str, (string) $html);
}

public function testIsEmpty()
public function testIsEmpty(): void
{
// Check if HtmlString correctly identifies an empty string as empty
$this->assertTrue((new HtmlString(''))->isEmpty());

// HtmlString with whitespace should not be considered as empty
$this->assertFalse((new HtmlString(' '))->isEmpty());

// HtmlString with content should not be considered as empty
$this->assertFalse((new HtmlString('<p>Hello</p>'))->isEmpty());
}

public function testIsNotEmpty()
Expand Down