Commit 1d75784a authored by catch's avatar catch
Browse files

Issue #2672604 by saurabh.tripathi.cs: Replace deprecated usage of...

Issue #2672604 by saurabh.tripathi.cs: Replace deprecated usage of entity_create('taxonomy_term') and entity_create('taxonomy_vocabulary') with a direct call to Term::create() and Vocabulary::create()
parent aa44ae42
......@@ -16,6 +16,7 @@
use Drupal\shortcut\Entity\ShortcutSet;
use Drupal\contact\Entity\ContactForm;
use Drupal\filter\Entity\FilterFormat;
use Drupal\taxonomy\Entity\Vocabulary;
/**
* Visit all lists.
......@@ -165,11 +166,11 @@ protected function doMenuListTest() {
protected function doVocabularyListTest() {
// Create a test vocabulary to decouple looking for translate operations
// link so this does not test more than necessary.
$vocabulary = entity_create('taxonomy_vocabulary', array(
$vocabulary = Vocabulary::create([
'name' => $this->randomMachineName(),
'description' => $this->randomMachineName(),
'vid' => Unicode::strtolower($this->randomMachineName()),
));
]);
$vocabulary->save();
// Get the Taxonomy listing.
......
......@@ -79,18 +79,18 @@ protected function setUp() {
$this->installSchema('comment', ['comment_entity_statistics']);
$this->installSchema('node', ['node_access']);
$this->vocabulary = entity_create('taxonomy_vocabulary', array(
$this->vocabulary = Vocabulary::create([
'name' => $this->randomMachineName(),
'vid' => Unicode::strtolower($this->randomMachineName()),
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
));
]);
$this->vocabulary->save();
$this->term = entity_create('taxonomy_term', array(
$this->term = Term::create([
'name' => $this->randomMachineName(),
'vid' => $this->vocabulary->id(),
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
));
]);
$this->term->save();
$this->entityStringId = EntityTestStringId::create([
......@@ -141,11 +141,11 @@ public function testContentEntityReferenceItem() {
$this->assertEqual($term->getName(), $new_name);
// Make sure the computed term reflects updates to the term id.
$term2 = entity_create('taxonomy_term', array(
$term2 = Term::create([
'name' => $this->randomMachineName(),
'vid' => $this->term->bundle(),
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
));
]);
$term2->save();
// Test all the possible ways of assigning a value.
......@@ -233,11 +233,11 @@ public function testConfigEntityReferenceItem() {
$this->assertEqual($vocabulary->label(), $new_name);
// Make sure the computed term reflects updates to the term id.
$vocabulary2 = entity_create('taxonomy_vocabulary', array(
$vocabulary2 = $vocabulary = Vocabulary::create([
'name' => $this->randomMachineName(),
'vid' => Unicode::strtolower($this->randomMachineName()),
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
));
]);
$vocabulary2->save();
$entity->field_test_taxonomy_vocabulary->target_id = $vocabulary2->id();
......@@ -280,11 +280,11 @@ public function testEntityAutoCreate() {
*/
public function testEntitySaveOrder() {
// The term entity is unsaved here.
$term = entity_create('taxonomy_term', array(
$term = Term::create([
'name' => $this->randomMachineName(),
'vid' => $this->term->bundle(),
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
));
]);
$entity = EntityTest::create();
// Now assign the unsaved term to the field.
$entity->field_test_taxonomy_term->entity = $term;
......
......@@ -339,13 +339,13 @@ private function doAdminTests($user) {
// Create a default vocabulary named "Tags".
$description = 'Use tags to group articles on similar topics into categories.';
$help = 'Enter a comma-separated list of words to describe your content.';
$vocabulary = entity_create('taxonomy_vocabulary', array(
$vocabulary = Vocabulary::create([
'name' => 'Tags',
'description' => $description,
'vid' => 'tags',
'langcode' => \Drupal::languageManager()->getDefaultLanguage()->getId(),
'help' => $help,
));
]);
$vocabulary->save();
// Test tags vocabulary form is not affected.
$this->drupalGet('admin/structure/taxonomy/manage/tags');
......
......@@ -12,6 +12,7 @@
use Drupal\node\Entity\NodeType;
use Drupal\simpletest\WebTestBase;
use Drupal\comment\Entity\Comment;
use Drupal\taxonomy\Entity\Term;
/**
* Tests forum module uninstallation.
......@@ -37,14 +38,14 @@ public function testForumUninstallWithField() {
$this->assertNotNull($field_storage, 'The taxonomy_forums field storage exists.');
// Create a taxonomy term.
$term = entity_create('taxonomy_term', array(
$term = Term::create([
'name' => t('A term'),
'langcode' => \Drupal::languageManager()->getDefaultLanguage()->getId(),
'description' => '',
'parent' => array(0),
'vid' => 'forums',
'forum_container' => 0,
));
]);
$term->save();
// Create a forum node.
......
......@@ -11,6 +11,8 @@
use Drupal\comment\Entity\Comment;
use Drupal\user\Entity\User;
use Drupal\node\Entity\NodeType;
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\Entity\Vocabulary;
/**
* Tests that nodes and terms are correctly normalized and denormalized.
......@@ -89,7 +91,7 @@ public function testNode() {
* Tests the normalization of terms.
*/
public function testTerm() {
$vocabulary = entity_create('taxonomy_vocabulary', array('vid' => 'example_vocabulary'));
$vocabulary = Vocabulary::create(['vid' => 'example_vocabulary']);
$vocabulary->save();
$account = User::create(['name' => $this->randomMachineName()]);
......@@ -97,12 +99,12 @@ public function testTerm() {
// @todo Until https://www.drupal.org/node/2327935 is fixed, if no parent is
// set, the test fails because target_id => 0 is reserialized to NULL.
$term_parent = entity_create('taxonomy_term', array(
$term_parent = Term::create([
'name' => $this->randomMachineName(),
'vid' => $vocabulary->id(),
));
]);
$term_parent->save();
$term = entity_create('taxonomy_term', array(
$term = Term::create([
'name' => $this->randomMachineName(),
'vid' => $vocabulary->id(),
'description' => array(
......@@ -110,7 +112,7 @@ public function testTerm() {
'format' => $this->randomMachineName(),
),
'parent' => $term_parent->id(),
));
]);
$term->save();
$original_values = $term->toArray();
......
......@@ -11,6 +11,7 @@
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\simpletest\WebTestBase;
use Drupal\taxonomy\Entity\Vocabulary;
/**
* Tests the features of the language configuration element field.
......@@ -223,10 +224,10 @@ public function testNodeTypeDelete() {
* Tests that the configuration is retained when a vocabulary is updated.
*/
public function testTaxonomyVocabularyUpdate() {
$vocabulary = entity_create('taxonomy_vocabulary', array(
$vocabulary = Vocabulary::create([
'name' => 'Country',
'vid' => 'country',
));
]);
$vocabulary->save();
$admin_user = $this->drupalCreateUser(array('administer taxonomy'));
......
......@@ -15,6 +15,8 @@
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\node\Entity\NodeType;
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\Entity\Vocabulary;
/**
* Tests the node entity preview functionality.
......@@ -48,24 +50,24 @@ protected function setUp() {
$this->drupalLogin($web_user);
// Add a vocabulary so we can test different view modes.
$vocabulary = entity_create('taxonomy_vocabulary', array(
$vocabulary = Vocabulary::create([
'name' => $this->randomMachineName(),
'description' => $this->randomMachineName(),
'vid' => $this->randomMachineName(),
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
'help' => '',
));
]);
$vocabulary->save();
$this->vocabulary = $vocabulary;
// Add a term to the vocabulary.
$term = entity_create('taxonomy_term', array(
$term = Term::create([
'name' => $this->randomMachineName(),
'description' => $this->randomMachineName(),
'vid' => $this->vocabulary->id(),
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
));
]);
$term->save();
$this->term = $term;
......
......@@ -27,10 +27,10 @@ protected function setUp() {
parent::setUp();
// Create a Tags vocabulary for the Article node type.
$vocabulary = entity_create('taxonomy_vocabulary', array(
$vocabulary = Vocabulary::create([
'name' => t('Tags'),
'vid' => 'tags',
));
]);
$vocabulary->save();
// Create and login user.
......
......@@ -12,6 +12,8 @@
use Drupal\Core\Language\LanguageInterface;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\simpletest\WebTestBase;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\taxonomy\Entity\Term;
/**
* Tests in-place editing of autocomplete tags.
......@@ -78,7 +80,7 @@ protected function setUp() {
'type' => 'article',
));
// Create the vocabulary for the tag field.
$this->vocabulary = entity_create('taxonomy_vocabulary', [
$this->vocabulary = Vocabulary::create([
'name' => 'quickedit testing tags',
'vid' => 'quickedit_testing_tags',
]);
......@@ -202,14 +204,14 @@ public function testAutocompleteQuickEdit() {
protected function createTerm() {
$filter_formats = filter_formats();
$format = array_pop($filter_formats);
$term = entity_create('taxonomy_term', array(
$term = Term::create([
'name' => $this->randomMachineName(),
'description' => $this->randomMachineName(),
// Use the first available text format.
'format' => $format->id(),
'vid' => $this->vocabulary->id(),
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
));
]);
$term->save();
return $term;
}
......
......@@ -14,6 +14,7 @@
use Drupal\node\NodeInterface;
use Drupal\simpletest\WebTestBase;
use Drupal\comment\Entity\Comment;
use Drupal\taxonomy\Entity\Term;
/**
* Tests the RDF mappings and RDFa markup of the standard profile.
......@@ -132,11 +133,11 @@ protected function setUp() {
$this->drupalLogin($this->adminUser);
// Create term.
$this->term = entity_create('taxonomy_term', array(
$this->term = Term::create([
'name' => $this->randomMachineName(),
'description' => $this->randomMachineName(),
'vid' => 'tags',
));
]);
$this->term->save();
// Create image.
......
......@@ -358,23 +358,23 @@ public function testNodeHooks() {
public function testTaxonomyTermHooks() {
$this->installEntitySchema('taxonomy_term');
$vocabulary = entity_create('taxonomy_vocabulary', array(
$vocabulary = Vocabulary::create([
'name' => 'Test vocabulary',
'vid' => 'test',
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
'description' => NULL,
'module' => 'entity_crud_hook_test',
));
]);
$vocabulary->save();
$GLOBALS['entity_crud_hook_test'] = array();
$term = entity_create('taxonomy_term', array(
$term = Term::create([
'vid' => $vocabulary->id(),
'name' => 'Test term',
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
'description' => NULL,
'format' => 1,
));
]);
$this->assertHookMessageOrder(array(
'entity_crud_hook_test_taxonomy_term_create called',
......@@ -427,13 +427,13 @@ public function testTaxonomyTermHooks() {
public function testTaxonomyVocabularyHooks() {
$this->installEntitySchema('taxonomy_term');
$vocabulary = entity_create('taxonomy_vocabulary', array(
$vocabulary = Vocabulary::create([
'name' => 'Test vocabulary',
'vid' => 'test',
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
'description' => NULL,
'module' => 'entity_crud_hook_test',
));
]);
$this->assertHookMessageOrder(array(
'entity_crud_hook_test_taxonomy_vocabulary_create called',
......
......@@ -9,6 +9,8 @@
use Drupal\Component\Utility\Unicode;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\taxonomy\Entity\Term;
/**
* Tests the Entity Query relationship API.
......@@ -73,9 +75,9 @@ protected function setUp() {
// We want an entity reference field. It needs a vocabulary, terms, a field
// storage and a field. First, create the vocabulary.
$vocabulary = entity_create('taxonomy_vocabulary', array(
$vocabulary = Vocabulary::create([
'vid' => Unicode::strtolower($this->randomMachineName()),
));
]);
$vocabulary->save();
// Second, create the field.
......@@ -91,10 +93,10 @@ protected function setUp() {
// Create two terms and also two accounts.
for ($i = 0; $i <= 1; $i++) {
$term = entity_create('taxonomy_term', array(
$term = Term::create([
'name' => $this->randomMachineName(),
'vid' => $vocabulary->id(),
));
]);
$term->save();
$this->terms[] = $term;
$this->accounts[] = $this->createUser();
......
......@@ -8,6 +8,7 @@
namespace Drupal\system\Tests\Path;
use Drupal\simpletest\WebTestBase;
use Drupal\taxonomy\Entity\Term;
/**
* Tests altering the inbound path and the outbound path.
......@@ -64,10 +65,10 @@ function testUrlAlter() {
$this->assertUrlOutboundAlter('/forum', '/community');
$forum_vid = $this->config('forum.settings')->get('vocabulary');
$term_name = $this->randomMachineName();
$term = entity_create('taxonomy_term', array(
$term = Term::create([
'name' => $term_name,
'vid' => $forum_vid,
));
]);
$term->save();
$this->drupalGet("community/" . $term->id());
$this->assertText($term_name, 'The community/{tid} path gets resolved correctly');
......
......@@ -13,6 +13,7 @@
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\simpletest\WebTestBase;
use Drupal\comment\Entity\Comment;
use Drupal\taxonomy\Entity\Term;
/**
* Tests themed output for each entity type in all available themes to ensure
......@@ -94,10 +95,10 @@ protected function setUp() {
$this->drupalLogin($this->user);
// Create a test term.
$this->term = entity_create('taxonomy_term', array(
$this->term = Term::create([
'name' => $this->xssLabel,
'vid' => 1,
));
]);
$this->term->save();
// Add a comment field.
......
......@@ -16,6 +16,8 @@
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\views\Views;
use Drupal\comment\Entity\Comment;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\taxonomy\Entity\Term;
/**
* Tests the default views provided by views.
......@@ -53,7 +55,7 @@ protected function setUp() {
// Create Basic page node type.
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
$vocabulary = entity_create('taxonomy_vocabulary', array(
$vocabulary = Vocabulary::create([
'name' => $this->randomMachineName(),
'description' => $this->randomMachineName(),
'vid' => Unicode::strtolower($this->randomMachineName()),
......@@ -61,7 +63,7 @@ protected function setUp() {
'help' => '',
'nodes' => array('page' => 'page'),
'weight' => mt_rand(0, 10),
));
]);
$vocabulary->save();
// Create a field.
......@@ -149,14 +151,14 @@ public function testDefaultViews() {
function createTerm($vocabulary) {
$filter_formats = filter_formats();
$format = array_pop($filter_formats);
$term = entity_create('taxonomy_term', array(
$term = Term::create([
'name' => $this->randomMachineName(),
'description' => $this->randomMachineName(),
// Use the first available text format.
'format' => $format->id(),
'vid' => $vocabulary->id(),
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
));
]);
$term->save();
return $term;
}
......
......@@ -10,6 +10,8 @@
use Drupal\Core\Form\FormState;
use Drupal\views\Views;
use Drupal\views\Tests\ViewKernelTestBase;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\taxonomy\Entity\Term;
/**
* Tests the generic entity row plugin.
......@@ -48,9 +50,9 @@ protected function setUp() {
* Tests the entity row handler.
*/
public function testEntityRow() {
$vocab = entity_create('taxonomy_vocabulary', array('name' => $this->randomMachineName(), 'vid' => strtolower($this->randomMachineName())));
$vocab = Vocabulary::create(['name' => $this->randomMachineName(), 'vid' => strtolower($this->randomMachineName())]);
$vocab->save();
$term = entity_create('taxonomy_term', array('name' => $this->randomMachineName(), 'vid' => $vocab->id() ));
$term = Term::create(['name' => $this->randomMachineName(), 'vid' => $vocab->id() ]);
$term->save();
$view = Views::getView('test_entity_row');
......
......@@ -10,6 +10,7 @@
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\taxonomy\Entity\Vocabulary;
/**
* Tests the ability of the views wizard to create views filtered by taxonomy.
......@@ -78,10 +79,10 @@ protected function setUp() {
$this->nodeTypeWithoutTags = $this->drupalCreateContentType();
// Create the vocabulary for the tag field.
$this->tagVocabulary = entity_create('taxonomy_vocabulary', array(
$this->tagVocabulary = Vocabulary::create([
'name' => 'Views testing tags',
'vid' => 'views_testing_tags',
));
]);
$this->tagVocabulary->save();
// Create the tag field itself.
......
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