Projet

Général

Profil

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

root / htmltest / sites / all / modules / views / tests / views_module.test @ 4543c6c7

1
<?php
2

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

    
8
/**
9
 * Tests basic functions from the Views module.
10
 */
11
class ViewsModuleTest extends ViewsSqlTest {
12
  public static function getInfo() {
13
    return array(
14
      'name' => 'Tests views.module',
15
      'description' => 'Tests some basic functions of views.module',
16
      'group' => 'Views',
17
    );
18
  }
19

    
20
  public function setUp() {
21
    parent::setUp();
22
    drupal_theme_rebuild();
23
  }
24

    
25
  public function viewsData() {
26
    $data = parent::viewsData();
27
    $data['views_test_previous'] = array();
28
    $data['views_test_previous']['id']['field']['moved to'] = array('views_test', 'id');
29
    $data['views_test_previous']['id']['filter']['moved to'] = array('views_test', 'id');
30
    $data['views_test']['age_previous']['field']['moved to'] = array('views_test', 'age');
31
    $data['views_test']['age_previous']['sort']['moved to'] = array('views_test', 'age');
32
    $data['views_test_previous']['name_previous']['field']['moved to'] = array('views_test', 'name');
33
    $data['views_test_previous']['name_previous']['argument']['moved to'] = array('views_test', 'name');
34

    
35
    return $data;
36
  }
37

    
38
  public function test_views_trim_text() {
39
    // Test unicode, @see http://drupal.org/node/513396#comment-2839416
40
    $text = array(
41
      'Tuy nhiên, những hi vọng',
42
      'Giả sử chúng tôi có 3 Apple',
43
      'siêu nhỏ này là bộ xử lý',
44
      'Di động của nhà sản xuất Phần Lan',
45
      'khoảng cách từ đại lí đến',
46
      'của hãng bao gồm ba dòng',
47
      'сд асд асд ас',
48
      'асд асд асд ас'
49
    );
50
    // Just test maxlength without word boundry.
51
    $alter = array(
52
      'max_length' => 10,
53
    );
54
    $expect = array(
55
      'Tuy nhiên,',
56
      'Giả sử chú',
57
      'siêu nhỏ n',
58
      'Di động củ',
59
      'khoảng các',
60
      'của hãng b',
61
      'сд асд асд',
62
      'асд асд ас',
63
    );
64

    
65
    foreach ($text as $key => $line) {
66
      $result_text = views_trim_text($alter, $line);
67
      $this->assertEqual($result_text, $expect[$key]);
68
    }
69

    
70
    // Test also word_boundary
71
    $alter['word_boundary'] = TRUE;
72
    $expect = array(
73
      'Tuy nhiên',
74
      'Giả sử',
75
      'siêu nhỏ',
76
      'Di động',
77
      'khoảng',
78
      'của hãng',
79
      'сд асд',
80
      'асд асд',
81
    );
82

    
83
    foreach ($text as $key => $line) {
84
      $result_text = views_trim_text($alter, $line);
85
      $this->assertEqual($result_text, $expect[$key]);
86
    }
87
  }
88

    
89
  /**
90
   * Tests the dynamic includes of templates via module feature.
91
   */
92
  function testModuleTemplates() {
93
    $views_status = variable_get('views_defaults', array());
94
    $views_status['frontpage'] = FALSE; // false is enabled
95
    variable_set('views_defaults', $views_status);
96

    
97
    $existing = array();
98
    $type = array();
99
    $theme = array();
100
    $path = array();
101
    $registry = views_theme($existing, $type, $theme, $path);
102
    $this->assertTrue(isset($registry['views_view__frontpage']));
103
  }
104

    
105
  /**
106
   * Tests the views_get_handler method.
107
   */
108
  function testviews_get_handler() {
109
    $types = array('field', 'area', 'filter');
110
    foreach ($types as $type) {
111
      $handler = views_get_handler($this->randomName(), $this->randomName(), $type);
112
      $this->assertEqual('views_handler_' . $type . '_broken', get_class($handler), t('Make sure that a broken handler of type: @type are created', array('@type' => $type)));
113
    }
114

    
115
    $views_data = $this->viewsData();
116
    $test_tables = array('views_test' => array('id', 'name'));
117
    foreach ($test_tables as $table => $fields) {
118
      foreach ($fields as $field) {
119
        $data = $views_data[$table][$field];
120
        foreach ($data as $id => $field_data) {
121
          if (!in_array($id, array('title', 'help'))) {
122
            $handler = views_get_handler($table, $field, $id);
123
            $this->assertInstanceHandler($handler, $table, $field, $id);
124
          }
125
        }
126
      }
127
    }
128

    
129
    // Test the automatic conversion feature.
130

    
131
    // Test the automatic table renaming.
132
    $handler = views_get_handler('views_test_previous', 'id', 'field');
133
    $this->assertInstanceHandler($handler, 'views_test', 'id', 'field');
134
    $handler = views_get_handler('views_test_previous', 'id', 'filter');
135
    $this->assertInstanceHandler($handler, 'views_test', 'id', 'filter');
136

    
137
    // Test the automatic field renaming.
138
    $handler = views_get_handler('views_test', 'age_previous', 'field');
139
    $this->assertInstanceHandler($handler, 'views_test', 'age', 'field');
140
    $handler = views_get_handler('views_test', 'age_previous', 'sort');
141
    $this->assertInstanceHandler($handler, 'views_test', 'age', 'sort');
142

    
143
    // Test the automatic table and field renaming.
144
    $handler = views_get_handler('views_test_previous', 'name_previous', 'field');
145
    $this->assertInstanceHandler($handler, 'views_test', 'name', 'field');
146
    $handler = views_get_handler('views_test_previous', 'name_previous', 'argument');
147
    $this->assertInstanceHandler($handler, 'views_test', 'name', 'argument');
148

    
149
    // Test the override handler feature.
150
    $handler = views_get_handler('views_test', 'job', 'filter', 'views_handler_filter');
151
    $this->assertEqual('views_handler_filter', get_class($handler));
152
  }
153

    
154
  /**
155
   * Ensure that a certain handler is a instance of a certain table/field.
156
   */
157
  function assertInstanceHandler($handler, $table, $field, $id) {
158
    $table_data = views_fetch_data($table);
159
    $field_data = $table_data[$field][$id];
160

    
161
    $this->assertEqual($field_data['handler'], get_class($handler));
162
  }
163
}