protected function ReferenceWidgetTest::prepareFormElementMock in Select (or other) 8
Same name and namespace in other branches
- 8.3 Tests/src/Unit/ReferenceWidgetTest.php \Drupal\Tests\select_or_other\Unit\ReferenceWidgetTest::prepareFormElementMock()
- 4.x tests/src/Unit/ReferenceWidgetTest.php \Drupal\Tests\select_or_other\Unit\ReferenceWidgetTest::prepareFormElementMock()
1 call to ReferenceWidgetTest::prepareFormElementMock()
- ReferenceWidgetTest::testFormElement in tests/
src/ Unit/ ReferenceWidgetTest.php - Test if formElement() adds the expected information.
File
- tests/
src/ Unit/ ReferenceWidgetTest.php, line 30
Class
- ReferenceWidgetTest
- Tests the form element implementation.
Namespace
Drupal\Tests\select_or_other\UnitCode
protected function prepareFormElementMock($target_type = 'entity', $tested_class_name = FALSE) {
$methods = [
'getColumn',
'getOptions',
'getSelectedOptions',
'getFieldSetting',
'getAutoCreateBundle',
];
// Get the mockBuilder.
if ($tested_class_name) {
$builder = $this
->getMockBuilder($tested_class_name);
}
else {
$builder = $this->mockBuilder;
}
// Configure the mockBuilder.
$field_definition = $this
->getMockForAbstractClass('\\Drupal\\Core\\Field\\FieldDefinitionInterface');
$field_definition
->expects($this
->any())
->method('getFieldStorageDefinition')
->willReturn($this
->getMockForAbstractClass('Drupal\\Core\\Field\\FieldStorageDefinitionInterface'));
$constructor_arguments = [
'',
'',
$field_definition,
[],
[],
];
$builder
->setConstructorArgs($constructor_arguments)
->setMethods($methods);
if ($tested_class_name) {
$class = new \ReflectionClass($tested_class_name);
$mock = $class
->isAbstract() ? $builder
->getMockForAbstractClass() : $builder
->getMock();
}
else {
$mock = $builder
->getMock();
}
// Configure the mock.
$mock
->method('getColumn')
->willReturn('column');
$mock
->method('getOptions')
->willReturn([]);
$mock
->method('getSelectedOptions')
->willReturn([]);
$mock
->method('getFieldSetting')
->willReturnOnConsecutiveCalls($target_type, 'some_handler', [], $target_type);
$mock
->method('getAutoCreateBundle')
->willReturn('autoCreateBundle');
return $mock;
}