You are here

public function TranslateEntityProcessorTest::facetDataProvider in Facets 8

Provides mock data for the tests in this class.

We create a data definition for both entity reference and entity reference revision field types so we can test with both the label tranformation.

Return value

array The facet and results test data.

File

tests/src/Unit/Plugin/processor/TranslateEntityProcessorTest.php, line 79

Class

TranslateEntityProcessorTest
Unit test for processor.

Namespace

Drupal\Tests\facets\Unit\Plugin\processor

Code

public function facetDataProvider() {
  $data = [];
  foreach ([
    'entity_reference',
    'entity_reference_revision',
  ] as $field_type) {

    // Mock the typed data chain.
    $target_field_definition = $this
      ->createMock(EntityDataDefinition::class);
    $target_field_definition
      ->expects($this
      ->once())
      ->method('getEntityTypeId')
      ->willReturn('entity_type');
    $property_definition = $this
      ->createMock(DataReferenceDefinitionInterface::class);
    $property_definition
      ->expects($this
      ->any())
      ->method('getTargetDefinition')
      ->willReturn($target_field_definition);
    $property_definition
      ->expects($this
      ->any())
      ->method('getDataType')
      ->willReturn($field_type);
    $data_definition = $this
      ->createMock(ComplexDataDefinitionInterface::class);
    $data_definition
      ->expects($this
      ->any())
      ->method('getPropertyDefinition')
      ->willReturn($property_definition);
    $data_definition
      ->expects($this
      ->any())
      ->method('getPropertyDefinitions')
      ->willReturn([
      $property_definition,
    ]);

    // Create the actual facet.
    $facet = $this
      ->getMockBuilder(Facet::class)
      ->disableOriginalConstructor()
      ->getMock();
    $facet
      ->expects($this
      ->any())
      ->method('getDataDefinition')
      ->willReturn($data_definition);

    // Add a field identifier.
    $facet
      ->expects($this
      ->any())
      ->method('getFieldIdentifier')
      ->willReturn('testfield');
    $results = [
      new Result($facet, 2, 2, 5),
    ];
    $facet
      ->setResults($results);
    $data[$field_type][] = $facet;
    $data[$field_type][] = $results;
  }
  return $data;
}