1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Definition of viewsHandlerFieldUserNameTest.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Tests the field username handler.
|
10
|
*
|
11
|
* @see views_handler_field_user_name
|
12
|
*/
|
13
|
class viewsHandlerFieldUserNameTest extends ViewsSqlTest {
|
14
|
public static function getInfo() {
|
15
|
return array(
|
16
|
'name' => 'Tests user: name field',
|
17
|
'description' => 'Tests the handler of the user: name field',
|
18
|
'group' => 'Views Modules',
|
19
|
);
|
20
|
}
|
21
|
|
22
|
function testUserName() {
|
23
|
$view = $this->view_user_name();
|
24
|
$view->init_display();
|
25
|
$this->executeView($view);
|
26
|
|
27
|
$view->row_index = 0;
|
28
|
|
29
|
$view->field['name']->options['link_to_user'] = TRUE;
|
30
|
$username = $view->result[0]->users_name = $this->randomName();
|
31
|
$view->result[0]->uid = 1;
|
32
|
$render = $view->field['name']->advanced_render($view->result[0]);
|
33
|
$this->assertTrue(strpos($render, $username) !== FALSE, 'If link to user is checked the username should be part of the output.');
|
34
|
$this->assertTrue(strpos($render, 'user/1') !== FALSE, 'If link to user is checked the link to the user should appear as well.');
|
35
|
|
36
|
$view->field['name']->options['link_to_user'] = FALSE;
|
37
|
$username = $view->result[0]->users_name = $this->randomName();
|
38
|
$view->result[0]->uid = 1;
|
39
|
$render = $view->field['name']->advanced_render($view->result[0]);
|
40
|
$this->assertIdentical($render, $username, 'If the user is not linked the username should be printed out for a normal user.');
|
41
|
|
42
|
$view->result[0]->uid = 0;
|
43
|
$anon_name = variable_get('anonymous', t('Anonymous'));
|
44
|
$view->result[0]->users_name = '';
|
45
|
$render = $view->field['name']->advanced_render($view->result[0]);
|
46
|
$this->assertIdentical($render, $anon_name , 'For user0 it should use the default anonymous name by default.');
|
47
|
|
48
|
$view->field['name']->options['overwrite_anonymous'] = TRUE;
|
49
|
$anon_name = $view->field['name']->options['anonymous_text'] = $this->randomName();
|
50
|
$render = $view->field['name']->advanced_render($view->result[0]);
|
51
|
$this->assertIdentical($render, $anon_name , 'For user0 it should use the configured anonymous text if overwrite_anonymous is checked.');
|
52
|
|
53
|
|
54
|
}
|
55
|
function view_user_name() {
|
56
|
$view = new view;
|
57
|
$view->name = 'test_views_handler_field_user_name';
|
58
|
$view->description = '';
|
59
|
$view->tag = 'default';
|
60
|
$view->base_table = 'users';
|
61
|
$view->human_name = 'test_views_handler_field_user_name';
|
62
|
$view->core = 7;
|
63
|
$view->api_version = '3.0';
|
64
|
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
|
65
|
|
66
|
/* Display: Master */
|
67
|
$handler = $view->new_display('default', 'Master', 'default');
|
68
|
$handler->display->display_options['access']['type'] = 'none';
|
69
|
$handler->display->display_options['cache']['type'] = 'none';
|
70
|
$handler->display->display_options['query']['type'] = 'views_query';
|
71
|
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
|
72
|
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
73
|
$handler->display->display_options['pager']['type'] = 'full';
|
74
|
$handler->display->display_options['style_plugin'] = 'default';
|
75
|
$handler->display->display_options['row_plugin'] = 'fields';
|
76
|
/* Field: User: Name */
|
77
|
$handler->display->display_options['fields']['name']['id'] = 'name';
|
78
|
$handler->display->display_options['fields']['name']['table'] = 'users';
|
79
|
$handler->display->display_options['fields']['name']['field'] = 'name';
|
80
|
$handler->display->display_options['fields']['name']['label'] = '';
|
81
|
$handler->display->display_options['fields']['name']['alter']['alter_text'] = 0;
|
82
|
$handler->display->display_options['fields']['name']['alter']['make_link'] = 0;
|
83
|
$handler->display->display_options['fields']['name']['alter']['absolute'] = 0;
|
84
|
$handler->display->display_options['fields']['name']['alter']['word_boundary'] = 0;
|
85
|
$handler->display->display_options['fields']['name']['alter']['ellipsis'] = 0;
|
86
|
$handler->display->display_options['fields']['name']['alter']['strip_tags'] = 0;
|
87
|
$handler->display->display_options['fields']['name']['alter']['trim'] = 0;
|
88
|
$handler->display->display_options['fields']['name']['alter']['html'] = 0;
|
89
|
$handler->display->display_options['fields']['name']['hide_empty'] = 0;
|
90
|
$handler->display->display_options['fields']['name']['empty_zero'] = 0;
|
91
|
$handler->display->display_options['fields']['name']['link_to_user'] = 1;
|
92
|
$handler->display->display_options['fields']['name']['overwrite_anonymous'] = 0;
|
93
|
|
94
|
return $view;
|
95
|
}
|
96
|
}
|