summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2016-06-02 13:24:33 (GMT)
committerAlex Pott2016-06-02 13:24:33 (GMT)
commit770fcd0fc08c8674b257d9515f8ae4d4aa54e0f6 (patch)
tree35729ff5c661c0e6883ab7a78b3dcb9c10b0d771
parentedad386212137224beefa9b5199844aa9ae0042d (diff)
Issue #2561993 by jhedstrom, jonathanjfshaw, yoroy, emma.maria, mpdonadio: Better labelling for Date time form select elements
-rw-r--r--core/lib/Drupal/Core/Datetime/Element/Datelist.php1
-rw-r--r--core/modules/datetime/src/Tests/DateTimeFieldTest.php6
-rw-r--r--core/modules/simpletest/src/AssertContentTrait.php18
3 files changed, 25 insertions, 0 deletions
diff --git a/core/lib/Drupal/Core/Datetime/Element/Datelist.php b/core/lib/Drupal/Core/Datetime/Element/Datelist.php
index 76f61bb..f39d0a2 100644
--- a/core/lib/Drupal/Core/Datetime/Element/Datelist.php
+++ b/core/lib/Drupal/Core/Datetime/Element/Datelist.php
@@ -268,6 +268,7 @@ class Datelist extends DateElementBase {
'#options' => $options,
'#required' => $element['#required'],
'#error_no_message' => FALSE,
+ '#empty_option' => $title,
);
}
diff --git a/core/modules/datetime/src/Tests/DateTimeFieldTest.php b/core/modules/datetime/src/Tests/DateTimeFieldTest.php
index 6458183..bf3ba07 100644
--- a/core/modules/datetime/src/Tests/DateTimeFieldTest.php
+++ b/core/modules/datetime/src/Tests/DateTimeFieldTest.php
@@ -448,17 +448,23 @@ class DateTimeFieldTest extends WebTestBase {
$this->assertFieldByXPath("//*[@id=\"edit-$field_name-0-value-year\"]", NULL, 'Year element found.');
$this->assertOptionSelected("edit-$field_name-0-value-year", '', 'No year selected.');
+ $this->assertOptionByText("edit-$field_name-0-value-year", t('Year'));
$this->assertFieldByXPath("//*[@id=\"edit-$field_name-0-value-month\"]", NULL, 'Month element found.');
$this->assertOptionSelected("edit-$field_name-0-value-month", '', 'No month selected.');
+ $this->assertOptionByText("edit-$field_name-0-value-month", t('Month'));
$this->assertFieldByXPath("//*[@id=\"edit-$field_name-0-value-day\"]", NULL, 'Day element found.');
$this->assertOptionSelected("edit-$field_name-0-value-day", '', 'No day selected.');
+ $this->assertOptionByText("edit-$field_name-0-value-day", t('Day'));
$this->assertFieldByXPath("//*[@id=\"edit-$field_name-0-value-hour\"]", NULL, 'Hour element found.');
$this->assertOptionSelected("edit-$field_name-0-value-hour", '', 'No hour selected.');
+ $this->assertOptionByText("edit-$field_name-0-value-hour", t('Hour'));
$this->assertFieldByXPath("//*[@id=\"edit-$field_name-0-value-minute\"]", NULL, 'Minute element found.');
$this->assertOptionSelected("edit-$field_name-0-value-minute", '', 'No minute selected.');
+ $this->assertOptionByText("edit-$field_name-0-value-minute", t('Minute'));
$this->assertNoFieldByXPath("//*[@id=\"edit-$field_name-0-value-second\"]", NULL, 'Second element not found.');
$this->assertFieldByXPath("//*[@id=\"edit-$field_name-0-value-ampm\"]", NULL, 'AMPM element found.');
$this->assertOptionSelected("edit-$field_name-0-value-ampm", '', 'No ampm selected.');
+ $this->assertOptionByText("edit-$field_name-0-value-ampm", t('AM/PM'));
// Submit a valid date and ensure it is accepted.
$date_value = array('year' => 2012, 'month' => 12, 'day' => 31, 'hour' => 5, 'minute' => 15);
diff --git a/core/modules/simpletest/src/AssertContentTrait.php b/core/modules/simpletest/src/AssertContentTrait.php
index e8da02c..e428e71 100644
--- a/core/modules/simpletest/src/AssertContentTrait.php
+++ b/core/modules/simpletest/src/AssertContentTrait.php
@@ -1242,6 +1242,24 @@ trait AssertContentTrait {
}
/**
+ * Asserts that a select option with the visible text exists.
+ *
+ * @param string $id
+ * The ID of the select field to assert.
+ * @param string $text
+ * The text for the option tag to assert.
+ * @param string $message
+ * (optional) A message to display with the assertion.
+ *
+ * @return bool
+ * TRUE on pass, FALSE on fail.
+ */
+ protected function assertOptionByText($id, $text, $message = '') {
+ $options = $this->xpath('//select[@id=:id]//option[normalize-space(text())=:text]', [':id' => $id, ':text' => $text]);
+ return $this->assertTrue(isset($options[0]), $message ?: 'Option with text label ' . $text . ' for select field ' . $id . ' exits.');
+ }
+
+ /**
* Asserts that a select option in the current page exists.
*
* @param string $drupal_selector