Projet

Général

Profil

Paste
Télécharger (4,43 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / tests / views_basic.test @ 4003efde

1
<?php
2

    
3
/**
4
 * @file
5
 */
6

    
7
/**
8
 * Basic test class for Views query builder tests.
9
 */
10
/**
11
 *
12
 */
13
class ViewsBasicTest extends ViewsSqlTest {
14
  public static function getInfo() {
15
    return array(
16
      'name' => 'Basic query test',
17
      'description' => 'A basic query test for Views.',
18
      'group' => 'Views',
19
    );
20
  }
21

    
22
  /**
23
   * Tests a trivial result set.
24
   */
25
  public function testSimpleResultSet() {
26
    $view = $this->getBasicView();
27

    
28
    // Execute the view.
29
    $this->executeView($view);
30

    
31
    // Verify the result.
32
    $this->assertEqual(5, count($view->result), t('The number of returned rows match.'));
33
    $this->assertIdenticalResultset($view, $this->dataSet(), array(
34
      'views_test_name' => 'name',
35
      'views_test_age' => 'age',
36
    ));
37
  }
38

    
39
  /**
40
   * Tests filtering of the result set.
41
   */
42
  public function testSimpleFiltering() {
43
    $view = $this->getBasicView();
44

    
45
    // Add a filter.
46
    $view->display['default']->handler->override_option('filters', array(
47
      'age' => array(
48
        'operator' => '<',
49
        'value' => array(
50
          'value' => '28',
51
          'min' => '',
52
          'max' => '',
53
        ),
54
        'group' => '0',
55
        'exposed' => FALSE,
56
        'expose' => array(
57
          'operator' => FALSE,
58
          'label' => '',
59
        ),
60
        'id' => 'age',
61
        'table' => 'views_test',
62
        'field' => 'age',
63
        'relationship' => 'none',
64
      ),
65
    ));
66

    
67
    // Execute the view.
68
    $this->executeView($view);
69

    
70
    // Build the expected result.
71
    $dataset = array(
72
      array(
73
        'id' => 1,
74
        'name' => 'John',
75
        'age' => 25,
76
      ),
77
      array(
78
        'id' => 2,
79
        'name' => 'George',
80
        'age' => 27,
81
      ),
82
      array(
83
        'id' => 4,
84
        'name' => 'Paul',
85
        'age' => 26,
86
      ),
87
    );
88

    
89
    // Verify the result.
90
    $this->assertEqual(3, count($view->result), t('The number of returned rows match.'));
91
    $this->assertIdenticalResultSet($view, $dataset, array(
92
      'views_test_name' => 'name',
93
      'views_test_age' => 'age',
94
    ));
95
  }
96

    
97
  /**
98
   * Tests simple argument.
99
   */
100
  public function testSimpleArgument() {
101
    $view = $this->getBasicView();
102

    
103
    // Add a argument.
104
    $view->display['default']->handler->override_option('arguments', array(
105
      'age' => array(
106
        'default_action' => 'ignore',
107
        'style_plugin' => 'default_summary',
108
        'style_options' => array(),
109
        'wildcard' => 'all',
110
        'wildcard_substitution' => 'All',
111
        'title' => '',
112
        'breadcrumb' => '',
113
        'default_argument_type' => 'fixed',
114
        'default_argument' => '',
115
        'validate_type' => 'none',
116
        'validate_fail' => 'not found',
117
        'break_phrase' => 0,
118
        'not' => 0,
119
        'id' => 'age',
120
        'table' => 'views_test',
121
        'field' => 'age',
122
        'validate_user_argument_type' => 'uid',
123
        'validate_user_roles' => array(
124
          '2' => 0,
125
        ),
126
        'relationship' => 'none',
127
        'default_options_div_prefix' => '',
128
        'default_argument_user' => 0,
129
        'default_argument_fixed' => '',
130
        'default_argument_php' => '',
131
        'validate_argument_node_type' => array(
132
          'page' => 0,
133
          'story' => 0,
134
        ),
135
        'validate_argument_node_access' => 0,
136
        'validate_argument_nid_type' => 'nid',
137
        'validate_argument_vocabulary' => array(),
138
        'validate_argument_type' => 'tid',
139
        'validate_argument_transform' => 0,
140
        'validate_user_restrict_roles' => 0,
141
        'validate_argument_php' => '',
142
      ),
143
    ));
144

    
145
    $saved_view = clone $view;
146

    
147
    // Execute with a view.
148
    $view->set_arguments(array(27));
149
    $this->executeView($view);
150

    
151
    // Build the expected result.
152
    $dataset = array(
153
      array(
154
        'id' => 2,
155
        'name' => 'George',
156
        'age' => 27,
157
      ),
158
    );
159

    
160
    // Verify the result.
161
    $this->assertEqual(1, count($view->result), t('The number of returned rows match.'));
162
    $this->assertIdenticalResultSet($view, $dataset, array(
163
      'views_test_name' => 'name',
164
      'views_test_age' => 'age',
165
    ));
166

    
167
    // Test "show all" if no argument is present.
168
    $view = $saved_view;
169
    $this->executeView($view);
170

    
171
    // Build the expected result.
172
    $dataset = $this->dataSet();
173

    
174
    $this->assertEqual(5, count($view->result), t('The number of returned rows match.'));
175
    $this->assertIdenticalResultSet($view, $dataset, array(
176
      'views_test_name' => 'name',
177
      'views_test_age' => 'age',
178
    ));
179
  }
180

    
181
}