Skip to content
This repository has been archived by the owner on Nov 15, 2020. It is now read-only.

Commit

Permalink
Validation when time or date is not filled
Browse files Browse the repository at this point in the history
  • Loading branch information
Vrtak-CZ committed Mar 26, 2015
1 parent 07f649d commit f771b4b
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Nella/Forms/DateTime/DateTimeInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function getValue()
*/
public function isFilled()
{
return !empty($this->date) && !empty($this->time);
return !empty($this->date) || !empty($this->time);
}

public function loadHttpData()
Expand Down
61 changes: 61 additions & 0 deletions tests/Nella/Forms/DateTime/DateTimeInputTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,67 @@ class DateTimeInputTest extends \Tester\TestCase
Assert::null($control->getLabelPart());
}

public function testFilledDate()
{
$control = $this->createControl(array(
'datetime' => array(
'date' => '1978-01-23',
),
));

$control->addRule([$control, 'validateDateTime'], 'test');

$control->validate();

Assert::true($control->isFilled());
Assert::true($control->hasErrors());
}

public function testFilledTime()
{
$control = $this->createControl(array(
'datetime' => array(
'time' => '12:00',
),
));

$control->addRule([$control, 'validateDateTime'], 'test');

$control->validate();

Assert::true($control->isFilled());
Assert::true($control->hasErrors());
}

public function testFilledBoth()
{
$control = $this->createControl(array(
'datetime' => array(
'date' => '1978-01-23',
'time' => '12:00',
),
));

$control->addRule([$control, 'validateDateTime'], 'test');

$control->validate();

Assert::true($control->isFilled());
Assert::false($control->hasErrors());
}

public function testNotFilled()
{
$control = $this->createControl();

$control->addRule([$control, 'validateDateTime'], 'test');

$control->validate();

Assert::false($control->isFilled());
Assert::false($control->hasErrors());
}

/**
* @throws \Nette\InvalidStateException
*/
Expand Down

0 comments on commit f771b4b

Please sign in to comment.