all contrib module security updates done

This commit is contained in:
2020-09-24 22:47:32 +02:00
parent 7d87153100
commit 0fbb9c4610
1612 changed files with 116663 additions and 32269 deletions
@@ -5,8 +5,7 @@
* Test date UI.
*/
class DateUITestCase extends DrupalWebTestCase {
protected $privileged_user;
class DateUITestCase extends DateFieldBasic {
/**
* @todo.
@@ -23,14 +22,7 @@ class DateUITestCase extends DrupalWebTestCase {
* @todo.
*/
public function setUp() {
// Load the date_api module.
parent::setUp('field', 'field_ui', 'date_api', 'date', 'date_popup', 'date_tools');
// Create and log in our privileged user.
$this->privileged_user = $this->drupalCreateUser(
array('administer content types', 'administer nodes', 'bypass node access', 'administer date tools')
);
$this->drupalLogin($this->privileged_user);
parent::setUp();
variable_set('date_format_long', 'D, m/d/Y - H:i');
}
@@ -39,82 +31,34 @@ class DateUITestCase extends DrupalWebTestCase {
* @todo.
*/
public function testFieldUI() {
$edit = array();
$edit['name'] = 'Story';
$edit['type'] = 'story';
$this->drupalPost('admin/structure/types/add', $edit, t('Save content type'));
$this->assertText('The content type Story has been added.', 'Content type added.');
$label = 'Test';
$current_year = date('Y');
// Creates select list field stored as a date with default settings.
$this->createDateField($type = 'date', $widget = 'date_select');
$edit = array();
$this->drupalPost(NULL, $edit, t('Save field settings'));
$this->dateForm($options = 'select');
$this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a date field using the date_select widget.');
$this->deleteDateField();
// Creates text field stored as a date with default settings.
$this->createDateField($type = 'date', $widget = 'date_text');
$edit = array();
$this->drupalPost(NULL, $edit, t('Save field settings'));
$this->dateForm($options = 'text');
$this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a date field using the date_text widget.');
$this->deleteDateField();
// Creates popup field stored as a date with default settings.
$this->createDateField($type = 'date', $widget = 'date_popup');
$edit = array();
$this->drupalPost(NULL, $edit, t('Save field settings'));
$this->dateForm($options = 'popup');
$this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a date field using the date_popup widget.');
$this->deleteDateField();
// Creates select list field stored as a datestamp with default settings.
$this->createDateField($type = 'datestamp', $widget = 'date_select');
$edit = array();
$this->drupalPost(NULL, $edit, t('Save field settings'));
$this->dateForm($options = 'select');
$this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datestamp field using the date_select widget.');
$this->deleteDateField();
// Creates text field stored as a datestamp with default settings.
$this->createDateField($type = 'datestamp', $widget = 'date_text');
$edit = array();
$this->drupalPost(NULL, $edit, t('Save field settings'));
$this->dateForm($options = 'text');
$this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datestamp field using the date_text widget.');
$this->deleteDateField();
// Creates popup field stored as a datestamp with default settings.
$this->createDateField($type = 'datestamp', $widget = 'date_popup');
$edit = array();
$this->drupalPost(NULL, $edit, t('Save field settings'));
$this->dateForm($options = 'popup');
$this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datestamp field using the date_popup widget.');
$this->deleteDateField();
// Creates select list field stored as a datetime with default settings.
$this->createDateField($type = 'datetime', $widget = 'date_select');
$edit = array();
$this->drupalPost(NULL, $edit, t('Save field settings'));
$this->dateForm($options = 'select');
$this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datetime field using the date_select widget.');
$this->deleteDateField();
// Creates text field stored as a datetime with default settings.
$this->createDateField($type = 'datetime', $widget = 'date_text');
$edit = array();
$this->drupalPost(NULL, $edit, t('Save field settings'));
$this->dateForm($options = 'text');
$this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datetime field using the date_text widget.');
$this->deleteDateField();
// Creates popup field stored as a datetime with default settings.
$this->createDateField($type = 'datetime', $widget = 'date_popup');
$edit = array();
$this->drupalPost(NULL, $edit, t('Save field settings'));
$this->dateForm($options = 'popup');
$this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datetime field using the date_popup widget.');
$this->deleteDateField();
$field_types = array('date', 'datestamp', 'datetime');
$widget_types = array('date_select', 'date_text', 'date_popup');
// Test widgets with default settings using every widget and field type.
foreach ($field_types as $field_type) {
foreach ($widget_types as $widget_type) {
$this->createDateField(
array(
'label' => $label,
'field_type' => $field_type,
'widget_type' => $widget_type,
)
);
$this->dateForm($widget_type);
$this->assertText(format_string('10/07/!year - 10:30', array('!year' => $current_year)), 'Found the correct date for a date field using the ' . $widget_type . ' widget.');
$this->deleteDateField($label);
}
}
// Test timezone handling validation on the field settings form.
$this->createDateField($type = 'date', $widget = 'date_select');
$this->createDateField(array('label' => $label, 'field_type' => 'date', 'widget_type' => 'date_select', 'granularity' => array('year', 'month', 'day')));
$edit = array('field[settings][granularity][hour]' => FALSE);
$this->drupalPost(NULL, $edit, t('Save field settings'));
$this->drupalPost('admin/structure/types/manage/story/fields/field_' . strtolower($label), $edit, t('Save settings'));
$this->assertText("Dates without hours granularity must not use any timezone handling.", "Dates without hours granularity required to use timezone handling of 'none.'");
$this->deleteDateField();
$this->deleteDateField($label);
}
/**
@@ -125,44 +69,23 @@ class DateUITestCase extends DrupalWebTestCase {
$edit = array();
$edit['title'] = $this->randomName(8);
$edit['body[und][0][value]'] = $this->randomName(16);
if ($options == 'select') {
$edit['field_test[und][0][value][year]'] = '2010';
$current_year = date('Y');
if ($options == 'date_select') {
$edit['field_test[und][0][value][year]'] = $current_year;
$edit['field_test[und][0][value][month]'] = '10';
$edit['field_test[und][0][value][day]'] = '7';
$edit['field_test[und][0][value][hour]'] = '10';
$edit['field_test[und][0][value][minute]'] = '30';
}
elseif ($options == 'text') {
$edit['field_test[und][0][value][date]'] = '10/07/2010 - 10:30';
elseif ($options == 'date_text') {
$edit['field_test[und][0][value][date]'] = format_string('10/07/!year - 10:30', array('!year' => $current_year));
}
elseif ($options == 'popup') {
$edit['field_test[und][0][value][date]'] = '10/07/2010';
elseif ($options == 'date_popup') {
$edit['field_test[und][0][value][date]'] = format_string('10/07/!year', array('!year' => $current_year));
$edit['field_test[und][0][value][time]'] = '10:30';
}
$this->drupalPost('node/add/story', $edit, t('Save'));
$this->assertText($edit['body[und][0][value]'], 'Test node has been created');
}
/**
* @todo.
*/
function createDateField($type, $widget) {
$edit = array();
$edit['fields[_add_new_field][label]'] = 'Test';
$edit['fields[_add_new_field][field_name]'] = 'test';
$edit['fields[_add_new_field][weight]'] = '-4';
$edit['fields[_add_new_field][type]'] = $type;
$edit['fields[_add_new_field][widget_type]'] = $widget;
$this->drupalPost('admin/structure/types/manage/story/fields', $edit, t('Save'));
}
/**
* @todo.
*/
function deleteDateField() {
$this->drupalGet('admin/structure/types/manage/story/fields');
$this->clickLink('delete');
$this->drupalPost(NULL, NULL, t('Delete'));
$this->assertText('The field Test has been deleted from the Story content type.', 'Removed date field.');
}
}
@@ -132,11 +132,11 @@ class DateAPITestCase extends DrupalWebTestCase {
// Test week range with calendar weeks.
variable_set('date_first_day', 0);
variable_set('date_api_use_iso8601', FALSE);
$expected = '2008-01-27 to 2008-02-03';
$expected = '2008-01-27 to 2008-02-02';
$result = date_week_range(5, 2008);
$value = $result[0]->format(DATE_FORMAT_DATE) . ' to ' . $result[1]->format(DATE_FORMAT_DATE);
$this->assertEqual($expected, $value, "Test calendar date_week_range(5, 2008): should be $expected, found $value.");
$expected = '2009-01-25 to 2009-02-01';
$expected = '2009-01-25 to 2009-01-31';
$result = date_week_range(5, 2009);
$value = $result[0]->format(DATE_FORMAT_DATE) . ' to ' . $result[1]->format(DATE_FORMAT_DATE);
$this->assertEqual($expected, $value, "Test calendar date_week_range(5, 2009): should be $expected, found $value.");
@@ -144,11 +144,11 @@ class DateAPITestCase extends DrupalWebTestCase {
// And now with ISO weeks.
variable_set('date_first_day', 1);
variable_set('date_api_use_iso8601', TRUE);
$expected = '2008-01-28 to 2008-02-04';
$expected = '2008-01-28 to 2008-02-03';
$result = date_week_range(5, 2008);
$value = $result[0]->format(DATE_FORMAT_DATE) . ' to ' . $result[1]->format(DATE_FORMAT_DATE);
$this->assertEqual($expected, $value, "Test ISO date_week_range(5, 2008): should be $expected, found $value.");
$expected = '2009-01-26 to 2009-02-02';
$expected = '2009-01-26 to 2009-02-01';
$result = date_week_range(5, 2009);
$value = $result[0]->format(DATE_FORMAT_DATE) . ' to ' . $result[1]->format(DATE_FORMAT_DATE);
$this->assertEqual($expected, $value, "Test ISO date_week_range(5, 2009): should be $expected, found $value.");
@@ -393,9 +393,31 @@ class DateAPITestCase extends DrupalWebTestCase {
$input = '23 abc 2012';
$timezone = NULL;
$format = 'd M Y';
$date = new dateObject($input, $timezone, $format);
$date = @new dateObject($input, $timezone, $format);
$this->assertNotEqual(count($date->errors), 0, '23 abc 2012 should be an invalid date');
// Test Granularity.
$input = '2005-06-01 10:30:45';
$timezone = NULL;
$format = 'Y-m-d H:i:s';
$date = new dateObject($input, $timezone, $format);
$date->removeGranularity('hour');
$date->removeGranularity('second');
$date->removeGranularity('minute');
$value = $date->format($format);
$expected = '2005-06-01';
$this->assertEqual($expected, $value, "The date with removed granularity should be $expected, found $value.");
$date->addGranularity('hour');
$date->addGranularity('second');
$date->addGranularity('minute');
$value = $date->format($format);
$expected = '2005-06-01 10:30:45';
$this->assertEqual($expected, $value, "The date with added granularity should be $expected, found $value.");
}
/**
@@ -16,7 +16,7 @@ abstract class DateFieldBasic extends DrupalWebTestCase {
// Create and log in our privileged user.
$this->privileged_user = $this->drupalCreateUser(
array('administer content types', 'administer nodes', 'bypass node access', 'administer date tools')
array('administer content types', 'administer nodes', 'bypass node access', 'administer date tools', 'administer fields')
);
$this->drupalLogin($this->privileged_user);
@@ -52,7 +52,7 @@ abstract class DateFieldBasic extends DrupalWebTestCase {
$repeat = !empty($repeat) ? $repeat : 0;
$todate = !empty($todate) ? $todate : 'optional';
$widget_type = !empty($widget_type) ? $widget_type : 'date_select';
$tz_handling = !empty($tz_handing) ? $tz_handling : 'site';
$tz_handling = !empty($tz_handling) ? $tz_handling : 'site';
$granularity = !empty($granularity) ? $granularity : array('year', 'month', 'day', 'hour', 'minute');
$year_range = !empty($year_range) ? $year_range : '2010:+1';
$input_format = !empty($input_format) ? $input_format : date_default_format($widget_type);
@@ -151,6 +151,123 @@ abstract class DateFieldBasic extends DrupalWebTestCase {
}
/**
* Creates a date field from an array of settings values.
*
* All values have defaults, only need to specify values that need to be
* different.
*/
protected function createMultiDateField($values = array()) {
extract($values);
$field_name = !empty($field_name) ? $field_name : 'field_test';
$entity_type = !empty($entity_type) ? $entity_type : 'node';
$bundle = !empty($bundle) ? $bundle : 'story';
$label = !empty($label) ? $label : 'Test';
$field_type = !empty($field_type) ? $field_type : 'datetime';
$repeat = !empty($repeat) ? $repeat : 0;
$todate = !empty($todate) ? $todate : 'optional';
$widget_type = !empty($widget_type) ? $widget_type : 'date_select';
$this->verbose(!empty($tz_handling));
$tz_handling = !empty($tz_handling) ? $tz_handling : 'site';
$granularity = !empty($granularity) ? $granularity : array('year', 'month', 'day', 'hour', 'minute');
$year_range = !empty($year_range) ? $year_range : '2010:+1';
$input_format = !empty($input_format) ? $input_format : date_default_format($widget_type);
$input_format_custom = !empty($input_format_custom) ? $input_format_custom : '';
$text_parts = !empty($text_parts) ? $text_parts : array();
$increment = !empty($increment) ? $increment : 15;
$default_value = !empty($default_value) ? $default_value : 'now';
$default_value2 = !empty($default_value2) ? $default_value2 : 'blank';
$default_format = !empty($default_format) ? $default_format : 'long';
$cache_enabled = !empty($cache_enabled);
$cache_count = !empty($cache_count) ? $cache_count : 4;
$cardinality = !empty($cardinality) ? $cardinality : 1;
$field = array(
'field_name' => $field_name,
'type' => $field_type,
'cardinality' => $cardinality,
'settings' => array(
'granularity' => $granularity,
'tz_handling' => $tz_handling,
'timezone_db' => date_get_timezone_db($tz_handling),
'repeat' => $repeat,
'todate' => $todate,
'cache_enabled' => $cache_enabled,
'cache_count' => $cache_count,
),
);
$instance = array(
'entity_type' => $entity_type,
'field_name' => $field_name,
'label' => $label,
'bundle' => $bundle,
// Move the date right below the title.
'weight' => -4,
'widget' => array(
'type' => $widget_type,
// Increment for minutes and seconds, can be 1, 5, 10, 15, or 30.
'settings' => array(
'increment' => $increment,
// The number of years to go back and forward in drop-down year
// selectors.
'year_range' => $year_range,
'input_format' => $input_format,
'input_format_custom' => $input_format_custom,
'text_parts' => $text_parts,
'label_position' => 'above',
'repeat_collapsed' => 0,
),
'weight' => -4,
),
'settings' => array(
'default_value' => $default_value,
'default_value2' => $default_value2,
),
);
$instance['display'] = array(
'default' => array(
'label' => 'above',
'type' => 'date_default',
'settings' => array(
'format_type' => $default_format,
'show_repeat_rule' => 'show',
'multiple_number' => '',
'multiple_from' => '',
'multiple_to' => '',
'fromto' => 'both',
),
'module' => 'date',
'weight' => 0 ,
),
'teaser' => array(
'label' => 'above',
'type' => 'date_default',
'weight' => 0,
'settings' => array(
'format_type' => $default_format,
'show_repeat_rule' => 'show',
'multiple_number' => '',
'multiple_from' => '',
'multiple_to' => '',
'fromto' => 'both',
),
'module' => 'date',
),
);
$field = field_create_field($field);
$instance = field_create_instance($instance);
field_info_cache_clear(TRUE);
field_cache_clear(TRUE);
// Look at how the field got configured.
$this->drupalGet("admin/structure/types/manage/$bundle/fields/$field_name");
$this->drupalGet("admin/structure/types/manage/$bundle/display");
}
/**
* @todo.
*/
@@ -0,0 +1,30 @@
<?php
/**
* @file
* Contains form specific date element test cases.
*/
class DateFormTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => t('Date Form test'),
'description' => t('Test Date form functions.') ,
'group' => t('Date'),
);
}
public function setUp() {
// Load the date_api module.
parent::setUp('date_test');
}
/**
* Tests rendering of a date element in a form.
*/
public function testDateForm() {
$this->drupalGet('date-test/form');
}
}
@@ -0,0 +1,81 @@
<?php
/**
* @file
* Test for using date fields with Migrate module.
*/
/**
* Test date migration.
*/
class DateMigrateExampleUnitTest extends DrupalWebTestCase {
/**
* Provides information about this test.
*/
public static function getInfo() {
return array(
'name' => 'Date Migration',
'description' => 'Test migration into date fields',
'group' => 'Date',
'dependencies' => array('migrate', 'features'),
);
}
/**
* Declars the module dependencies for the test.
*/
function setUp() {
parent::setUp('migrate', 'features', 'date', 'date_repeat',
'date_repeat_field', 'date_migrate_example');
// Make sure the migration is registered.
if (function_exists('migrate_static_registration')) {
// Migrate 2.6 and later
migrate_static_registration();
}
else {
// Migrate 2.5 and earlier
migrate_get_module_apis(TRUE);
}
}
/**
* Verify that date fields are imported correctly. When no timezone is
* explicitly provided with the source data, we want the displayed time on the
* Drupal site to match that in the source data. To validate that, we make
* sure we have set a consistent timezone at the PHP and Drupal levels, and
* that the format used on the page is not locale-dependent (no day or month
* names). Then, we can just look for the desired date/time strings in the
* node page.
*/
function testDateImport() {
date_default_timezone_set('America/Los_Angeles');
variable_set('date_default_timezone', 'America/Los_Angeles');
variable_set('date_format_medium', 'Y-m-d H:i');
$migration = Migration::getInstance('DateExample');
$result = $migration->processImport();
$this->assertEqual($result, Migration::RESULT_COMPLETED, t('Variety term import returned RESULT_COMPLETED'));
$rawnodes = node_load_multiple(FALSE, array('type' => 'date_migrate_example'), TRUE);
$this->assertEqual(count($rawnodes), 2, t('Two sample nodes created'));
$node = reset($rawnodes);
$this->drupalGet('/node/' . $node->nid);
$this->assertText('2011-05-12 19:43', t('Simple date field found'));
$this->assertText('2011-06-13 18:32 to 2011-07-23 10:32', t('Date range field found'));
$this->assertText('2011-07-22 12:13', t('Datestamp field found'));
$this->assertText('2011-08-01 00:00 to 2011-09-01 00:00', t('Datestamp range field found'));
$this->assertText('2011-11-18 15:00', t('Datetime field with +9 timezone found'));
$this->assertText('2011-10-30 14:43 to 2011-12-31 17:59', t('Datetime range field with -5 timezone found'));
$this->assertText('2011-11-25 09:01', t('First date repeat instance found'));
$this->assertText('2011-12-09 09:01', t('Second date repeat instance found'));
$this->assertNoText('2011-12-23 09:01', t('Skipped date repeat instance not found'));
$this->assertText('2012-05-11 09:01', t('Last date repeat instance found'));
$node = next($rawnodes);
$this->drupalGet('/node/' . $node->nid);
$this->assertText('2012-06-21 15:32', t('First date value found'));
$this->assertText('2012-12-02 11:08', t('Second date value found'));
$this->assertText('2004-02-03 01:15', t('Start for first date range found'));
$this->assertText('2005-03-04 22:11', t('End for first date range found'));
$this->assertText('2014-09-01 17:21', t('Start for second date range found'));
$this->assertText('2015-12-23 00:01', t('End for first second range found'));
}
}
@@ -0,0 +1,14 @@
name = "Date module tests"
description = "Support module for date related testing."
package = Date/Time
version = VERSION
core = 7.x
hidden = TRUE
dependencies[] = date
; Information added by Drupal.org packaging script on 2017-04-07
version = "7.x-2.10"
core = "7.x"
project = "date"
datestamp = "1491562090"
@@ -0,0 +1,40 @@
<?php
/**
* @file
* Contains date test implementations.
*/
/**
* Implements hook_menu().
*/
function date_test_menu() {
$items['date-test/form'] = array(
'title' => 'Test form with date element',
'description' => "Form with date element to make form related tests",
'page callback' => 'drupal_get_form',
'page arguments' => array('date_test_sample_form'),
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Form callback. Generates a test form with date elements.
*/
function date_test_sample_form($form, &$form_state) {
$form['date_test_select'] = array(
'#type' => 'date_select',
'#title' => t('Sample from'),
'#date_format' => 'H:i:s a',
'#default_value' => array(
'hour' => 7,
'minute' => 0,
'second' => 0,
'ampm' => 'am'
),
);
return $form;
}
@@ -16,6 +16,16 @@ class DateTimezoneTestCase extends DateFieldBasic {
);
}
public function setUp() {
parent::setUp();
// Set the timezone explicitly. Otherwise the site's default timezone is
// used, which defaults to the server timezone when installing Drupal. This
// depends on the environment and is therefore uncertain.
// The Australia/Sydney timezone is chosen so all tests are run using an
// edge case scenario (UTC+10 and DST).
variable_set('date_default_timezone', 'Australia/Sydney');
}
/**
* @todo.
*/
@@ -23,7 +33,7 @@ class DateTimezoneTestCase extends DateFieldBasic {
// Create a date fields with combinations of various timezone handling and
// granularity.
foreach (array('date', 'datestamp', 'datetime') as $field_type) {
foreach (array('site', 'none', 'date', 'user', 'utc') as $tz_handling) {
foreach (array('site', 'none', 'date', 'user', 'utc', 'Europe/Dublin') as $tz_handling) {
foreach (array('year', 'month', 'day', 'hour', 'minute', 'second') as $max_granularity) {
// Skip invalid combinations.
if (in_array($max_granularity, array('year', 'month', 'day')) && $tz_handling != 'none') {
@@ -50,6 +60,111 @@ class DateTimezoneTestCase extends DateFieldBasic {
}
}
/**
* Validates timezone handling with a multi-value date field.
*/
public function testMultiUserTimezone() {
// Create date fields with combinations of various types and granularity
// using the "Date's Timezone" strategy.
$field_type = 'datetime';
$tz_handling = 'date';
$max_granularity = 'minute';
// Create date field
$field_name = "field_test";
$label = 'Test';
$options = array(
'label' => $label,
'widget_type' => 'date_text',
'field_name' => $field_name,
'field_type' => $field_type,
'input_format' => 'custom',
'input_format_custom' => 'm/d/Y - H:i:s T',
'cardinality' => 3,
'tz_handling' => $tz_handling,
);
$this->createMultiDateField($options);
// Submit a date field form with multiple values
$this->dateMultiValueForm($field_name, $field_type, $max_granularity, $tz_handling);
$this->deleteDateField($label);
}
/**
* Tests the submission of a date field's widget form when using unlimited
* cardinality
*/
public function dateMultiValueForm($field_name, $field_type, $max_granularity, $tz_handling) {
variable_set('date_format_long', 'D, m/d/Y - H:i:s T');
$edit = array();
$should_be = array();
$edit['title'] = $this->randomName(8);
$timezones = array('America/Chicago', 'America/Los_Angeles', 'America/New_York');
switch ($max_granularity) {
case 'hour':
$edit[$field_name . '[und][0][value][date]'] = '10/07/2010 - 10:30';
$edit[$field_name . '[und][0][timezone][timezone]'] = 'America/Chicago';
$should_be[0] = 'Thu, 10/07/2010 - 10 CDT';
$edit[$field_name . '[und][1][value][date]'] = '10/07/2010 - 10:30';
$edit[$field_name . '[und][1][timezone][timezone]'] = 'America/Los_Angeles';
$should_be[1] = 'Thu, 10/07/2010 - 10 PDT';
$edit[$field_name . '[und][2][value][date]'] = '10/07/2010 - 10:30';
$edit[$field_name . '[und][2][timezone][timezone]'] = 'America/New_York';
$should_be[2] = 'Thu, 10/07/2010 - 10 EDT';
break;
case 'minute':
$edit[$field_name . '[und][0][value][date]'] = '10/07/2010 - 10:30';
$edit[$field_name . '[und][0][timezone][timezone]'] = 'America/Chicago';
$should_be[0] = 'Thu, 10/07/2010 - 10:30 CDT';
$edit[$field_name . '[und][1][value][date]'] = '10/07/2010 - 10:30';
$edit[$field_name . '[und][1][timezone][timezone]'] = 'America/Los_Angeles';
$should_be[1] = 'Thu, 10/07/2010 - 10:30 PDT';
$edit[$field_name . '[und][2][value][date]'] = '10/07/2010 - 10:30';
$edit[$field_name . '[und][2][timezone][timezone]'] = 'America/New_York';
$should_be[2] = 'Thu, 10/07/2010 - 10:30 EDT';
break;
case 'second':
$edit[$field_name . '[und][0][value][date]'] = '10/07/2010 - 10:30';
$edit[$field_name . '[und][0][timezone][timezone]'] = 'America/Chicago';
$should_be[0] = 'Thu, 10/07/2010 - 10:30:30 CDT';
$edit[$field_name . '[und][1][value][date]'] = '10/07/2010 - 10:30';
$edit[$field_name . '[und][1][timezone][timezone]'] = 'America/Los_Angeles';
$should_be[1] = 'Thu, 10/07/2010 - 10:30:30 PDT';
$edit[$field_name . '[und][2][value][date]'] = '10/07/2010 - 10:30';
$edit[$field_name . '[und][2][timezone][timezone]'] = 'America/New_York';
$should_be[2] = 'Thu, 10/07/2010 - 10:30:30 EDT';
break;
}
$this->drupalPost('node/add/story', $edit, t('Save'));
$this->assertText($edit['title'], "Node has been created");
foreach ($should_be as $assertion) {
$this->assertText($assertion, "Found the correct date for a $field_type field using $max_granularity granularity with $tz_handling timezone handling.");
}
// Goto the edit page and save the node again.
$node = $this->drupalGetNodeByTitle($edit['title']);
$this->drupalGet('node/' . $node->nid . '/edit');
// Re-assert the proper date timezones.
foreach ($timezones as $key => $timezone) {
$this->assertOptionSelected('edit-field-test-und-' . $key . '-timezone-timezone', $timezone, "Found the correct timezone $timezone for a $field_type field using $max_granularity granularity with $tz_handling timezone handling.");
}
}
/**
* @todo.
*/
@@ -77,17 +192,32 @@ class DateTimezoneTestCase extends DateFieldBasic {
case 'hour':
$edit[$field_name . '[und][0][value][date]'] = '10/07/2010 - 10';
$edit[$field_name . '[und][0][value2][date]'] = '10/07/2010 - 11';
$should_be = 'Thu, 10/07/2010 - 10 to Thu, 10/07/2010 - 11';
if ($tz_handling == 'utc') {
$should_be = 'Thu, 10/07/2010 - 21 to Thu, 10/07/2010 - 22';
}
else {
$should_be = 'Thu, 10/07/2010 - 10 to Thu, 10/07/2010 - 11';
}
break;
case 'minute':
$edit[$field_name . '[und][0][value][date]'] = '10/07/2010 - 10:30';
$edit[$field_name . '[und][0][value2][date]'] = '10/07/2010 - 11:30';
$should_be = 'Thu, 10/07/2010 - 10:30 to 11:30';
if ($tz_handling == 'utc') {
$should_be = 'Thu, 10/07/2010 - 21:30 to 22:30';
}
else {
$should_be = 'Thu, 10/07/2010 - 10:30 to 11:30';
}
break;
case 'second':
$edit[$field_name . '[und][0][value][date]'] = '10/07/2010 - 10:30:30';
$edit[$field_name . '[und][0][value2][date]'] = '10/07/2010 - 11:30:30';
$should_be = 'Thu, 10/07/2010 - 10:30:30 to 11:30:30';
if ($tz_handling == 'utc') {
$should_be = 'Thu, 10/07/2010 - 21:30:30 to 22:30:30';
}
else {
$should_be = 'Thu, 10/07/2010 - 10:30:30 to 11:30:30';
}
break;
}
$this->drupalPost('node/add/story', $edit, t('Save'));
@@ -0,0 +1,129 @@
<?php
/**
* @file
* Views date pager test.
*/
class ViewsPagerTestCase extends DrupalWebTestCase {
/**
* Test info.
*/
public static function getInfo() {
return array(
'name' => 'Date views pager skipping test',
'description' => "Views date pager, option to skip empty pages test",
'group' => 'Date',
);
}
/**
* Test setup actions.
*/
public function setUp() {
// Load the 'date_views', 'views', 'views_ui', 'ctools' modules.
parent::setUp('date_views', 'views', 'views_ui', 'ctools');
// Set required permissions.
$permissions = array('administer views', 'administer site configuration');
// Create admin user and login.
$admin_user = $this->drupalCreateUser($permissions);
$this->drupalLogin($admin_user);
// Create a new view for test.
$view = new view();
$view->name = 'test_date_pager';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'test_date_pager';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'test_date_pager';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'date_views_pager';
$handler->display->display_options['pager']['options']['skip_empty_pages'] = 1;
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'node';
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Contextual filter: Date: Date (node) */
$handler->display->display_options['arguments']['date_argument']['id'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['table'] = 'node';
$handler->display->display_options['arguments']['date_argument']['field'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['default_action'] = 'default';
$handler->display->display_options['arguments']['date_argument']['default_argument_type'] = 'date';
$handler->display->display_options['arguments']['date_argument']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['date_argument']['granularity'] = 'hour';
$handler->display->display_options['arguments']['date_argument']['date_fields'] = array(
'node.created' => 'node.created',
);
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->display->display_options['path'] = 'test_date_pager';
$view->save();
}
/**
* Test pager skipping.
*/
public function testPagerSkipping() {
// Go to view admin page.
$this->drupalGet('admin/structure/views/view/display/test_date_pager/edit');
// Go to pager options.
$this->drupalGet('admin/structure/views/nojs/display/test_date_pager/default/pager_options');
// Check if "Skip empty pages" text - exist.
$this->assertText('Skip empty pages');
// Check if field and it's value is correct.
$this->assertFieldByName('pager_options[skip_empty_pages]', '1');
// Go back to view admin page.
$this->drupalGet('admin/structure/views/view/display/test_date_pager/edit');
// Check if pager on empty page are gone.
$this->assertNoText('« Prev', 'Previous pager does not exist');
$this->assertNoText('Next »', 'Next pager does not exist');
}
/**
* Test the view page has no PHP warnings.
*/
public function testPagerWarning() {
$this->drupalCreateNode(array('type' => 'blog'));
// Set pager to skip empty pages.
$edit = array(
'pager_options[skip_empty_pages]' => FALSE,
);
$this->drupalPost('admin/structure/views/nojs/display/test_date_pager/default/pager_options', $edit, t('Apply'));
// Save the view.
$this->drupalPost('admin/structure/views/view/test_date_pager/edit', array(), t('Save'));
// Visit view page. This will throw error, if any PHP warnings or errors.
$this->drupalGet('test_date_pager');
}
}
@@ -0,0 +1,106 @@
<?php
/**
* @file
* Tests date popup in Views
*/
class DateViewsPopupTestCase extends DateFieldBasic {
/**
* Test info.
*/
public static function getInfo() {
return array(
'name' => 'Date Views - Popup Test',
'description' => 'Tests date popup in Views',
'group' => 'Date',
);
}
/**
* Test setup actions.
*/
public function setUp() {
parent::setUp();
// Load the 'date_popup', 'date_views', 'views', 'views_ui', 'ctools' modules.
$modules = array('date_popup', 'date_views', 'views', 'views_ui', 'ctools');
$success = module_enable($modules, TRUE);
$this->assertTrue($success, t('Enabled modules: %modules', array('%modules' => implode(', ', $modules))));
// Reset/rebuild all data structures after enabling the modules.
$this->resetAll();
// Create a date field.
$field_name = "field_test_date_popup";
$label = 'Test';
$options = array(
'label' => 'Test',
'widget_type' => 'date_popup',
'field_name' => $field_name,
'field_type' => 'datetime',
'input_format' => 'm/d/Y - H:i',
);
$this->createDateField($options);
// Set required permissions.
$permissions = array('administer views', 'administer site configuration');
// Create admin user and login.
$admin_user = $this->drupalCreateUser($permissions);
$this->drupalLogin($admin_user);
// Create the view.
$view = new view();
$view->name = 'test_date_popup';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Test date_popup';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'test_date_popup_page';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'none';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'node';
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
/* Filter criterion: Content: test_date_popup (field_test_date_popup) */
$handler->display->display_options['filters']['field_test_date_popup_value']['id'] = 'field_test_date_popup_value';
$handler->display->display_options['filters']['field_test_date_popup_value']['table'] = 'field_data_field_test_date_popup';
$handler->display->display_options['filters']['field_test_date_popup_value']['field'] = 'field_test_date_popup_value';
$handler->display->display_options['filters']['field_test_date_popup_value']['exposed'] = TRUE;
$handler->display->display_options['filters']['field_test_date_popup_value']['expose']['operator_id'] = 'field_test_date_popup_value_op';
$handler->display->display_options['filters']['field_test_date_popup_value']['expose']['label'] = 'test_date_popup (field_test_date_popup)';
$handler->display->display_options['filters']['field_test_date_popup_value']['expose']['operator'] = 'field_test_date_popup_value_op';
$handler->display->display_options['filters']['field_test_date_popup_value']['expose']['identifier'] = 'field_test_date_popup_value';
$handler->display->display_options['filters']['field_test_date_popup_value']['form_type'] = 'date_popup';
/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'test-date-popup';
$view->save();
}
/**
* Test date popup.
*/
public function testDatePopup() {
// Go to view page.
$this->drupalGet('test-date-popup');
}
}