summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaren Stevenson2011-12-09 09:05:05 (GMT)
committer Karen Stevenson2011-12-09 09:05:05 (GMT)
commite7f1ffb3622ce2c90bdfaaf1f138cffffc7518ac (patch)
treeba7b7b9992929b4227960357aadcad0b5374395d
parent447edaff36b8bbb01aca8ba84d61d949ee28d219 (diff)
Follow up for Issue #1354606 by temaruk, code cleanup and more tests.
-rw-r--r--date_api/date.css44
-rw-r--r--date_api/date_api_elements.inc1
-rw-r--r--date_repeat/date_repeat_form.inc9
-rw-r--r--date_repeat/tests/date_repeat_form.test296
4 files changed, 224 insertions, 126 deletions
diff --git a/date_api/date.css b/date_api/date.css
index 8b40659..58f62d0 100644
--- a/date_api/date.css
+++ b/date_api/date.css
@@ -57,6 +57,7 @@
/* The exposed Views form doesn't need some of these styles */
.container-inline-date .date-padding {
padding: 10px;
+ float: left;
}
.views-exposed-form .container-inline-date .date-padding {
padding: 0;
@@ -142,12 +143,55 @@ span.date-display-end {
.range-of-repeat .until .form-wrapper {
margin: 0 0.5em;
+ display: inline-block;
+ vertical-align: middle;
+}
+
+.range-of-repeat .until .form-radio,
+.range-of-repeat .until .date-prefix-inline {
+ margin: 0 0 1.4em 0;
+ vertical-align: middle;
+}
+
+.range-of-repeat .until.widget-date_popup.label-above .form-radio,
+.range-of-repeat .until.widget-date_popup.label-above .date-prefix-inline {
+ margin: 0;
+ vertical-align: middle;
+}
+
+.range-of-repeat .until.widget-date_select.label-within .form-radio,
+.range-of-repeat .until.widget-date_select.label-within .date-prefix-inline {
+ margin: 0;
+ vertical-align: middle;
+}
+
+.range-of-repeat .until.widget-date_select.label-above .form-radio,
+.range-of-repeat .until.widget-date_select.label-above .date-prefix-inline {
+ margin: 1.4em 0 0 0;
+ vertical-align: middle;
+}
+
+.range-of-repeat .until .form-type-date-text .date-padding {
+ padding: 0;
+}
+
+.range-of-repeat .until.widget-date_select.label-within .date-padding {
+ padding: 0;
+}
+
+.range-of-repeat .until.widget-date_select.label-above .date-padding {
+ padding: 0;
}
.range-of-repeat .until .form-type-date-select,
.range-of-repeat .until .form-type-date-popup,
.range-of-repeat .until .form-type-date-text {
border: none;
+ margin: 0;
+}
+
+.date-prefix-inline {
+ display: inline-block;
}
.date-views-filter-wrapper {
diff --git a/date_api/date_api_elements.inc b/date_api/date_api_elements.inc
index 38a48a1..7d76206 100644
--- a/date_api/date_api_elements.inc
+++ b/date_api/date_api_elements.inc
@@ -302,6 +302,7 @@ function date_text_element_process($element, $form_state, $form) {
$element['date']['#type'] = 'textfield';
$element['date']['#weight'] = !empty($element['date']['#weight']) ? $element['date']['#weight'] : $element['#weight'];
$element['date']['#attributes'] = array('class' => isset($element['#attributes']['class']) ? $element['#attributes']['class'] += array('date-date') : array('date-date'));
+ $element['date']['#attributes']['placeholder'] = array($element['#date_format']);
$element['date']['#description'] = ' ' . t('Format: @date', array('@date' => date_now()->format($element['#date_format'])));
// Keep the system from creating an error message for the sub-element.
diff --git a/date_repeat/date_repeat_form.inc b/date_repeat/date_repeat_form.inc
index 415b993..0d21d3e 100644
--- a/date_repeat/date_repeat_form.inc
+++ b/date_repeat/date_repeat_form.inc
@@ -142,6 +142,7 @@ function _date_repeat_rrule_process($element, &$form_state, $form) {
'#title_display' => 'invisible',
'#default_value' => (!empty($rrule['INTERVAL']) ? $rrule['INTERVAL'] : 1),
'#element_validate' => array('element_validate_integer_positive'),
+ '#attributes' => array('placeholder' => array('#')),
'#size' => 3,
'#maxlength' => 3,
'#prefix' => '<div class="date-clear">',
@@ -156,6 +157,7 @@ function _date_repeat_rrule_process($element, &$form_state, $form) {
'#title' => t('Repeats', array(), array('context' => 'Date repeat')),
'#default_value' => (!empty($rrule['INTERVAL']) ? $rrule['INTERVAL'] : 1),
'#element_validate' => array('element_validate_integer_positive'),
+ '#attributes' => array('placeholder' => array('#')),
'#size' => 3,
'#maxlength' => 3,
'#prefix' => '<div class="date-clear">',
@@ -171,6 +173,7 @@ function _date_repeat_rrule_process($element, &$form_state, $form) {
'#title' => t('Repeats', array(), array('context' => 'Date repeat')),
'#default_value' => (!empty($rrule['INTERVAL']) ? $rrule['INTERVAL'] : 1),
'#element_validate' => array('element_validate_integer_positive'),
+ '#attributes' => array('placeholder' => array('#')),
'#size' => 3,
'#maxlength' => 3,
'#prefix' => '<div class="date-clear">',
@@ -185,6 +188,7 @@ function _date_repeat_rrule_process($element, &$form_state, $form) {
'#title' => t('Repeats', array(), array('context' => 'Date repeat')),
'#default_value' => (!empty($rrule['INTERVAL']) ? $rrule['INTERVAL'] : 1),
'#element_validate' => array('element_validate_integer_positive'),
+ '#attributes' => array('placeholder' => array('#')),
'#size' => 3,
'#maxlength' => 3,
'#prefix' => '<div class="date-clear">',
@@ -466,6 +470,7 @@ function _date_repeat_rrule_process($element, &$form_state, $form) {
'#title' => t('Count', array(), array('context' => 'Date repeat')),
'#default_value' => $COUNT,
'#element_validate' => array('element_validate_integer_positive'),
+ '#attributes' => array('placeholder' => array('#')),
'#prefix' => $prefix,
'#suffix' => $suffix,
'#size' => 10,
@@ -475,7 +480,7 @@ function _date_repeat_rrule_process($element, &$form_state, $form) {
$until_form_element = array(
'#type' => 'container',
'#tree' => TRUE,
- '#prefix' => t('On', array(), array('context' => 'Date repeat')),
+ '#prefix' => '<div class="date-prefix-inline">' . t('On', array(), array('context' => 'Date repeat')) . '</div>',
'datetime' => array(
'#type' => $element['#date_repeat_widget'],
'#title' => t('Until', array(), array('context' => 'Date repeat')),
@@ -518,7 +523,7 @@ function _date_repeat_rrule_process($element, &$form_state, $form) {
'until_child' => $until_form_element,
'#div_classes' => array(
'container-inline count',
- 'container-inline until',
+ "until widget-{$element['#date_repeat_widget']} label-{$element['#date_label_position']}",
),
);
diff --git a/date_repeat/tests/date_repeat_form.test b/date_repeat/tests/date_repeat_form.test
index fd2e289..aefa4c7 100644
--- a/date_repeat/tests/date_repeat_form.test
+++ b/date_repeat/tests/date_repeat_form.test
@@ -26,8 +26,7 @@ class DateRepeatFormTestCase extends DrupalWebTestCase {
));
$this->drupalLogin($this->privileged_user);
- //variable_set('date_format_long', 'D, m/d/Y - H:i');
- variable_set('date_format_long', 'Y-m-d H:i');
+ variable_set('date_format_short', 'Y-m-d H:i');
}
public function testDateRepeatForm() {
@@ -37,166 +36,157 @@ class DateRepeatFormTestCase extends DrupalWebTestCase {
$this->drupalPost('admin/structure/types/add', $edit, t('Save content type'));
$this->assertText('The content type Date has been added.', 'Content type added.');
- // Daily tests
- // Creates select list date field stored as a date with default settings.
- $this->createDateField($type = 'datetime', $widget = 'date_select');
+ // Testing options.
+ $widget_options = array(
+ 'date_select' => 'select',
+ 'date_text' => 'text',
+ 'date_popup' => 'popup');
- $form_edit = $this->dateForm($options = 'select', 'daily_1');
- $this->verifyDateForm($form_edit);
+ foreach ($widget_options as $widget => $options) {
+ // Daily tests
+ // Creates date field stored as a datetime.
+ $this->createDateField($type = 'datetime', $widget);
- $form_edit = $this->dateForm($options = 'select', 'daily_2');
- $this->verifyDateForm($form_edit);
+ $form_edit = $this->dateForm($options, 'daily_1');
+ $this->verifyDateForm($form_edit);
- $form_edit = $this->dateForm($options = 'select', 'daily_3');
- $this->verifyDateForm($form_edit);
+ $form_edit = $this->dateForm($options, 'daily_2');
+ $this->verifyDateForm($form_edit);
- $form_edit = $this->dateForm($options = 'select', 'daily_4');
- $this->verifyDateForm($form_edit);
+ $form_edit = $this->dateForm($options, 'daily_3');
+ $this->verifyDateForm($form_edit);
- $form_edit = $this->dateForm($options = 'select', 'daily_1', TRUE);
- $this->verifyDateForm($form_edit);
+ $form_edit = $this->dateForm($options, 'daily_4');
+ $this->verifyDateForm($form_edit);
- $form_edit = $this->dateForm($options = 'select', 'daily_2', TRUE);
- $this->verifyDateForm($form_edit);
+ $form_edit = $this->dateForm($options, 'daily_1', TRUE);
+ $this->verifyDateForm($form_edit);
- $form_edit = $this->dateForm($options = 'select', 'daily_3', TRUE);
- $this->verifyDateForm($form_edit);
+ $form_edit = $this->dateForm($options, 'daily_2', TRUE);
+ $this->verifyDateForm($form_edit);
- $form_edit = $this->dateForm($options = 'select', 'daily_4', TRUE);
- $this->verifyDateForm($form_edit);
+ $form_edit = $this->dateForm($options, 'daily_3', TRUE);
+ $this->verifyDateForm($form_edit);
- $this->deleteDateField();
+ $form_edit = $this->dateForm($options, 'daily_4', TRUE);
+ $this->verifyDateForm($form_edit);
- // Weekly tests
- // Creates select list date field stored as a date with default settings.
- $this->createDateField($type = 'datetime', $widget = 'date_select');
+ $form_edit = $this->dateForm($options, 'daily_1', FALSE, 'exclude');
+ $this->verifyDateForm($form_edit);
- $form_edit = $this->dateForm($options = 'select', 'weekly_1');
- $this->verifyDateForm($form_edit);
+ $form_edit = $this->dateForm($options, 'daily_1', FALSE, 'include');
+ $this->verifyDateForm($form_edit);
- $form_edit = $this->dateForm($options = 'select', 'weekly_2');
- $this->verifyDateForm($form_edit);
+ $form_edit = $this->dateForm($options, 'daily_1', FALSE, 'exclude_include');
+ $this->verifyDateForm($form_edit);
- $form_edit = $this->dateForm($options = 'select', 'weekly_3');
- $this->verifyDateForm($form_edit);
+ // Weekly tests
- $form_edit = $this->dateForm($options = 'select', 'weekly_4');
- $this->verifyDateForm($form_edit);
+ $form_edit = $this->dateForm($options, 'weekly_1');
+ $this->verifyDateForm($form_edit);
- $form_edit = $this->dateForm($options = 'select', 'weekly_1', TRUE);
- $this->verifyDateForm($form_edit);
+ $form_edit = $this->dateForm($options, 'weekly_2');
+ $this->verifyDateForm($form_edit);
- $form_edit = $this->dateForm($options = 'select', 'weekly_2', TRUE);
- $this->verifyDateForm($form_edit);
+ $form_edit = $this->dateForm($options, 'weekly_3');
+ $this->verifyDateForm($form_edit);
- $form_edit = $this->dateForm($options = 'select', 'weekly_3', TRUE);
- $this->verifyDateForm($form_edit);
+ $form_edit = $this->dateForm($options, 'weekly_4');
+ $this->verifyDateForm($form_edit);
- $form_edit = $this->dateForm($options = 'select', 'weekly_4', TRUE);
- $this->verifyDateForm($form_edit);
+ $form_edit = $this->dateForm($options, 'weekly_1', TRUE);
+ $this->verifyDateForm($form_edit);
- $this->deleteDateField();
+ $form_edit = $this->dateForm($options, 'weekly_2', TRUE);
+ $this->verifyDateForm($form_edit);
- // Monthly tests
- // Creates select list date field stored as a date with default settings.
- $this->createDateField($type = 'datetime', $widget = 'date_select');
+ $form_edit = $this->dateForm($options, 'weekly_3', TRUE);
+ $this->verifyDateForm($form_edit);
- $form_edit = $this->dateForm($options = 'select', 'monthly_1');
- $this->verifyDateForm($form_edit);
+ $form_edit = $this->dateForm($options, 'weekly_4', TRUE);
+ $this->verifyDateForm($form_edit);
- $form_edit = $this->dateForm($options = 'select', 'monthly_2');
- $this->verifyDateForm($form_edit);
+ // Monthly tests
- $form_edit = $this->dateForm($options = 'select', 'monthly_3');
- $this->verifyDateForm($form_edit);
+ $form_edit = $this->dateForm($options, 'monthly_1');
+ $this->verifyDateForm($form_edit);
- $form_edit = $this->dateForm($options = 'select', 'monthly_4');
- $this->verifyDateForm($form_edit);
+ $form_edit = $this->dateForm($options, 'monthly_2');
+ $this->verifyDateForm($form_edit);
- $form_edit = $this->dateForm($options = 'select', 'monthly_5');
- $this->verifyDateForm($form_edit);
+ $form_edit = $this->dateForm($options, 'monthly_3');
+ $this->verifyDateForm($form_edit);
- $form_edit = $this->dateForm($options = 'select', 'monthly_6');
- $this->verifyDateForm($form_edit);
+ $form_edit = $this->dateForm($options, 'monthly_4');
+ $this->verifyDateForm($form_edit);
- $form_edit = $this->dateForm($options = 'select', 'monthly_1', TRUE);
- $this->verifyDateForm($form_edit);
+ $form_edit = $this->dateForm($options, 'monthly_5');
+ $this->verifyDateForm($form_edit);
- $form_edit = $this->dateForm($options = 'select', 'monthly_2', TRUE);
- $this->verifyDateForm($form_edit);
+ $form_edit = $this->dateForm($options, 'monthly_6');
+ $this->verifyDateForm($form_edit);
- $form_edit = $this->dateForm($options = 'select', 'monthly_3', TRUE);
- $this->verifyDateForm($form_edit);
+ $form_edit = $this->dateForm($options, 'monthly_1', TRUE);
+ $this->verifyDateForm($form_edit);
- $form_edit = $this->dateForm($options = 'select', 'monthly_4', TRUE);
- $this->verifyDateForm($form_edit);
+ $form_edit = $this->dateForm($options, 'monthly_2', TRUE);
+ $this->verifyDateForm($form_edit);
- $form_edit = $this->dateForm($options = 'select', 'monthly_5', TRUE);
- $this->verifyDateForm($form_edit);
+ $form_edit = $this->dateForm($options, 'monthly_3', TRUE);
+ $this->verifyDateForm($form_edit);
- $form_edit = $this->dateForm($options = 'select', 'monthly_6', TRUE);
- $this->verifyDateForm($form_edit);
+ $form_edit = $this->dateForm($options, 'monthly_4', TRUE);
+ $this->verifyDateForm($form_edit);
- $this->deleteDateField();
+ $form_edit = $this->dateForm($options, 'monthly_5', TRUE);
+ $this->verifyDateForm($form_edit);
- // Yearly tests
- // Creates select list date field stored as a date with default settings.
- $this->createDateField($type = 'datetime', $widget = 'date_select');
+ $form_edit = $this->dateForm($options, 'monthly_6', TRUE);
+ $this->verifyDateForm($form_edit);
- $form_edit = $this->dateForm($options = 'select', 'yearly_1');
- $this->verifyDateForm($form_edit);
+ // Yearly tests
- $form_edit = $this->dateForm($options = 'select', 'yearly_2');
- $this->verifyDateForm($form_edit);
+ $form_edit = $this->dateForm($options, 'yearly_1');
+ $this->verifyDateForm($form_edit);
- $form_edit = $this->dateForm($options = 'select', 'yearly_3');
- $this->verifyDateForm($form_edit);
+ $form_edit = $this->dateForm($options, 'yearly_2');
+ $this->verifyDateForm($form_edit);
- $form_edit = $this->dateForm($options = 'select', 'yearly_4');
- $this->verifyDateForm($form_edit);
+ $form_edit = $this->dateForm($options, 'yearly_3');
+ $this->verifyDateForm($form_edit);
- $form_edit = $this->dateForm($options = 'select', 'yearly_5');
- $this->verifyDateForm($form_edit);
+ $form_edit = $this->dateForm($options, 'yearly_4');
+ $this->verifyDateForm($form_edit);
- $form_edit = $this->dateForm($options = 'select', 'yearly_6');
- $this->verifyDateForm($form_edit);
+ $form_edit = $this->dateForm($options, 'yearly_5');
+ $this->verifyDateForm($form_edit);
- $form_edit = $this->dateForm($options = 'select', 'yearly_1', TRUE);
- $this->verifyDateForm($form_edit);
+ $form_edit = $this->dateForm($options, 'yearly_6');
+ $this->verifyDateForm($form_edit);
- $form_edit = $this->dateForm($options = 'select', 'yearly_2', TRUE);
- $this->verifyDateForm($form_edit);
+ $form_edit = $this->dateForm($options, 'yearly_1', TRUE);
+ $this->verifyDateForm($form_edit);
- $form_edit = $this->dateForm($options = 'select', 'yearly_3', TRUE);
- $this->verifyDateForm($form_edit);
+ $form_edit = $this->dateForm($options, 'yearly_2', TRUE);
+ $this->verifyDateForm($form_edit);
- $form_edit = $this->dateForm($options = 'select', 'yearly_4', TRUE);
- $this->verifyDateForm($form_edit);
+ $form_edit = $this->dateForm($options, 'yearly_3', TRUE);
+ $this->verifyDateForm($form_edit);
- $form_edit = $this->dateForm($options = 'select', 'yearly_5', TRUE);
- $this->verifyDateForm($form_edit);
+ $form_edit = $this->dateForm($options, 'yearly_4', TRUE);
+ $this->verifyDateForm($form_edit);
- $form_edit = $this->dateForm($options = 'select', 'yearly_6', TRUE);
- $this->verifyDateForm($form_edit);
+ $form_edit = $this->dateForm($options, 'yearly_5', TRUE);
+ $this->verifyDateForm($form_edit);
- $this->deleteDateField();
+ $form_edit = $this->dateForm($options, 'yearly_6', TRUE);
+ $this->verifyDateForm($form_edit);
- /*// Creates text date field stored as a date with default settings.
- $this->createDateField($type = 'datetime', $widget = 'date_text');
- $form_edit = $this->dateForm($options = 'text', 'daily_1');
- $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a date field using the date_text widget.');
- $this->verifyDateForm($form_edit);
- $this->deleteDateField();
-
- // Creates popup date field stored as a date with default settings.
- $this->createDateField($type = 'datetime', $widget = 'date_popup');
- $form_edit = $this->dateForm($options = 'popup', 'daily_1');
- $this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a date field using the date_popup widget.');
- $this->verifyDateForm($form_edit);
- $this->deleteDateField();*/
+ $this->deleteDateField();
+ }
}
- function dateForm($options, $test_id = NULL, $is_count = FALSE) {
+ function dateForm($options, $test_id = NULL, $is_count = FALSE, $exclude_include = NULL) {
// Tests that date field functions properly.
$edit = array();
$edit['title'] = $this->randomName(8);
@@ -211,10 +201,10 @@ class DateRepeatFormTestCase extends DrupalWebTestCase {
$edit['field_test[und][0][value][minute]'] = '30';
break;
case 'text':
- $edit['field_test[und][0][value][date]'] = '10-07-2010 10:30';
+ $edit['field_test[und][0][value][date]'] = '2010-10-07 10:30';
break;
case 'popup':
- $edit['field_test[und][0][value][date]'] = '10-07-2010';
+ $edit['field_test[und][0][value][date]'] = '2010-10-07';
$edit['field_test[und][0][value][time]'] = '10:30';
break;
}
@@ -376,23 +366,62 @@ class DateRepeatFormTestCase extends DrupalWebTestCase {
break;
}
+ // Test COUNT or UNTIL (default)
if ($is_count) {
$edit['field_test[und][0][rrule][range_of_repeat]'] = 'COUNT';
$edit['field_test[und][0][rrule][count_child]'] = $count;
}
else {
$edit['field_test[und][0][rrule][range_of_repeat]'] = 'UNTIL';
- switch ($options) {
- case 'select':
- $edit['field_test[und][0][rrule][until_child][datetime][year]'] = '2011';
- $edit['field_test[und][0][rrule][until_child][datetime][month]'] = '10';
- $edit['field_test[und][0][rrule][until_child][datetime][day]'] = '7';
- break;
- case 'text':
- case 'popup':
- $edit['field_test[und][0][rrule][until_child][datetime][date]'] = '10-07-2011';
- break;
+ $date = array(
+ 'year' => '2011',
+ 'month' => '10',
+ 'day' => '07'
+ );
+ $edit += $this->formatDateForRRULEInputs('field_test[und][0][rrule][until_child]', $options, $date);
+ }
+
+ // Test date exceptions and/or additions
+ if ($exclude_include !== NULL) {
+ $exclude_include_edit = array();
+ switch ($exclude_include) {
+ case 'exclude':
+ $exclude_include_edit['field_test[und][0][rrule][show_exceptions]'] = TRUE;
+ $date = array(
+ 'year' => '2010',
+ 'month' => '10',
+ 'day' => '07'
+ );
+ $exclude_include_edit += $this->formatDateForRRULEInputs('field_test[und][0][rrule][exceptions][EXDATE][0]', $options, $date);
+ break;
+ case 'include':
+ $exclude_include_edit['field_test[und][0][rrule][show_additions]'] = TRUE;
+ $date = array(
+ 'year' => '2013',
+ 'month' => '10',
+ 'day' => '07'
+ );
+ $exclude_include_edit += $this->formatDateForRRULEInputs('field_test[und][0][rrule][additions][RDATE][0]', $options, $date);
+ break;
+ case 'exclude_include':
+ $exclude_include_edit['field_test[und][0][rrule][show_exceptions]'] = TRUE;
+ $date = array(
+ 'year' => '2010',
+ 'month' => '10',
+ 'day' => '07'
+ );
+ $exclude_include_edit += $this->formatDateForRRULEInputs('field_test[und][0][rrule][exceptions][EXDATE][0]', $options, $date);
+
+ $exclude_include_edit['field_test[und][0][rrule][show_additions]'] = TRUE;
+ $date = array(
+ 'year' => '2013',
+ 'month' => '10',
+ 'day' => '07'
+ );
+ $exclude_include_edit += $this->formatDateForRRULEInputs('field_test[und][0][rrule][additions][RDATE][0]', $options, $date);
+ break;
}
+ $edit += $exclude_include_edit;
}
}
@@ -462,4 +491,23 @@ class DateRepeatFormTestCase extends DrupalWebTestCase {
$this->drupalPost(NULL, NULL, t('Delete'));
$this->assertText(t('The field Test has been deleted from the Date content type.'), t('Removed date field.'));
}
+
+ function formatDateForRRULEInputs($form_field_name, $date_widget_type, $date) {
+ $return = array();
+
+ switch ($date_widget_type) {
+ case 'select':
+ $return["{$form_field_name}[datetime][year]"] = $date['year'];
+ $return["{$form_field_name}[datetime][month]"] = $date['month'];
+ $return["{$form_field_name}[datetime][day]"] = ltrim($date['day'], '0');
+ break;
+ case 'text':
+ case 'popup':
+ //$return["{$field_name}[datetime][date]"] = '2011-10-07';
+ $return["{$form_field_name}[datetime][date]"] = "{$date['year']}-{$date['month']}-{$date['day']}";
+ break;
+ }
+
+ return $return;
+ }
}