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