diff --git a/core/lib/Drupal/Core/Datetime/Element/Datelist.php b/core/lib/Drupal/Core/Datetime/Element/Datelist.php index b92cdb2..b0a990f 100644 --- a/core/lib/Drupal/Core/Datetime/Element/Datelist.php +++ b/core/lib/Drupal/Core/Datetime/Element/Datelist.php @@ -75,7 +75,7 @@ public static function valueCallback(&$element, $input, FormStateInterface $form $timezone = !empty($element['#date_timezone']) ? $element['#date_timezone'] : NULL; $date = DrupalDateTime::createFromArray($input, $timezone); if ($date instanceOf DrupalDateTime && !$date->hasErrors()) { - date_increment_round($date, $increment); + static::incrementRound($date, $increment); } } } diff --git a/core/modules/datetime/src/Tests/DateTimeFieldTest.php b/core/modules/datetime/src/Tests/DateTimeFieldTest.php index 60637ff..43b4ad7 100644 --- a/core/modules/datetime/src/Tests/DateTimeFieldTest.php +++ b/core/modules/datetime/src/Tests/DateTimeFieldTest.php @@ -478,6 +478,33 @@ function testDatelistWidget() { $this->assertOptionSelected("edit-$field_name-0-value-day", '31', 'Correct day selected.'); $this->assertOptionSelected("edit-$field_name-0-value-hour", '17', 'Correct hour selected.'); $this->assertOptionSelected("edit-$field_name-0-value-minute", '15', 'Correct minute selected.'); + + // Test the widget for partial completion of fields. + entity_get_form_display($this->field->getTargetEntityTypeId(), $this->field->getTargetBundle(), 'default') + ->setComponent($field_name, array( + 'type' => 'datetime_datelist', + 'settings' => array( + 'increment' => 1, + 'date_order' => 'YMD', + 'time_type' => '24', + ), + )) + ->save(); + \Drupal::entityManager()->clearCachedFieldDefinitions(); + + // Display creation form. + $this->drupalGet('entity_test/add'); + + // Submit a partial date and ensure and error message is provided + $date_value = array('year' => 2012, 'month' => '', 'day' => '', 'hour' => '', 'minute' => ''); + $edit = array(); + foreach ($date_value as $part => $value) { + $edit["{$field_name}[0][value][$part]"] = $value; + } + + $this->drupalPostForm(NULL, $edit, t('Save')); + $this->assertResponse(200); + $this->assertText('error has been found'); } /** diff --git a/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php b/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php index 2592333..7bccf89 100644 --- a/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php +++ b/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php @@ -249,6 +249,24 @@ public function testDateTimezoneWithDateTimeObject() { } /** + * Tests the checkArray method. + * + * @param mixed $expected + * Expected result of checkArray method + * @param array $date_value + * Input argument for DateTimePlus::checkArray(). + * @param string $message + * Message to print on test failure. + * + * @dataProvider providerTestCheckArray + * + * @covers ::checkArray + */ + public function testCheckArray($expected, $date_value) { + $this->assertEquals($expected, DateTimePlus::checkArray($date_value)); + } + + /** * Provides data for date tests. * * @return array @@ -533,4 +551,32 @@ public function providerTestDateTimestamp() { ); } + /** + * Data provider for testCheckArray(). + * + * @return array + * An array of arrays, each containing: + * - 'expected' - The expected result of DateTimePlusTest::checkArray(). + * - 'input' - Input for DateTimePlusTest::checkArray(). + * + * @see testCheckArray() + */ + public function providerTestCheckArray() { + + $data = array( + // Checks for completion of date array + array(FALSE, array('year' => 2013, 'month' => '', 'day' => '', 'hour' => '', 'minute' => '')), + array(FALSE, array('year' => 2013, 'month' => '12', 'day' => '', 'hour' => '', 'minute' => '')), + array(FALSE, array('year' => 2013, 'month' => '12', 'day' => '11', 'hour' => '', 'minute' => '')), + array(FALSE, array('year' => 2013, 'month' => '12', 'day' => '11', 'hour' => '10', 'minute' => '')), + array(TRUE, array('year' => 2013, 'month' => '12', 'day' => '11', 'hour' => '10', 'minute' => '09')), + + // Checks for invalid time pairings + array(FALSE, array('year' => 2013, 'month' => '12', 'day' => '11', 'hour' => '10', 'minute' => '61')), + array(FALSE, array('year' => 2013, 'month' => '12', 'day' => '11', 'hour' => '25', 'minute' => '09')), + ); + + return $data; + } + }