HandlerFieldUserNameTest.php 4.51 KB
Newer Older
merlinofchaos's avatar
merlinofchaos committed
1
2
3
4
<?php

/**
 * @file
5
 * Definition of Drupal\views\Tests\User\HandlerFieldUserNameTest.
merlinofchaos's avatar
merlinofchaos committed
6
7
 */

8
9
namespace Drupal\views\Tests\User;

10
use Drupal\views\View;
11
use ViewsSqlTest;
12

merlinofchaos's avatar
merlinofchaos committed
13
14
15
16
17
/**
 * Tests the field username handler.
 *
 * @see views_handler_field_user_name
 */
18
class HandlerFieldUserNameTest extends ViewsSqlTest {
merlinofchaos's avatar
merlinofchaos committed
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
  public static function getInfo() {
    return array(
      'name' => 'Tests user: name field',
      'description' => 'Tests the handler of the user: name field',
      'group' => 'Views Modules',
    );
  }

  function testUserName() {
    $view = $this->view_user_name();
    $view->init_display();
    $this->executeView($view);

    $view->row_index = 0;

    $view->field['name']->options['link_to_user'] = TRUE;
    $username = $view->result[0]->users_name = $this->randomName();
    $view->result[0]->uid = 1;
    $render = $view->field['name']->advanced_render($view->result[0]);
    $this->assertTrue(strpos($render, $username) !== FALSE, 'If link to user is checked the username should be part of the output.');
    $this->assertTrue(strpos($render, 'user/1') !== FALSE, 'If link to user is checked the link to the user should appear as well.');

    $view->field['name']->options['link_to_user'] = FALSE;
    $username = $view->result[0]->users_name = $this->randomName();
    $view->result[0]->uid = 1;
    $render = $view->field['name']->advanced_render($view->result[0]);
    $this->assertIdentical($render, $username, 'If the user is not linked the username should be printed out for a normal user.');

    $view->result[0]->uid = 0;
    $anon_name = variable_get('anonymous', t('Anonymous'));
    $view->result[0]->users_name = '';
    $render = $view->field['name']->advanced_render($view->result[0]);
    $this->assertIdentical($render, $anon_name , 'For user0 it should use the default anonymous name by default.');

    $view->field['name']->options['overwrite_anonymous'] = TRUE;
    $anon_name = $view->field['name']->options['anonymous_text'] = $this->randomName();
    $render = $view->field['name']->advanced_render($view->result[0]);
    $this->assertIdentical($render, $anon_name , 'For user0 it should use the configured anonymous text if overwrite_anonymous is checked.');


  }
  function view_user_name() {
61
    $view = new View();
merlinofchaos's avatar
merlinofchaos committed
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
    $view->name = 'test_views_handler_field_user_name';
    $view->description = '';
    $view->tag = 'default';
    $view->base_table = 'users';
    $view->human_name = 'test_views_handler_field_user_name';
    $view->core = 7;
    $view->api_version = '3.0';
    $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

    /* Display: Master */
    $handler = $view->new_display('default', 'Master', 'default');
    $handler->display->display_options['access']['type'] = 'none';
    $handler->display->display_options['cache']['type'] = 'none';
    $handler->display->display_options['query']['type'] = 'views_query';
    $handler->display->display_options['query']['options']['query_comment'] = FALSE;
    $handler->display->display_options['exposed_form']['type'] = 'basic';
    $handler->display->display_options['pager']['type'] = 'full';
    $handler->display->display_options['style_plugin'] = 'default';
    $handler->display->display_options['row_plugin'] = 'fields';
    /* Field: User: Name */
    $handler->display->display_options['fields']['name']['id'] = 'name';
    $handler->display->display_options['fields']['name']['table'] = 'users';
    $handler->display->display_options['fields']['name']['field'] = 'name';
    $handler->display->display_options['fields']['name']['label'] = '';
    $handler->display->display_options['fields']['name']['alter']['alter_text'] = 0;
    $handler->display->display_options['fields']['name']['alter']['make_link'] = 0;
    $handler->display->display_options['fields']['name']['alter']['absolute'] = 0;
    $handler->display->display_options['fields']['name']['alter']['word_boundary'] = 0;
    $handler->display->display_options['fields']['name']['alter']['ellipsis'] = 0;
    $handler->display->display_options['fields']['name']['alter']['strip_tags'] = 0;
    $handler->display->display_options['fields']['name']['alter']['trim'] = 0;
    $handler->display->display_options['fields']['name']['alter']['html'] = 0;
    $handler->display->display_options['fields']['name']['hide_empty'] = 0;
    $handler->display->display_options['fields']['name']['empty_zero'] = 0;
    $handler->display->display_options['fields']['name']['link_to_user'] = 1;
    $handler->display->display_options['fields']['name']['overwrite_anonymous'] = 0;

    return $view;
  }
}