You are here

protected function EntityViewsDataTest::setUp in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Unit/EntityViewsDataTest.php \Drupal\Tests\views\Unit\EntityViewsDataTest::setUp()

Overrides UnitTestCase::setUp

File

core/modules/views/tests/src/Unit/EntityViewsDataTest.php, line 93
Contains \Drupal\Tests\views\Unit\EntityViewsDataTest.

Class

EntityViewsDataTest
@coversDefaultClass \Drupal\views\EntityViewsData @group Views

Namespace

Drupal\Tests\views\Unit

Code

protected function setUp() {
  $this->entityStorage = $this
    ->getMockBuilder('Drupal\\Core\\Entity\\Sql\\SqlContentEntityStorage')
    ->disableOriginalConstructor()
    ->getMock();
  $this->entityTypeManager = $this
    ->createMock(EntityTypeManagerInterface::class);
  $this->entityFieldManager = $this
    ->createMock(EntityFieldManagerInterface::class);
  $typed_data_manager = $this
    ->createMock(TypedDataManagerInterface::class);
  $typed_data_manager
    ->expects($this
    ->any())
    ->method('createDataDefinition')
    ->willReturn($this
    ->createMock('Drupal\\Core\\TypedData\\DataDefinitionInterface'));
  $typed_data_manager
    ->expects($this
    ->any())
    ->method('getDefinition')
    ->will($this
    ->returnValueMap([
    'entity:user' => [
      'class' => '\\Drupal\\Core\\TypedData\\DataDefinitionInterface',
    ],
    'field_item:string_long' => [
      'class' => '\\Drupal\\Core\\Field\\Plugin\\Field\\FieldType\\StringLongItem',
    ],
  ]));
  $this->baseEntityType = new TestEntityType([
    'base_table' => 'entity_test',
    'id' => 'entity_test',
    'label' => 'Entity test',
    'entity_keys' => [
      'uuid' => 'uuid',
      'id' => 'id',
      'langcode' => 'langcode',
      'bundle' => 'type',
      'revision' => 'revision_id',
    ],
    'provider' => 'entity_test',
    'list_cache_contexts' => [
      'entity_test_list_cache_context',
    ],
  ]);
  $this->translationManager = $this
    ->getStringTranslationStub();
  $this->baseEntityType
    ->setStringTranslation($this->translationManager);
  $this->moduleHandler = $this
    ->createMock('Drupal\\Core\\Extension\\ModuleHandlerInterface');
  $this->viewsData = new TestEntityViewsData($this->baseEntityType, $this->entityStorage, $this->entityTypeManager, $this->moduleHandler, $this->translationManager, $this->entityFieldManager);
  $field_type_manager = $this
    ->getMockBuilder('Drupal\\Core\\Field\\FieldTypePluginManager')
    ->disableOriginalConstructor()
    ->getMock();
  $field_type_manager
    ->expects($this
    ->any())
    ->method('getDefaultStorageSettings')
    ->willReturn([]);
  $field_type_manager
    ->expects($this
    ->any())
    ->method('getDefaultFieldSettings')
    ->willReturn([]);
  $state = $this
    ->prophesize(StateInterface::class);
  $state
    ->get(Argument::any(), [])
    ->willReturn([]);
  $container = new ContainerBuilder();
  $container
    ->set('plugin.manager.field.field_type', $field_type_manager);
  $container
    ->set('entity_type.manager', $this->entityTypeManager);
  $container
    ->set('entity_field.manager', $this->entityFieldManager);
  $container
    ->set('typed_data_manager', $typed_data_manager);
  $container
    ->set('state', $state
    ->reveal());
  \Drupal::setContainer($container);
}