function FieldItemListTest::testDefaultValuesForm

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Field/FieldItemListTest.php \Drupal\Tests\Core\Field\FieldItemListTest::testDefaultValuesForm()
  2. 8.9.x core/tests/Drupal/Tests/Core/Field/FieldItemListTest.php \Drupal\Tests\Core\Field\FieldItemListTest::testDefaultValuesForm()
  3. 10 core/tests/Drupal/Tests/Core/Field/FieldItemListTest.php \Drupal\Tests\Core\Field\FieldItemListTest::testDefaultValuesForm()

@covers ::defaultValuesForm

File

core/tests/Drupal/Tests/Core/Field/FieldItemListTest.php, line 295

Class

FieldItemListTest
@coversDefaultClass \Drupal\Core\Field\FieldItemList @group Field

Namespace

Drupal\Tests\Core\Field

Code

public function testDefaultValuesForm() : void {
    $field_definition = $this->createMock(FieldDefinitionInterface::class);
    $field_definition->expects($this->any())
        ->method('getType')
        ->willReturn('field_type');
    
    /** @var \Drupal\Core\Field\FieldItemList|\PHPUnit\Framework\MockObject\MockObject $field_list */
    $field_list = $this->getMockBuilder(FieldItemList::class)
        ->onlyMethods([
        'defaultValueWidget',
    ])
        ->setConstructorArgs([
        $field_definition,
    ])
        ->getMock();
    $field_list->expects($this->any())
        ->method('defaultValueWidget')
        ->willReturn(NULL);
    $form = [];
    $form_state = new FormState();
    $string_translation = $this->getStringTranslationStub();
    $field_list->setStringTranslation($string_translation);
    $this->assertEquals('No widget available for: <em class="placeholder">field_type</em>.', $field_list->defaultValuesForm($form, $form_state)['#markup']);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.