diff options
author | Nathaniel Catchpole | 2016-02-15 12:37:55 (GMT) |
---|---|---|
committer | Nathaniel Catchpole | 2016-02-15 12:37:55 (GMT) |
commit | c3ae8b4c56ff898379527eb154f4a5a04909b110 (patch) | |
tree | 1566f9df7a0b60ab371526464825c3e6c5b66d56 | |
parent | 68e9f226677cdd87ca1c40e76de4090d020f8eaa (diff) |
Issue #2641596 by Mac_Weber, heykarthikwithu: Replace deprecated usage of entity_create('node') with a direct call to Node::create()
7 files changed, 22 insertions, 16 deletions
diff --git a/core/modules/node/src/Tests/Condition/NodeConditionTest.php b/core/modules/node/src/Tests/Condition/NodeConditionTest.php index d739751..a3839c6 100644 --- a/core/modules/node/src/Tests/Condition/NodeConditionTest.php +++ b/core/modules/node/src/Tests/Condition/NodeConditionTest.php @@ -7,6 +7,7 @@ namespace Drupal\node\Tests\Condition; +use Drupal\node\Entity\Node; use Drupal\system\Tests\Entity\EntityUnitTestBase; /** @@ -38,11 +39,11 @@ class NodeConditionTest extends EntityUnitTestBase { $this->createUser(); // Get some nodes of various types to check against. - $page = entity_create('node', array('type' => 'page', 'title' => $this->randomMachineName(), 'uid' => 1)); + $page = Node::create(['type' => 'page', 'title' => $this->randomMachineName(), 'uid' => 1]); $page->save(); - $article = entity_create('node', array('type' => 'article', 'title' => $this->randomMachineName(), 'uid' => 1)); + $article = Node::create(['type' => 'article', 'title' => $this->randomMachineName(), 'uid' => 1]); $article->save(); - $test = entity_create('node', array('type' => 'test', 'title' => $this->randomMachineName(), 'uid' => 1)); + $test = Node::create(['type' => 'test', 'title' => $this->randomMachineName(), 'uid' => 1]); $test->save(); // Grab the node type condition and configure it to check against node type diff --git a/core/modules/node/src/Tests/NodeCacheTagsTest.php b/core/modules/node/src/Tests/NodeCacheTagsTest.php index 5940d4c..82b01b7 100644 --- a/core/modules/node/src/Tests/NodeCacheTagsTest.php +++ b/core/modules/node/src/Tests/NodeCacheTagsTest.php @@ -8,6 +8,7 @@ namespace Drupal\node\Tests; use Drupal\Core\Entity\EntityInterface; +use Drupal\node\Entity\Node; use Drupal\system\Tests\Entity\EntityWithUriCacheTagsTestBase; /** @@ -33,7 +34,7 @@ class NodeCacheTagsTest extends EntityWithUriCacheTagsTestBase { ))->save(); // Create a "Llama" node. - $node = entity_create('node', array('type' => 'camelids')); + $node = Node::create(['type' => 'camelids']); $node->setTitle('Llama') ->setPublished(TRUE) ->save(); diff --git a/core/modules/node/src/Tests/NodeCreationTest.php b/core/modules/node/src/Tests/NodeCreationTest.php index abe7ba7..d625e52 100644 --- a/core/modules/node/src/Tests/NodeCreationTest.php +++ b/core/modules/node/src/Tests/NodeCreationTest.php @@ -9,6 +9,7 @@ namespace Drupal\node\Tests; use Drupal\Core\Database\Database; use Drupal\Core\Language\LanguageInterface; +use Drupal\node\Entity\Node; /** * Create a node and test saving it. @@ -90,7 +91,7 @@ class NodeCreationTest extends NodeTestBase { try { // An exception is generated by node_test_exception_node_insert() if the // title is 'testing_transaction_exception'. - entity_create('node', $edit)->save(); + Node::create($edit)->save(); $this->fail(t('Expected exception has not been thrown.')); } catch (\Exception $e) { diff --git a/core/modules/node/src/Tests/NodeSaveTest.php b/core/modules/node/src/Tests/NodeSaveTest.php index 3acbf82..7fcea9b 100644 --- a/core/modules/node/src/Tests/NodeSaveTest.php +++ b/core/modules/node/src/Tests/NodeSaveTest.php @@ -64,7 +64,7 @@ class NodeSaveTest extends NodeTestBase { 'nid' => $test_nid, ); /** @var \Drupal\node\NodeInterface $node */ - $node = entity_create('node', $node); + $node = Node::create($node); $node->enforceIsNew(); $this->assertEqual($node->getOwnerId(), $this->webUser->id()); @@ -89,7 +89,7 @@ class NodeSaveTest extends NodeTestBase { 'title' => $this->randomMachineName(8), ); - entity_create('node', $edit)->save(); + Node::create($edit)->save(); $node = $this->drupalGetNodeByTitle($edit['title']); $this->assertEqual($node->getCreatedTime(), REQUEST_TIME, 'Creating a node sets default "created" timestamp.'); $this->assertEqual($node->getChangedTime(), REQUEST_TIME, 'Creating a node sets default "changed" timestamp.'); @@ -118,7 +118,7 @@ class NodeSaveTest extends NodeTestBase { 'changed' => 979534800, // Drupal 1.0 release. ); - entity_create('node', $edit)->save(); + Node::create($edit)->save(); $node = $this->drupalGetNodeByTitle($edit['title']); $this->assertEqual($node->getCreatedTime(), 280299600, 'Creating a node programmatically uses programmatically set "created" timestamp.'); $this->assertEqual($node->getChangedTime(), 979534800, 'Creating a node programmatically uses programmatically set "changed" timestamp.'); @@ -144,11 +144,11 @@ class NodeSaveTest extends NodeTestBase { */ function testDeterminingChanges() { // Initial creation. - $node = entity_create('node', array( + $node = Node::create([ 'uid' => $this->webUser->id(), 'type' => 'article', 'title' => 'test_changes', - )); + ]); $node->save(); // Update the node without applying changes. diff --git a/core/modules/node/src/Tests/NodeTokenReplaceTest.php b/core/modules/node/src/Tests/NodeTokenReplaceTest.php index bc6a049..b71fe22 100644 --- a/core/modules/node/src/Tests/NodeTokenReplaceTest.php +++ b/core/modules/node/src/Tests/NodeTokenReplaceTest.php @@ -10,6 +10,7 @@ namespace Drupal\node\Tests; use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Utility\Html; use Drupal\Core\Render\BubbleableMetadata; +use Drupal\node\Entity\Node; use Drupal\system\Tests\System\TokenReplaceUnitTestBase; /** @@ -51,13 +52,13 @@ class NodeTokenReplaceTest extends TokenReplaceUnitTestBase { // Create a user and a node. $account = $this->createUser(); /* @var $node \Drupal\node\NodeInterface */ - $node = entity_create('node', array( + $node = Node::create([ 'type' => 'article', 'tnid' => 0, 'uid' => $account->id(), 'title' => '<blink>Blinking Text</blink>', 'body' => [['value' => 'Regular NODE body for the test.', 'summary' => 'Fancy NODE summary.', 'format' => 'plain_text']], - )); + ]); $node->save(); // Generate and test tokens. @@ -110,12 +111,12 @@ class NodeTokenReplaceTest extends TokenReplaceUnitTestBase { } // Repeat for a node without a summary. - $node = entity_create('node', array( + $node = Node::create([ 'type' => 'article', 'uid' => $account->id(), 'title' => '<blink>Blinking Text</blink>', 'body' => [['value' => 'A string that looks random like TR5c2I', 'format' => 'plain_text']], - )); + ]); $node->save(); // Generate and test token - use full body as expected value. diff --git a/core/modules/node/src/Tests/NodeValidationTest.php b/core/modules/node/src/Tests/NodeValidationTest.php index 9f6bccc..77f20fb 100644 --- a/core/modules/node/src/Tests/NodeValidationTest.php +++ b/core/modules/node/src/Tests/NodeValidationTest.php @@ -7,6 +7,7 @@ namespace Drupal\node\Tests; +use Drupal\node\Entity\Node; use Drupal\system\Tests\Entity\EntityUnitTestBase; /** @@ -39,7 +40,7 @@ class NodeValidationTest extends EntityUnitTestBase { */ public function testValidation() { $this->createUser(); - $node = entity_create('node', array('type' => 'page', 'title' => 'test', 'uid' => 1)); + $node = Node::create(['type' => 'page', 'title' => 'test', 'uid' => 1]); $violations = $node->validate(); $this->assertEqual(count($violations), 0, 'No violations when validating a default node.'); diff --git a/core/modules/node/src/Tests/Views/NodeFieldTokensTest.php b/core/modules/node/src/Tests/Views/NodeFieldTokensTest.php index 5cc96c7..a6b3121 100644 --- a/core/modules/node/src/Tests/Views/NodeFieldTokensTest.php +++ b/core/modules/node/src/Tests/Views/NodeFieldTokensTest.php @@ -6,6 +6,7 @@ */ namespace Drupal\node\Tests\Views; +use Drupal\node\Entity\Node; /** * Tests replacement of Views tokens supplied by the Node module. @@ -38,7 +39,7 @@ class NodeFieldTokensTest extends NodeTestBase { $summary = $this->randomMachineName(16); /** @var $node \Drupal\node\NodeInterface */ - $node = entity_create('node', [ + $node = Node::create([ 'type' => 'article', 'tnid' => 0, 'uid' => $account->id(), |