Unverified Commit 31d7616a authored by Lauri Timmanee's avatar Lauri Timmanee
Browse files

Issue #2890726 by pooja saraah, poornachandran, quietone, alexpott,...

Issue #2890726 by pooja saraah, poornachandran, quietone, alexpott, DanielVeza, borisson_, rdworianyn, smustgrave: Custom role with all numeric name results in fatal error after assigning to user

(cherry picked from commit c72e216d)
(cherry picked from commit d8dc23fa)
parent 152c4236
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -85,7 +85,7 @@ public function preRender(&$values) {
        $sorted_keys = array_intersect_key($ordered_roles, $user_roles);
        // Merge with the unsorted array of role information which has the
        // effect of sorting it.
        $user_roles = array_merge($sorted_keys, $user_roles);
        $user_roles = array_replace($sorted_keys, $user_roles);
      }
    }
  }
+41 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\user\Kernel\Views;

use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\user\Entity\Role;
use Drupal\user\Entity\User;
use Drupal\views\Views;

/**
 * Tests rendering when the role is numeric.
 *
 * @group user
 */
class UserRoleTest extends ViewsKernelTestBase {

  /**
   * Tests numeric role.
   */
  public function testNumericRole() {
    $this->installEntitySchema('user');
    $this->installSchema('user', ['users_data']);

    Role::create(['id' => 123, 'label' => 'Numeric'])
      ->save();

    $user = User::create([
      'uid' => 2,
      'name' => 'foo',
      'roles' => 123,
    ]);
    $user->save();

    $view = Views::getView('user_admin_people');
    $this->executeView($view);
    $view->render('user_admin_people');
    $output = $view->field['roles_target_id']->render($view->result[0]);
    $this->assertEquals(2, $output);
  }

}