You are here

public function EntityDisplayTraitTest::testGetWidgetSettings in CCK Select Other 8

Asserts that select other widget settings are returned or not.

@dataProvider getWidgetSettingsProvider().

Parameters

string $plugin_id: The plugin ID.

array $expected: The expected result.

File

tests/src/Unit/EntityDisplayTraitTest.php, line 129

Class

EntityDisplayTraitTest
Tests the entity display trait.

Namespace

Drupal\Tests\cck_select_other\Unit

Code

public function testGetWidgetSettings($plugin_id, array $expected) {

  // Mock Field plugin settings.
  $fieldSettings = $this
    ->getMockBuilder('\\Drupal\\Core\\Field\\PluginSettingsInterface')
    ->disableOriginalConstructor()
    ->getMock();
  $fieldSettings
    ->expects($this
    ->any())
    ->method('getPluginId')
    ->willReturn($plugin_id);
  $fieldSettings
    ->expects($this
    ->any())
    ->method('getSettings')
    ->willReturn($expected);

  // Mock Entity Form Display.
  $entityDisplay = $this
    ->getMockBuilder('\\Drupal\\Core\\Entity\\Display\\EntityDisplayInterface')
    ->disableOriginalConstructor()
    ->getMock();
  $entityDisplay
    ->expects($this
    ->any())
    ->method('getRenderer')
    ->with('field_list')
    ->willReturn($fieldSettings);

  // Mock the entity storage interface.
  $entityStorage = $this
    ->getMockBuilder('\\Drupal\\Core\\Entity\\EntityStorageInterface')
    ->disableOriginalConstructor()
    ->getMock();
  $entityStorage
    ->expects($this
    ->any())
    ->method('loadByProperties')
    ->with([
    'targetEntityType' => 'entity_test',
  ])
    ->willReturn([
    'entity_test.display.mock' => $entityDisplay,
  ]);

  // Mock entity manager methods.
  $this->entityManager
    ->expects($this
    ->any())
    ->method('getStorage')
    ->with('entity_form_display')
    ->willReturn($entityStorage);

  // Mock the definition.
  $definition = $this
    ->getMockBuilder('\\Drupal\\Core\\Field\\FieldDefinitionInterface')
    ->disableOriginalConstructor()
    ->getMock();
  $definition
    ->expects($this
    ->any())
    ->method('getTargetEntityTypeId')
    ->willReturn('entity_test');
  $definition
    ->expects($this
    ->any())
    ->method('getName')
    ->willReturn('field_list');
  $this
    ->assertEquals($expected, $this->mock
    ->getWidgetSettings($definition));
}