Issue #1479454 by Hugo Wetterberg, galooph, dawehner, andypost, marcingy, heyrocker...
[project/drupal.git] / core / modules / user / lib / Drupal / user / Tests / Views / HandlerFieldRoleTest.php
1 <?php
2
3 /**
4 * @file
5 * Contains Drupal\user\Tests\Views\HandlerFieldRoleTest.
6 */
7
8 namespace Drupal\user\Tests\Views;
9
10 /**
11 * Tests the role field handler.
12 *
13 * @see views_handler_field_user_name
14 */
15 class HandlerFieldRoleTest extends UserTestBase {
16
17 /**
18 * Views used by this test.
19 *
20 * @var array
21 */
22 public static $testViews = array('test_views_handler_field_role');
23
24 public static function getInfo() {
25 return array(
26 'name' => 'User: Role Field',
27 'description' => 'Tests the handler of the user: role field.',
28 'group' => 'Views Modules',
29 );
30 }
31
32 public function testRole() {
33 // Create a couple of roles for the view.
34 $rolename_a = 'a' . $this->randomName(8);
35 $rid_a = $this->drupalCreateRole(array('access content'), $rolename_a, $rolename_a, 9);
36
37 $rolename_b = 'b' . $this->randomName(8);
38 $rid_b = $this->drupalCreateRole(array('access content'), $rolename_b, $rolename_b, 8);
39
40 $rolename_not_assigned = $this->randomName(8);
41 $this->drupalCreateRole(array('access content'), $rolename_not_assigned, $rolename_not_assigned);
42
43 // Add roles to user 1.
44 $user = user_load(1);
45 $user->roles[$rid_a] = $rolename_a;
46 $user->roles[$rid_b] = $rolename_b;
47 $user->save();
48
49 $view = views_get_view('test_views_handler_field_role');
50 $this->executeView($view);
51 $view->row_index = 0;
52 // The role field is populated during pre_render.
53 $view->field['rid']->pre_render($view->result);
54 $render = $view->field['rid']->advanced_render($view->result[0]);
55
56 $this->assertEqual($rolename_b . $rolename_a, $render, 'View test_views_handler_field_role renders role assigned to user in the correct order.');
57 $this->assertFalse(strpos($render, $rolename_not_assigned), 'View test_views_handler_field_role does not render a role not assigned to a user.');
58 }
59
60 }