You are here

protected function DataFetcherAutocompleteTest::setUp in Typed Data API enhancements 8

Overrides KernelTestBase::setUp

File

tests/src/Kernel/DataFetcherAutocompleteTest.php, line 57

Class

DataFetcherAutocompleteTest
Tests that data fetcher autocomplete function works correctly.

Namespace

Drupal\Tests\typed_data\Kernel

Code

protected function setUp() : void {
  parent::setUp();
  $this
    ->installEntitySchema('user');
  $this
    ->installEntitySchema('node');

  // The global CurrentUserContext doesn't work properly without a
  // fully-installed user module.
  // @see https://www.drupal.org/project/rules/issues/2989417
  $this->container
    ->get('module_handler')
    ->loadInclude('user', 'install');
  user_install();
  $this->dataFetcher = $this->container
    ->get('typed_data.data_fetcher');
  $this->typedDataManager = $this->container
    ->get('typed_data_manager');
  $entity_type_manager = $this->container
    ->get('entity_type.manager');
  $entity_type_manager
    ->getStorage('node_type')
    ->create([
    'type' => 'page',
  ])
    ->save();

  // Create a multi-value integer field for testing.
  FieldStorageConfig::create([
    'field_name' => 'field_integer',
    'type' => 'integer',
    'entity_type' => 'node',
    'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
  ])
    ->save();
  FieldConfig::create([
    'field_name' => 'field_integer',
    'entity_type' => 'node',
    'bundle' => 'page',
  ])
    ->save();
  $node = $entity_type_manager
    ->getStorage('node')
    ->create([
    'title' => 'test',
    'type' => 'page',
  ]);
  $this->nodeDefinition = $node
    ->getTypedData()
    ->getDataDefinition();
  $contexts = $this->container
    ->get('context.repository')
    ->getAvailableContexts();
  $this->globalNodeDefinition = $contexts['@node.node_route_context:node']
    ->getContextDefinition()
    ->getDataDefinition();
}