Same filename and directory in other branches
- 8.9.x core/modules/taxonomy/tests/src/Traits/TaxonomyTestTrait.php
- 9 core/modules/taxonomy/tests/src/Traits/TaxonomyTestTrait.php
Namespace
Drupal\Tests\taxonomy\Traits
File
core/modules/taxonomy/tests/src/Traits/TaxonomyTestTrait.php
View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\taxonomy\Traits;
use Drupal\Core\Language\LanguageInterface;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\TermInterface;
use Drupal\taxonomy\VocabularyInterface;
trait TaxonomyTestTrait {
public function createVocabulary(array $values = []) {
$values += [
'name' => $this
->randomMachineName(),
'description' => $this
->randomMachineName(),
'vid' => $this
->randomMachineName(),
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
'weight' => mt_rand(0, 10),
];
$vocabulary = Vocabulary::create($values);
$vocabulary
->save();
return $vocabulary;
}
public function createTerm(VocabularyInterface $vocabulary, $values = []) {
$term = Term::create($values + [
'name' => $this
->randomMachineName(),
'description' => [
'value' => $this
->randomMachineName(),
'format' => filter_fallback_format(),
],
'vid' => $vocabulary
->id(),
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
]);
$term
->save();
return $term;
}
protected function createTaxonomyTermRevision(TermInterface $term) {
$term
->set('name', $this
->randomMachineName());
$term
->setNewRevision();
$term
->save();
return $term;
}
}
Traits