diff --git a/src/Nella/Forms/DateTime/DateTimeInput.php b/src/Nella/Forms/DateTime/DateTimeInput.php index 85c1300..5461f64 100644 --- a/src/Nella/Forms/DateTime/DateTimeInput.php +++ b/src/Nella/Forms/DateTime/DateTimeInput.php @@ -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() diff --git a/tests/Nella/Forms/DateTime/DateTimeInputTest.phpt b/tests/Nella/Forms/DateTime/DateTimeInputTest.phpt index f1e1877..04db883 100644 --- a/tests/Nella/Forms/DateTime/DateTimeInputTest.phpt +++ b/tests/Nella/Forms/DateTime/DateTimeInputTest.phpt @@ -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 */