diff --git a/src/Tests/ProcessorIntegrationTest.php b/src/Tests/ProcessorIntegrationTest.php index bd91153..27120e5 100644 --- a/src/Tests/ProcessorIntegrationTest.php +++ b/src/Tests/ProcessorIntegrationTest.php @@ -283,35 +283,42 @@ public function checkAggregatedFieldsIntegration() { * Tests the UI for the "Content access" processor. */ public function checkContentAccessIntegration() { - $this->checkContentAccessPreIndexSave(); $this->enableProcessor('content_access'); - $this->checkContentAccessPreIndexSave(); - } - /** - * Tests the preIndexSave() for the "Content access" processor. - */ - public function checkContentAccessPreIndexSave() { + // Ensure the fields required for the "Content access" processor are now + // indexed. $index = $this->loadIndex(); $index->save(); - $processors = $index->getProcessors(); - $content_access_fields = [ - 'status' => 'boolean', - 'uid' => 'integer', - 'node_grants' => 'string', - ]; - $available_field = $index->getFields(); - $available_ac_fields = array_intersect_key($available_field, $content_access_fields); - if (!isset($processors['content_access'])) { - $this->assertTrue(is_array($available_ac_fields) && empty($available_ac_fields), 'There is no access control fields in index.'); - } - else { - $this->assertTrue(is_array($available_ac_fields) && !empty($available_ac_fields), 'There is access control fields available in index.'); - foreach ($content_access_fields as $field => $type) { - $field_message = new FormattableMarkup('Field @field has type @type.', ['@field' => $field, '@type' => $type]); - $this->assertTrue($available_field[$field]->getType() == $type, $field_message); + $content_access_fields = array( + 'status' => array( + 'datasource_id' => 'entity:node', + 'property_path' => 'status', + 'type' => 'boolean', + 'indexed_locked' => TRUE, + 'type_locked' => TRUE, + ), + 'uid' => array( + 'datasource_id' => 'entity:node', + 'property_path' => 'uid', + 'type' => 'integer', + 'indexed_locked' => TRUE, + 'type_locked' => TRUE, + ), + 'node_grants' => array( + 'property_path' => 'search_api_node_grants', + 'type' => 'string', + 'indexed_locked' => TRUE, + 'type_locked' => TRUE, + 'hidden' => TRUE, + ), + ); + $index_fields = $index->getFields(); + foreach ($content_access_fields as $field_id => $settings) { + if ($this->assertTrue(!empty($index_fields[$field_id]), "Field $field_id (required by \"Content access\" processor) is present.")) { + $field_settings = $index_fields[$field_id]->getSettings(); + unset($field_settings['label'], $field_settings['dependencies']); + $this->assertEqual($settings, $field_settings, "Field $field_id has the correct settings."); } - $this->assertTrue($available_field['node_grants']->isHidden(), 'Field node_grants is hidden'); } } @@ -327,91 +334,6 @@ public function checkHighlightIntegration() { 'suffix' => '', ); $this->editSettingsForm($configuration, 'highlight'); - $this->checkProcessorPreIndexSave('highlight', 'exclude_fields'); - } - - /** - * Tests for preIndexSave() method. - * - * Used for the "Highlight" processor test and for - * \Drupal\search_api\Processor\FieldsProcessorPluginBase::preIndexSave. - * - * @param string $processor_name - * Processor name. - * @param string $parameter - * Processor configuration parameter name. - */ - public function checkProcessorPreIndexSave($processor_name, $parameter) { - $index = $this->loadIndex(); - $index->save(); - - $html_ids = [ - 'highlight' => 'edit-processors-highlight-settings-exclude-fields-body', - 'stopwords' => 'edit-processors-stopwords-settings-fields-body' - ]; - - // Check if there is a fulltext field is not available in the index via API. - $fulltext_fields = $index->getFulltextFields(); - $this->assertEqual($fulltext_fields, [], 'There is no fulltext fields in index via API.'); - - // Check if there is a fulltext field is not available in the index via - // user interface. - $this->loadProcessorsTab(); - $rows = $this->xpath('//*[@id="' . $html_ids[$processor_name] . '"]'); - $this->assertTrue(is_array($rows) && empty($rows), 'There is no fulltext fields in index via user interface.'); - - // Add the body field into index. - $body_field = new Field($index, 'body'); - $body_field->setType('text'); - $body_field->setPropertyPath('body'); - $body_field->setDatasourceId('entity:node'); - $body_field->setLabel('Body'); - $index->addField($body_field); - $index->save(); - - // Check if there is a fulltext field is available in the index via user - // interface. - $this->loadProcessorsTab(TRUE); - $rows = $this->xpath('//*[@id="' . $html_ids[$processor_name] . '"]'); - $field_message = new FormattableMarkup('Body field listed on @processor processor config form via user interface.', ['@processor' => $processor_name]); - $this->assertTrue(is_array($rows) && !empty($rows), $field_message); - - $processor = $index->getProcessor($processor_name); - - // Check if there is a fulltext field is available in the index via API. - $conf = $processor->getConfiguration(); - $conf[$parameter] = ['body']; - $processor->setConfiguration($conf); - $index->save(); - $post_save_conf = $processor->getConfiguration(); - $field_message = new FormattableMarkup('Body field is available and selected in @processor processor config via API.', ['@processor' => $processor_name]); - $this->assertEqual($conf[$parameter], $post_save_conf[$parameter], $field_message); - - // Check if there is a fulltext field is available in the index via user - // interface and it excluded. - $this->loadProcessorsTab(TRUE); - $rows = $this->xpath('//*[@id="' . $html_ids[$processor_name] . '" and @checked]'); - $field_message = new FormattableMarkup('Body field is available and selected in @processor processor config via user interface.', ['@processor' => $processor_name]); - $this->assertTrue(is_array($rows) && !empty($rows), $field_message); - - // When the field is renamed it should be renamed in the - // processor configuration also. - $index->renameField('body', 'body1'); - $index->save(); - $post_save_conf = $processor->getConfiguration(); - $field_message = new FormattableMarkup('Renamed Body field is available and selected in @processor processor config via API.', ['@processor' => $processor_name]); - $this->assertEqual($post_save_conf[$parameter], ['body1'], $field_message); - - // Check if there is a renamed fulltext field is available in the index - // via user interface and it excluded. - $this->loadProcessorsTab(TRUE); - $rows = $this->xpath('//*[@id="' . $html_ids[$processor_name] . '1" and @checked]'); - $field_message = new FormattableMarkup('Renamed Body field is available and selected in @processor processor config via user interface.', ['@processor' => $processor_name]); - $this->assertTrue(is_array($rows) && !empty($rows), $field_message); - - // Cleanup. - $index->removeField('body1'); - $index->save(); } /** @@ -547,9 +469,6 @@ public function checkStopWordsIntegration() { 'stopwords' => 'the', ); $this->editSettingsForm($configuration, 'stopwords', $form_values); - - // Check FieldsProcessorPluginBase::PreIndexSave(). - $this->checkProcessorPreIndexSave('stopwords', 'fields'); } /**