1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Definition of ViewsUpgradeTestCase.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Try to test the upgrade path of all conversions.
|
10
|
*
|
11
|
* You can find all conversions by searching for "moved to".
|
12
|
*/
|
13
|
class ViewsUpgradeTestCase extends ViewsSqlTest {
|
14
|
|
15
|
/**
|
16
|
*
|
17
|
*/
|
18
|
public static function getInfo() {
|
19
|
return array(
|
20
|
'name' => 'Views Upgrade test',
|
21
|
'description' => 'Try to test the upgrade path of modules which were changed.',
|
22
|
'group' => 'Views',
|
23
|
);
|
24
|
}
|
25
|
|
26
|
/**
|
27
|
* {@inheritdoc}
|
28
|
*/
|
29
|
protected function setUp() {
|
30
|
// To import a view the user needs use PHP for settings rights, so enable
|
31
|
// PHP module.
|
32
|
parent::setUp();
|
33
|
|
34
|
module_enable(array('php'));
|
35
|
$this->resetAll();
|
36
|
}
|
37
|
|
38
|
/**
|
39
|
*
|
40
|
*/
|
41
|
function viewsData() {
|
42
|
$data = parent::viewsData();
|
43
|
$data['views_test']['old_field_1']['moved to'] = array('views_test', 'id');
|
44
|
$data['views_test']['old_field_2']['field']['moved to'] = array('views_test', 'name');
|
45
|
$data['views_test']['old_field_3']['filter']['moved to'] = array('views_test', 'age');
|
46
|
|
47
|
// @todo Test this scenario, too.
|
48
|
$data['views_old_table_2']['old_field']['moved to'] = array('views_test', 'job');
|
49
|
|
50
|
$data['views_old_table']['moved to'] = 'views_test';
|
51
|
|
52
|
return $data;
|
53
|
}
|
54
|
|
55
|
/**
|
56
|
*
|
57
|
*/
|
58
|
function debugField($field) {
|
59
|
$keys = array('id', 'table', 'field', 'actual_field', 'original_field', 'real_field');
|
60
|
$info = array();
|
61
|
foreach ($keys as $key) {
|
62
|
$info[$key] = $field->{$key};
|
63
|
}
|
64
|
debug($info, NULL, TRUE);
|
65
|
}
|
66
|
|
67
|
/**
|
68
|
* Tests the moved to parameter in general.
|
69
|
*/
|
70
|
public function testMovedTo() {
|
71
|
// Test moving on field lavel.
|
72
|
$view = $this->viewsMovedToField();
|
73
|
$view->update();
|
74
|
$view->build();
|
75
|
|
76
|
// $this->assertEqual('old_field_1',
|
77
|
// $view->field['old_field_1']->options['id'],
|
78
|
// "Id shouldn't change during conversion");
|
79
|
// $this->assertEqual('id', $view->field['old_field_1']->field,
|
80
|
// 'The field should change during conversion');
|
81
|
$this->assertEqual('id', $view->field['old_field_1']->real_field);
|
82
|
$this->assertEqual('views_test', $view->field['old_field_1']->table);
|
83
|
$this->assertEqual('old_field_1', $view->field['old_field_1']->original_field, 'The field should have stored the original_field');
|
84
|
|
85
|
// Test moving on handler lavel.
|
86
|
$view = $this->viewsMovedToHandler();
|
87
|
$view->update();
|
88
|
$view->build();
|
89
|
|
90
|
// $this->assertEqual('old_field_2',
|
91
|
// $view->field['old_field_2']->options['id']);
|
92
|
$this->assertEqual('name', $view->field['old_field_2']->real_field);
|
93
|
$this->assertEqual('views_test', $view->field['old_field_2']->table);
|
94
|
|
95
|
// $this->assertEqual('old_field_3',
|
96
|
// $view->filter['old_field_3']->options['id']);
|
97
|
$this->assertEqual('age', $view->filter['old_field_3']->real_field);
|
98
|
$this->assertEqual('views_test', $view->filter['old_field_3']->table);
|
99
|
|
100
|
// Test moving on table level.
|
101
|
$view = $this->viewsMovedToTable();
|
102
|
$view->update();
|
103
|
$view->build();
|
104
|
|
105
|
$this->assertEqual('views_test', $view->base_table, 'Make sure that view->base_table gets automatically converted.');
|
106
|
// $this->assertEqual('id', $view->field['id']->field,
|
107
|
// 'If we move a whole table fields of this table should work, too.');
|
108
|
$this->assertEqual('id', $view->field['id']->real_field, 'To run the query right the real_field has to be set right.');
|
109
|
$this->assertEqual('views_test', $view->field['id']->table);
|
110
|
}
|
111
|
|
112
|
/**
|
113
|
* Tests a import via ui.
|
114
|
*
|
115
|
* To ensure the general functionality, the recent comments view from drupal6
|
116
|
* is used.
|
117
|
*/
|
118
|
public function testUpgradeImport() {
|
119
|
$admin_user = $this->drupalCreateUser(array('administer views', 'administer site configuration', 'use PHP for settings'));
|
120
|
$this->drupalLogin($admin_user);
|
121
|
$edit = array(
|
122
|
'view' => $this->viewUpgradeImport(),
|
123
|
);
|
124
|
$this->drupalPost('admin/structure/views/import', $edit, t('Import'));
|
125
|
|
126
|
$this->assertText('Recent comments');
|
127
|
}
|
128
|
|
129
|
/**
|
130
|
*
|
131
|
*/
|
132
|
public function viewsMovedToField() {
|
133
|
$view = new view();
|
134
|
$view->name = 'test_views_move_to_field';
|
135
|
$view->description = '';
|
136
|
$view->tag = '';
|
137
|
$view->view_php = '';
|
138
|
$view->base_table = 'views_test';
|
139
|
$view->is_cacheable = FALSE;
|
140
|
$view->api_version = 2;
|
141
|
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
|
142
|
|
143
|
/* Display: Master */
|
144
|
$handler = $view->new_display('default', 'Master', 'default');
|
145
|
|
146
|
$handler->display->display_options['fields']['old_field_1']['id'] = 'old_field_1';
|
147
|
$handler->display->display_options['fields']['old_field_1']['table'] = 'views_test';
|
148
|
$handler->display->display_options['fields']['old_field_1']['field'] = 'old_field_1';
|
149
|
|
150
|
return $view;
|
151
|
}
|
152
|
|
153
|
/**
|
154
|
*
|
155
|
*/
|
156
|
public function viewsMovedToHandler() {
|
157
|
$view = new view();
|
158
|
$view->name = 'test_views_move_to_handler';
|
159
|
$view->description = '';
|
160
|
$view->tag = '';
|
161
|
$view->view_php = '';
|
162
|
$view->base_table = 'views_test';
|
163
|
$view->is_cacheable = FALSE;
|
164
|
$view->api_version = 2;
|
165
|
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
|
166
|
|
167
|
/* Display: Master */
|
168
|
$handler = $view->new_display('default', 'Master', 'default');
|
169
|
|
170
|
$handler->display->display_options['fields']['old_field_2']['id'] = 'old_field_2';
|
171
|
$handler->display->display_options['fields']['old_field_2']['table'] = 'views_test';
|
172
|
$handler->display->display_options['fields']['old_field_2']['field'] = 'old_field_2';
|
173
|
|
174
|
$handler->display->display_options['filters']['old_field_3']['id'] = 'old_field_3';
|
175
|
$handler->display->display_options['filters']['old_field_3']['table'] = 'views_test';
|
176
|
$handler->display->display_options['filters']['old_field_3']['field'] = 'old_field_3';
|
177
|
|
178
|
return $view;
|
179
|
}
|
180
|
|
181
|
/**
|
182
|
*
|
183
|
*/
|
184
|
public function viewsMovedToTable() {
|
185
|
$view = new view();
|
186
|
$view->name = 'test_views_move_to_table';
|
187
|
$view->description = '';
|
188
|
$view->tag = '';
|
189
|
$view->view_php = '';
|
190
|
$view->base_table = 'views_old_table';
|
191
|
$view->is_cacheable = FALSE;
|
192
|
$view->api_version = 2;
|
193
|
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
|
194
|
|
195
|
/* Display: Master */
|
196
|
$handler = $view->new_display('default', 'Master', 'default');
|
197
|
|
198
|
$handler->display->display_options['fields']['id']['id'] = 'id';
|
199
|
$handler->display->display_options['fields']['id']['table'] = 'views_old_table';
|
200
|
$handler->display->display_options['fields']['id']['field'] = 'id';
|
201
|
|
202
|
return $view;
|
203
|
}
|
204
|
|
205
|
/**
|
206
|
*
|
207
|
*/
|
208
|
protected function viewUpgradeImport() {
|
209
|
$import = '
|
210
|
$view = new view;
|
211
|
$view->name = "comments_recent";
|
212
|
$view->description = "Contains a block and a page to list recent comments; the block will automatically link to the page, which displays the comment body as well as a link to the node.";
|
213
|
$view->tag = "default";
|
214
|
$view->base_table = "comments";
|
215
|
$view->human_name = "";
|
216
|
$view->core = 0;
|
217
|
$view->api_version = "3.0-alpha1";
|
218
|
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
|
219
|
|
220
|
/* Display: Defaults */
|
221
|
$handler = $view->new_display("default", "Defaults", "default");
|
222
|
$handler->display->display_options["title"] = "Recent comments";
|
223
|
$handler->display->display_options["use_more"] = TRUE;
|
224
|
$handler->display->display_options["access"]["type"] = "none";
|
225
|
$handler->display->display_options["cache"]["type"] = "none";
|
226
|
$handler->display->display_options["query"]["type"] = "views_query";
|
227
|
$handler->display->display_options["exposed_form"]["type"] = "basic";
|
228
|
$handler->display->display_options["pager"]["type"] = "some";
|
229
|
$handler->display->display_options["pager"]["options"]["items_per_page"] = 5;
|
230
|
$handler->display->display_options["style_plugin"] = "list";
|
231
|
$handler->display->display_options["row_plugin"] = "fields";
|
232
|
/* Relationship: Comment: Node */
|
233
|
$handler->display->display_options["relationships"]["nid"]["id"] = "nid";
|
234
|
$handler->display->display_options["relationships"]["nid"]["table"] = "comments";
|
235
|
$handler->display->display_options["relationships"]["nid"]["field"] = "nid";
|
236
|
/* Field: Comment: Title */
|
237
|
$handler->display->display_options["fields"]["subject"]["id"] = "subject";
|
238
|
$handler->display->display_options["fields"]["subject"]["table"] = "comments";
|
239
|
$handler->display->display_options["fields"]["subject"]["field"] = "subject";
|
240
|
$handler->display->display_options["fields"]["subject"]["label"] = "";
|
241
|
$handler->display->display_options["fields"]["subject"]["link_to_comment"] = 1;
|
242
|
/* Field: Comment: Post date */
|
243
|
$handler->display->display_options["fields"]["timestamp"]["id"] = "timestamp";
|
244
|
$handler->display->display_options["fields"]["timestamp"]["table"] = "comments";
|
245
|
$handler->display->display_options["fields"]["timestamp"]["field"] = "timestamp";
|
246
|
$handler->display->display_options["fields"]["timestamp"]["label"] = "";
|
247
|
$handler->display->display_options["fields"]["timestamp"]["date_format"] = "time ago";
|
248
|
/* Sort criterion: Comment: Post date */
|
249
|
$handler->display->display_options["sorts"]["timestamp"]["id"] = "timestamp";
|
250
|
$handler->display->display_options["sorts"]["timestamp"]["table"] = "comments";
|
251
|
$handler->display->display_options["sorts"]["timestamp"]["field"] = "timestamp";
|
252
|
$handler->display->display_options["sorts"]["timestamp"]["order"] = "DESC";
|
253
|
/* Filter: Node: Published or admin */
|
254
|
$handler->display->display_options["filters"]["status_extra"]["id"] = "status_extra";
|
255
|
$handler->display->display_options["filters"]["status_extra"]["table"] = "node";
|
256
|
$handler->display->display_options["filters"]["status_extra"]["field"] = "status_extra";
|
257
|
$handler->display->display_options["filters"]["status_extra"]["relationship"] = "nid";
|
258
|
$handler->display->display_options["filters"]["status_extra"]["group"] = 0;
|
259
|
$handler->display->display_options["filters"]["status_extra"]["expose"]["operator"] = FALSE;
|
260
|
|
261
|
/* Display: Page */
|
262
|
$handler = $view->new_display("page", "Page", "page");
|
263
|
$handler->display->display_options["defaults"]["items_per_page"] = FALSE;
|
264
|
$handler->display->display_options["defaults"]["style_plugin"] = FALSE;
|
265
|
$handler->display->display_options["style_plugin"] = "list";
|
266
|
$handler->display->display_options["defaults"]["style_options"] = FALSE;
|
267
|
$handler->display->display_options["defaults"]["row_plugin"] = FALSE;
|
268
|
$handler->display->display_options["row_plugin"] = "fields";
|
269
|
$handler->display->display_options["row_options"]["inline"] = array(
|
270
|
"title" => "title",
|
271
|
"timestamp" => "timestamp",
|
272
|
);
|
273
|
$handler->display->display_options["row_options"]["separator"] = " ";
|
274
|
$handler->display->display_options["defaults"]["row_options"] = FALSE;
|
275
|
$handler->display->display_options["defaults"]["fields"] = FALSE;
|
276
|
/* Field: Node: Title */
|
277
|
$handler->display->display_options["fields"]["title"]["id"] = "title";
|
278
|
$handler->display->display_options["fields"]["title"]["table"] = "node";
|
279
|
$handler->display->display_options["fields"]["title"]["field"] = "title";
|
280
|
$handler->display->display_options["fields"]["title"]["relationship"] = "nid";
|
281
|
$handler->display->display_options["fields"]["title"]["label"] = "Reply to";
|
282
|
$handler->display->display_options["fields"]["title"]["link_to_node"] = 1;
|
283
|
/* Field: Comment: Post date */
|
284
|
$handler->display->display_options["fields"]["timestamp"]["id"] = "timestamp";
|
285
|
$handler->display->display_options["fields"]["timestamp"]["table"] = "comments";
|
286
|
$handler->display->display_options["fields"]["timestamp"]["field"] = "timestamp";
|
287
|
$handler->display->display_options["fields"]["timestamp"]["label"] = "";
|
288
|
$handler->display->display_options["fields"]["timestamp"]["date_format"] = "time ago";
|
289
|
/* Field: Comment: Title */
|
290
|
$handler->display->display_options["fields"]["subject"]["id"] = "subject";
|
291
|
$handler->display->display_options["fields"]["subject"]["table"] = "comments";
|
292
|
$handler->display->display_options["fields"]["subject"]["field"] = "subject";
|
293
|
$handler->display->display_options["fields"]["subject"]["label"] = "";
|
294
|
$handler->display->display_options["fields"]["subject"]["link_to_comment"] = 1;
|
295
|
/* Field: Comment: Body */
|
296
|
$handler->display->display_options["fields"]["comment"]["id"] = "comment";
|
297
|
$handler->display->display_options["fields"]["comment"]["table"] = "comments";
|
298
|
$handler->display->display_options["fields"]["comment"]["field"] = "comment";
|
299
|
$handler->display->display_options["fields"]["comment"]["label"] = "";
|
300
|
$handler->display->display_options["path"] = "comments/recent";
|
301
|
|
302
|
/* Display: Block */
|
303
|
$handler = $view->new_display("block", "Block", "block");
|
304
|
$handler->display->display_options["block_description"] = "Recent comments view"
|
305
|
;';
|
306
|
|
307
|
return $import;
|
308
|
}
|
309
|
|
310
|
}
|