Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / taxonomy / src / Tests / TaxonomyTestTrait.php
1 <?php
2
3 namespace Drupal\taxonomy\Tests;
4
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);
6
7 use Drupal\Core\Language\LanguageInterface;
8 use Drupal\taxonomy\Entity\Vocabulary;
9 use Drupal\taxonomy\Entity\Term;
10
11 /**
12  * Provides common helper methods for Taxonomy module tests.
13  *
14  * @deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0.
15  * Use \Drupal\Tests\taxonomy\Functional\TaxonomyTestTrait
16  */
17 trait TaxonomyTestTrait {
18
19   /**
20    * Returns a new vocabulary with random properties.
21    */
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),
30     ]);
31     $vocabulary->save();
32     return $vocabulary;
33   }
34
35   /**
36    * Returns a new term with random properties in vocabulary $vid.
37    *
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.
43    *
44    * @return \Drupal\taxonomy\Entity\Term
45    *   The new taxonomy term object.
46    */
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(),
52       'description' => [
53         'value' => $this->randomMachineName(),
54         // Use the first available text format.
55         'format' => $format->id(),
56       ],
57       'vid' => $vocabulary->id(),
58       'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
59     ]);
60     $term->save();
61     return $term;
62   }
63
64 }