Projet

Général

Profil

Paste
Télécharger (4,42 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / tests / user / views_handler_field_user_name.test @ 5d12d676

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
  function view_user_name() {
55
    $view = new view();
56
    $view->name = 'test_views_handler_field_user_name';
57
    $view->description = '';
58
    $view->tag = 'default';
59
    $view->base_table = 'users';
60
    $view->human_name = 'test_views_handler_field_user_name';
61
    $view->core = 7;
62
    $view->api_version = '3.0';
63
    $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
64

    
65
    /* Display: Master */
66
    $handler = $view->new_display('default', 'Master', 'default');
67
    $handler->display->display_options['access']['type'] = 'none';
68
    $handler->display->display_options['cache']['type'] = 'none';
69
    $handler->display->display_options['query']['type'] = 'views_query';
70
    $handler->display->display_options['query']['options']['query_comment'] = FALSE;
71
    $handler->display->display_options['exposed_form']['type'] = 'basic';
72
    $handler->display->display_options['pager']['type'] = 'full';
73
    $handler->display->display_options['style_plugin'] = 'default';
74
    $handler->display->display_options['row_plugin'] = 'fields';
75
    /* Field: User: Name */
76
    $handler->display->display_options['fields']['name']['id'] = 'name';
77
    $handler->display->display_options['fields']['name']['table'] = 'users';
78
    $handler->display->display_options['fields']['name']['field'] = 'name';
79
    $handler->display->display_options['fields']['name']['label'] = '';
80
    $handler->display->display_options['fields']['name']['alter']['alter_text'] = 0;
81
    $handler->display->display_options['fields']['name']['alter']['make_link'] = 0;
82
    $handler->display->display_options['fields']['name']['alter']['absolute'] = 0;
83
    $handler->display->display_options['fields']['name']['alter']['word_boundary'] = 0;
84
    $handler->display->display_options['fields']['name']['alter']['ellipsis'] = 0;
85
    $handler->display->display_options['fields']['name']['alter']['strip_tags'] = 0;
86
    $handler->display->display_options['fields']['name']['alter']['trim'] = 0;
87
    $handler->display->display_options['fields']['name']['alter']['html'] = 0;
88
    $handler->display->display_options['fields']['name']['hide_empty'] = 0;
89
    $handler->display->display_options['fields']['name']['empty_zero'] = 0;
90
    $handler->display->display_options['fields']['name']['link_to_user'] = 1;
91
    $handler->display->display_options['fields']['name']['overwrite_anonymous'] = 0;
92

    
93
    return $view;
94
  }
95

    
96
}