public function RealisticDummyContentTermReferenceFieldTest::testGetTid in Realistic Dummy Content 7.2
Same name and namespace in other branches
- 8.2 api/src/test/includes/RealisticDummyContentTermReferenceFieldTest.php \Drupal\realistic_dummy_content_api\Test\RealisticDummyContentTermReferenceFieldTest::testGetTid()
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/
src/ test/ includes/ RealisticDummyContentTermReferenceFieldTest.php, line 58
Class
- RealisticDummyContentTermReferenceFieldTest
- Tests for ...\includes\RealisticDummyContentTermReferenceField.
Namespace
Drupal\realistic_dummy_content_api\TestCode
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(array(
$this,
'callbackVocabularyMachineName',
)));
$object
->method('taxonomyLoadTree')
->will($this
->returnCallback(array(
$this,
'callbackTaxonomyLoadTree',
)));
$object
->method('termId')
->will($this
->returnCallback(array(
$this,
'callbackTermId',
)));
$object
->method('termName')
->will($this
->returnCallback(array(
$this,
'callbackTermId',
)));
if ($expect_exception) {
$this
->expectException(\Exception::class);
}
$result = $object
->getTid($name);
$this
->assertTrue($result == $expected, $message);
}