Skip to content

Commit

Permalink
Add input Email::class widget. (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Jan 12, 2024
1 parent fe7f47e commit fe9ec4c
Show file tree
Hide file tree
Showing 3 changed files with 497 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/Input/Email.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace PHPForge\Html\Input;

use PHPForge\Html\Attribute;

/**
* The input element with a type attribute whose value is "email" represents a control for editing a list of e-mail
* addresses given in the element’s value.
*
* @link https://www.w3.org/TR/2012/WD-html-markup-20120329/input.email.html#input.email
*/
final class Email extends Base\AbstractInput implements
Contract\LengthInterface,
Contract\PatternInterface,
Contract\PlaceholderInterface,
Contract\RequiredInterface
{
use Attribute\Custom\HasWidgetValidation;
use Attribute\Input\CanBeMultiple;
use Attribute\Input\CanBeRequired;
use Attribute\Input\HasMaxLength;
use Attribute\Input\HasMinLength;
use Attribute\Input\HasPattern;
use Attribute\Input\HasPlaceholder;
use Attribute\Input\HasSize;

protected function run(): string
{
$this->validateString($this->getValue());

return $this->buildInputTag($this->attributes, 'email');
}
}
23 changes: 23 additions & 0 deletions tests/Input/Email/ExceptionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace PHPForge\Html\Tests\Input\Email;

use InvalidArgumentException;
use PHPForge\Html\Input\Email;
use PHPUnit\Framework\TestCase;

/**
* @psalm-suppress PropertyNotSetInConstructor
*/
final class ExceptionTest extends TestCase
{
public function testValue(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Email::class widget must be a string or null value.');

Email::widget()->value(1)->render();
}
}

0 comments on commit fe9ec4c

Please sign in to comment.