You are here

public function GroupingBuildFormTest::testBuildForm in Search API Grouping 8

Test if the form of the processor is built correctly.

File

tests/src/Unit/GroupingBuildFormTest.php, line 50

Class

GroupingBuildFormTest
Test the getSupportedFields method.

Namespace

Drupal\Tests\search_api_grouping\Unit

Code

public function testBuildForm() {
  $form_state = $this
    ->getMockBuilder(FormStateInterface::class)
    ->disableOriginalConstructor()
    ->getMock();
  $form = [];
  $field = $this
    ->getMockBuilder(FieldInterface::class)
    ->disableOriginalConstructor()
    ->getMock();
  $field
    ->method('getType')
    ->willReturn('string');
  $field
    ->method('getLabel')
    ->willReturn('Author');
  $fields[] = $field;
  $this->index = $this
    ->getMockBuilder(IndexInterface::class)
    ->disableOriginalConstructor()
    ->getMock();
  $this->index
    ->method('getFields')
    ->willReturn($fields);
  $this->processor
    ->setIndex($this->index);
  $form = $this->processor
    ->buildConfigurationForm($form, $form_state);
  $this
    ->assertEquals([], $form['grouping_fields']['#default_value']);
  $this
    ->assertEquals([], $form['group_sort']['#default_value']);
  $this
    ->assertEquals('asc', $form['group_sort_direction']['#default_value']);
  $this
    ->assertFalse($form['truncate']['#default_value']);
  $this
    ->assertEquals(1, $form['group_limit']['#default_value']);
}