views_handler_field_user_name.test 4.4 KB

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