Skip to content
Snippets Groups Projects
Commit 5d8ea5f8 authored by catch's avatar catch
Browse files

Issue #2669926 by felribeiro, dimaro, kostyashupenko: Replace deprecated usage...

Issue #2669926 by felribeiro, dimaro, kostyashupenko: Replace deprecated usage of entity_create('taxonomy*') with a direct call to Vocabulary::create()
parent a3f5ca8a
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,7 @@
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use \Drupal\taxonomy\Entity\Vocabulary;
/**
* Posts an article with a taxonomy term and a date prior to 1970.
......@@ -28,10 +29,10 @@ protected function setUp() {
parent::setUp();
// Create a tags vocabulary for the 'article' content type.
$vocabulary = entity_create('taxonomy_vocabulary', array(
$vocabulary = Vocabulary::create([
'name' => 'Tags',
'vid' => 'tags',
));
]);
$vocabulary->save();
$field_name = 'field_' . $vocabulary->id();
......@@ -69,4 +70,5 @@ function testTaxonomyLegacyNode() {
$node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
$this->assertEqual($node->getCreatedTime(), $date->getTimestamp(), 'Legacy node was saved with the right date.');
}
}
......@@ -10,6 +10,7 @@
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Language\LanguageInterface;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\taxonomy\Entity\Term;
/**
* Provides common helper methods for Taxonomy module tests.
......@@ -21,13 +22,13 @@ trait TaxonomyTestTrait {
*/
function createVocabulary() {
// Create a vocabulary.
$vocabulary = entity_create('taxonomy_vocabulary', array(
$vocabulary = Vocabulary::create([
'name' => $this->randomMachineName(),
'description' => $this->randomMachineName(),
'vid' => Unicode::strtolower($this->randomMachineName()),
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
'weight' => mt_rand(0, 10),
));
]);
$vocabulary->save();
return $vocabulary;
}
......@@ -47,16 +48,16 @@ function createVocabulary() {
function createTerm(Vocabulary $vocabulary, $values = array()) {
$filter_formats = filter_formats();
$format = array_pop($filter_formats);
$term = entity_create('taxonomy_term', $values + array(
$term = Term::create($values + [
'name' => $this->randomMachineName(),
'description' => array(
'description' => [
'value' => $this->randomMachineName(),
// Use the first available text format.
'format' => $format->id(),
),
],
'vid' => $vocabulary->id(),
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
));
]);
$term->save();
return $term;
}
......
......@@ -8,6 +8,8 @@
namespace Drupal\taxonomy\Tests;
use Drupal\system\Tests\Entity\EntityWithUriCacheTagsTestBase;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\taxonomy\Entity\Term;
/**
* Tests the Taxonomy term entity's cache tags.
......@@ -26,17 +28,17 @@ class TermCacheTagsTest extends EntityWithUriCacheTagsTestBase {
*/
protected function createEntity() {
// Create a "Camelids" vocabulary.
$vocabulary = entity_create('taxonomy_vocabulary', array(
$vocabulary = Vocabulary::create([
'name' => 'Camelids',
'vid' => 'camelids',
));
]);
$vocabulary->save();
// Create a "Llama" taxonomy term.
$term = entity_create('taxonomy_term', array(
$term = Term::create([
'name' => 'Llama',
'vid' => $vocabulary->id(),
));
]);
$term->save();
return $term;
......
......@@ -495,10 +495,10 @@ function testTaxonomyGetTermByName() {
// Create a new term in a different vocabulary with the same name.
$new_vocabulary = $this->createVocabulary();
$new_term = entity_create('taxonomy_term', array(
$new_term = Term::create([
'name' => $term->getName(),
'vid' => $new_vocabulary->id(),
));
]);
$new_term->save();
// Load multiple terms with the same name.
......
......@@ -9,6 +9,7 @@
use Drupal\content_translation\Tests\ContentTranslationUITestBase;
use Drupal\Core\Language\LanguageInterface;
use Drupal\taxonomy\Entity\Vocabulary;
/**
* Tests the Term Translation UI.
......@@ -44,13 +45,13 @@ protected function setupBundle() {
parent::setupBundle();
// Create a vocabulary.
$this->vocabulary = entity_create('taxonomy_vocabulary', array(
$this->vocabulary = Vocabulary::create([
'name' => $this->bundle,
'description' => $this->randomMachineName(),
'vid' => $this->bundle,
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
'weight' => mt_rand(0, 10),
));
]);
$this->vocabulary->save();
}
......@@ -113,13 +114,13 @@ function testTranslateLinkVocabularyAdminPage() {
$translatable_tid = $this->createEntity($values, $this->langcodes[0], $this->vocabulary->id());
// Create an untranslatable vocabulary.
$untranslatable_vocabulary = entity_create('taxonomy_vocabulary', array(
$untranslatable_vocabulary = Vocabulary::create([
'name' => 'untranslatable_voc',
'description' => $this->randomMachineName(),
'vid' => 'untranslatable_voc',
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
'weight' => mt_rand(0, 10),
));
]);
$untranslatable_vocabulary->save();
$values = array(
......
......@@ -14,6 +14,8 @@
use Drupal\views\Tests\ViewTestData;
use Drupal\views\Views;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\taxonomy\Entity\Term;
/**
* Tests taxonomy field filters with translations.
......@@ -63,10 +65,10 @@ function setUp() {
);
// Create a vocabulary.
$this->vocabulary = entity_create('taxonomy_vocabulary', array(
$this->vocabulary = Vocabulary::create([
'name' => 'Views testing tags',
'vid' => 'views_testing_tags',
));
]);
$this->vocabulary->save();
// Add a translatable field to the vocabulary.
......@@ -173,13 +175,13 @@ protected function createTermWithProperties($properties) {
'field_foo' => $this->randomMachineName(),
);
$term = entity_create('taxonomy_term', array(
$term = Term::create([
'name' => $properties['name'],
'description' => $properties['description'],
'format' => $format->id(),
'vid' => $this->vocabulary->id(),
'langcode' => $properties['langcode'],
));
]);
$term->field_foo->value = $properties['field_foo'];
$term->save();
return $term;
......
......@@ -12,6 +12,8 @@
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\views\Tests\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\taxonomy\Entity\Term;
/**
* Base class for all taxonomy tests.
......@@ -85,10 +87,10 @@ protected function mockStandardInstall() {
'type' => 'article',
));
// Create the vocabulary for the tag field.
$this->vocabulary = entity_create('taxonomy_vocabulary', array(
$this->vocabulary = Vocabulary::create([
'name' => 'Views testing tags',
'vid' => 'views_testing_tags',
));
]);
$this->vocabulary->save();
$field_name = 'field_' . $this->vocabulary->id();
......@@ -148,7 +150,7 @@ protected function createTerm(array $settings = []) {
'vid' => $this->vocabulary->id(),
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
];
$term = entity_create('taxonomy_term', $settings);
$term = Term::create($settings);
$term->save();
return $term;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment