views_natural_sort_text_field_test.module 4.19 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
<?php
/**
 * @file
 * Testing module for Views Natural Sort Text Field.
 */

/**
 * Implements hook_form().
 */
function views_natural_sort_text_field_test_form($node, $form_state) {
  return node_content_form($node, $form_state);
}

/**
 * Implements hook_node_info().
 */
function views_natural_sort_text_field_test_node_info() {
  return array(
    'vns_text_field_test_content' => array(
      'name' => t('Views Natural Sort Text Field Test Content'),
      'base' => 'node_content',
      'description' => t('Content type used for testing the basic functionality of the Views Natural Sort Text Field module.'),

    ),
  );
}

/**
 * Implements hook_views_api().
 */
function views_natural_sort_text_field_test_views_api() {
  return array(
    'api' => 3.0,
    'path' => drupal_get_path('module', 'views_natural_sort_text_field_test'),
  );
}

/**
 * Implements hook_views_default_views().
 */
function views_natural_sort_text_field_test_views_default_views() {
  $view = new view();
  $view->name = 'views_natural_sort_text_field_test';
  $view->description = '';
  $view->tag = 'default';
  $view->base_table = 'node';
  $view->human_name = 'Views Natural Sort Text Field Test';
  $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['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'] = 'fields';
  /* Field: Content: Test VNS Sort */
  $handler->display->display_options['fields']['field_test_vns_sort']['id'] = 'field_test_vns_sort';
  $handler->display->display_options['fields']['field_test_vns_sort']['table'] = 'field_data_field_test_vns_sort';
  $handler->display->display_options['fields']['field_test_vns_sort']['field'] = 'field_test_vns_sort';
  $handler->display->display_options['fields']['field_test_vns_sort']['label'] = '';
  $handler->display->display_options['fields']['field_test_vns_sort']['element_label_colon'] = FALSE;
  /* Sort criterion: Content: Test VNS Sort (field_test_vns_sort) */
  $handler->display->display_options['sorts']['field_test_vns_sort_value']['id'] = 'field_test_vns_sort_value';
  $handler->display->display_options['sorts']['field_test_vns_sort_value']['table'] = 'field_data_field_test_vns_sort';
  $handler->display->display_options['sorts']['field_test_vns_sort_value']['field'] = 'field_test_vns_sort_value';
  $handler->display->display_options['sorts']['field_test_vns_sort_value']['order'] = 'NASC';
  /* Filter criterion: Content: Type */
  $handler->display->display_options['filters']['type']['id'] = 'type';
  $handler->display->display_options['filters']['type']['table'] = 'node';
  $handler->display->display_options['filters']['type']['field'] = 'type';
  $handler->display->display_options['filters']['type']['value'] = array(
    'vns_text_field_test_content' => 'vns_text_field_test_content',
  );

  $views[$view->name] = $view;
  return $views;
}

/**
 * A convieance function that will create content used for testing.
 */
function views_natural_sort_text_field_test_views_create_test_content() {
  $titles = array(
    '1 apple',
    '2 apples',
    '10 apples',
    '-1 apples',
    '-10 apples',
    '-2 apples',
    '-3.550 apples',
    '-3.5501 apples',
    '3.5501 apples',
    '3.550 apples',
    'A(Z',
    'A[B',
    'A\\C',
    'A Stripped Zebra',
    'Oklahoma',
    'The King And I',
  );
  foreach ($titles as $title) {
    $node = new stdClass();
    $node->type = 'vns_text_field_test_content';
    $node->title = $title;
    $node->field_test_vns_sort[LANGUAGE_NONE][0]['value'] = $title;
    node_object_prepare($node);
    $node = node_submit($node);
    node_save($node);
  }
}