Projet

Général

Profil

Révision 5d12d676

Ajouté par Assos Assos il y a environ 6 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/views/tests/views_groupby.test
2 2

  
3 3
/**
4 4
 * @file
5
 * Tests aggregate functionality of Views.
5
 * Definitions of ViewsQueryGroupByTest and ViewsUiGroupbyTestCase.
6 6
 */
7 7

  
8 8
/**
9 9
 * Tests aggregate functionality of views, for example count.
10 10
 */
11 11
class ViewsQueryGroupByTest extends ViewsSqlTest {
12

  
13
  /**
14
   * Test meta data.
15
   */
12 16
  public static function getInfo() {
13 17
    return array(
14 18
      'name' => 'Groupby',
15 19
      'description' => 'Tests aggregate functionality of views, for example count.',
16 20
      'group' => 'Views',
17 21
    );
22
  }
23

  
24
  // tests ambiguous group by column error (postgresql)
25
  public function testAggregateAmbiguity() {
26
    // Create 4 nodes of type1
27
    $type1 = $this->drupalCreateContentType();
28

  
29
    $node_1 = array(
30
      'type' => $type1->type,
31
    );
32
    $this->drupalCreateNode($node_1);
33
    $this->drupalCreateNode($node_1);
34
    $this->drupalCreateNode($node_1);
35
    $this->drupalCreateNode($node_1);
36

  
37
    $view = $this->viewsAggregateAmbiguityView();
38
    $output = $view->execute_display();
18 39

  
40
    $this->assertEqual(count($view->result), 1, 'Make sure there are no ambiguity problems with the group by operation.');
41
  }
42

  
43
  public function viewsAggregateAmbiguityView() {
44
    $view = new view();
45
    $view->name = 'aggregate_ambiguity';
46
    $view->description = '';
47
    $view->tag = 'default';
48
    $view->base_table = 'node';
49
    $view->human_name = '';
50
    $view->core = 7;
51
    $view->api_version = '3.0';
52
    $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
53

  
54
    /* Display: Master */
55
    $handler = $view->new_display('default', 'Master', 'default');
56
    $handler->display->display_options['use_more_always'] = FALSE;
57
    $handler->display->display_options['group_by'] = TRUE;
58
    $handler->display->display_options['access']['type'] = 'none';
59
    $handler->display->display_options['cache']['type'] = 'none';
60
    $handler->display->display_options['query']['type'] = 'views_query';
61
    $handler->display->display_options['exposed_form']['type'] = 'basic';
62
    $handler->display->display_options['pager']['type'] = 'full';
63
    $handler->display->display_options['style_plugin'] = 'default';
64
    $handler->display->display_options['row_plugin'] = 'fields';
65
    /* Field: COUNT(Content revision: Nid) */
66
    $handler->display->display_options['fields']['nid']['id'] = 'nid';
67
    $handler->display->display_options['fields']['nid']['table'] = 'node_revision';
68
    $handler->display->display_options['fields']['nid']['field'] = 'nid';
69
    $handler->display->display_options['fields']['nid']['group_type'] = 'count';
70
    $handler->display->display_options['fields']['nid']['alter']['alter_text'] = 0;
71
    $handler->display->display_options['fields']['nid']['alter']['make_link'] = 0;
72
    $handler->display->display_options['fields']['nid']['alter']['word_boundary'] = 1;
73
    $handler->display->display_options['fields']['nid']['alter']['ellipsis'] = 1;
74
    $handler->display->display_options['fields']['nid']['alter']['strip_tags'] = 0;
75
    $handler->display->display_options['fields']['nid']['alter']['trim'] = 0;
76
    $handler->display->display_options['fields']['nid']['alter']['html'] = 0;
77
    $handler->display->display_options['fields']['nid']['hide_empty'] = 0;
78
    $handler->display->display_options['fields']['nid']['empty_zero'] = 0;
79
    /* Field: Content: Nid */
80
    $handler->display->display_options['fields']['nid_1']['id'] = 'nid_1';
81
    $handler->display->display_options['fields']['nid_1']['table'] = 'node';
82
    $handler->display->display_options['fields']['nid_1']['field'] = 'nid';
83
    $handler->display->display_options['fields']['nid_1']['alter']['alter_text'] = 0;
84
    $handler->display->display_options['fields']['nid_1']['alter']['make_link'] = 0;
85
    $handler->display->display_options['fields']['nid_1']['alter']['word_boundary'] = 1;
86
    $handler->display->display_options['fields']['nid_1']['alter']['ellipsis'] = 1;
87
    $handler->display->display_options['fields']['nid_1']['alter']['strip_tags'] = 0;
88
    $handler->display->display_options['fields']['nid_1']['alter']['trim'] = 0;
89
    $handler->display->display_options['fields']['nid_1']['alter']['html'] = 0;
90
    $handler->display->display_options['fields']['nid_1']['hide_empty'] = 0;
91
    $handler->display->display_options['fields']['nid_1']['empty_zero'] = 0;
92
    /* Contextual filter: Content: Type */
93
    $handler->display->display_options['arguments']['type']['id'] = 'type';
94
    $handler->display->display_options['arguments']['type']['table'] = 'node';
95
    $handler->display->display_options['arguments']['type']['field'] = 'type';
96
    $handler->display->display_options['arguments']['type']['default_action'] = 'summary';
97
    $handler->display->display_options['arguments']['type']['default_argument_type'] = 'fixed';
98
    $handler->display->display_options['arguments']['type']['summary']['format'] = 'default_summary';
99

  
100

  
101
    return $view;
19 102
  }
20 103

  
21 104
  /**
......
48 131

  
49 132
    $types = array();
50 133
    foreach ($view->result as $item) {
51
      // num_records is a alias for nid.
134
      // 'num_records' is a alias for nid.
52 135
      $types[$item->node_type] = $item->num_records;
53 136
    }
54 137

  
......
56 139
    $this->assertEqual($types[$type2->type], 3);
57 140
  }
58 141

  
59
  //public function testAggregateSum() {
60
  //}
142
  /**
143
   *
144
   */
145
  // public function testAggregateSum() {
146
  // }
61 147

  
148
  /**
149
   *
150
   */
62 151
  public function viewsAggregateCountView() {
63 152
    $view = new view;
64 153
    $view->name = 'aggregate_count';
......
103 192
    $handler->display->display_options['arguments']['type']['default_argument_type'] = 'fixed';
104 193
    $handler->display->display_options['arguments']['type']['summary']['format'] = 'default_summary';
105 194

  
106

  
107 195
    return $view;
108 196
  }
109 197

  
......
144 232
    // There's no need for a function in order to have aggregation.
145 233
    if (empty($group_by)) {
146 234
      $types = array($type1->type, $type2->type);
147
      $results = array_map(function ($item) { return $item->node_type; }, $view->result);
235
      $results = array_map(function ($item) {
236
        return $item->node_type;
237
      }, $view->result);
148 238
      sort($types);
149 239
      sort($results);
150 240
      $this->assertIdentical($results, $types);
......
160 250
    $this->assertEqual($results[$type2->type], $values[1]);
161 251
  }
162 252

  
253
  /**
254
   *
255
   */
163 256
  function viewsGroupByViewHelper($group_by = NULL) {
164 257
    $view = new view;
165 258
    $view->name = 'group_by_count';
......
219 312
    return $view;
220 313
  }
221 314

  
315
  /**
316
   *
317
   */
222 318
  public function testGroupByCount() {
223 319
    $this->GroupByTestHelper('count', array(4, 3));
224 320
  }
225 321

  
226
  function testGroupBySum() {
322
  /**
323
   *
324
   */
325
  public function testGroupBySum() {
227 326
    $this->GroupByTestHelper('sum', array(10, 18));
228 327
  }
229 328

  
230

  
231
  function testGroupByAverage() {
329
  /**
330
   *
331
   */
332
  public function testGroupByAverage() {
232 333
    $this->GroupByTestHelper('avg', array(2.5, 6));
233 334
  }
234 335

  
235
  function testGroupByMin() {
336
  /**
337
   *
338
   */
339
  public function testGroupByMin() {
236 340
    $this->GroupByTestHelper('min', array(1, 5));
237 341
  }
238 342

  
239
  function testGroupByMax() {
343
  /**
344
   * {@inheritdoc}
345
   */
346
  public function testGroupByMax() {
240 347
    $this->GroupByTestHelper('max', array(4, 7));
241 348
  }
242 349

  
243
  function testGroupByNone() {
350
  /**
351
   *
352
   */
353
  public function testGroupByNone() {
244 354
    $this->GroupByTestHelper();
245 355
  }
246 356

  
357
  /**
358
   *
359
   */
247 360
  public function testGroupByCountOnlyFilters() {
248 361
    // Check if GROUP BY and HAVING are included when a view
249 362
    // Doesn't display SUM, COUNT, MAX... functions in SELECT statment
......
264 377
    $this->assertTrue(strpos($view->build_info['query'], 'HAVING'), t('Make sure that HAVING is in the query'));
265 378
  }
266 379

  
380
  /**
381
   *
382
   */
267 383
  function viewsGroupByCountViewOnlyFilters() {
268 384
    $view = new view;
269 385
    $view->name = 'group_by_in_filters';
......
308 424

  
309 425
    return $view;
310 426
  }
427

  
311 428
}
312 429

  
313 430
/**
314
 * Tests UI of aggregate functionality..
431
 * Tests UI of aggregate functionality.
315 432
 */
316
class viewsUiGroupbyTestCase extends DrupalWebTestCase {
433
class ViewsUiGroupbyTestCase extends DrupalWebTestCase {
434

  
435
  /**
436
   * {@inheritdoc}
437
   */
317 438
  function setUp() {
318 439
    // Enable views_ui.
319 440
    parent::setUp('views_ui', 'views_test');
......
323 444
    $this->drupalLogin($views_admin);
324 445
  }
325 446

  
447
  /**
448
   * Test meta data.
449
   */
326 450
  public static function getInfo() {
327 451
    return array(
328 452
      'name' => 'Groupby UI',
......
349 473

  
350 474
    $this->drupalGet('admin/structure/views/nojs/display/test_views_groupby_save/default/group_by');
351 475
  }
476

  
352 477
}

Formats disponibles : Unified diff