function FieldConfigEntityUnitTest::testToArray

Same name and namespace in other branches
  1. 9 core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php \Drupal\Tests\field\Unit\FieldConfigEntityUnitTest::testToArray()
  2. 8.9.x core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php \Drupal\Tests\field\Unit\FieldConfigEntityUnitTest::testToArray()
  3. 10 core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php \Drupal\Tests\field\Unit\FieldConfigEntityUnitTest::testToArray()

@covers ::toArray

File

core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php, line 226

Class

FieldConfigEntityUnitTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21field%21src%21Entity%21FieldConfig.php/class/FieldConfig/11.x" title="Defines the Field entity." class="local">\Drupal\field\Entity\FieldConfig</a> @group field

Namespace

Drupal\Tests\field\Unit

Code

public function testToArray() : void {
    $field = new FieldConfig([
        'field_name' => $this->fieldStorage
            ->getName(),
        'entity_type' => 'test_entity_type',
        'bundle' => 'test_bundle',
        'field_type' => 'test_field',
    ], $this->entityTypeId);
    $expected = [
        'id' => 'test_entity_type.test_bundle.field_test',
        'uuid' => NULL,
        'status' => TRUE,
        'langcode' => 'en',
        'field_name' => 'field_test',
        'entity_type' => 'test_entity_type',
        'bundle' => 'test_bundle',
        'label' => '',
        'description' => '',
        'required' => FALSE,
        'default_value' => [],
        'default_value_callback' => '',
        'settings' => [],
        'dependencies' => [],
        'field_type' => 'test_field',
    ];
    $this->entityTypeManager
        ->expects($this->any())
        ->method('getDefinition')
        ->with($this->entityTypeId)
        ->willReturn($this->entityType);
    $this->entityType
        ->expects($this->once())
        ->method('getKey')
        ->with('id')
        ->willReturn('id');
    $this->entityType
        ->expects($this->once())
        ->method('getPropertiesToExport')
        ->with('test_entity_type.test_bundle.field_test')
        ->willReturn(array_combine(array_keys($expected), array_keys($expected)));
    $export = $field->toArray();
    $this->assertEquals($expected, $export);
}

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