Skip to content

Custom AssertableHtmlElement classes #5

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

Closed
wants to merge 5 commits into from
Closed

Conversation

ziadoz
Copy link
Owner

@ziadoz ziadoz commented Jan 18, 2025

This PR adds the ability to return custom element assertable classes:

$form->element(function (AssertableHtmlFormElement $form) {
    $form->assertMethodPost();
    $form->assertAction('/foo/bar');
    $form->assertAcceptsUploads();
    $form->assertContainsFileUploadInputs();
});

Investigate original upgradable element idea: $assertableElement->upgrade() which returns AssertableFormElement.

@ziadoz ziadoz added the prototype Prototype of an idea or new feature label Jan 28, 2025
@ziadoz ziadoz marked this pull request as draft June 3, 2025 22:10
@@ -41,18 +42,23 @@ public function test_assertable_html(): void
<li id="baz">Baz</li>
</ul>

<!-- Custom Element -->
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need separate test methods per promoted/custom element in new PR.

* Assert only if the given input is null.
* Useful if you want to fail when a child element isn't matched before attempting to chain on more assertions.
*/
protected function assertIfNull(mixed $value, ?string $message = null): static
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need something like this in new PR? Maybe something that accepts a callback?

use Ziadoz\AssertableHtml\Contracts\AssertableHtmlElementMatcherInterface;
use Ziadoz\AssertableHtml\Dom\AssertableHtmlElement;

readonly class AssertableHtmlFormElement extends AssertableHtmlElement implements AssertableHtmlElementMatcherInterface
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to port bits over from this into new PR.

/** Assert the form's hidden _method input matches the given value. */
private function assertHiddenInputMethod(string $method, ?string $message = null): static
{
$this->assertIfNull($this->querySelector('input[type="hidden"][name="_method"]'), sprintf(
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In new PR could this be:

$this->assertPresent('input[type="hidden"][name="_method"]')->assertAttribute('value', 'delete');

Would need to add assertPresent/Missing() aliases to assertCount() for element. Might also want an attribute case insensitive/trimmed assertion, as will be useful for GET vs get etc.

@ziadoz ziadoz closed this Jul 27, 2025
@ziadoz ziadoz deleted the wip-custom-els branch July 27, 2025 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
prototype Prototype of an idea or new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant