Issue #2641604 by Mac_Weber, lluvigne, heykarthikwithu: Replace deprecated usage of entity_create('node_type') with a direct call to NodeType::create()

8.1.x
Nathaniel Catchpole 2016-02-17 09:24:04 +09:00
parent 436ac08336
commit a55d4651e0
15 changed files with 41 additions and 27 deletions

View File

@ -63,10 +63,10 @@ class ConfigImportRecreateTest extends KernelTestBase {
public function testRecreateEntity() { public function testRecreateEntity() {
$type_name = Unicode::strtolower($this->randomMachineName(16)); $type_name = Unicode::strtolower($this->randomMachineName(16));
$content_type = entity_create('node_type', array( $content_type = NodeType::create([
'type' => $type_name, 'type' => $type_name,
'name' => 'Node type one', 'name' => 'Node type one',
)); ]);
$content_type->save(); $content_type->save();
node_add_body_field($content_type); node_add_body_field($content_type);
/** @var \Drupal\Core\Config\StorageInterface $active */ /** @var \Drupal\Core\Config\StorageInterface $active */
@ -82,10 +82,10 @@ class ConfigImportRecreateTest extends KernelTestBase {
$content_type->delete(); $content_type->delete();
$this->assertFalse($active->exists($config_name), 'Content type\'s old name does not exist active store.'); $this->assertFalse($active->exists($config_name), 'Content type\'s old name does not exist active store.');
// Recreate with the same type - this will have a different UUID. // Recreate with the same type - this will have a different UUID.
$content_type = entity_create('node_type', array( $content_type = NodeType::create([
'type' => $type_name, 'type' => $type_name,
'name' => 'Node type two', 'name' => 'Node type two',
)); ]);
$content_type->save(); $content_type->save();
node_add_body_field($content_type); node_add_body_field($content_type);

View File

@ -13,6 +13,7 @@ use Drupal\Component\Uuid\Php;
use Drupal\Core\Config\ConfigImporter; use Drupal\Core\Config\ConfigImporter;
use Drupal\Core\Config\ConfigImporterException; use Drupal\Core\Config\ConfigImporterException;
use Drupal\Core\Config\StorageComparer; use Drupal\Core\Config\StorageComparer;
use Drupal\node\Entity\NodeType;
use Drupal\simpletest\KernelTestBase; use Drupal\simpletest\KernelTestBase;
/** /**
@ -85,11 +86,11 @@ class ConfigImportRenameValidationTest extends KernelTestBase {
$test_entity->delete(); $test_entity->delete();
// Create a content type with a matching UUID in the active storage. // Create a content type with a matching UUID in the active storage.
$content_type = entity_create('node_type', array( $content_type = NodeType::create([
'type' => Unicode::strtolower($this->randomMachineName(16)), 'type' => Unicode::strtolower($this->randomMachineName(16)),
'name' => $this->randomMachineName(), 'name' => $this->randomMachineName(),
'uuid' => $uuid, 'uuid' => $uuid,
)); ]);
$content_type->save(); $content_type->save();
// Confirm that the staged configuration is detected as a rename since the // Confirm that the staged configuration is detected as a rename since the

View File

@ -9,6 +9,7 @@ namespace Drupal\datetime\Tests\Views;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem; use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;
use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldConfig;
use Drupal\node\Entity\NodeType;
use Drupal\views\Tests\Handler\HandlerTestBase; use Drupal\views\Tests\Handler\HandlerTestBase;
use Drupal\views\Tests\ViewTestData; use Drupal\views\Tests\ViewTestData;
use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldStorageConfig;
@ -46,7 +47,7 @@ abstract class DateTimeHandlerTestBase extends HandlerTestBase {
parent::setUp(); parent::setUp();
// Add a date field to page nodes. // Add a date field to page nodes.
$node_type = entity_create('node_type', [ $node_type = NodeType::create([
'type' => 'page', 'type' => 'page',
'name' => 'page' 'name' => 'page'
]); ]);

View File

@ -8,6 +8,7 @@
namespace Drupal\editor\Tests; namespace Drupal\editor\Tests;
use Drupal\editor\Entity\Editor; use Drupal\editor\Entity\Editor;
use Drupal\node\Entity\NodeType;
use Drupal\system\Tests\Entity\EntityUnitTestBase; use Drupal\system\Tests\Entity\EntityUnitTestBase;
use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface;
@ -55,7 +56,7 @@ class EditorFileUsageTest extends EntityUnitTestBase {
$editor->save(); $editor->save();
// Create a node type for testing. // Create a node type for testing.
$type = entity_create('node_type', array('type' => 'page', 'name' => 'page')); $type = NodeType::create(['type' => 'page', 'name' => 'page']);
$type->save(); $type->save();
node_add_body_field($type); node_add_body_field($type);
} }

View File

@ -20,6 +20,7 @@
namespace Drupal\field\Tests\Views; namespace Drupal\field\Tests\Views;
use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldConfig;
use Drupal\node\Entity\NodeType;
use Drupal\views\Tests\ViewTestBase; use Drupal\views\Tests\ViewTestBase;
use Drupal\views\Tests\ViewTestData; use Drupal\views\Tests\ViewTestData;
use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldStorageConfig;
@ -55,10 +56,10 @@ abstract class FieldTestBase extends ViewTestBase {
parent::setUp(); parent::setUp();
// Ensure the page node type exists. // Ensure the page node type exists.
entity_create('node_type', array( NodeType::create([
'type' => 'page', 'type' => 'page',
'name' => 'page', 'name' => 'page',
))->save(); ])->save();
ViewTestData::createTestViews(get_class($this), array('field_test_views')); ViewTestData::createTestViews(get_class($this), array('field_test_views'));
} }

View File

@ -10,6 +10,7 @@ namespace Drupal\hal\Tests;
use Drupal\comment\Tests\CommentTestTrait; use Drupal\comment\Tests\CommentTestTrait;
use Drupal\comment\Entity\Comment; use Drupal\comment\Entity\Comment;
use Drupal\user\Entity\User; use Drupal\user\Entity\User;
use Drupal\node\Entity\NodeType;
/** /**
* Tests that nodes and terms are correctly normalized and denormalized. * Tests that nodes and terms are correctly normalized and denormalized.
@ -44,7 +45,7 @@ class EntityTest extends NormalizerTestBase {
* Tests the normalization of nodes. * Tests the normalization of nodes.
*/ */
public function testNode() { public function testNode() {
$node_type = entity_create('node_type', array('type' => 'example_type')); $node_type = NodeType::create(['type' => 'example_type']);
$node_type->save(); $node_type->save();
$user = User::create(['name' => $this->randomMachineName()]); $user = User::create(['name' => $this->randomMachineName()]);
@ -140,7 +141,7 @@ class EntityTest extends NormalizerTestBase {
* Tests the normalization of comments. * Tests the normalization of comments.
*/ */
public function testComment() { public function testComment() {
$node_type = entity_create('node_type', array('type' => 'example_type')); $node_type = NodeType::create(['type' => 'example_type']);
$node_type->save(); $node_type->save();
$account = User::create(['name' => $this->randomMachineName()]); $account = User::create(['name' => $this->randomMachineName()]);

View File

@ -8,6 +8,7 @@
namespace Drupal\node\Tests\Condition; namespace Drupal\node\Tests\Condition;
use Drupal\node\Entity\Node; use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\system\Tests\Entity\EntityUnitTestBase; use Drupal\system\Tests\Entity\EntityUnitTestBase;
/** /**
@ -23,11 +24,11 @@ class NodeConditionTest extends EntityUnitTestBase {
parent::setUp(); parent::setUp();
// Create the node bundles required for testing. // Create the node bundles required for testing.
$type = entity_create('node_type', array('type' => 'page', 'name' => 'page')); $type = NodeType::create(['type' => 'page', 'name' => 'page']);
$type->save(); $type->save();
$type = entity_create('node_type', array('type' => 'article', 'name' => 'article')); $type = NodeType::create(['type' => 'article', 'name' => 'article']);
$type->save(); $type->save();
$type = entity_create('node_type', array('type' => 'test', 'name' => 'test')); $type = NodeType::create(['type' => 'test', 'name' => 'test']);
$type->save(); $type->save();
} }

View File

@ -9,6 +9,7 @@ namespace Drupal\node\Tests;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\node\Entity\Node; use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\system\Tests\Entity\EntityWithUriCacheTagsTestBase; use Drupal\system\Tests\Entity\EntityWithUriCacheTagsTestBase;
/** /**
@ -28,10 +29,10 @@ class NodeCacheTagsTest extends EntityWithUriCacheTagsTestBase {
*/ */
protected function createEntity() { protected function createEntity() {
// Create a "Camelids" node type. // Create a "Camelids" node type.
entity_create('node_type', array( NodeType::create([
'name' => 'Camelids', 'name' => 'Camelids',
'type' => 'camelids', 'type' => 'camelids',
))->save(); ])->save();
// Create a "Llama" node. // Create a "Llama" node.
$node = Node::create(['type' => 'camelids']); $node = Node::create(['type' => 'camelids']);

View File

@ -11,6 +11,7 @@ use Drupal\Component\Render\FormattableMarkup;
use Drupal\Component\Utility\Html; use Drupal\Component\Utility\Html;
use Drupal\Core\Render\BubbleableMetadata; use Drupal\Core\Render\BubbleableMetadata;
use Drupal\node\Entity\Node; use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\system\Tests\System\TokenReplaceUnitTestBase; use Drupal\system\Tests\System\TokenReplaceUnitTestBase;
/** /**
@ -35,7 +36,7 @@ class NodeTokenReplaceTest extends TokenReplaceUnitTestBase {
parent::setUp(); parent::setUp();
$this->installConfig(array('filter', 'node')); $this->installConfig(array('filter', 'node'));
$node_type = entity_create('node_type', array('type' => 'article', 'name' => 'Article')); $node_type = NodeType::create(['type' => 'article', 'name' => 'Article']);
$node_type->save(); $node_type->save();
node_add_body_field($node_type); node_add_body_field($node_type);
} }

View File

@ -8,6 +8,7 @@
namespace Drupal\node\Tests; namespace Drupal\node\Tests;
use Drupal\node\Entity\Node; use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\system\Tests\Entity\EntityUnitTestBase; use Drupal\system\Tests\Entity\EntityUnitTestBase;
/** /**
@ -31,7 +32,7 @@ class NodeValidationTest extends EntityUnitTestBase {
parent::setUp(); parent::setUp();
// Create a node type for testing. // Create a node type for testing.
$type = entity_create('node_type', array('type' => 'page', 'name' => 'page')); $type = NodeType::create(['type' => 'page', 'name' => 'page']);
$type->save(); $type->save();
} }

View File

@ -7,6 +7,7 @@
namespace Drupal\node\Tests\Views; namespace Drupal\node\Tests\Views;
use Drupal\node\Entity\Node; use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
/** /**
* Tests replacement of Views tokens supplied by the Node module. * Tests replacement of Views tokens supplied by the Node module.
@ -29,7 +30,7 @@ class NodeFieldTokensTest extends NodeTestBase {
public function testViewsTokenReplacement() { public function testViewsTokenReplacement() {
// Create the Article content type with a standard body field. // Create the Article content type with a standard body field.
/* @var $node_type \Drupal\node\NodeTypeInterface */ /* @var $node_type \Drupal\node\NodeTypeInterface */
$node_type = entity_create('node_type', ['type' => 'article', 'name' => 'Article']); $node_type = NodeType::create(['type' => 'article', 'name' => 'Article']);
$node_type->save(); $node_type->save();
node_add_body_field($node_type); node_add_body_field($node_type);

View File

@ -13,6 +13,7 @@ use Drupal\comment\Tests\CommentTestTrait;
use Drupal\Core\Database\Database; use Drupal\Core\Database\Database;
use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageInterface;
use Drupal\block\Entity\Block; use Drupal\block\Entity\Block;
use Drupal\node\Entity\NodeType;
use Drupal\taxonomy\Entity\Term; use Drupal\taxonomy\Entity\Term;
use Drupal\node\Entity\Node; use Drupal\node\Entity\Node;
use Drupal\taxonomy\Entity\Vocabulary; use Drupal\taxonomy\Entity\Vocabulary;
@ -142,10 +143,10 @@ class EntityCrudHookTest extends EntityUnitTestBase {
*/ */
public function testCommentHooks() { public function testCommentHooks() {
$account = $this->createUser(); $account = $this->createUser();
entity_create('node_type', array( NodeType::create([
'type' => 'article', 'type' => 'article',
'name' => 'Article', 'name' => 'Article',
))->save(); ])->save();
$this->addDefaultCommentField('node', 'article', 'comment', CommentItemInterface::OPEN); $this->addDefaultCommentField('node', 'article', 'comment', CommentItemInterface::OPEN);
$node = entity_create('node', array( $node = entity_create('node', array(

View File

@ -10,6 +10,7 @@ namespace Drupal\system\Tests\Module;
use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\Cache;
use Drupal\Component\Utility\SafeMarkup; use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Entity\EntityMalformedException; use Drupal\Core\Entity\EntityMalformedException;
use Drupal\node\Entity\NodeType;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
/** /**
@ -46,7 +47,7 @@ class UninstallTest extends WebTestBase {
$this->drupalLogin($account); $this->drupalLogin($account);
// Create a node type. // Create a node type.
$node_type = entity_create('node_type', array('type' => 'uninstall_blocker', 'name' => 'Uninstall blocker')); $node_type = NodeType::create(['type' => 'uninstall_blocker', 'name' => 'Uninstall blocker']);
// Create a dependency that can be fixed. // Create a dependency that can be fixed.
$node_type->setThirdPartySetting('module_test', 'key', 'value'); $node_type->setThirdPartySetting('module_test', 'key', 'value');
$node_type->save(); $node_type->save();

View File

@ -10,6 +10,7 @@ namespace Drupal\views\Tests\Entity;
use Drupal\Component\Utility\Unicode; use Drupal\Component\Utility\Unicode;
use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldStorageConfig;
use Drupal\node\Entity\NodeType;
use Drupal\views\Tests\ViewTestData; use Drupal\views\Tests\ViewTestData;
use Drupal\views\Tests\ViewKernelTestBase; use Drupal\views\Tests\ViewKernelTestBase;
use Drupal\views\Views; use Drupal\views\Views;
@ -54,10 +55,10 @@ class ViewEntityDependenciesTest extends ViewKernelTestBase {
)); ));
$comment_type->save(); $comment_type->save();
$content_type = entity_create('node_type', array( $content_type = NodeType::create([
'type' => $this->randomMachineName(), 'type' => $this->randomMachineName(),
'name' => $this->randomString(), 'name' => $this->randomString(),
)); ]);
$content_type->save(); $content_type->save();
$field_storage = FieldStorageConfig::create(array( $field_storage = FieldStorageConfig::create(array(
'field_name' => Unicode::strtolower($this->randomMachineName()), 'field_name' => Unicode::strtolower($this->randomMachineName()),

View File

@ -9,6 +9,7 @@ namespace Drupal\views\Tests;
use Drupal\comment\Tests\CommentTestTrait; use Drupal\comment\Tests\CommentTestTrait;
use Drupal\Component\Utility\Xss; use Drupal\Component\Utility\Xss;
use Drupal\node\Entity\NodeType;
use Drupal\views\Entity\View; use Drupal\views\Entity\View;
use Drupal\views\Views; use Drupal\views\Views;
use Drupal\views\ViewExecutable; use Drupal\views\ViewExecutable;
@ -87,10 +88,10 @@ class ViewExecutableTest extends ViewKernelTestBase {
$this->installSchema('comment', array('comment_entity_statistics')); $this->installSchema('comment', array('comment_entity_statistics'));
$this->installConfig(array('system', 'field', 'node', 'comment')); $this->installConfig(array('system', 'field', 'node', 'comment'));
entity_create('node_type', array( NodeType::create([
'type' => 'page', 'type' => 'page',
'name' => 'Page', 'name' => 'Page',
))->save(); ])->save();
$this->addDefaultCommentField('node', 'page'); $this->addDefaultCommentField('node', 'page');
parent::setUpFixtures(); parent::setUpFixtures();