Projet

Général

Profil

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

root / drupal7 / sites / all / modules / views / tests / views_basic.test @ 7547bb19

1
<?php
2

    
3
/**
4
 * @file
5
 * Definition of ViewsBasicTest.
6
 */
7

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

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

    
26
    // Execute the view.
27
    $this->executeView($view);
28

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

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

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

    
65
    // Execute the view.
66
    $this->executeView($view);
67

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

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

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

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

    
143
    $saved_view = clone $view;
144

    
145
    // Execute with a view
146
    $view->set_arguments(array(27));
147
    $this->executeView($view);
148

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

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

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

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

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