generated from yii-tools/template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Color input element and ExceptionTest class. (#168)
- Loading branch information
1 parent
b3f1923
commit 77cfd82
Showing
5 changed files
with
500 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PHPForge\Html\Input\Base; | ||
|
||
use InvalidArgumentException; | ||
|
||
use function is_string; | ||
|
||
abstract class AbstractColor extends AbstractInput | ||
{ | ||
protected string $type = 'color'; | ||
|
||
/** | ||
* @return string the generated input tag. | ||
*/ | ||
protected function run(): string | ||
{ | ||
$attributes = $this->attributes; | ||
$value = $attributes['value'] ?? null; | ||
|
||
/** | ||
* @link https://www.w3.org/TR/2012/WD-html-markup-20120329/input.color.html#input.color.attrs.value | ||
*/ | ||
if ($value !== null && is_string($value) === false) { | ||
throw new InvalidArgumentException( | ||
sprintf('%s::class widget must be a string or null value.', static::class) | ||
); | ||
} | ||
|
||
return parent::run(); | ||
} | ||
} |
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,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PHPForge\Html\Input; | ||
|
||
/** | ||
* The input element with a type attribute whose value is "color" represents a color-well control, for setting the | ||
* element’s value to a string representing a simple color. | ||
* | ||
* @link https://www.w3.org/TR/2012/WD-html-markup-20120329/input.color.html#input.color | ||
*/ | ||
final class Color extends Base\AbstractColor | ||
{ | ||
} |
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,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PHPForge\Html\Tests\Input\Color; | ||
|
||
use InvalidArgumentException; | ||
use PHPForge\Html\Input\Color; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @psalm-suppress PropertyNotSetInConstructor | ||
*/ | ||
final class ExceptionTest extends TestCase | ||
{ | ||
public function testValue(): void | ||
{ | ||
$this->expectException(InvalidArgumentException::class); | ||
$this->expectExceptionMessage('Color::class widget must be a string or null value.'); | ||
|
||
Color::widget()->value([])->render(); | ||
} | ||
} |
Oops, something went wrong.