You are here

public function ReferenceWidgetTest::testIsApplicable in Select (or other) 8

Same name and namespace in other branches
  1. 8.3 Tests/src/Unit/ReferenceWidgetTest.php \Drupal\Tests\select_or_other\Unit\ReferenceWidgetTest::testIsApplicable()
  2. 4.x tests/src/Unit/ReferenceWidgetTest.php \Drupal\Tests\select_or_other\Unit\ReferenceWidgetTest::testIsApplicable()

Tests if the widget correctly determines if it is applicable.

File

tests/src/Unit/ReferenceWidgetTest.php, line 203

Class

ReferenceWidgetTest
Tests the form element implementation.

Namespace

Drupal\Tests\select_or_other\Unit

Code

public function testIsApplicable() {
  $entity_reference_selection = $this
    ->getMockBuilder('Drupal\\Core\\Entity\\EntityReferenceSelection\\SelectionPluginManager')
    ->disableOriginalConstructor()
    ->getMock();
  $entity_reference_selection
    ->expects($this
    ->exactly(4))
    ->method('getInstance')
    ->willReturnOnConsecutiveCalls($this
    ->getMockForAbstractClass('Drupal\\Core\\Entity\\EntityReferenceSelection\\SelectionInterface'), $this
    ->getMockForAbstractClass('Drupal\\Core\\Entity\\EntityReferenceSelection\\SelectionWithAutocreateInterface'), $this
    ->getMockForAbstractClass('Drupal\\Core\\Entity\\EntityReferenceSelection\\SelectionInterface'), $this
    ->getMockForAbstractClass('Drupal\\Core\\Entity\\EntityReferenceSelection\\SelectionWithAutocreateInterface'));
  $this
    ->registerServiceWithContainerMock('plugin.manager.entity_reference_selection', $entity_reference_selection);
  $definition = $this
    ->getMockBuilder('Drupal\\Core\\Field\\FieldDefinitionInterface')
    ->getMockForAbstractClass();
  $definition
    ->expects($this
    ->exactly(4))
    ->method('getSettings')
    ->willReturnOnConsecutiveCalls([], [], [
    'handler_settings' => [
      'auto_create' => TRUE,
    ],
  ], [
    'handler_settings' => [
      'auto_create' => TRUE,
    ],
  ]);

  /** @var \Drupal\Core\Field\FieldDefinitionInterface $definition */
  $this
    ->assertFalse(ReferenceWidget::isApplicable($definition));
  $this
    ->assertFalse(ReferenceWidget::isApplicable($definition));
  $this
    ->assertFalse(ReferenceWidget::isApplicable($definition));
  $this
    ->assertTrue(ReferenceWidget::isApplicable($definition));
}