Commit 854649c9 authored by catch's avatar catch

Issue #2641624 by heykarthikwithu, Mac_Weber, kostyashupenko: Replace...

Issue #2641624 by heykarthikwithu, Mac_Weber, kostyashupenko: Replace deprecated usage of  entity_create('user') with a direct call to User::create()
parent f1d74855
......@@ -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(
......
......@@ -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);
......
......@@ -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.
......
......@@ -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'])));
......
......@@ -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');
......
......@@ -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',
......
......@@ -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 {
......
......@@ -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;
......
......@@ -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);
......
......@@ -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());
......
......@@ -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;
......
......@@ -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]);
}
/**
......
......@@ -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();
......
......@@ -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);
......
......@@ -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()));
......
......@@ -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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment