summaryrefslogtreecommitdiffstats
path: root/tests/modules/views_natural_sort_test/views_natural_sort_test.module
blob: d6786fe3548c42457e4e1e5ff6a62dc4909d716a (plain)
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.
 */

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

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

    ),
  );
}

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

/**
 * Implements hook_views_default_views().
 */
function views_natural_sort_test_views_default_views() {
  $view = new view();
  $view->name = 'views_natural_sort_test';
  $view->description = '';
  $view->tag = 'default';
  $view->base_table = 'node';
  $view->human_name = 'Views Natural Sort 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: 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: Title */
  $handler->display->display_options['sorts']['title']['id'] = 'title';
  $handler->display->display_options['sorts']['title']['table'] = 'node';
  $handler->display->display_options['sorts']['title']['field'] = 'title';
  $handler->display->display_options['sorts']['title']['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(
    'views_natural_sort_test_content' => 'views_natural_sort_test_content',
  );
  $views[$view->name] = $view;
  return $views;
}

/**
 * A convieance function that will create content used for testing.
 */
function views_natural_sort_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 = 'views_natural_sort_test_content';
    $node->title = $title;
    node_object_prepare($node);
    $node = node_submit($node);
    node_save($node);
  }
}