You are here

protected function SliderIntegrationTest::createIntegerField in Facets 8

Create integer field.

1 call to SliderIntegrationTest::createIntegerField()
SliderIntegrationTest::testSliderWidget in modules/facets_range_widget/tests/src/Functional/SliderIntegrationTest.php
Tests slider widget.

File

modules/facets_range_widget/tests/src/Functional/SliderIntegrationTest.php, line 86

Class

SliderIntegrationTest
Tests the overall functionality of the Facets admin UI.

Namespace

Drupal\Tests\facets_range_widget\Functional

Code

protected function createIntegerField() {
  $index = $this
    ->getIndex();

  // Create integer field.
  $field_name = 'field_integer';
  $field_storage = FieldStorageConfig::create([
    'field_name' => $field_name,
    'entity_type' => 'entity_test_mulrev_changed',
    'type' => 'integer',
  ]);
  $field_storage
    ->save();
  $field = FieldConfig::create([
    'field_storage' => $field_storage,
    'bundle' => 'item',
  ]);
  $field
    ->save();

  // Create the field for search api.
  $intfield = new Field($index, $field_name);
  $intfield
    ->setType('integer');
  $intfield
    ->setPropertyPath($field_name);
  $intfield
    ->setDatasourceId('entity:entity_test_mulrev_changed');
  $intfield
    ->setLabel('IntegerField');

  // Add to field to the index.
  $index
    ->addField($intfield);
  $index
    ->save();
  $this
    ->indexItems($this->indexId);

  // Add new entities.
  $entity_test_storage = \Drupal::entityTypeManager()
    ->getStorage('entity_test_mulrev_changed');
  for ($i = 1; $i < 8; $i++) {
    $entity_test_storage
      ->create([
      'name' => 'foo bar baz ' . $i,
      'body' => 'test ' . $i . ' test',
      'type' => 'item',
      'keywords' => [
        'orange',
      ],
      'category' => 'item_category',
      'field_integer' => (bool) $i % 2 ? $i : $i + 1,
    ])
      ->save();
  }

  // Index all the items.
  $this
    ->indexItems($this->indexId);
}