Révision 5d12d676
Ajouté par Assos Assos il y a environ 6 ans
drupal7/sites/all/modules/views/tests/field/views_fieldapi.test | ||
---|---|---|
6 | 6 |
*/ |
7 | 7 |
|
8 | 8 |
/** |
9 |
* @TODO |
|
10 |
* - Test on a generic entity not on a node. |
|
9 |
* @todo Test on a generic entity not on a node. |
|
11 | 10 |
* |
12 | 11 |
* What has to be tested: |
13 |
* - Take sure that every wanted field is added to the according entity type. |
|
14 |
* - Take sure the joins are done correct. |
|
15 |
* - Use basic fields and take sure that the full wanted object is build. |
|
16 |
* - Use relationships between different entity types, for example node and the node author(user). |
|
12 |
* - Take sure that every wanted field is added to the according entity type. |
|
13 |
* - Take sure the joins are done correct. |
|
14 |
* - Use basic fields and take sure that the full wanted object is build. |
|
15 |
* - Use relationships between different entity types, for example node and |
|
16 |
* the node author(user). |
|
17 | 17 |
*/ |
18 | 18 |
|
19 | 19 |
/** |
20 | 20 |
* Provides some helper methods for testing fieldapi integration into views. |
21 | 21 |
*/ |
22 | 22 |
class ViewsFieldApiTestHelper extends ViewsSqlTest { |
23 |
|
|
23 | 24 |
/** |
24 | 25 |
* Stores the field definitions used by the test. |
26 |
* |
|
25 | 27 |
* @var array |
26 | 28 |
*/ |
27 | 29 |
public $fields; |
30 |
|
|
28 | 31 |
/** |
29 | 32 |
* Stores the instances of the fields. They have |
30 | 33 |
* the same keys as the fields. |
34 |
* |
|
31 | 35 |
* @var array |
32 | 36 |
*/ |
33 | 37 |
public $instances; |
34 | 38 |
|
35 |
protected function CreateUser($extra_edit = array()) { |
|
39 |
/** |
|
40 |
* |
|
41 |
*/ |
|
42 |
protected function createUser($extra_edit = array()) { |
|
36 | 43 |
$permissions = array('access comments', 'access content', 'post comments', 'skip comment approval'); |
37 | 44 |
// Create a role with the given permission set. |
38 | 45 |
if (!($rid = $this->drupalCreateRole($permissions))) { |
... | ... | |
92 | 99 |
drupal_static_reset('_views_fetch_data_recursion_protected'); |
93 | 100 |
drupal_static_reset('_views_fetch_data_fully_loaded'); |
94 | 101 |
} |
102 |
|
|
95 | 103 |
} |
96 | 104 |
|
97 | 105 |
/** |
... | ... | |
116 | 124 |
|
117 | 125 |
$langcode = LANGUAGE_NONE; |
118 | 126 |
|
119 |
|
|
120 | 127 |
$field_names = $this->setUpFields(); |
121 | 128 |
|
122 | 129 |
// The first one will be attached to nodes only. |
... | ... | |
152 | 159 |
// Now create some example nodes/users for the view result. |
153 | 160 |
for ($i = 0; $i < 5; $i++) { |
154 | 161 |
$edit = array( |
155 |
// @TODO Write a helper method to create such values.
|
|
162 |
// @todo Write a helper method to create such values.
|
|
156 | 163 |
'field_name_0' => array($langcode => array((array('value' => $this->randomName())))), |
157 | 164 |
'field_name_2' => array($langcode => array((array('value' => $this->randomName())))), |
158 | 165 |
); |
... | ... | |
164 | 171 |
'field_name_1' => array($langcode => array((array('value' => $this->randomName())))), |
165 | 172 |
'field_name_2' => array($langcode => array((array('value' => $this->randomName())))), |
166 | 173 |
); |
167 |
$this->users[] = $this->CreateUser($edit);
|
|
174 |
$this->users[] = $this->createUser($edit);
|
|
168 | 175 |
} |
169 | 176 |
|
170 | 177 |
// Reset views data cache. |
... | ... | |
178 | 185 |
*/ |
179 | 186 |
function testViewsData() { |
180 | 187 |
$data = views_fetch_data(); |
181 |
|
|
188 |
|
|
182 | 189 |
// Check the table and the joins of the first field. |
183 | 190 |
// Attached to node only. |
184 | 191 |
$field = $this->fields[0]; |
... | ... | |
210 | 217 |
); |
211 | 218 |
$this->assertEqual($expected_join, $data[$revision_table]['table']['join']['node_revision']); |
212 | 219 |
|
213 |
|
|
214 | 220 |
// Check the table and the joins of the second field. |
215 | 221 |
// Attached to both node and user. |
216 | 222 |
$field_2 = $this->fields[2]; |
... | ... | |
230 | 236 |
'extra' => array( |
231 | 237 |
array('field' => 'entity_type', 'value' => 'node'), |
232 | 238 |
array('field' => 'deleted', 'value' => 0, 'numeric' => TRUE), |
233 |
) |
|
239 |
),
|
|
234 | 240 |
); |
235 | 241 |
$this->assertEqual($expected_join, $data[$current_table_2]['table']['join']['node']); |
236 | 242 |
$expected_join = array( |
... | ... | |
239 | 245 |
'extra' => array( |
240 | 246 |
array('field' => 'entity_type', 'value' => 'node'), |
241 | 247 |
array('field' => 'deleted', 'value' => 0, 'numeric' => TRUE), |
242 |
) |
|
248 |
),
|
|
243 | 249 |
); |
244 | 250 |
$this->assertEqual($expected_join, $data[$revision_table_2]['table']['join']['node_revision']); |
245 | 251 |
$expected_join = array( |
... | ... | |
248 | 254 |
'extra' => array( |
249 | 255 |
array('field' => 'entity_type', 'value' => 'user'), |
250 | 256 |
array('field' => 'deleted', 'value' => 0, 'numeric' => TRUE), |
251 |
) |
|
257 |
),
|
|
252 | 258 |
); |
253 | 259 |
$this->assertEqual($expected_join, $data[$current_table_2]['table']['join']['users']); |
254 | 260 |
|
255 |
// Check the fields |
|
256 |
// @todo |
|
257 |
|
|
258 |
// Check the arguments |
|
259 |
// @todo |
|
260 |
|
|
261 |
// Check the sort criterias |
|
262 |
// @todo |
|
263 |
|
|
264 |
// Check the relationships |
|
265 |
// @todo |
|
266 |
|
|
261 |
// @todo Check the fields. |
|
262 |
// @todo Check the arguments. |
|
263 |
// @todo Check the sort criterias. |
|
264 |
// @todo Check the relationships. |
|
267 | 265 |
} |
266 |
|
|
268 | 267 |
} |
269 | 268 |
|
270 | 269 |
/** |
271 | 270 |
* Tests the field_field handler. |
272 |
* @TODO
|
|
273 |
* Check a entity-type with bundles
|
|
274 |
* Check a entity-type without bundles
|
|
275 |
* Check locale:disabled, locale:enabled and locale:enabled with another language
|
|
276 |
* Check revisions
|
|
271 |
* |
|
272 |
* @todo Check a entity-type with bundles.
|
|
273 |
* @todo Check a entity-type without bundles.
|
|
274 |
* @todo Check locale:disabled, locale:enabled and locale:enabled with another language.
|
|
275 |
* @todo Check revisions.
|
|
277 | 276 |
*/ |
278 | 277 |
class viewsHandlerFieldFieldTest extends ViewsFieldApiTestHelper { |
279 | 278 |
public $nodes; |
... | ... | |
282 | 281 |
return array( |
283 | 282 |
'name' => 'Fieldapi: Field handler', |
284 | 283 |
'description' => 'Tests the field itself of the fieldapi integration', |
285 |
'group' => 'Views Modules' |
|
284 |
'group' => 'Views Modules',
|
|
286 | 285 |
); |
287 | 286 |
} |
288 | 287 |
|
... | ... | |
353 | 352 |
$this->executeView($view); |
354 | 353 |
|
355 | 354 |
// Take sure that the formatter works as expected. |
356 |
// @TODO: actually there should be a specific formatter.
|
|
355 |
// @todo actually there should be a specific formatter.
|
|
357 | 356 |
for ($i = 0; $i < 2; $i++) { |
358 | 357 |
$rendered_field = $view->style_plugin->get_field($i, $this->fields[0]['field_name']); |
359 | 358 |
$this->assertEqual(strlen($rendered_field), 3); |
... | ... | |
384 | 383 |
|
385 | 384 |
$view->destroy(); |
386 | 385 |
|
387 |
// Test delta limit + offset |
|
386 |
// Test delta limit + offset.
|
|
388 | 387 |
$view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['group_rows'] = TRUE; |
389 | 388 |
$view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['delta_limit'] = 3; |
390 | 389 |
$view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['delta_offset'] = 1; |
... | ... | |
459 | 458 |
} |
460 | 459 |
|
461 | 460 |
protected function getFieldView() { |
462 |
$view = new view; |
|
461 |
$view = new view();
|
|
463 | 462 |
$view->name = 'view_fieldapi'; |
464 | 463 |
$view->description = ''; |
465 | 464 |
$view->tag = 'default'; |
... | ... | |
491 | 490 |
} |
492 | 491 |
|
493 | 492 |
} |
494 |
|
Formats disponibles : Unified diff
Weekly update of contrib modules