You are here

public function ListWidgetTest::testGetOptions in Select (or other) 8

Same name and namespace in other branches
  1. 4.x tests/src/Unit/ListWidgetTest.php \Drupal\Tests\select_or_other\Unit\ListWidgetTest::testGetOptions()

Test if defaultSettings() returns the correct keys.

File

tests/src/Unit/ListWidgetTest.php, line 31

Class

ListWidgetTest
Tests the form element implementation.

Namespace

Drupal\Tests\select_or_other\Unit

Code

public function testGetOptions() {
  $expected = [
    1,
    2,
  ];
  $options_provider = $this
    ->getMockForAbstractClass('Drupal\\Core\\TypedData\\OptionsProviderInterface');
  $options_provider
    ->method('getSettableOptions')
    ->willReturn($expected);
  $storage_definition = $this
    ->getMockForAbstractClass('Drupal\\Core\\Field\\FieldStorageDefinitionInterface');
  $storage_definition
    ->method('getOptionsProvider')
    ->willReturn($options_provider);
  $field_definition = $this
    ->getMockForAbstractClass('Drupal\\Core\\Field\\FieldDefinitionInterface');
  $field_definition
    ->method('getFieldStorageDefinition')
    ->willReturn($storage_definition);
  $constructor_arguments = [
    '',
    '',
    $field_definition,
    [],
    [],
  ];
  $mock = $this->mockBuilder
    ->setConstructorArgs($constructor_arguments)
    ->setMethods([
    'getColumn',
  ])
    ->getMock();
  $mock
    ->method('getColumn')
    ->willReturn([
    'column',
  ]);
  $get_options = new ReflectionMethod($mock, 'getOptions');
  $get_options
    ->setAccessible(TRUE);
  $options = $get_options
    ->invoke($mock, $this
    ->getMockForAbstractClass('Drupal\\Core\\Entity\\FieldableEntityInterface'));
  $this
    ->assertArrayEquals($expected, $options);
}