Projet

Général

Profil

Paste
Télécharger (7,37 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / tests / user / views_handler_field_user_name.test @ 4003efde

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
  /**
56
   * Tests that deselecting 'link_to_user' and 'format_username' works.
57
   */
58
  public function testOptions() {
59
    $view = $this->view_raw_user_name();
60
    $view->init_display();
61
    $this->executeView($view);
62

    
63
    $view->row_index = 0;
64

    
65
    $username = $view->result[0]->users_name = 'test';
66
    $view->result[0]->uid = 1;
67
    $render = $view->field['name']->advanced_render($view->result[0]);
68
    $this->assertTrue(strpos($render, $username) !== FALSE, 'If link to user is checked the username should be part of the output.');
69
  }
70

    
71
  function view_user_name() {
72
    $view = new view();
73
    $view->name = 'test_views_handler_field_user_name';
74
    $view->description = '';
75
    $view->tag = 'default';
76
    $view->base_table = 'users';
77
    $view->human_name = 'test_views_handler_field_user_name';
78
    $view->core = 7;
79
    $view->api_version = '3.0';
80
    $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
81

    
82
    /* Display: Master */
83
    $handler = $view->new_display('default', 'Master', 'default');
84
    $handler->display->display_options['access']['type'] = 'none';
85
    $handler->display->display_options['cache']['type'] = 'none';
86
    $handler->display->display_options['query']['type'] = 'views_query';
87
    $handler->display->display_options['query']['options']['query_comment'] = FALSE;
88
    $handler->display->display_options['exposed_form']['type'] = 'basic';
89
    $handler->display->display_options['pager']['type'] = 'full';
90
    $handler->display->display_options['style_plugin'] = 'default';
91
    $handler->display->display_options['row_plugin'] = 'fields';
92
    /* Field: User: Name */
93
    $handler->display->display_options['fields']['name']['id'] = 'name';
94
    $handler->display->display_options['fields']['name']['table'] = 'users';
95
    $handler->display->display_options['fields']['name']['field'] = 'name';
96
    $handler->display->display_options['fields']['name']['label'] = '';
97
    $handler->display->display_options['fields']['name']['alter']['alter_text'] = 0;
98
    $handler->display->display_options['fields']['name']['alter']['make_link'] = 0;
99
    $handler->display->display_options['fields']['name']['alter']['absolute'] = 0;
100
    $handler->display->display_options['fields']['name']['alter']['word_boundary'] = 0;
101
    $handler->display->display_options['fields']['name']['alter']['ellipsis'] = 0;
102
    $handler->display->display_options['fields']['name']['alter']['strip_tags'] = 0;
103
    $handler->display->display_options['fields']['name']['alter']['trim'] = 0;
104
    $handler->display->display_options['fields']['name']['alter']['html'] = 0;
105
    $handler->display->display_options['fields']['name']['hide_empty'] = 0;
106
    $handler->display->display_options['fields']['name']['empty_zero'] = 0;
107
    $handler->display->display_options['fields']['name']['link_to_user'] = 1;
108
    $handler->display->display_options['fields']['name']['overwrite_anonymous'] = 0;
109

    
110
    return $view;
111
  }
112

    
113
  function view_raw_user_name() {
114
    $view = new view;
115
    $view->name = 'test_views_handler_field_user_name';
116
    $view->description = '';
117
    $view->tag = 'default';
118
    $view->base_table = 'users';
119
    $view->human_name = 'test_views_handler_field_user_name';
120
    $view->core = 7;
121
    $view->api_version = '3.0';
122
    $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
123

    
124
    /* Display: Master */
125
    $handler = $view->new_display('default', 'Master', 'default');
126
    $handler->display->display_options['access']['type'] = 'none';
127
    $handler->display->display_options['cache']['type'] = 'none';
128
    $handler->display->display_options['query']['type'] = 'views_query';
129
    $handler->display->display_options['query']['options']['query_comment'] = FALSE;
130
    $handler->display->display_options['exposed_form']['type'] = 'basic';
131
    $handler->display->display_options['pager']['type'] = 'full';
132
    $handler->display->display_options['style_plugin'] = 'default';
133
    $handler->display->display_options['row_plugin'] = 'fields';
134
    /* Field: User: Name */
135
    $handler->display->display_options['fields']['name']['id'] = 'name';
136
    $handler->display->display_options['fields']['name']['table'] = 'users';
137
    $handler->display->display_options['fields']['name']['field'] = 'name';
138
    $handler->display->display_options['fields']['name']['label'] = '';
139
    $handler->display->display_options['fields']['name']['alter']['alter_text'] = 0;
140
    $handler->display->display_options['fields']['name']['alter']['make_link'] = 0;
141
    $handler->display->display_options['fields']['name']['alter']['absolute'] = 0;
142
    $handler->display->display_options['fields']['name']['alter']['word_boundary'] = 0;
143
    $handler->display->display_options['fields']['name']['alter']['ellipsis'] = 0;
144
    $handler->display->display_options['fields']['name']['alter']['strip_tags'] = 0;
145
    $handler->display->display_options['fields']['name']['alter']['trim'] = 0;
146
    $handler->display->display_options['fields']['name']['alter']['html'] = 0;
147
    $handler->display->display_options['fields']['name']['hide_empty'] = 0;
148
    $handler->display->display_options['fields']['name']['empty_zero'] = 0;
149
    $handler->display->display_options['fields']['name']['link_to_user'] = 0;
150
    $handler->display->display_options['fields']['name']['format_username'] = 0;
151
    $handler->display->display_options['fields']['name']['overwrite_anonymous'] = 0;
152

    
153
    return $view;
154
  }
155
}