- <?php
-
- * @file
- * Tests date popup in Views
- */
-
- require_once BACKDROP_ROOT . '/core/modules/date/tests/date_field.test';
-
- class DateViewsTestCase extends DateFieldBasic {
-
-
- * Test setup actions.
- */
- public function setUp($modules = array()) {
- parent::setUp(array('views', 'views_ui', 'views_test'));
-
-
- $field_name = 'field_test_date_popup';
- $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);
-
-
- $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;
-
-
- $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';
-
- $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;
-
- $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';
-
-
- $handler = $view->new_display('page', 'Page', 'page');
- $handler->display->display_options['path'] = 'test-date-popup';
-
- $view->save();
- }
-
-
- * Test date popup.
- */
- public function testDateViews() {
-
- $this->backdropGet('test-date-popup');
-
-
- $this->assertField('field_test_date_popup_value[value][date]');
- $this->assertNoField('field_test_date_popup_value[value][time]');
- }
-
- public function testDateViewsFields() {
-
- $expected_keys = array();
- foreach (array('date', 'datestamp', 'datetime') as $field_type) {
- foreach (array('date_select', 'date_popup', 'date_text') as $widget_type) {
- $field_name = "field_test_{$field_type}_{$widget_type}";
- $label = 'Test ' . $field_type . '-' . $widget_type;
- $options = array(
- 'label' => $label,
- 'widget_type' => $widget_type,
- 'field_name' => $field_name,
- 'field_type' => $field_type,
- 'input_format' => 'm/d/Y - g:ia',
- );
- $this->createDateField($options);
- $expected_keys[] = 'field_data_' . $field_name . '.' . $field_name . '_value';
- $expected_keys[] = 'field_data_' . $field_name . '.' . $field_name . '_value2';
- }
- }
- sort($expected_keys);
-
- $this->clearViewsCaches();
-
- module_load_include('inc', 'views_ui','views_ui.admin');
- $fields = date_views_fields();
-
-
-
-
- $fields_keys = array_keys($fields['name']);
- $our_keys = array_intersect($fields_keys, $expected_keys);
- sort($our_keys);
- $this->assertEqual($our_keys, $expected_keys, 'Call date_views_fields().');
-
-
- foreach (array('date', 'datestamp', 'datetime') as $field_type) {
- foreach (array('date_select', 'date_popup', 'date_text') as $widget_type) {
- $field_name = "field_test_{$field_type}_{$widget_type}";
- $label = 'Test ' . $field_type . '-' . $widget_type;
- $this->deleteDateField($label, $field_name);
- }
- }
- }
-
-
- * Clear all views caches and static caches which are required for the patch.
- */
- function clearViewsCaches() {
-
- backdrop_static_reset('_views_fetch_data_cache');
- backdrop_static_reset('_views_fetch_data_recursion_protected');
- backdrop_static_reset('_views_fetch_data_fully_loaded');
- }
-
-
- * Test the date views pager plugin.
- */
- public function testDateViewsPagerPlugin() {
- $this->backdropCreateNode();
-
- $this->backdropGet('date-views-pager-test');
- $format = config_get('date_views.settings', 'date_views_month_format_with_year');
- $expected_heading = format_date(time(), 'custom', $format);
- $this->assertText($expected_heading, 'Date pager shows the expected heading');
- $this->assertLink('« Prev');
- $this->assertLink('Next »');
-
- $format = 'M Y';
- config_set('date_views.settings', 'date_views_month_format_with_year', $format);
- $this->backdropGet('date-views-pager-test');
- $expected_heading = format_date(time(), 'custom', $format);
- $this->assertText($expected_heading, 'Date pager shows the expected heading after changing the format');
- }
-
- }