Projet

Général

Profil

Paste
Télécharger (3,47 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / tests / handlers / views_handler_argument_string.test @ 5d12d676

1
<?php
2
/**
3
 * @file
4
 * Definition of ViewsHandlerArgumentNullTest.
5
 */
6

    
7
/**
8
 * Tests the core views_handler_argument_string handler.
9
 */
10
class ViewsHandlerArgumentStringTest extends ViewsSqlTest {
11
  public static function getInfo() {
12
    return array(
13
      'name' => 'Argument: String',
14
      'description' => 'Test the core views_handler_argument_string handler.',
15
      'group' => 'Views Handlers',
16
    );
17
  }
18

    
19
  /**
20
   * Tests the glossary feature.
21
   */
22
  function testGlossary() {
23
    // Setup some nodes, one with a, two with b and three with c.
24
    $counter = 1;
25
    foreach (array('a', 'b', 'c') as $char) {
26
      for ($i = 0; $i < $counter; $i++) {
27
        $edit = array(
28
          'title' => $char . $this->randomName(),
29
        );
30
        $this->drupalCreateNode($edit);
31
      }
32
    }
33

    
34
    $view = $this->viewGlossary();
35
    $view->init_display();
36
    $this->executeView($view);
37

    
38
    $count_field = 'nid';
39
    foreach ($view->result as &$row) {
40
      if (strpos($row->node_title, 'a') === 0) {
41
        $this->assertEqual(1, $row->{$count_field});
42
      }
43
      if (strpos($row->node_title, 'b') === 0) {
44
        $this->assertEqual(2, $row->{$count_field});
45
      }
46
      if (strpos($row->node_title, 'c') === 0) {
47
        $this->assertEqual(3, $row->{$count_field});
48
      }
49
    }
50
  }
51

    
52
  /**
53
   * Provide a test view for testGlossary.
54
   *
55
   * @see testGlossary
56
   *
57
   * @return view
58
   */
59
  function viewGlossary() {
60
    $view = new view();
61
    $view->name = 'test_glossary';
62
    $view->description = '';
63
    $view->tag = 'default';
64
    $view->base_table = 'node';
65
    $view->human_name = 'test_glossary';
66
    $view->core = 7;
67
    $view->api_version = '3.0';
68
    $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
69

    
70
    /* Display: Master */
71
    $handler = $view->new_display('default', 'Master', 'default');
72
    $handler->display->display_options['access']['type'] = 'perm';
73
    $handler->display->display_options['cache']['type'] = 'none';
74
    $handler->display->display_options['query']['type'] = 'views_query';
75
    $handler->display->display_options['exposed_form']['type'] = 'basic';
76
    $handler->display->display_options['pager']['type'] = 'full';
77
    $handler->display->display_options['style_plugin'] = 'default';
78
    $handler->display->display_options['row_plugin'] = 'fields';
79
    /* Field: Content: Title */
80
    $handler->display->display_options['fields']['title']['id'] = 'title';
81
    $handler->display->display_options['fields']['title']['table'] = 'node';
82
    $handler->display->display_options['fields']['title']['field'] = 'title';
83
    $handler->display->display_options['fields']['title']['label'] = '';
84
    /* Contextual filter: Content: Title */
85
    $handler->display->display_options['arguments']['title']['id'] = 'title';
86
    $handler->display->display_options['arguments']['title']['table'] = 'node';
87
    $handler->display->display_options['arguments']['title']['field'] = 'title';
88
    $handler->display->display_options['arguments']['title']['default_argument_type'] = 'fixed';
89
    $handler->display->display_options['arguments']['title']['summary']['number_of_records'] = '0';
90
    $handler->display->display_options['arguments']['title']['summary']['format'] = 'default_summary';
91
    $handler->display->display_options['arguments']['title']['summary_options']['items_per_page'] = '25';
92
    $handler->display->display_options['arguments']['title']['glossary'] = TRUE;
93
    $handler->display->display_options['arguments']['title']['limit'] = '1';
94

    
95
    return $view;
96
  }
97

    
98
}