Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/Inputs/ColorPicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Contributte\FormsBootstrap\Traits\StandardValidationTrait;
use Nette\Utils\Html;

class ColorPicker extends \Nette\Forms\Controls\ColorPicker
class ColorPicker extends \Nette\Forms\Controls\ColorPicker implements IValidationInput
{

use StandardValidationTrait;
Expand Down
2 changes: 1 addition & 1 deletion src/Inputs/DateTimeControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Contributte\FormsBootstrap\Traits\StandardValidationTrait;
use Nette\Utils\Html;

class DateTimeControl extends \Nette\Forms\Controls\DateTimeControl
class DateTimeControl extends \Nette\Forms\Controls\DateTimeControl implements IValidationInput
{

use StandardValidationTrait;
Expand Down
19 changes: 19 additions & 0 deletions tests/Inputs/ColorPickerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Tests\Inputs;

use Contributte\FormsBootstrap\BootstrapForm;
use Contributte\FormsBootstrap\Inputs\IValidationInput;
use Nette\Application\UI\Presenter;
use Tests\BaseTestCase;

class ColorPickerTest extends BaseTestCase
Expand All @@ -16,4 +18,21 @@ public function testDefaultTextInput(): void
$this->assertEquals('<label for="frm-color">Choose color</label>', (string) $input->getLabel());
}

public function testShowsValidationState(): void
{
$form = new BootstrapForm();
// Rendering a form requires a presenter with a non-empty action; see BaseTestCase users.
$form->setParent($this->createMock(Presenter::class));
$form->setAction('/');

$input = $form->addColor('color', 'Choose color');
$this->assertInstanceOf(IValidationInput::class, $input);

$input->addError('Foobar error message');

$html = (string) $form;
$this->assertStringContainsString('class="form-control is-invalid"', $html);
$this->assertStringContainsString('<div class="invalid-feedback">Foobar error message<br></div>', $html);
}

}
19 changes: 19 additions & 0 deletions tests/Inputs/DateTimeControlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Tests\Inputs;

use Contributte\FormsBootstrap\BootstrapForm;
use Contributte\FormsBootstrap\Inputs\IValidationInput;
use Nette\Application\UI\Presenter;
use Tests\BaseTestCase;

class DateTimeControlTest extends BaseTestCase
Expand All @@ -15,4 +17,21 @@ public function testDefaultDate(): void
$this->assertEquals('<input type="date" name="date" id="frm-date" class="form-control">', $dt->getControl()->render());
}

public function testShowsValidationState(): void
{
$form = new BootstrapForm();
// Rendering a form requires a presenter with a non-empty action; see BaseTestCase users.
$form->setParent($this->createMock(Presenter::class));
$form->setAction('/');

$dt = $form->addDate('date', 'Date');
$this->assertInstanceOf(IValidationInput::class, $dt);

$dt->addError('Foobar error message');

$html = (string) $form;
$this->assertStringContainsString('class="form-control is-invalid"', $html);
$this->assertStringContainsString('<div class="invalid-feedback">Foobar error message<br></div>', $html);
}

}
Loading