private function MetatagHelperTrait::createTerm in Metatag 8
Create a taxonomy term.
Parameters
array $values: Items passed to the term. Requires the 'vid' element.
Return value
Drupal\taxonomy\Entity\Term A fully formatted term object.
1 call to MetatagHelperTrait::createTerm()
- DefaultTags::testTerm in tests/
src/ Functional/ DefaultTags.php - Test the default values for a Term entity.
File
- tests/
src/ Functional/ MetatagHelperTrait.php, line 133
Class
- MetatagHelperTrait
- Misc helper functions for the automated tests.
Namespace
Drupal\Tests\metatag\FunctionalCode
private function createTerm(array $values = []) {
// Populate defaults array.
$values += [
'description' => [
[
'value' => $this
->randomMachineName(32),
'format' => filter_default_format(),
],
],
'name' => $this
->randomMachineName(8),
];
$term = Term::create($values);
$status = $term
->save();
if ($this instanceof \PHPUnit_Framework_TestCase) {
$this
->assertSame($status, SAVED_NEW, (new FormattableMarkup('Created term %name.', [
'%name' => $term
->label(),
]))
->__toString());
}
else {
self::assertEquals($status, SAVED_NEW, (new FormattableMarkup('Created term %name.', [
'%name' => $term
->label(),
]))
->__toString());
}
return $term;
}