-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Element assertions and HTML String (#528)
* Add macro support to factories * Adding HTML String class * Fixing helper * Linting fixes * CHANGELOG * Add assertContains/assertNotContains methods * Test for ID * Adding assertion messages * CHANGELOG date * Phpstan fixes
- Loading branch information
Showing
9 changed files
with
284 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
/** | ||
* HTML_String class file | ||
* | ||
* phpcs:disable WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid | ||
* | ||
* @package Mantle | ||
*/ | ||
|
||
namespace Mantle\Testing; | ||
|
||
use Mantle\Testing\Concerns\Element_Assertions; | ||
use PHPUnit\Framework\Assert; | ||
|
||
/** | ||
* HTML String | ||
* | ||
* Perform assertions against a HTML string. | ||
*/ | ||
class Assertable_HTML_String { | ||
use Element_Assertions; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param string $content The HTML content to test. | ||
*/ | ||
public function __construct( protected string $content ) {} | ||
|
||
/** | ||
* Retrieve the content. | ||
*/ | ||
protected function get_content(): string { | ||
return $this->content; | ||
} | ||
|
||
/** | ||
* Assert that the content contains the expected string. | ||
* | ||
* @param string $needle The $needle to assert against. | ||
*/ | ||
public function assertContains( string $needle ): static { | ||
Assert::assertStringContainsString( $needle, $this->content, 'The content does not contain the expected string.' ); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Assert that the content does not contain the expected string. | ||
* | ||
* @param string $needle The $needle to assert against. | ||
*/ | ||
public function assertNotContains( string $needle ): static { | ||
Assert::assertStringNotContainsString( $needle, $this->content, 'The content contains the unexpected string.' ); | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
/** | ||
* Helper for assertions against elements. | ||
* | ||
* @package Mantle | ||
*/ | ||
|
||
namespace Mantle\Testing; | ||
|
||
/** | ||
* Create a new HTML_String instance. | ||
* | ||
* @param string $html The HTML string to test. | ||
*/ | ||
function html_string( string $html ): Assertable_HTML_String { | ||
return new Assertable_HTML_String( $html ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.