You are here

protected function SerializationTest::createTestField in Search API 8

Creates a field for testing purposes.

Parameters

string $id: (optional) The field ID (and property path).

string|null $datasource_id: (optional) The field's datasource ID.

Return value

\Drupal\search_api\Item\FieldInterface A test field.

2 calls to SerializationTest::createTestField()
SerializationTest::createTestItem in tests/src/Kernel/System/SerializationTest.php
Creates an item for testing purposes.
SerializationTest::testFieldSerialization in tests/src/Kernel/System/SerializationTest.php
Tests that serialization of fields works correctly.

File

tests/src/Kernel/System/SerializationTest.php, line 330

Class

SerializationTest
Tests that various classes can be properly serialized and/or cloned.

Namespace

Drupal\Tests\search_api\Kernel\System

Code

protected function createTestField($id = 'test', $datasource_id = NULL) {
  $field = new Field($this->index, $id);
  $field
    ->setDatasourceId($datasource_id);
  $field
    ->setPropertyPath($id);
  $field
    ->setLabel('Foo');
  $field
    ->setDescription('Bar');
  $field
    ->setType('float');
  $field
    ->setBoost(2);
  $field
    ->setIndexedLocked();
  $field
    ->setConfiguration([
    'foo' => 'bar',
    'test' => TRUE,
  ]);
  $field
    ->setValues([
    1,
    3,
    5,
  ]);
  return $field;
}