You are here

public function EntityDisplayTraitTest::testHasSelectOtherWidget in CCK Select Other 8

Assert that select other widget is detected on form displays.

@dataProvider hasSelectOtherWidgetProvider

Parameters

string $plugin_id: The plugin ID.

bool $expected: The expected result.

File

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

Class

EntityDisplayTraitTest
Tests the entity display trait.

Namespace

Drupal\Tests\cck_select_other\Unit

Code

public function testHasSelectOtherWidget($plugin_id, $expected) {

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

  // 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
    ->hasSelectOtherWidget($definition));
}