diff --git a/tests/src/Functional/AggregatedFieldTest.php b/tests/src/Functional/AggregatedFieldTest.php index c0e2c8e..b049319 100644 --- a/tests/src/Functional/AggregatedFieldTest.php +++ b/tests/src/Functional/AggregatedFieldTest.php @@ -4,6 +4,7 @@ use Drupal\entity_test\Entity\EntityTestMulRevChanged; use Drupal\search_api\Entity\Index; +use Drupal\search_api\Plugin\search_api\processor\Property\AggregatedFieldProperty; use Drupal\search_api\Utility\Utility; use Drupal\user\Entity\User; @@ -35,15 +36,15 @@ public function setUp() { foreach ([7 => 'Owl', 8 => 'Robin', 9 => 'Hawk'] as $i => $value) { $this->users[$i] = User::create([ 'uid' => $i, - 'name' => "User $i", + 'name' => "User $value", ]); $this->users[$i]->save(); $this->entities[$i] = EntityTestMulRevChanged::create([ 'id' => $i, 'user_id' => $i, - 'name' => "Test entity $i name", - 'body' => "Test entity $i body", + 'name' => "Test entity $value name", + 'body' => "Test entity $value body", ]); $this->entities[$i]->save(); } @@ -53,9 +54,16 @@ public function setUp() { /** @var \Drupal\search_api\IndexInterface $index */ $index = Index::load($this->indexId); + + // Add the user as a datasource. $index->addDatasource($plugin_creation_helper->createDatasourcePlugin($index, 'entity:user')); - $index->addProcessor($plugin_creation_helper->createProcessorPlugin($index, 'aggregated_field')); - $field = $fields_helper->createField($index, 'aggregated_field', ['property_path' => 'aggregated_field']); + + // Create the aggregated field property. + $property = AggregatedFieldProperty::create('string'); + + // Add and configure the aggregated field. + $field = $fields_helper->createFieldFromProperty($index, $property, NULL, 'aggregated_field', 'aggregated_field', 'string'); + $field->setLabel('Aggregated field'); $field->setConfiguration([ 'type' => 'union', 'fields' => [ @@ -63,12 +71,11 @@ public function setUp() { Utility::createCombinedId('entity:user', 'name'), ], ]); - $field->setDataDefinition(); $index->addField($field); $index->save(); - $this->drupalGet('admin/config/search/search-api/index/'); - $this->indexItems($this->indexId); + // Index all items, users and content. + $this->assertEquals(16, $this->indexItems($this->indexId)); } /** @@ -91,10 +98,11 @@ public function testAggregatedField() { 'facet_source_configs[search_api:views_page__search_api_test_view__page_1][field_identifier]' => 'aggregated_field', ]; - // Try filling out the form, but without having filled in a name for the - // facet to test for form errors. + // Try filling out the form, and configure it to use the aggregated field. $this->drupalPostForm(NULL, ['facet_source_id' => 'search_api:views_page__search_api_test_view__page_1'], 'Configure facet source'); $this->drupalPostForm(NULL, $form_values, 'Save'); + + // Check that nothing breaks. $this->assertSession()->statusCodeEquals(200); }