3 namespace Drupal\taxonomy\Tests;
5 @trigger_error(__NAMESPACE__ . '\TaxonomyTestTrait is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\taxonomy\Functional\TaxonomyTestTrait', E_USER_DEPRECATED);
7 use Drupal\Core\Language\LanguageInterface;
8 use Drupal\taxonomy\Entity\Vocabulary;
9 use Drupal\taxonomy\Entity\Term;
12 * Provides common helper methods for Taxonomy module tests.
14 * @deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0.
15 * Use \Drupal\Tests\taxonomy\Functional\TaxonomyTestTrait
17 trait TaxonomyTestTrait {
20 * Returns a new vocabulary with random properties.
22 public function createVocabulary() {
23 // Create a vocabulary.
24 $vocabulary = Vocabulary::create([
25 'name' => $this->randomMachineName(),
26 'description' => $this->randomMachineName(),
27 'vid' => mb_strtolower($this->randomMachineName()),
28 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
29 'weight' => mt_rand(0, 10),
36 * Returns a new term with random properties in vocabulary $vid.
38 * @param \Drupal\taxonomy\Entity\Vocabulary $vocabulary
39 * The vocabulary object.
40 * @param array $values
41 * (optional) An array of values to set, keyed by property name. If the
42 * entity type has bundles, the bundle key has to be specified.
44 * @return \Drupal\taxonomy\Entity\Term
45 * The new taxonomy term object.
47 public function createTerm(Vocabulary $vocabulary, $values = []) {
48 $filter_formats = filter_formats();
49 $format = array_pop($filter_formats);
50 $term = Term::create($values + [
51 'name' => $this->randomMachineName(),
53 'value' => $this->randomMachineName(),
54 // Use the first available text format.
55 'format' => $format->id(),
57 'vid' => $vocabulary->id(),
58 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,