From 2c8e80eef025e6bfb464a79b90423c92434bf7fe Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Tue, 2 Apr 2019 09:38:16 +0100
Subject: [PATCH] =?UTF-8?q?Issue=20#3041042=20by=20Krzysztof=20Doma=C5=84s?=
 =?UTF-8?q?ki,=20claudiu.cristea,=20Berdir,=20Lendude,=20phenaproxima:=20C?=
 =?UTF-8?q?onvert=20UserEntityCallbacksTest=20to=20a=20kernel=20test?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

(cherry picked from commit 36cf951852f6baa0a13896784d4008599747d91f)
---
 .../Functional/UserEntityCallbacksTest.php    | 64 -------------------
 .../Kernel/UserEntityLabelCallbackTest.php    | 55 ++++++++++++++++
 2 files changed, 55 insertions(+), 64 deletions(-)
 delete mode 100644 core/modules/user/tests/src/Functional/UserEntityCallbacksTest.php
 create mode 100644 core/modules/user/tests/src/Kernel/UserEntityLabelCallbackTest.php

diff --git a/core/modules/user/tests/src/Functional/UserEntityCallbacksTest.php b/core/modules/user/tests/src/Functional/UserEntityCallbacksTest.php
deleted file mode 100644
index 381ee1402bb5..000000000000
--- a/core/modules/user/tests/src/Functional/UserEntityCallbacksTest.php
+++ /dev/null
@@ -1,64 +0,0 @@
-<?php
-
-namespace Drupal\Tests\user\Functional;
-
-use Drupal\Tests\BrowserTestBase;
-use Drupal\user\Entity\User;
-
-/**
- * Tests specific parts of the user entity like the URI callback and the label
- * callback.
- *
- * @group user
- */
-class UserEntityCallbacksTest extends BrowserTestBase {
-
-  /**
-   * Modules to enable.
-   *
-   * @var array
-   */
-  public static $modules = ['user', 'user_hooks_test'];
-
-  /**
-   * An authenticated user to use for testing.
-   *
-   * @var \Drupal\user\UserInterface
-   */
-  protected $account;
-
-  /**
-   * An anonymous user to use for testing.
-   *
-   * @var \Drupal\user\UserInterface
-   */
-  protected $anonymous;
-
-  protected function setUp() {
-    parent::setUp();
-
-    $this->account = $this->drupalCreateUser();
-    $this->anonymous = User::create(['uid' => 0]);
-  }
-
-  /**
-   * Test label callback.
-   */
-  public function testLabelCallback() {
-    $this->assertEqual($this->account->label(), $this->account->getAccountName(), 'The username should be used as label');
-
-    // Setup a random anonymous name to be sure the name is used.
-    $name = $this->randomMachineName();
-    $this->config('user.settings')->set('anonymous', $name)->save();
-    $this->assertEqual($this->anonymous->label(), $name, 'The variable anonymous should be used for name of uid 0');
-    $this->assertEqual($this->anonymous->getDisplayName(), $name, 'The variable anonymous should be used for display name of uid 0');
-    $this->assertEqual($this->anonymous->getAccountName(), '', 'The raw anonymous user name should be empty string');
-
-    // Set to test the altered username.
-    \Drupal::state()->set('user_hooks_test_user_format_name_alter', TRUE);
-
-    $this->assertEqual($this->account->getDisplayName(), '<em>' . $this->account->id() . '</em>', 'The user display name should be altered.');
-    $this->assertEqual($this->account->getAccountName(), $this->account->name->value, 'The user name should not be altered.');
-  }
-
-}
diff --git a/core/modules/user/tests/src/Kernel/UserEntityLabelCallbackTest.php b/core/modules/user/tests/src/Kernel/UserEntityLabelCallbackTest.php
new file mode 100644
index 000000000000..e815c4c0af28
--- /dev/null
+++ b/core/modules/user/tests/src/Kernel/UserEntityLabelCallbackTest.php
@@ -0,0 +1,55 @@
+<?php
+
+namespace Drupal\Tests\user\Kernel;
+
+use Drupal\KernelTests\KernelTestBase;
+use Drupal\Tests\user\Traits\UserCreationTrait;
+use Drupal\user\Entity\User;
+
+/**
+ * Tests the label callback.
+ *
+ * @group user
+ */
+class UserEntityLabelCallbackTest extends KernelTestBase {
+
+  use UserCreationTrait;
+
+  /**
+   * {@inheritdoc}
+   */
+  protected static $modules = [
+    'system',
+    'user',
+    'user_hooks_test',
+  ];
+
+  /**
+   * Tests label callback.
+   */
+  public function testLabelCallback() {
+    $this->installSchema('system', ['sequences']);
+    $this->installEntitySchema('user');
+
+    $account = $this->createUser();
+    $anonymous = User::create(['uid' => 0]);
+
+    $this->assertEquals($account->getAccountName(), $account->label());
+
+    // Setup a random anonymous name to be sure the name is used.
+    $name = $this->randomMachineName();
+    $this->config('user.settings')->set('anonymous', $name)->save();
+    $this->assertEquals($name, $anonymous->label());
+    $this->assertEquals($name, $anonymous->getDisplayName());
+    $this->assertEmpty($anonymous->getAccountName());
+
+    // Set to test the altered username.
+    \Drupal::state()->set('user_hooks_test_user_format_name_alter', TRUE);
+
+    // The user display name should be altered.
+    $this->assertEquals('<em>' . $account->id() . '</em>', $account->getDisplayName());
+    // The user login name should not be altered.
+    $this->assertEquals($account->name->value, $account->getAccountName());
+  }
+
+}
-- 
GitLab