function DateTimeFieldTest::datelistDataProvider

Same name in other branches
  1. 9 core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php \Drupal\Tests\datetime\Functional\DateTimeFieldTest::datelistDataProvider()
  2. 8.9.x core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php \Drupal\Tests\datetime\Functional\DateTimeFieldTest::datelistDataProvider()
  3. 11.x core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php \Drupal\Tests\datetime\Functional\DateTimeFieldTest::datelistDataProvider()

The data provider for testing the validation of the datelist widget.

Parameters

string $field_label: The label of the field being tested.

Return value

array An array of datelist input permutations to test.

1 call to DateTimeFieldTest::datelistDataProvider()
DateTimeFieldTest::testDatelistWidget in core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php
Tests Date List Widget functionality.

File

core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php, line 614

Class

DateTimeFieldTest
Tests Datetime field functionality.

Namespace

Drupal\Tests\datetime\Functional

Code

protected function datelistDataProvider($field_label) {
    return [
        // Nothing selected.
[
            [
                'year' => '',
                'month' => '',
                'day' => '',
                'hour' => '',
                'minute' => '',
            ],
            [
                "The {$field_label} date is required.",
            ],
        ],
        // Year only selected, validation error on Month, Day, Hour, Minute.
[
            [
                'year' => 2012,
                'month' => '',
                'day' => '',
                'hour' => '',
                'minute' => '',
            ],
            [
                "The {$field_label} date is incomplete.",
                'A value must be selected for month.',
                'A value must be selected for day.',
                'A value must be selected for hour.',
                'A value must be selected for minute.',
            ],
        ],
        // Year and Month selected, validation error on Day, Hour, Minute.
[
            [
                'year' => 2012,
                'month' => '12',
                'day' => '',
                'hour' => '',
                'minute' => '',
            ],
            [
                "The {$field_label} date is incomplete.",
                'A value must be selected for day.',
                'A value must be selected for hour.',
                'A value must be selected for minute.',
            ],
        ],
        // Year, Month and Day selected, validation error on Hour, Minute.
[
            [
                'year' => 2012,
                'month' => '12',
                'day' => '31',
                'hour' => '',
                'minute' => '',
            ],
            [
                "The {$field_label} date is incomplete.",
                'A value must be selected for hour.',
                'A value must be selected for minute.',
            ],
        ],
        // Year, Month, Day and Hour selected, validation error on Minute only.
[
            [
                'year' => 2012,
                'month' => '12',
                'day' => '31',
                'hour' => '0',
                'minute' => '',
            ],
            [
                "The {$field_label} date is incomplete.",
                'A value must be selected for minute.',
            ],
        ],
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.