public function RealisticDummyContentTermReferenceFieldTest::testGetTid in Realistic Dummy Content 3.x
Test getTid()
@dataProvider providerGetTid
Parameters
string $message: A test message.
array $vocabularies: All vocabularies in the system.
array $field_info: Information about the current field.
bool $expect_exception: Whether or not we are expecting an exception.
string $name: The taxonomy name to pass to the function.
mixed $expected: The expected result.
File
- api/
tests/ src/ Unit/ includes/ RealisticDummyContentTermReferenceFieldTest.php, line 54
Class
- RealisticDummyContentTermReferenceFieldTest
- Tests for ...\includes\RealisticDummyContentTermReferenceField.
Namespace
Drupal\Tests\realistic_dummy_content_api\Unit\includesCode
public function testGetTid(string $message, array $vocabularies, array $field_info, bool $expect_exception, string $name, $expected) {
$object = $this
->getMockBuilder(RealisticDummyContentTermReferenceField::class)
->setMethods([
'getAllVocabularies',
'fieldInfoField',
'vocabularyMachineName',
'taxonomyLoadTree',
'termId',
'termName',
'newVocabularyTerm',
])
->disableOriginalConstructor()
->getMock();
$object
->method('getAllVocabularies')
->willReturn($vocabularies);
$object
->method('newVocabularyTerm')
->willReturn([
'id' => 'this-is-a-new-term',
]);
$object
->method('fieldInfoField')
->willReturn([
'settings' => [
'allowed_values' => $field_info,
],
]);
$object
->method('vocabularyMachineName')
->will($this
->returnCallback([
$this,
'callbackVocabularyMachineName',
]));
$object
->method('taxonomyLoadTree')
->will($this
->returnCallback([
$this,
'callbackTaxonomyLoadTree',
]));
$object
->method('termId')
->will($this
->returnCallback([
$this,
'callbackTermId',
]));
$object
->method('termName')
->will($this
->returnCallback([
$this,
'callbackTermId',
]));
if ($expect_exception) {
$this
->expectException(\Exception::class);
}
$result = $object
->getTid($name);
$this
->assertTrue($result == $expected, $message);
}