views_module.test
5.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
/**
* @file
* Definition of ViewsModuleTest.
*/
/**
* Tests basic functions from the Views module.
*/
class ViewsModuleTest extends ViewsSqlTest {
public static function getInfo() {
return array(
'name' => 'Tests views.module',
'description' => 'Tests some basic functions of views.module',
'group' => 'Views',
);
}
public function setUp() {
parent::setUp();
drupal_theme_rebuild();
}
public function viewsData() {
$data = parent::viewsData();
$data['views_test_previous'] = array();
$data['views_test_previous']['id']['field']['moved to'] = array('views_test', 'id');
$data['views_test_previous']['id']['filter']['moved to'] = array('views_test', 'id');
$data['views_test']['age_previous']['field']['moved to'] = array('views_test', 'age');
$data['views_test']['age_previous']['sort']['moved to'] = array('views_test', 'age');
$data['views_test_previous']['name_previous']['field']['moved to'] = array('views_test', 'name');
$data['views_test_previous']['name_previous']['argument']['moved to'] = array('views_test', 'name');
return $data;
}
public function test_views_trim_text() {
// Test unicode, @see http://drupal.org/node/513396#comment-2839416
$text = array(
'Tuy nhiên, những hi vọng',
'Giả sử chúng tôi có 3 Apple',
'siêu nhỏ này là bộ xử lý',
'Di động của nhà sản xuất Phần Lan',
'khoảng cách từ đại lí đến',
'của hãng bao gồm ba dòng',
'сд асд асд ас',
'асд асд асд ас'
);
// Just test maxlength without word boundry.
$alter = array(
'max_length' => 10,
);
$expect = array(
'Tuy nhiên,',
'Giả sử chú',
'siêu nhỏ n',
'Di động củ',
'khoảng các',
'của hãng b',
'сд асд асд',
'асд асд ас',
);
foreach ($text as $key => $line) {
$result_text = views_trim_text($alter, $line);
$this->assertEqual($result_text, $expect[$key]);
}
// Test also word_boundary
$alter['word_boundary'] = TRUE;
$expect = array(
'Tuy nhiên',
'Giả sử',
'siêu nhỏ',
'Di động',
'khoảng',
'của hãng',
'сд асд',
'асд асд',
);
foreach ($text as $key => $line) {
$result_text = views_trim_text($alter, $line);
$this->assertEqual($result_text, $expect[$key]);
}
}
/**
* Tests the dynamic includes of templates via module feature.
*/
function testModuleTemplates() {
$views_status = variable_get('views_defaults', array());
$views_status['frontpage'] = FALSE; // false is enabled
variable_set('views_defaults', $views_status);
$existing = array();
$type = array();
$theme = array();
$path = array();
$registry = views_theme($existing, $type, $theme, $path);
$this->assertTrue(isset($registry['views_view__frontpage']));
}
/**
* Tests the views_get_handler method.
*/
function testviews_get_handler() {
$types = array('field', 'area', 'filter');
foreach ($types as $type) {
$handler = views_get_handler($this->randomName(), $this->randomName(), $type);
$this->assertEqual('views_handler_' . $type . '_broken', get_class($handler), t('Make sure that a broken handler of type: @type are created', array('@type' => $type)));
}
$views_data = $this->viewsData();
$test_tables = array('views_test' => array('id', 'name'));
foreach ($test_tables as $table => $fields) {
foreach ($fields as $field) {
$data = $views_data[$table][$field];
foreach ($data as $id => $field_data) {
if (!in_array($id, array('title', 'help'))) {
$handler = views_get_handler($table, $field, $id);
$this->assertInstanceHandler($handler, $table, $field, $id);
}
}
}
}
// Test the automatic conversion feature.
// Test the automatic table renaming.
$handler = views_get_handler('views_test_previous', 'id', 'field');
$this->assertInstanceHandler($handler, 'views_test', 'id', 'field');
$handler = views_get_handler('views_test_previous', 'id', 'filter');
$this->assertInstanceHandler($handler, 'views_test', 'id', 'filter');
// Test the automatic field renaming.
$handler = views_get_handler('views_test', 'age_previous', 'field');
$this->assertInstanceHandler($handler, 'views_test', 'age', 'field');
$handler = views_get_handler('views_test', 'age_previous', 'sort');
$this->assertInstanceHandler($handler, 'views_test', 'age', 'sort');
// Test the automatic table and field renaming.
$handler = views_get_handler('views_test_previous', 'name_previous', 'field');
$this->assertInstanceHandler($handler, 'views_test', 'name', 'field');
$handler = views_get_handler('views_test_previous', 'name_previous', 'argument');
$this->assertInstanceHandler($handler, 'views_test', 'name', 'argument');
// Test the override handler feature.
$handler = views_get_handler('views_test', 'job', 'filter', 'views_handler_filter');
$this->assertEqual('views_handler_filter', get_class($handler));
}
/**
* Ensure that a certain handler is a instance of a certain table/field.
*/
function assertInstanceHandler($handler, $table, $field, $id) {
$table_data = views_fetch_data($table);
$field_data = $table_data[$field][$id];
$this->assertEqual($field_data['handler'], get_class($handler));
}
}