summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2016-02-16 07:54:49 (GMT)
committerNathaniel Catchpole2016-02-16 07:54:49 (GMT)
commit854649c9238aa79ad17d294e3f2864ce11bc4f83 (patch)
treec54cdb0a23879ce709793d92000c03d7af749e17
parentf1d748553cd8d351846664a23c4fd1fddb81f060 (diff)
Issue #2641624 by heykarthikwithu, Mac_Weber, kostyashupenko: Replace deprecated usage of entity_create('user') with a direct call to User::create()
-rw-r--r--core/modules/comment/src/Plugin/views/field/StatisticsLastCommentName.php3
-rw-r--r--core/modules/file/src/Tests/FileManagedUnitTestBase.php3
-rw-r--r--core/modules/hal/src/Tests/EntityTest.php7
-rw-r--r--core/modules/simpletest/src/BrowserTestBase.php3
-rw-r--r--core/modules/system/src/Tests/Database/SelectComplexTest.php5
-rw-r--r--core/modules/system/src/Tests/Entity/EntityCrudHookTest.php4
-rw-r--r--core/modules/system/src/Tests/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php2
-rw-r--r--core/modules/system/src/Tests/Entity/EntityUnitTestBase.php5
-rw-r--r--core/modules/system/src/Tests/Entity/FieldAccessTest.php3
-rw-r--r--core/modules/system/src/Tests/Plugin/ContextPluginTest.php3
-rw-r--r--core/modules/user/src/Tests/UserCacheTagsTest.php5
-rw-r--r--core/modules/user/src/Tests/UserEntityCallbacksTest.php3
-rw-r--r--core/modules/user/src/Tests/UserSaveTest.php4
-rw-r--r--core/modules/user/src/Tests/UserValidationTest.php8
-rw-r--r--core/modules/views/src/Tests/Entity/FieldEntityTest.php3
-rw-r--r--core/modules/views/src/Tests/Plugin/RelationshipJoinTestBase.php3
16 files changed, 38 insertions, 26 deletions
diff --git a/core/modules/comment/src/Plugin/views/field/StatisticsLastCommentName.php b/core/modules/comment/src/Plugin/views/field/StatisticsLastCommentName.php
index 1c8c41a..7264ccc 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 @@ class StatisticsLastCommentName extends FieldPluginBase {
*/
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 c9f0c6b..61e5b25 100644
--- a/core/modules/file/src/Tests/FileManagedUnitTestBase.php
+++ b/core/modules/file/src/Tests/FileManagedUnitTestBase.php
@@ -9,6 +9,7 @@ namespace Drupal\file\Tests;
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 @@ abstract class FileManagedUnitTestBase extends KernelTestBase {
// 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 ef0698b..c1572dc 100644
--- a/core/modules/hal/src/Tests/EntityTest.php
+++ b/core/modules/hal/src/Tests/EntityTest.php
@@ -9,6 +9,7 @@ namespace Drupal\hal\Tests;
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 @@ class EntityTest extends NormalizerTestBase {
$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 @@ class EntityTest extends NormalizerTestBase {
$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 @@ class EntityTest extends NormalizerTestBase {
$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 4f8c3fa..b5da13c 100644
--- a/core/modules/simpletest/src/BrowserTestBase.php
+++ b/core/modules/simpletest/src/BrowserTestBase.php
@@ -26,6 +26,7 @@ use Drupal\Core\StreamWrapper\StreamWrapperInterface;
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 @@ abstract class BrowserTestBase extends \PHPUnit_Framework_TestCase {
$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 880c6eb..dce52b1 100644
--- a/core/modules/system/src/Tests/Database/SelectComplexTest.php
+++ b/core/modules/system/src/Tests/Database/SelectComplexTest.php
@@ -9,6 +9,7 @@ namespace Drupal\system\Tests\Database;
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 @@ class SelectComplexTest extends DatabaseTestBase {
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 4b04e6b..8c4ec91 100644
--- a/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php
@@ -482,13 +482,13 @@ class EntityCrudHookTest extends EntityUnitTestBase {
* 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 0cb2fc0..92efca6 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 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
$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 255765c..ff9941b 100644
--- a/core/modules/system/src/Tests/Entity/EntityUnitTestBase.php
+++ b/core/modules/system/src/Tests/Entity/EntityUnitTestBase.php
@@ -10,6 +10,7 @@ namespace Drupal\system\Tests\Entity;
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 @@ abstract class EntityUnitTestBase extends KernelTestBase {
$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 70fc629..0e4fe59 100644
--- a/core/modules/system/src/Tests/Entity/FieldAccessTest.php
+++ b/core/modules/system/src/Tests/Entity/FieldAccessTest.php
@@ -9,6 +9,7 @@ namespace Drupal\system\Tests\Entity;
use Drupal\Core\Access\AccessResult;
use Drupal\simpletest\KernelTestBase;
+use Drupal\user\Entity\User;
/**
* Tests Field level access hooks.
@@ -64,7 +65,7 @@ class FieldAccessTest extends KernelTestBase {
// 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 05c4c7e..92be3e5 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\Core\Plugin\Context\ContextDefinition;
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 @@ class ContextPluginTest extends KernelTestBase {
// 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 8bb2a6a..450f7bc 100644
--- a/core/modules/user/src/Tests/UserCacheTagsTest.php
+++ b/core/modules/user/src/Tests/UserCacheTagsTest.php
@@ -9,6 +9,7 @@ namespace Drupal\user\Tests;
use Drupal\system\Tests\Entity\EntityWithUriCacheTagsTestBase;
use Drupal\user\Entity\Role;
+use Drupal\user\Entity\User;
use Drupal\user\RoleInterface;
/**
@@ -41,10 +42,10 @@ class UserCacheTagsTest extends EntityWithUriCacheTagsTestBase {
*/
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 ce7726a..2a2caaf 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 @@ class UserEntityCallbacksTest extends WebTestBase {
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 2a4e7b1..b174341 100644
--- a/core/modules/user/src/Tests/UserSaveTest.php
+++ b/core/modules/user/src/Tests/UserSaveTest.php
@@ -32,13 +32,13 @@ class UserSaveTest extends WebTestBase {
$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 dfa8a21..54e0983 100644
--- a/core/modules/user/src/Tests/UserValidationTest.php
+++ b/core/modules/user/src/Tests/UserValidationTest.php
@@ -91,10 +91,10 @@ class UserValidationTest extends KernelTestBase {
$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 @@ class UserValidationTest extends KernelTestBase {
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 c121157..1044dff 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 @@ class FieldEntityTest extends ViewTestBase {
// 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 d57fa27..9954c08 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 @@ abstract class RelationshipJoinTestBase extends PluginKernelTestBase {
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();