diff --git a/core/modules/comment/src/Plugin/views/field/StatisticsLastCommentName.php b/core/modules/comment/src/Plugin/views/field/StatisticsLastCommentName.php index 1c8c41ab28e5f3394f46814b6794dddf7a44243e..7264ccc5997dd8017ae550087e0eab833da4436a 100644 --- a/core/modules/comment/src/Plugin/views/field/StatisticsLastCommentName.php +++ b/core/modules/comment/src/Plugin/views/field/StatisticsLastCommentName.php @@ -7,6 +7,7 @@ namespace Drupal\comment\Plugin\views\field; +use Drupal\user\Entity\User; use Drupal\views\Plugin\views\field\FieldPluginBase; use Drupal\views\ResultRow; @@ -67,7 +68,7 @@ protected function defineOptions() { */ public function render(ResultRow $values) { if (!empty($this->options['link_to_user'])) { - $account = entity_create('user'); + $account = User::create(); $account->name = $this->getValue($values); $account->uid = $values->{$this->uid}; $username = array( diff --git a/core/modules/file/src/Tests/FileManagedUnitTestBase.php b/core/modules/file/src/Tests/FileManagedUnitTestBase.php index c9f0c6ba1f8f6832e90cad1da7b20739db5c2d42..61e5b25f019cc77dc3f44c6fd79f19a52fa875d9 100644 --- a/core/modules/file/src/Tests/FileManagedUnitTestBase.php +++ b/core/modules/file/src/Tests/FileManagedUnitTestBase.php @@ -9,6 +9,7 @@ use Drupal\file\FileInterface; use Drupal\simpletest\KernelTestBase; +use Drupal\user\Entity\User; /** * Base class for file unit tests that use the file_test module to test uploads and @@ -35,7 +36,7 @@ protected function setUp() { // Make sure that a user with uid 1 exists, self::createFile() relies on // it. - $user = entity_create('user', array('uid' => 1, 'name' => $this->randomMachineName())); + $user = User::create(['uid' => 1, 'name' => $this->randomMachineName()]); $user->enforceIsNew(); $user->save(); \Drupal::currentUser()->setAccount($user); diff --git a/core/modules/hal/src/Tests/EntityTest.php b/core/modules/hal/src/Tests/EntityTest.php index ef0698b16ac45376b458b3482eefc363c72cf8c8..c1572dcd90a8bada9242321470528184dc5c04fa 100644 --- a/core/modules/hal/src/Tests/EntityTest.php +++ b/core/modules/hal/src/Tests/EntityTest.php @@ -9,6 +9,7 @@ use Drupal\comment\Tests\CommentTestTrait; use Drupal\comment\Entity\Comment; +use Drupal\user\Entity\User; /** * Tests that nodes and terms are correctly normalized and denormalized. @@ -46,7 +47,7 @@ public function testNode() { $node_type = entity_create('node_type', array('type' => 'example_type')); $node_type->save(); - $user = entity_create('user', array('name' => $this->randomMachineName())); + $user = User::create(['name' => $this->randomMachineName()]); $user->save(); // Add comment type. @@ -98,7 +99,7 @@ public function testTerm() { $vocabulary = entity_create('taxonomy_vocabulary', array('vid' => 'example_vocabulary')); $vocabulary->save(); - $account = entity_create('user', array('name' => $this->randomMachineName())); + $account = User::create(['name' => $this->randomMachineName()]); $account->save(); // @todo Until https://www.drupal.org/node/2327935 is fixed, if no parent is @@ -142,7 +143,7 @@ public function testComment() { $node_type = entity_create('node_type', array('type' => 'example_type')); $node_type->save(); - $account = entity_create('user', array('name' => $this->randomMachineName())); + $account = User::create(['name' => $this->randomMachineName()]); $account->save(); // Add comment type. diff --git a/core/modules/simpletest/src/BrowserTestBase.php b/core/modules/simpletest/src/BrowserTestBase.php index 4f8c3fae726058e9ae63b068a7c2159cd2ec674f..b5da13c38e5948f9a344881fe73cce37dba8af6c 100644 --- a/core/modules/simpletest/src/BrowserTestBase.php +++ b/core/modules/simpletest/src/BrowserTestBase.php @@ -26,6 +26,7 @@ use Drupal\Core\Test\TestRunnerKernel; use Drupal\Core\Url; use Drupal\user\Entity\Role; +use Drupal\user\Entity\User; use Drupal\user\UserInterface; use Symfony\Component\HttpFoundation\Request; @@ -567,7 +568,7 @@ protected function drupalCreateUser(array $permissions = array(), $name = NULL) $edit['roles'] = array($rid); } - $account = entity_create('user', $edit); + $account = User::create($edit); $account->save(); $this->assertNotNull($account->id(), SafeMarkup::format('User created with name %name and pass %pass', array('%name' => $edit['name'], '%pass' => $edit['pass']))); diff --git a/core/modules/system/src/Tests/Database/SelectComplexTest.php b/core/modules/system/src/Tests/Database/SelectComplexTest.php index 880c6ebcb537715e5cae0ae3ac8da2a869ea7cc8..dce52b11766637e8436b7356c84c1a32b24bb61a 100644 --- a/core/modules/system/src/Tests/Database/SelectComplexTest.php +++ b/core/modules/system/src/Tests/Database/SelectComplexTest.php @@ -9,6 +9,7 @@ use Drupal\Core\Database\Database; use Drupal\Core\Database\RowCountException; +use Drupal\user\Entity\User; /** * Tests the Select query builder with more complex queries. @@ -328,10 +329,10 @@ function testJoinTwice() { function testJoinSubquery() { $this->installSchema('system', 'sequences'); - $account = entity_create('user', array( + $account = User::create([ 'name' => $this->randomMachineName(), 'mail' => $this->randomMachineName() . '@example.com', - )); + ]); $query = db_select('test_task', 'tt', array('target' => 'replica')); $query->addExpression('tt.pid + 1', 'abc'); diff --git a/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php b/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php index 4b04e6b831b6c41f4a8210376e7fdb00cc9d07ab..8c4ec9183b55f979fc0368fef7085a32d8cab73c 100644 --- a/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php +++ b/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php @@ -482,13 +482,13 @@ public function testTaxonomyVocabularyHooks() { * Tests hook invocations for CRUD operations on users. */ public function testUserHooks() { - $account = entity_create('user', array( + $account = User::create([ 'name' => 'Test user', 'mail' => 'test@example.com', 'created' => REQUEST_TIME, 'status' => 1, 'language' => 'en', - )); + ]); $this->assertHookMessageOrder(array( 'entity_crud_hook_test_user_create called', diff --git a/core/modules/system/src/Tests/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php b/core/modules/system/src/Tests/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php index 0cb2fc0a397b9d0b97f2124b1b95cadc9295c6fa..92efca69d6c910a9368a3df5fc970edbf52f7c9d 100644 --- a/core/modules/system/src/Tests/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php +++ b/core/modules/system/src/Tests/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php @@ -235,7 +235,7 @@ public function testUserHandler() { $user_labels = array(); foreach ($user_values as $key => $values) { if (is_array($values)) { - $account = entity_create('user', $values); + $account = User::create($values); $account->save(); } else { diff --git a/core/modules/system/src/Tests/Entity/EntityUnitTestBase.php b/core/modules/system/src/Tests/Entity/EntityUnitTestBase.php index 255765cb23714c0696d9d890625d25b88de7345f..ff9941b05ea4ae9e91d39a5a7e5d556af00f1bdc 100644 --- a/core/modules/system/src/Tests/Entity/EntityUnitTestBase.php +++ b/core/modules/system/src/Tests/Entity/EntityUnitTestBase.php @@ -10,6 +10,7 @@ use Drupal\simpletest\KernelTestBase; use Drupal\Core\Entity\EntityInterface; use Drupal\user\Entity\Role; +use Drupal\user\Entity\User; /** * Defines an abstract test base for entity unit tests. @@ -109,10 +110,10 @@ protected function createUser($values = array(), $permissions = array()) { $values['roles'][] = $role->id(); } - $account = entity_create('user', $values + array( + $account = User::create($values + [ 'name' => $this->randomMachineName(), 'status' => 1, - )); + ]); $account->enforceIsNew(); $account->save(); return $account; diff --git a/core/modules/system/src/Tests/Entity/FieldAccessTest.php b/core/modules/system/src/Tests/Entity/FieldAccessTest.php index 70fc629fb0cff627ec9810b1177b3297724ea849..0e4fe592636e7ec5b1bf10f9d399a348541c9f15 100644 --- a/core/modules/system/src/Tests/Entity/FieldAccessTest.php +++ b/core/modules/system/src/Tests/Entity/FieldAccessTest.php @@ -9,6 +9,7 @@ use Drupal\Core\Access\AccessResult; use Drupal\simpletest\KernelTestBase; +use Drupal\user\Entity\User; /** * Tests Field level access hooks. @@ -64,7 +65,7 @@ function testFieldAccess() { // Create a dummy user account for testing access with. $values = array('name' => 'test'); - $account = entity_create('user', $values); + $account = User::create($values); $this->assertFalse($entity->field_test_text->access('view', $account), 'Access to the field was denied.'); $expected = AccessResult::forbidden()->cacheUntilEntityChanges($entity); diff --git a/core/modules/system/src/Tests/Plugin/ContextPluginTest.php b/core/modules/system/src/Tests/Plugin/ContextPluginTest.php index 05c4c7e0a136448ab181ed1c1c95255fecf1d3be..92be3e5361517eaac02e6f89c695c28ac225201d 100644 --- a/core/modules/system/src/Tests/Plugin/ContextPluginTest.php +++ b/core/modules/system/src/Tests/Plugin/ContextPluginTest.php @@ -12,6 +12,7 @@ use Drupal\node\Entity\NodeType; use Drupal\plugin_test\Plugin\MockBlockManager; use Drupal\simpletest\KernelTestBase; +use Drupal\user\Entity\User; /** * Tests that contexts are properly set and working within plugins. @@ -72,7 +73,7 @@ function testContext() { // Set an appropriate context value and check to make sure its methods work // as expected. - $user = entity_create('user', array('name' => $name)); + $user = User::create(['name' => $name]); $plugin->setContextValue('user', $user); $this->assertEqual($plugin->getContextValue('user')->getUsername(), $user->getUsername()); diff --git a/core/modules/user/src/Tests/UserCacheTagsTest.php b/core/modules/user/src/Tests/UserCacheTagsTest.php index 8bb2a6a14ff3e6c2970211fd02f2ccfd97b770f5..450f7bc2a7de874a36157697240317cf1042968c 100644 --- a/core/modules/user/src/Tests/UserCacheTagsTest.php +++ b/core/modules/user/src/Tests/UserCacheTagsTest.php @@ -9,6 +9,7 @@ use Drupal\system\Tests\Entity\EntityWithUriCacheTagsTestBase; use Drupal\user\Entity\Role; +use Drupal\user\Entity\User; use Drupal\user\RoleInterface; /** @@ -41,10 +42,10 @@ protected function setUp() { */ protected function createEntity() { // Create a "Llama" user. - $user = entity_create('user', array( + $user = User::create([ 'name' => 'Llama', 'status' => TRUE, - )); + ]); $user->save(); return $user; diff --git a/core/modules/user/src/Tests/UserEntityCallbacksTest.php b/core/modules/user/src/Tests/UserEntityCallbacksTest.php index ce7726a20fc0dc438d797e48ff2944b97ef2a347..2a2caafa89bfe0fa7293ad3d5472f2c2c606fb08 100644 --- a/core/modules/user/src/Tests/UserEntityCallbacksTest.php +++ b/core/modules/user/src/Tests/UserEntityCallbacksTest.php @@ -8,6 +8,7 @@ namespace Drupal\user\Tests; use Drupal\simpletest\WebTestBase; +use Drupal\user\Entity\User; /** * Tests specific parts of the user entity like the URI callback and the label @@ -42,7 +43,7 @@ protected function setUp() { parent::setUp(); $this->account = $this->drupalCreateUser(); - $this->anonymous = entity_create('user', array('uid' => 0)); + $this->anonymous = User::create(['uid' => 0]); } /** diff --git a/core/modules/user/src/Tests/UserSaveTest.php b/core/modules/user/src/Tests/UserSaveTest.php index 2a4e7b1d312ed8114f88ec5133d9377167feb5d6..b174341ab2eeaef9ee4736d16f81b42207ee809b 100644 --- a/core/modules/user/src/Tests/UserSaveTest.php +++ b/core/modules/user/src/Tests/UserSaveTest.php @@ -32,13 +32,13 @@ function testUserImport() { $test_name = $this->randomMachineName(); // Create the base user, based on drupalCreateUser(). - $user = entity_create('user', array( + $user = User::create([ 'name' => $test_name, 'uid' => $test_uid, 'mail' => $test_name . '@example.com', 'pass' => user_password(), 'status' => 1, - )); + ]); $user->enforceIsNew(); $user->save(); diff --git a/core/modules/user/src/Tests/UserValidationTest.php b/core/modules/user/src/Tests/UserValidationTest.php index dfa8a2114568d57c0edd584f144e01f9a376af7a..54e0983cce1243cf1bb997bf3fa999fbeeb2a64e 100644 --- a/core/modules/user/src/Tests/UserValidationTest.php +++ b/core/modules/user/src/Tests/UserValidationTest.php @@ -91,10 +91,10 @@ function testValidation() { $this->assertEqual($violations[0]->getMessage(), t('The username %name is too long: it must be %max characters or less.', array('%name' => $name, '%max' => 60))); // Create a second test user to provoke a name collision. - $user2 = entity_create('user', array( + $user2 = User::create([ 'name' => 'existing', 'mail' => 'existing@example.com', - )); + ]); $user2->save(); $user->set('name', 'existing'); $violations = $user->validate(); @@ -165,11 +165,11 @@ function testValidation() { Role::create(array('id' => 'role2'))->save(); // Test cardinality of user roles. - $user = entity_create('user', array( + $user = User::create([ 'name' => 'role_test', 'mail' => 'test@example.com', 'roles' => array('role1', 'role2'), - )); + ]); $violations = $user->validate(); $this->assertEqual(count($violations), 0); diff --git a/core/modules/views/src/Tests/Entity/FieldEntityTest.php b/core/modules/views/src/Tests/Entity/FieldEntityTest.php index c121157f45431606e3f2ce3251fce7cee8147e5b..1044dfffc3cb84008ebdd9d20ef9fff515fdb4d1 100644 --- a/core/modules/views/src/Tests/Entity/FieldEntityTest.php +++ b/core/modules/views/src/Tests/Entity/FieldEntityTest.php @@ -8,6 +8,7 @@ namespace Drupal\views\Tests\Entity; use Drupal\comment\Tests\CommentTestTrait; +use Drupal\user\Entity\User; use Drupal\views\Tests\ViewTestBase; use Drupal\views\Tests\ViewTestData; use Drupal\views\Views; @@ -55,7 +56,7 @@ public function testGetEntity() { // The view is a view of comments, their nodes and their authors, so there // are three layers of entities. - $account = entity_create('user', array('name' => $this->randomMachineName(), 'bundle' => 'user')); + $account = User::create(['name' => $this->randomMachineName(), 'bundle' => 'user']); $account->save(); $node = entity_create('node', array('uid' => $account->id(), 'type' => 'page', 'title' => $this->randomString())); diff --git a/core/modules/views/src/Tests/Plugin/RelationshipJoinTestBase.php b/core/modules/views/src/Tests/Plugin/RelationshipJoinTestBase.php index d57fa27b0e4789aa6a9aa2a442caccea9ba329a0..9954c088e05cbf1fd9df62038c68342f6e595e63 100644 --- a/core/modules/views/src/Tests/Plugin/RelationshipJoinTestBase.php +++ b/core/modules/views/src/Tests/Plugin/RelationshipJoinTestBase.php @@ -7,6 +7,7 @@ namespace Drupal\views\Tests\Plugin; +use Drupal\user\Entity\User; use Drupal\views\Views; /** @@ -38,7 +39,7 @@ protected function setUpFixtures() { parent::setUpFixtures(); // Create a record for uid 1. - $this->rootUser = entity_create('user', array('name' => $this->randomMachineName())); + $this->rootUser = User::create(['name' => $this->randomMachineName()]); $this->rootUser->save(); Views::viewsData()->clear();