Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ACMS-1972: Fixing new search index field on field settings and storage page. #1642

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
*/
abstract class ContentTypeListTestBase extends ExistingSiteBase {

use AssertLinksTrait;
use SetBackendAvailabilityTrait;
use AssertLinksTrait, SetBackendAvailabilityTrait;

/**
* The machine name of the content type under test.
Expand Down Expand Up @@ -143,7 +142,7 @@ protected function setUp(): void {
'field_' . $this->nodeType . '_type' => $types[2],
'created' => $time++,
]);

\Drupal::getContainer()->get('search_api.post_request_indexing')->destruct();
apathak18 marked this conversation as resolved.
Show resolved Hide resolved
// Update additional field value.
$this->updateNodeFieldValues();
}
Expand All @@ -162,20 +161,20 @@ abstract protected function getView();
* @param string $langcode
* Langcode to visit tranlated page.
*/
abstract protected function visitListPage($langcode = NULL) : void;
abstract protected function visitListPage($langcode = NULL): void;

/**
* Update specific field value for nodes.
*/
protected function updateNodeFieldValues() : void {}
protected function updateNodeFieldValues(): void {}

/**
* Data provider for testing the listing page with different permissions.
*
* @return array[]
* Sets of arguments to pass to the test method.
*/
public function permissionProvider() : array {
public function permissionProvider(): array {
return [
'anonymous user' => [NULL],
// Search API is really stupid about node access, and does not properly
Expand Down Expand Up @@ -214,7 +213,6 @@ public function testListPage(array $permissions = NULL) {
$module_handler = $this->container->get('module_handler');
if ($module_handler->moduleExists('acquia_cms_search') && $module_handler->moduleExists('acquia_cms_site_studio')) {
$assert_session = $this->assertSession();

// Assert that all categories facets are available.
$assert_session->linkExists('Music (2)');
$assert_session->linkExists('Art (2)');
Expand Down Expand Up @@ -336,7 +334,7 @@ public function testFallback(array $permissions = NULL) {
/**
* {@inheritdoc}
*/
protected function getLinks() : array {
protected function getLinks(): array {
$links = $this->getSession()
->getPage()
->findAll('css', 'article a.card-link');
Expand All @@ -350,7 +348,7 @@ protected function getLinks() : array {
/**
* {@inheritdoc}
*/
protected function getExpectedLinks() : array {
protected function getExpectedLinks(): array {
$ids = $this->getQuery()->accessCheck(FALSE)->execute();

/** @var \Drupal\node\NodeInterface[] $content */
Expand All @@ -371,7 +369,7 @@ protected function getExpectedLinks() : array {
* An entity query object to find all published content of the type under
* test.
*/
protected function getQuery() : QueryInterface {
protected function getQuery(): QueryInterface {
return $this->container->get('entity_type.manager')
->getStorage('node')
->getQuery()
Expand Down
7 changes: 2 additions & 5 deletions modules/acquia_cms_search/acquia_cms_search.module
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ function _acquia_cms_search_add_category_facet(array $modules) {
* Implements hook_form_FORM_ID_alter().
*/
function acquia_cms_search_form_field_config_edit_form_alter(&$form, FormStateInterface $form_state) {

/** @var \Drupal\field_ui\Form\FieldConfigEditForm $field_config_form */
$field_config_form = $form_state->getFormObject();

Expand Down Expand Up @@ -224,8 +223,7 @@ function _acquia_cms_search_add_field_to_index_form_builder(string $entity_type,

if ($form_state->getValue('add_to_search_index')) {
$field_storage->setThirdPartySetting('acquia_cms_common', 'search_index', 'content')
->setThirdPartySetting('acquia_cms_common', 'search_label', $fieldConfig->getLabel())
->save();
->setThirdPartySetting('acquia_cms_common', 'search_label', $fieldConfig->getLabel());

// Index entity_reference field.
if ($search_facade->isAllowedTypeReferenceField($field_storage)) {
Expand All @@ -242,7 +240,6 @@ function _acquia_cms_search_add_field_to_index_form_builder(string $entity_type,
// Remove third party setting from fields.storage.config.
$field_storage
->unsetThirdPartySetting('acquia_cms_common', 'search_index')
->unsetThirdPartySetting('acquia_cms_common', 'search_label')
->save();
->unsetThirdPartySetting('acquia_cms_common', 'search_label');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ protected function createSampleContent(string $node_type) {
]);
}
$this->drupalPlaceBlock('facet_block:search_category', ['region' => 'content']);
\Drupal::getContainer()->get('search_api.post_request_indexing')->destruct();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use $this->container->get('search_api.post_request_indexing')->destruct();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getContainer method is static and with $this->container we won't get a destruct method CI repeats failing.
For example check below screenshot.
Screenshot 2023-10-04 at 2 38 15 PM

}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/src/ExistingSiteJavascript/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ protected function setUp(): void {
'title' => 'Test unpublished ' . $node_type_label,
'moderation_state' => 'draft',
]);
\Drupal::getContainer()->get('search_api.post_request_indexing')->destruct();
apathak18 marked this conversation as resolved.
Show resolved Hide resolved
$this->assertFalse($unpublished_node->isPublished());
}
}
Expand Down